diff --git a/crates/assistant/skills/print-layout/SKILL.md b/crates/assistant/skills/print-layout/SKILL.md index 09d0950db0..0c6ce92bab 100644 --- a/crates/assistant/skills/print-layout/SKILL.md +++ b/crates/assistant/skills/print-layout/SKILL.md @@ -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, diff --git a/crates/engine/command-surface.txt b/crates/engine/command-surface.txt index d0a77aac3a..68d9d0faeb 100644 --- a/crates/engine/command-surface.txt +++ b/crates/engine/command-surface.txt @@ -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 diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index ed9e60be24..df72569ec9 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -89,6 +89,7 @@ pub fn commands() -> Vec { 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"#, diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index c778f9126d..1f64466d37 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -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, @@ -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, ¬e, &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) }; @@ -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"), @@ -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) } @@ -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) }; @@ -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 @@ -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; @@ -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 diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index a8217e918a..70cb70b33e 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -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, } diff --git a/crates/engine/src/cmd/layout/publication/texts.rs b/crates/engine/src/cmd/layout/publication/texts.rs index 1f7acbb96e..afd7695997 100644 --- a/crates/engine/src/cmd/layout/publication/texts.rs +++ b/crates/engine/src/cmd/layout/publication/texts.rs @@ -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)>, String> { + const SHAPE: &str = "figures is a list of up to three {\"value\", \"label\"}, the value a text that isn't empty"; + 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 { diff --git a/crates/engine/src/tests/layout_edge.rs b/crates/engine/src/tests/layout_edge.rs index 840a1c56d8..4cadb55675 100644 --- a/crates/engine/src/tests/layout_edge.rs +++ b/crates/engine/src/tests/layout_edge.rs @@ -1,5 +1,6 @@ //! `layout.publication`'s edge style (#3104): the map from one side of the page to the other, on a -//! light or dark paper, with a kicker over the title and the footer under a thin rule. +//! light or dark paper, with a kicker over the title, headline figures under the map and the footer +//! under a thin rule. use super::*; use rustgis_map::Rgba; @@ -188,7 +189,8 @@ fn a_sheet_with_no_header_starts_its_map_at_the_top_margin() { #[test] fn paper_and_kicker_are_refused_with_another_style_and_on_a_figure() { let mut s = world(); - for (key, value) in [("paper", "#0B1B2B"), ("kicker", "Day 22")] { + let figures = json!([{"value": "12 %"}]); + for (key, value) in [("paper", json!("#0B1B2B")), ("kicker", json!("Day 22")), ("figures", figures), ("figures", json!([]))] { for style in ["classic", "banner", "panel", "editorial", "modular", "poster"] { let e = s.run("layout.publication", &json!({"extent": PIAUI, "style": style, key: value})).unwrap_err(); assert!(e.contains(key) && e.contains("\"edge\""), "{style}: {e}"); @@ -228,3 +230,163 @@ fn a_duplicated_edge_sheet_keeps_its_paper() { assert_eq!(s.project.layouts.len(), 2); assert_eq!(last(&s).paper, Some(Rgba::rgb(0x0B, 0x1B, 0x2B))); } + +fn three_figures() -> Value { + json!([{"value": "{count:Countries}", "label": "countries"}, {"value": "12 %", "label": "of the area"}, + {"value": "2001–2025"}]) +} + +/// Each figure's value and label sit in its own column, between the map and the footer's rule. +fn assert_figures(l: &Layout, n: usize, what: &str) { + let (frame, rule) = (named(l, "Map Frame"), named(l, "Footer Rule")); + let mut last_end = 0.0; + for i in 1..=n { + let value = named(l, &format!("Figure {i} Value")); + assert!(value.x >= last_end - 1e-6, "{what}: figure {i} overlaps the one before"); + last_end = value.x + value.w; + assert!((value.w - named(l, "Figure 1 Value").w).abs() < 1e-6, "{what}: columns of one width"); + let parts = [Some(value), find(l, &format!("Figure {i} Label"))]; + for e in parts.into_iter().flatten() { + assert_eq!(e.x, value.x, "{what}: {}", e.name); + assert!(e.y >= frame.y + frame.h - 1e-6, "{what}: {} over the map", e.name); + assert!(e.y + e.h <= rule.y + 1e-6, "{what}: {} under the rule", e.name); + } + if let Some(label) = find(l, &format!("Figure {i} Label")) { + assert!(label.y >= value.y + value.h - 1e-6, "{what}: label {i} under its value"); + } + } + assert!(find(l, &format!("Figure {} Value", n + 1)).is_none(), "{what}"); +} + +#[test] +fn headline_figures_sit_in_columns_between_the_map_and_the_rule() { + let mut s = world(); + edge(&mut s, json!({})).unwrap(); + let frame = named(last(&s), "Map Frame"); + let bare = (frame.y, frame.h); + for figures in [json!(null), json!([])] { + edge(&mut s, json!({"figures": figures})).unwrap(); + let l = last(&s); + assert_figures(l, 0, "none"); + assert_eq!((named(l, "Map Frame").y, named(l, "Map Frame").h), bare, "{figures}"); + } + let all = three_figures(); + for n in 1..=3 { + edge(&mut s, json!({"figures": all.as_array().unwrap()[..n]})).unwrap(); + let l = last(&s); + assert_figures(l, n, &format!("{n} figures")); + assert_edge_to_edge(l, &format!("{n} figures")); + assert!(named(l, "Map Frame").h < bare.1, "{n}: the map gives the figures their room"); + let ElementKind::Text { text, bold, size, .. } = &named(l, "Figure 1 Value").kind else { panic!() }; + assert_eq!((text.as_str(), *bold, *size), ("{count:Countries}", true, 22.0)); + } + assert!(find(last(&s), "Figure 3 Label").is_none()); +} + +#[test] +fn a_figure_value_with_a_statistic_keeps_its_token_and_wraps_as_drawn() { + let mut s = world(); + edge(&mut s, json!({"figures": [{"value": "{count:Countries}", "label": "{sum:Countries:pop_est} people"}]})).unwrap(); + let l = last(&s); + for (name, stored) in [("Figure 1 Value", "{count:Countries}"), ("Figure 1 Label", "{sum:Countries:pop_est} people")] { + let ElementKind::Text { text, wrap, .. } = &named(l, name).kind else { panic!() }; + assert_eq!((text.as_str(), *wrap), (stored, true), "{name}"); + } +} + +#[test] +fn headline_figures_are_up_to_three_values_with_an_optional_label() { + let mut s = world(); + let one = json!({"value": "1"}); + for bad in [ + json!([one, one, one, one]), + json!("12 %"), + json!({"value": "1"}), + json!(["12 %"]), + json!([{}]), + json!([{"value": ""}]), + json!([{"value": " "}]), + json!([{"value": 12}]), + json!([{"label": "houses"}]), + json!([{"value": "1", "label": 2}]), + json!([{"value": "1", "caption": "houses"}]), + json!([{"value": "x".repeat(2001)}]), + ] { + let e = edge(&mut s, json!({"figures": bad})).unwrap_err(); + assert!(e.contains("figures"), "{bad}: {e}"); + } + assert!(s.project.layouts.is_empty()); + edge(&mut s, json!({"figures": [{"value": "1", "label": null}, {"value": "2", "label": ""}]})).unwrap(); + let l = last(&s); + assert_figures(l, 2, "no label"); + assert!(find(l, "Figure 1 Label").is_none() && find(l, "Figure 2 Label").is_none()); +} + +#[test] +fn headline_figures_take_the_papers_ink() { + for (paper, ink, soft) in [("#F4EFE6", INK, SOFT), ("#0B1B2B", LIGHT_INK, LIGHT_SOFT)] { + let mut s = world(); + edge(&mut s, json!({"paper": paper, "figures": three_figures()})).unwrap(); + let l = last(&s); + assert_eq!(text_colour(l, "Figure 1 Value"), ink, "{paper}"); + assert_eq!(text_colour(l, "Figure 1 Label"), soft, "{paper}"); + } +} + +#[test] +fn headline_figures_fit_every_page_size() { + for profile in crate::cmd::layout::PUBLICATION_PROFILES.iter().filter(|p| p.sheet) { + let mut s = world(); + edge(&mut s, json!({"profile": profile.id, "kicker": "Day 22", "figures": three_figures()})) + .unwrap_or_else(|e| panic!("{}: {e}", profile.id)); + let l = last(&s); + assert_edge_to_edge(l, profile.id); + assert_figures(l, 3, profile.id); + } +} + +#[test] +fn headline_figures_never_squeeze_the_map_away() { + let long = "a figure's value that takes many lines of its column ".repeat(30); + for profile in ["a5-landscape", "a5-portrait", "a0-portrait"] { + let mut s = world(); + // A long label either leaves the map its room (a large sheet) or is refused. + match edge(&mut s, json!({"profile": profile, "figures": [{"value": "1", "label": long}]})) { + Ok(_) => { + let l = last(&s); + assert!(named(l, "Map Frame").h >= 40.0 * l.width.min(l.height) / 210.0, "{profile}"); + assert_figures(l, 1, profile); + } + Err(e) => assert!(e.contains("no room"), "{profile}: {e}"), + } + let e = edge(&mut s, json!({"profile": profile, "figures": [{"value": long}]})).unwrap_err(); + assert!(e.contains("no room") && e.contains("figures"), "{profile}: {e}"); + } +} + +/// The kicker is drawn in capitals whatever its tokens fill in, and its box is sized for them +/// (#3126). +#[test] +fn a_kickers_tokens_are_drawn_in_capitals_and_measured_so() { + use rustgis_map::layout::TextCase; + let name = "illicit little filly ".repeat(6); + let mut s = world(); + s.run("map.rename", &json!({"name": name})).unwrap(); + let kicker = |s: &mut Session, text: &str| { + edge(s, json!({"profile": "a5-portrait", "kicker": text})).unwrap(); + named(last(s), "Kicker").clone() + }; + let (token, typed) = (kicker(&mut s, "{map}"), kicker(&mut s, name.trim_end())); + let case_of = |e: &Element| match &e.kind { + ElementKind::Text { case, .. } => *case, + k => panic!("{k:?}"), + }; + // A text with no token is stored in capitals and needs no case, so asks no more of a reader. + assert_eq!((case_of(&token), case_of(&typed)), (TextCase::Upper, TextCase::None)); + assert_eq!(case_of(&kicker(&mut s, "{crs}")), TextCase::Upper); + assert_eq!(case_of(&kicker(&mut s, "Day {22")), TextCase::None); + assert!((token.h - typed.h).abs() < 1e-6, "{} {}", token.h, typed.h); + let stat = kicker(&mut s, "{count:Countries} countries"); + let ElementKind::Text { text, case, .. } = &stat.kind else { panic!() }; + assert_eq!((text.as_str(), *case), ("{count:Countries} COUNTRIES", TextCase::Upper)); +} diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 27c18088ac..b2ce5f8820 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -203,11 +203,13 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu in darker blocks with amber headings; `"edge"` runs the map from one side of the page to the other with no border, a kicker, the title and subtitle over it and the footer with no boxes under a thin rule. An edge sheet also takes `"paper"` (`#RRGGBB`, the page's colour; on a dark - one the texts are light) and `"kicker"` (a short line in spaced capitals over the title); - other styles and figures refuse both. Its graticule labels sit at the page's side edges, so a - printer with no bleed may clip them. `"accent"` (`#RRGGBB`) colours the band, the panel's - tint, the headings and rules, a poster's page and an edge sheet's kicker (a deep brown, green - or blue by default, a brick red on an edge sheet). + one the texts are light), `"kicker"` (a short line in spaced capitals over the title) and + `"figures"` (up to three `{"value", "label"}`, the label optional, in columns of one width + under the map, the value large and bold; a value or label may hold layer statistics such as + `{count:Cities}`); other styles and figures refuse the three. Its graticule labels sit at the + page's side edges, so a printer with no bleed may clip them. `"accent"` (`#RRGGBB`) colours the + band, the panel's tint, the headings and rules, a poster's page and an edge sheet's kicker (a + deep brown, green or blue by default, a brick red on an edge sheet). A figure leaves the style to its caption. In the menu, each sheet opens a list of the seven styles, each saying what it looks like, in its default accent (`"accent"` in the command picks another).