Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion crates/assistant/skills/print-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: Make a printable page layout — map frame, title, legend, north ar
1. Get the map right first: symbology, labels and extent. A layout's map frame shows the map's current view.
2. For a finished sheet or a figure for a paper in one step, use `layout.publication` with a `"profile"`
(a page size alone, `"a4"`, `"letter"`, `"legal"`, `"tabloid"`, `"a5"` to `"a0"`, for a sheet turned to the area's shape, or with its orientation, `"a4-portrait"`, `"letter-landscape"`, … to choose; `"figure-1col"`, `"thesis-full"`, … for a figure), the `"extent"`
to fit, and the texts: `"title"`, `"subtitle"`, `"sources"`, `"note"`, a `"locator"` (`"globe"`: the visible polygon layers held in the project, not streamed ones, over the basemap; `"inset"` or `"none"`; when omitted, `"globe"` on a sheet and `"none"` on a figure), and `"decimal": ","` for a map in a language with a decimal comma. A sheet's `"style"` arranges it: `"classic"` (the default), `"banner"`, `"panel"`, `"editorial"`, `"modular"`, `"poster"` (for a poster-like sheet) or `"edge"` (the map from side to side of the page; it also takes `"paper"`, the page colour as `"#RRGGBB"`, and `"kicker"`, a short line over the title), with an `"accent"` colour as `"#RRGGBB"`. Its
to fit, and the texts: `"title"`, `"subtitle"`, `"sources"`, `"note"`, a `"locator"` (`"globe"`: the visible polygon layers held in the project, not streamed ones, over the basemap; `"inset"` or `"none"`; when omitted, `"globe"` on a sheet and `"none"` on a figure), and `"decimal": ","` for a map in a language with a decimal comma. A sheet's `"style"` arranges it: `"classic"` (the default), `"banner"`, `"panel"`, `"editorial"`, `"modular"`, `"poster"` (for a poster-like sheet) or `"edge"` (the map from side to side of the page; it also takes `"paper"`, the page colour as `"#RRGGBB"`, `"kicker"`, a short line over the title, and `"figures"`, up to three `{"value", "label"}` under the map, whose texts may hold layer statistics such as `{count:Layer}`), with an `"accent"` colour as `"#RRGGBB"`. Its
surrounds (locator, north arrow, legend, scale bar) start from an `"arrangement"` (`"classic"`, `"mirrored"`, `"legendRight"`, `"legendTop"`, or a corner for each; `"best"`, the default, tries the user's favourite, set with `layout.arrangement`, and the others), and one over the data moves to the freest place in the frame, the largest first (the legend, as a rule); read its `"arrangement"`, `"moved"` and `"warnings"`. It places the frame at a round scale, the
graticule, legend (a long one in up to three columns: its own choice, though a legend takes up to six), scale bar and north arrow, and wraps the footer. `"grid"`, `"scaleBar"` and `"northArrow"` take `"none"` to leave that part out, or an object of its options (the grid's `"step"` or `"type"`, the bar's `"units"` or `"style"`, the arrow's `"style"`, `"fill"`, `"outline"` and `"show"`). Its result lists every element's id and name
(`"elements"`), so skip to step 5 to adjust them. Otherwise,
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/command-surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ layout.import path? text?
layout.move name? layout? to
layout.new name? page? orientation? width? height? template?
layout.page layout? page? orientation? width? height? decimal? color?
layout.publication profile? extent? name? title? subtitle? sources? reference? note? author? headings? locator? decimal? colorbar? veil? contextInLegend? northArrow? grid? scaleBar? legendBox? style? paper? kicker? accent? arrangement? coverage?
layout.publication profile? extent? name? title? subtitle? sources? reference? note? author? headings? locator? decimal? colorbar? veil? contextInLegend? northArrow? grid? scaleBar? legendBox? style? paper? kicker? figures? accent? arrangement? coverage?
layout.remove name? layout?
layout.removeElement layout? element
layout.rename name? layout? newName
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub fn commands() -> Vec<C> {
r#""style"?: "classic" (the default: the title over the map, the footer under it) | "banner" (the title and subtitle in a band of the accent colour across the top) | "panel" (the map at the left, a panel at the right with the title, locator, legend, sources and reference) | "editorial" (the title large in serif, a column at the right with the note, the locator and the legend) | "modular" (cards on a light page: the map, the locator and the legend each in one, the sources and reference in tinted ones) | "poster" (the page in the accent colour, the title in light text, the map in a light card, the footer in darker blocks) | "edge" (the map from one side of the page to the other with no border, a kicker and the title over it, the footer with no boxes under a thin rule) (a sheet's arrangement; figures leave it to the caption), "#,
r##""paper"?: "#RRGGBB" (an edge sheet's page colour, as layout.page's "color"; white by default; on a dark one its texts are light), "##,
r#""kicker"?: text (an edge sheet's short line in spaced capitals over the title, in the accent colour), "#,
r#""figures"?: up to three {"value": text, "label"?: text} (an edge sheet's headline figures, in columns under the map; a value may hold layer statistics such as {count:Layer}), "#,
r#""accent"?: a colour as #RRGGBB (the style's colour: its band, panel tint, headings and rules, a poster's page), "#,
r#""arrangement"?: "best" (the default: the favourite, each arrangement by name and each saved with layout.arrangement laid out, the one moving the least area off its corners kept, then the one leaving the least over the data, the favourite on a tie) | "favourite" (layout.arrangement's) | an arrangement by name (built in or saved) or corner by corner, as layout.arrangement takes (the corners the locator, north arrow, legend and scale bar are at home in; one covering what the map draws there still moves), "#,
r#""coverage"?: "*.png" (writes the coverage grid the placement searched, as it settled on it, three pixels a cell: what the map draws dark, the free cells white, both tinted blue in the strips the graticule's labels keep, the surrounds placed over the map outlined in red; the answer gives its path)} → a new layout of the active map at a round scale, its texts wrapped to their boxes; {projection}, {datum} and {grid} in the texts are filled from the map"#,
Expand Down
68 changes: 59 additions & 9 deletions crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
}
// Only an edge sheet draws these: given to another, they are refused rather than left out.
let edge = sheet && style == Style::Edge;
if let Some(k) = ["paper", "kicker"].into_iter().find(|k| !edge && p.get(*k).is_some_and(|v| !v.is_null())) {
if let Some(k) = ["paper", "kicker", "figures"].into_iter().find(|k| !edge && p.get(*k).is_some_and(|v| !v.is_null())) {
return Err(format!("{k} is for a sheet with \"style\": \"edge\""));
}
// White is the page's own colour, kept as none, as `layout.page` keeps it.
let page_colour = crate::cmd::opaque_color(p, "paper")?.flatten().filter(|c| *c != Rgba::rgb(0xFF, 0xFF, 0xFF));
let kicker = one("kicker")?;
let headlines = headline_figures(p)?;
// Where the coverage grid the placement searches is written as an image (#1379).
let coverage_path = match p.get("coverage") {
None | Some(Value::Null) => None,
Expand Down Expand Up @@ -203,11 +204,12 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
let (map_name, crs) = (s.map().name.clone(), s.map().projection.label());
// A layer statistic (#2853) by the figure it shows now, as `{map}` is by the map's name: the
// layers are in the project, so the box is sized for what is drawn, not for the token written.
let figures = {
let stats = {
let texts: Vec<&str> = [&kicker, &title, &subtitle, &note, &author]
.into_iter()
.filter_map(|t| t.as_deref())
.chain(sources.iter().chain(&reference).chain(&headings).map(String::as_str))
.chain(headlines.iter().flat_map(|(value, label)| [Some(value), label.as_ref()]).flatten().map(String::as_str))
.collect();
crate::render::layout::statistic_figures(s.map(), comma, &texts)
};
Expand All @@ -216,7 +218,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
if !t.contains('{') {
return t.to_string();
}
let t = figures.iter().fold(t.to_string(), |t, (token, figure)| t.replace(token.as_str(), figure));
let t = stats.iter().fold(t.to_string(), |t, (token, figure)| t.replace(token.as_str(), figure));
[
("{date}", "0000-00-00"),
("{time}", "00:00"),
Expand Down Expand Up @@ -391,7 +393,12 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
// The map's frame between `top` and `bottom`, at least 40 mm tall (on A4).
let room = |top: f64, bottom: f64| {
if bottom - top < 40.0 * k {
Err("the texts leave the map no room: shorten the footer, the note or the subtitle".to_string())
let texts = if headlines.is_empty() {
"the footer, the note or the subtitle"
} else {
"the footer, the note, the subtitle or the figures"
};
Err(format!("the texts leave the map no room: shorten {texts}"))
} else {
Ok(bottom - top)
}
Expand Down Expand Up @@ -562,8 +569,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
}
Style::Edge => {
// A kicker, the title and the subtitle at the top left; the map from one side
// of the page to the other; under a thin rule, the footer with no boxes. On a
// dark paper (the rule a presentation's blank page uses) the texts are light.
// of the page to the other; the headline figures; under a thin rule, the
// footer with no boxes. On a dark paper (the rule a presentation's blank
// page uses) the texts are light.
let dark = page_colour
.is_some_and(|c| 0.299 * f64::from(c.r()) + 0.587 * f64::from(c.g()) + 0.114 * f64::from(c.b()) < 140.0);
let (ink, soft) = if dark { (Rgba::rgb(0xF2, 0xEE, 0xE6), Rgba::rgb(0xCF, 0xC6, 0xB8)) } else { (ink, soft) };
Expand All @@ -575,8 +583,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
// As the renderer spaces them: 1.33 points of the drawing per point of spacing.
let added = spacing * 1.33 / rustgis_map::layout::PT_PER_MM;
let t = capitals(&fill(t));
// Measured as drawn: what its tokens fill in is in capitals too.
let width = |x: &str| {
let x = drawn(x);
let x = drawn(x).to_uppercase();
crate::render::report::width_mm(&x, pt as f32, true) + x.chars().count() as f64 * added
};
// As `broken`: a text with the map's name or a layer statistic is kept
Expand All @@ -590,8 +599,14 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
};
let kh = lines.lines.len() as f64 * pitch(pt) + 1.0 * k;
let mut kind = pub_text(lines, pt, accent, true, TextAlign::Left);
if let ElementKind::Text { letter_spacing, .. } = &mut kind {
// The stored text is in capitals but for its tokens, which the case
// covers (#3126). With nothing left to raise, no case: a saved project
// asks for none.
if let ElementKind::Text { text, letter_spacing, case, .. } = &mut kind {
*letter_spacing = spacing;
if *text != text.to_uppercase() {
*case = TextCase::Upper;
}
}
around.push(("Kicker".into(), (x0, y, iw, kh), kind));
y += kh;
Expand All @@ -617,7 +632,42 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
(x0, rule, iw, 1.0),
ElementKind::Line { color: soft, width: 0.5, dir: LineDir::Horizontal, head: LineHead::None, dash: None },
));
(page_w, page_h, (0.0, ft, page_w, room(ft, rule - 3.0 * k)?), None)
// The headline figures, in columns of one width between the map and the rule,
// as tall as the tallest.
let mut bottom = rule - 3.0 * k;
if !headlines.is_empty() {
let (gap, value_pt) = (5.0 * k, 22.0 * k);
let n = headlines.len() as f64;
let cw = (iw - gap * (n - 1.0)) / n;
let columns: Vec<(Broken, Broken)> = headlines
.iter()
.map(|(value, label)| {
let label = label.as_deref().map(|t| wrap(t, cw, body_pt)).unwrap_or_default();
(wrap_as(value, cw, value_pt, true), label)
})
.collect();
let height = |b: &Broken, pt: f64| b.lines.len() as f64 * pitch(pt);
let band = columns.iter().map(|(v, l)| height(v, value_pt) + height(l, body_pt)).fold(0.0, f64::max);
let top = bottom - band;
for (i, (value, label)) in columns.into_iter().enumerate() {
let x = x0 + i as f64 * (cw + gap);
let (vh, lh) = (height(&value, value_pt), height(&label, body_pt));
around.push((
format!("Figure {} Value", i + 1),
(x, top, cw, vh),
pub_text(value, value_pt, ink, true, TextAlign::Left),
));
if !label.lines.is_empty() {
around.push((
format!("Figure {} Label", i + 1),
(x, top + vh, cw, lh),
pub_text(label, body_pt, soft, false, TextAlign::Left),
));
}
}
bottom = top - 3.0 * k;
}
(page_w, page_h, (0.0, ft, page_w, room(ft, bottom)?), None)
}
Style::Panel => {
// The map at the left, as tall as the sheet allows; a pale panel at the right with
Expand Down
3 changes: 2 additions & 1 deletion crates/engine/src/cmd/layout/publication/sheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ pub(in crate::cmd::layout) enum Style {
/// map in a light card, the footer in darker blocks.
Poster,
/// The map from one side of the page to the other, on a paper of its own colour: a kicker and
/// the title over it, the footer unboxed under a thin rule.
/// the title over it, up to three headline figures under it, the footer unboxed under a thin
/// rule.
Edge,
}

Expand Down
21 changes: 21 additions & 0 deletions crates/engine/src/cmd/layout/publication/texts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ pub(in crate::cmd::layout) const GRID_STEPS: &[f64] = &[0.01, 0.02, 0.05, 0.1, 0
pub(in crate::cmd::layout) const LABEL_ROOM_SIDE: f64 = 9.0;
pub(in crate::cmd::layout) const LABEL_ROOM_END: f64 = 6.0;

/// An edge sheet's headline figures (#3104): up to three values, each with an optional label.
pub(in crate::cmd::layout) fn headline_figures(p: &Value) -> Result<Vec<(String, Option<String>)>, String> {
const SHAPE: &str = "figures is a list of up to three {\"value\", \"label\"}, the value a text that isn't empty";
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
let figure = |v: &Value| {
let o = v.as_object().filter(|o| o.keys().all(|k| k == "value" || k == "label")).ok_or(SHAPE)?;
let within = |t: &str| crate::cmd::within("figures", "a publication layout's text", t, MAX_PUBLICATION_TEXT);
let value = o.get("value").and_then(Value::as_str).filter(|t| !t.trim().is_empty()).ok_or(SHAPE)?;
let label = match o.get("label") {
None | Some(Value::Null) => None,
Some(Value::String(t)) => Some(within(t)?).filter(|t| !t.trim().is_empty()),
Some(_) => return Err(SHAPE.to_string()),
};
Ok((within(value)?, label))
};
match p.get("figures") {
None | Some(Value::Null) => Ok(Vec::new()),
Some(Value::Array(a)) if a.len() <= 3 => a.iter().map(figure).collect(),
Some(_) => Err(SHAPE.into()),
}
}

/// A scale denominator rounded up to two significant figures (1:1,234,567 to 1:1,300,000), so the
/// extent fitted at it still fits.
pub(crate) fn round_scale(scale: f64) -> f64 {
Expand Down
Loading
Loading