Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1453616
test(render): pin how a plain layout text draws, is measured and exports
m-hollis-1 Nov 26, 2026
b42fe40
feat(layout): a text's block alignment, line spacing and case in the …
m-hollis-1 Nov 26, 2026
699a911
feat(render): a layout text's block at the top, middle or bottom of i…
m-hollis-1 Nov 26, 2026
55c3aca
test(render): pin where a layout text's block and case are reported o…
m-hollis-1 Nov 26, 2026
40081ce
feat(render): a layout text's block, line spacing and case in SVG, as…
m-hollis-1 Nov 26, 2026
928f9e2
feat(layout): a text's block alignment, line spacing and case through…
m-hollis-1 Nov 26, 2026
421fecf
test(engine): a sample command for the text block capability
m-hollis-1 Nov 26, 2026
f9f1299
feat(ui): a layout text's vertical alignment, line spacing and case i…
m-hollis-1 Nov 26, 2026
777949c
fix(layout): a text's case reads "Upper case" and "Lower case" in menus
m-hollis-1 Nov 26, 2026
d84d71c
docs(layout): a text's vertical alignment, line spacing and case in t…
m-hollis-1 Nov 26, 2026
8fd4f20
refactor(layout): one reader for a text's line spacing range
m-hollis-1 Nov 26, 2026
1c88b48
test(render): a text block in SVG and PDF, compared with the page
m-hollis-1 Nov 26, 2026
d6cafbc
refactor(engine): one reader for a text's block settings in commands …
m-hollis-1 Nov 26, 2026
eb2d92a
test(ui): the Format pane's text block rows by their words, defaults …
m-hollis-1 Nov 26, 2026
bcee86a
docs(layout): the text block paragraph after the font paragraph
m-hollis-1 Nov 26, 2026
c2d4419
Merge upstream main into feat/layout-text-block
m-hollis-1 Nov 26, 2026
a1ae013
fix(layout): a publication's scale box is measured from its text in i…
m-hollis-1 Nov 26, 2026
48ad38d
docs(engine): a block key on another kind of element counts for the t…
m-hollis-1 Nov 26, 2026
b26aa64
perf(render): a turned text's picture starts at its block, not at its…
m-hollis-1 Nov 26, 2026
e068d54
docs(engine): reflow the text block capability's comment
m-hollis-1 Nov 26, 2026
49f4a15
refactor(render): the usual line spacing by its constant; the print-l…
m-hollis-1 Nov 26, 2026
c5af47b
docs: reflow comments to the files' width
m-hollis-1 Nov 26, 2026
fba8cf2
docs(render): say which pages the plain text pin draws at 300 dpi
m-hollis-1 Nov 26, 2026
b230fd5
fix(render): a text cut at the 200 lines it draws starts at the top o…
m-hollis-1 Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/assistant/skills/print-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ description: Make a printable page layout — map frame, title, legend, north ar
`"subdivisions"` (0–10), `"divisionsBeforeZero"` (0–2), `"labelPosition"` (`"above"`, `"below"`), `"unitLabel"`
(text; `""` for none), `"unitLabelPosition"` (`"afterLabels"`, `"afterBar"`, `"above"`, `"below"`), `"decimals"`
(`"auto"`, the default, or 0–3 fixed with the thousands set apart, as a chart's), `"textSize"` (4–100 pt, its
labels' size) and `"fit"` (`"adjustDivisionValue"`, `"adjustDivision"`, `"adjustWidth"`). `"grid"` adds a graticule to the frame
labels' size) and `"fit"` (`"adjustDivisionValue"`, `"adjustDivision"`, `"adjustWidth"`). A `"text"` or `"dynamicText"` can take
`"valign"` (`"top"`, `"middle"`, `"bottom"`), `"lineSpacing"` (0.5–3, default 1) and `"case"`
(`"none"`, `"upper"`, `"lower"`; applied when drawn, the text kept as typed). `"grid"` adds a graticule to the frame
(`"style": "ticks"` for neatline ticks, `"format": "dms"`, `"edges"`).
5. Adjust with `layout.update` (`{"element": id, "x", "y", "w", "h", "text", "size", "bold"}`). The ids come from the
5. Adjust with `layout.update` (`{"element": id, "x", "y", "w", "h", "text", "size", "bold", "valign", "lineSpacing", "case"}`). The ids come from the
results of the earlier calls.
6. `layout.export` `{"path": "map.pdf"}`, or `.png` with a `dpi` (300 for print). Exporting writes a file, so the
user is asked first. `layout.close` goes back to the map.
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/command-surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ layer.transparency layer? value
layer.visibility layer? visible?
layer.zoomTo layer?
layout.activate name layout
layout.addElement layout? kind frame? of? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? font? fallback? title? allClasses? hideOther? showNoData? exclude? columns? textSize? orientation? ticks? tickSide? reverse? fill? width? radius? dash? dir? head? angle? length? image? path? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? hideLabels? barOutline? rows? step? type? crs? short? mgrs? labels? style? tickLength? format? hemisphere? edges? labelOrientation? labelSize? off? outline? units? divisions? subdivisions? divisionsBeforeZero? labelPosition? unitLabel? unitLabelPosition? fit? x? y? w? h? background?
layout.addElement layout? kind frame? of? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? valign? lineSpacing? case? font? fallback? title? allClasses? hideOther? showNoData? exclude? columns? textSize? orientation? ticks? tickSide? reverse? fill? width? radius? dash? dir? head? angle? length? image? path? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? hideLabels? barOutline? rows? step? type? crs? short? mgrs? labels? style? tickLength? format? hemisphere? edges? labelOrientation? labelSize? off? outline? units? divisions? subdivisions? divisionsBeforeZero? labelPosition? unitLabel? unitLabelPosition? fit? x? y? w? h? background?
layout.addFrame layout? shape? points? map? x? y? w? h?
layout.arrange layout? element to
layout.arrangement favourite? save? arrangement? remove?
Expand All @@ -304,7 +304,7 @@ layout.save layout? path
layout.series layout? layer nameField? frame? margin? off?
layout.seriesPage layout? page
layout.seriesRefresh layout?
layout.update layout? element x? y? w? h? name? visible? locked? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? font? fallback? title? allClasses? hideOther? showNoData? exclude? labels? columns? textSize? orientation? ticks? tickSide? reverse? style? fill? outline? radius? width? dash? dir? head? angle? length? units? divisions? subdivisions? divisionsBeforeZero? labelPosition? unitLabel? unitLabelPosition? fit? map? scale? center? bearing? pitch? grid? extentIndicator? border? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? barOutline? hideLabels? rows? background?
layout.update layout? element x? y? w? h? name? visible? locked? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? valign? lineSpacing? case? font? fallback? title? allClasses? hideOther? showNoData? exclude? labels? columns? textSize? orientation? ticks? tickSide? reverse? style? fill? outline? radius? width? dash? dir? head? angle? length? units? divisions? subdivisions? divisionsBeforeZero? labelPosition? unitLabel? unitLabelPosition? fit? map? scale? center? bearing? pitch? grid? extentIndicator? border? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? barOutline? hideLabels? rows? background?
locator.find locator? text limit? zoom?
map.activate name
map.addTiles url kind? name? bounds? attribution? minZoom? maxZoom? tileSize? singleImage? tms? subdomains? layers? styleLayers? opacity? blend? resampling? overlay? top? replace? id? view? start? end? unit? interval? dates? legend? connection?
Expand Down
136 changes: 102 additions & 34 deletions crates/engine/src/cmd/layout.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub const CAPABILITIES: &[&str] = &[
"graticule-color",
"layout-element-ink",
"layout-element-wrap",
"layout-text-block",
"layout-chart-data",
"layout-chart-look",
"layout-chart-classes",
Expand Down
95 changes: 95 additions & 0 deletions crates/engine/src/project_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[
("graticule-color", command_colors_graticule),
("layout-element-ink", command_uses_element_ink),
("layout-element-wrap", command_uses_element_wrap),
("layout-text-block", command_uses_text_block),
("layout-chart-data", command_uses_chart_data),
("layout-chart-look", command_uses_chart_look),
("layout-chart-classes", command_uses_chart_classes),
Expand Down Expand Up @@ -372,6 +373,40 @@ fn command_uses_element_wrap(id: &str, params: &Value) -> bool {
}
}

/// Whether a layout element is a text placed in the middle or at the bottom of its box, spaced
/// other than at the usual line spacing, or drawn in upper or lower case, once brought into range:
/// an older reader would draw it at the top, at the usual spacing and as typed.
fn text_blocks(e: &rustgis_map::layout::Element) -> bool {
e.kind.text_uses_block()
}

/// A layout command that gives a text a block alignment, line spacing or case off its default:
/// an older reader ignores `valign`, `lineSpacing` and `case` and draws the text at the top, at
/// the usual spacing and as typed. Each is read on its own by the command's own reader
/// ([`crate::cmd::layout::text_block_settings`]), so the defaults (`"top"`, `1` or `"1"`, `"none"`,
/// in any case) and `null`, which leaves a text as it is, keep a text as an older reader draws it.
/// A value the command refuses on a text needs nothing either: the command changes nothing. The
/// keys are read here alone, so a block key given to another kind counts too, though its command
/// refuses it: an over-count that asks for the capability sooner, never a missing one. A
/// `layout.import` requires it for such a text once its layout is read into range, so a name it
/// doesn't know or a spacing that isn't a number, read as the default, needs nothing.
fn command_uses_text_block(id: &str, params: &Value) -> bool {
use rustgis_map::layout::{LINE_SPACING, TextCase, TextVAlign};
match id {
"layout.addElement" | "layout.update" => {
let usual = (TextVAlign::Top, LINE_SPACING, TextCase::None);
// Each key on its own, so one the command refuses doesn't hide another one set.
["valign", "lineSpacing", "case"].into_iter().any(|k| {
let one = Value::Object(params.get(k).into_iter().map(|v| (k.to_string(), v.clone())).collect());
crate::cmd::layout::text_block_settings(&one, usual).is_ok_and(|set| set != usual)
})
}
"layout.import" => imported_layout_uses(params, &["\"valign\"", "\"line_spacing\"", "\"case\""], text_blocks),
"script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_uses_text_block)),
_ => false,
}
}

/// Whether a layout element is a chart grouped, ordered, cut or gathered as an older reader's
/// can't be (#2487): it would draw a bar per feature, the 20 largest.
fn charts_data(e: &rustgis_map::layout::Element) -> bool {
Expand Down Expand Up @@ -954,6 +989,7 @@ fn layout_capabilities(layouts: &[rustgis_map::layout::Layout]) -> Vec<&'static
(elements().any(|e| e.background.is_some()), "layout-element-background"),
(elements().any(|e| e.kind.ink().is_some()), "layout-element-ink"),
(elements().any(wraps), "layout-element-wrap"),
(elements().any(text_blocks), "layout-text-block"),
(elements().any(charts_data), "layout-chart-data"),
(elements().any(charts_look), "layout-chart-look"),
(elements().any(charts_classes), "layout-chart-classes"),
Expand Down Expand Up @@ -1245,6 +1281,7 @@ mod tests {
(&["graticule-color"], "map.graticule", json!({"color": "#000000"})),
(&["layout-element-ink"], "layout.import", json!({"text": ink_layout})),
(&["layout-element-wrap"], "layout.addElement", json!({"kind": "text", "wrap": true})),
(&["layout-text-block"], "layout.update", json!({"element": 1, "lineSpacing": 1.5})),
(&["layout-chart-data"], "layout.addElement", json!({"kind": "chart", "group": "Region"})),
(&["layout-chart-look"], "layout.update", json!({"element": 1, "values": true})),
(&["layout-chart-classes"], "layout.update", json!({"element": 1, "classes": true})),
Expand Down Expand Up @@ -1906,6 +1943,64 @@ mod tests {
}
}

/// A text with a block setting is required where it is saved, so an older reader refuses the
/// project instead of drawing it at the top, at the usual spacing, as typed, and saving it again
/// without them; so is a saved command that sets one. The defaults, null and values read as
/// them need nothing.
#[test]
fn text_block_capability_follows_saved_layouts_and_commands() {
use rustgis_map::layout::ElementKind;
let fixture = Project::from_json(include_str!("../../../schema/fixtures/layout_text_block.rgis")).unwrap();
let saved = serde_json::to_value(&fixture).unwrap();
assert_eq!(saved["requires"], json!(["layout-text-block"]));
let reread = Project::from_json(&saved.to_string()).unwrap();
assert!(reread.layouts[0].elements[1].kind.text_uses_block());
assert!(!reread.layouts[0].elements[2].kind.text_uses_block());
let mut clean = fixture;
for e in &mut clean.layouts[0].elements {
if let ElementKind::Text { text, size, color, bold, .. } = &e.kind {
e.kind = ElementKind::text(text.clone(), *size, *color, *bold);
}
}
let base = serde_json::to_value(&clean).unwrap();
assert!(base.get("requires").is_none(), "a plain text needs nothing");
for key in ["valign", "line_spacing", "\"case\""] {
assert!(!base["layouts"].to_string().contains(key), "nor writes {key}");
}
// A name it doesn't know and a spacing that isn't a number read as the defaults.
let mut damaged = base["layouts"][0].clone();
damaged["elements"][1]["kind"]["Text"]["valign"] = json!("sideways");
damaged["elements"][1]["kind"]["Text"]["line_spacing"] = json!("x");
for (id, params, required) in [
("layout.addElement", json!({"kind": "text", "valign": "middle"}), true),
("layout.addElement", json!({"kind": "dynamicText", "case": "upper"}), true),
("layout.update", json!({"element": 2, "lineSpacing": 1.5}), true),
("layout.update", json!({"element": 2, "lineSpacing": "0.75"}), true),
("layout.update", json!({"element": 2, "valign": "top", "lineSpacing": 1, "case": "none"}), false),
("layout.update", json!({"element": 2, "valign": " Top ", "lineSpacing": "1", "case": "NONE"}), false),
("layout.update", json!({"element": 2, "lineSpacing": 1.0}), false),
("layout.update", json!({"element": 2, "valign": null, "lineSpacing": null, "case": null}), false),
("layout.update", json!({"element": 2, "wrap": false}), false),
("layout.import", json!({"text": saved["layouts"][0].to_string()}), true),
("layout.import", json!({"text": base["layouts"][0].to_string()}), false),
("layout.import", json!({"text": damaged.to_string()}), false),
("layout.import", json!({"path": "texts.rgislayout"}), false),
] {
let script = format!("{id}= {params}");
for value in [
json!([{"name": "Task", "steps": [{"title": "Text", "command": id, "params": params}]}]),
json!([{"name": "Script", "steps": [{"title": "Text", "command": "script.run", "params": {"script": script}}]}]),
] {
let mut document = base.clone();
document["tasks"] = value;
let saved = serde_json::to_value(Project::from_json(&document.to_string()).unwrap()).unwrap();
let requires = saved.get("requires").and_then(Value::as_array).cloned().unwrap_or_default();
assert_eq!(requires.contains(&json!("layout-text-block")), required, "{id} {params}");
assert!(requires.iter().all(|r| r == "layout-text-block"), "{id} {params}: {requires:?}");
}
}
}

/// A scale bar with details is required where it is saved, so an older reader refuses the project
/// instead of drawing a plain bar and saving it again without them; so is a saved command that
/// sets one. The defaults, or a unit label taken back to its abbreviation, need nothing.
Expand Down
Loading
Loading