From 8f376dacbebca4ebf19d346fdb790deec170bc61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 05:55:31 -0500 Subject: [PATCH 1/5] feat(layout): an edge-to-edge publication style on a light or dark paper (#3104) --- crates/assistant/skills/print-layout/SKILL.md | 2 +- crates/engine/command-surface.txt | 2 +- crates/engine/src/cmd/layout.rs | 4 +- .../engine/src/cmd/layout/publication/mod.rs | 101 +++++++-- .../src/cmd/layout/publication/sheet.rs | 10 +- crates/engine/src/tests.rs | 3 + crates/engine/src/tests/layout_edge.rs | 200 ++++++++++++++++++ crates/ui-egui/src/publicationwizard/mod.rs | 4 +- crates/ui-egui/src/ribbon.rs | 1 + docs/getting-started.md | 2 +- docs/user-guide/layouts.md | 12 +- 11 files changed, 317 insertions(+), 24 deletions(-) create mode 100644 crates/engine/src/tests/layout_edge.rs diff --git a/crates/assistant/skills/print-layout/SKILL.md b/crates/assistant/skills/print-layout/SKILL.md index 0e2c092285..c48b8d8cb4 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"` or `"poster"` (for a poster-like sheet), 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"`, and `"kicker"`, a short line over the title), 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), scale bar and north arrow, and wraps the footer. 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 261d473822..f3925b51ef 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? legendBox? style? accent? arrangement? coverage? +layout.publication profile? extent? name? title? subtitle? sources? reference? note? author? headings? locator? decimal? colorbar? veil? contextInLegend? northArrow? legendBox? style? paper? kicker? 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 b4209979bf..f0d01008dc 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -82,7 +82,9 @@ pub fn commands() -> Vec { r#""contextInLegend"?: false (the default: layers the placement takes as context around the data, polygons only outlined or, beside a layer drawn by classes or a raster, in one colour and running on past the frame, are left out of the legend, which a warning names) | true (the legend lists them), "#, r#""northArrow"?: "auto" (the default: none when the extent spans 20° or more on its longer side, where the graticule gives north, which a warning says) | "always" | "none", "#, r#""legendBox"?: "auto" (the default: over the map, the legend has no box where the map shows nothing under it but its light plain paper or water, with no layer, context, basemap shape or graticule line there and no veil; the answer's "legendBox" says whether it has one) | "always", "#, - 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) (a sheet's arrangement; figures leave it to the caption), "#, + 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#""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 655f4d4332..2d7dcf09ed 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -57,7 +57,9 @@ pub(in crate::cmd::layout) fn landscape_suits(aspect: f64, short: f64, long: f64 let k = short / 210.0; let map_w = |w: f64, h: f64| { let texts = if style == Style::Panel { 50.0 } else { 100.0 } * k; - let (iw, ih) = (w - 30.0 * k, h - texts); + // An edge sheet's map takes the page's whole width. + let sides = if style == Style::Edge { 0.0 } else { 30.0 * k }; + let (iw, ih) = (w - sides, h - texts); let fw = if matches!(style, Style::Panel | Style::Editorial | Style::Modular) { 0.68 * iw } else { iw }; let (fw, fh) = (fw - 2.0 * LABEL_ROOM_SIDE * k, ih - 2.0 * LABEL_ROOM_END * k); fw.min(fh / aspect.max(1e-6)) @@ -134,7 +136,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu None => Style::Classic, Some(raw) => Style::parse(raw).ok_or_else(|| { let x = raw.trim(); - format!("style is \"classic\", \"banner\", \"panel\", \"editorial\", \"modular\" or \"poster\", not \"{x}\"") + format!("style is \"classic\", \"banner\", \"panel\", \"editorial\", \"modular\", \"poster\" or \"edge\", not \"{x}\"") })?, }; let accent = color(p, "accent", style.accent())?; @@ -143,6 +145,13 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu if accent.a() != 255 { return Err("accent is an opaque colour as #RRGGBB".into()); } + // 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())) { + return Err(format!("{k} is for a sheet with \"style\": \"edge\"")); + } + let paper = crate::cmd::opaque_color(p, "paper")?.flatten(); + let kicker = one("kicker")?; // 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, @@ -169,7 +178,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu // 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 texts: Vec<&str> = [&title, &subtitle, ¬e, &author] + 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)) @@ -292,8 +301,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let (m, pad) = (10.0 * k, 5.0 * k); let (x0, iw) = (m + pad, page_w - 2.0 * (m + pad)); let (title_pt, sub_pt, head_pt, body_pt, small_pt) = (18.0 * k, 10.5 * k, 7.5 * k, 7.0 * k, 6.5 * k); - // A neatline round the sheet, but on a poster's coloured page or a page of cards. - if !style.cards() { + // A neatline round the sheet, but on a poster's coloured page, a page of cards or a + // sheet whose map runs to its edges. + if !style.cards() && !edge { page_wide.push(("Frame".into(), (m, m, page_w - 2.0 * m, page_full - 2.0 * m), pub_box(clear, ink, 0.8), true)); } // The footer, from the bottom up across the sheet: authorship, the note (unless the style @@ -323,8 +333,10 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu if !boxes_here { return foot; } - // The columns side by side (one alone takes the width). - let (gap, inner) = (4.0 * k, 2.5 * k); + // The columns side by side (one alone takes the width). A look with neither fill + // nor outline has no box, which would only be in the way of clicks. + let boxed = look.fill.a() > 0 || look.outline.a() > 0; + let (gap, inner) = (4.0 * k, if boxed { 2.5 * k } else { 0.0 }); let n = [!sources.is_empty(), !reference.is_empty()].iter().filter(|x| **x).count().max(1) as f64; let cw = (iw - gap * (n - 1.0)) / n; let tw = cw - 2.0 * inner; @@ -337,11 +349,13 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu foot -= bh + 2.0 * k; for (i, (name, head, lines)) in columns.into_iter().enumerate() { let bx = x0 + i as f64 * (cw + gap); - around.push(( - format!("{name} Box"), - (bx, foot, cw, bh), - pub_card(look.fill, look.outline, look.width, look.radius), - )); + if boxed { + around.push(( + format!("{name} Box"), + (bx, foot, cw, bh), + pub_card(look.fill, look.outline, look.width, look.radius), + )); + } let tx = bx + inner; around.push(( format!("{name} Heading"), @@ -528,6 +542,64 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let column = Column { x: cx + card_pad, y: y + card_pad, w: cw - 2.0 * card_pad, h: h - 2.0 * card_pad }; (page_w, page_h, frame, Some(column)) } + 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. + let dark = + paper.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) }; + let mut y = m + pad; + if let Some(t) = &kicker { + let pt = 9.0 * k; + // Letter spacing in points, and the millimetres it adds to each character. + let spacing = 0.18 * pt; + let added = spacing * 1.33 * 25.4 / 96.0; + let t = capitals(&fill(t)); + let width = |x: &str| { + let x = drawn(x); + 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 + // whole and wraps as it is drawn. + let live = t.contains("{map}") || !rustgis_map::layout::stat_tokens(&t).is_empty(); + let lines = if live { + let lines = crate::render::report::wrap_with(&drawn(&t), iw, width); + Broken { text: t, lines, wrap: true } + } else { + Broken::from(crate::render::report::wrap_with(&t, iw, width)) + }; + 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 { + *letter_spacing = spacing; + } + around.push(("Kicker".into(), (x0, y, iw, kh), kind)); + y += kh; + } + if let Some(t) = &title { + let big = title_pt * 1.3; + let lines = wrap_as(t, iw, big, true); + let th = lines.lines.len() as f64 * pitch(big); + around.push(("Title".into(), (x0, y, iw, th), pub_text(lines, big, ink, true, TextAlign::Left))); + y += th; + } + if let Some(t) = &subtitle { + let lines = wrap(t, iw, sub_pt); + let sh = lines.lines.len() as f64 * pitch(sub_pt); + around.push(("Subtitle".into(), (x0, y, iw, sh), pub_text(lines, sub_pt, soft, false, TextAlign::Left))); + y += sh; + } + let ft = if y > m + pad { y + 4.0 * k } else { y }; + let look = Look { head: ink, body: soft, small: soft, fill: clear, outline: clear, width: 0.0, radius: 0.0 }; + let rule = footer(&mut around, &look, true, true) - 3.0 * k; + around.push(( + "Footer Rule".into(), + (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) + } Style::Panel => { // The map at the left, as tall as the sheet allows; a pale panel at the right with // the title and subtitle, then the locator and the legend, and the sources and the @@ -781,7 +853,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let given = crate::cmd::within("name", "a layout's name", ps(p, "name").unwrap_or("Publication").trim(), crate::cmd::MAX_NAME)?; let (name, name_cut) = unique_name(s, "New Publication Layout", "the name given", &given); let mut l = Layout::new(name.clone(), w, h); - l.decimal_comma = comma; + (l.decimal_comma, l.paper) = (comma, paper); let (over, under): (Vec<_>, Vec<_>) = page_wide.into_iter().partition(|e| e.3); for (n, r, kind, _) in under { l.add(&n, r, kind); @@ -802,7 +874,8 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, border_color: rustgis_map::layout::FRAME_BORDER_COLOR, - border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, + // A map that runs to the page's edges has no border. + border_width: if edge { 0.0 } else { rustgis_map::layout::FRAME_BORDER_WIDTH }, bearing: 0.0, pitch: 0.0, }, diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index 72c54fa173..2982d637c8 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -52,6 +52,7 @@ pub const PUBLICATION_STYLES: &[(&str, &str)] = &[ ("editorial", "Editorial"), ("modular", "Modular"), ("poster", "Poster"), + ("edge", "Edge"), ]; /// The credit line `layout.publication` writes when `"author"` isn't given (`{date}` is filled @@ -85,6 +86,9 @@ pub(in crate::cmd::layout) enum Style { /// The page in the accent colour: the title and subtitle in light text across the top, the /// 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. + Edge, } impl Style { @@ -96,6 +100,7 @@ impl Style { "editorial" => Some(Style::Editorial), "modular" => Some(Style::Modular), "poster" => Some(Style::Poster), + "edge" => Some(Style::Edge), _ => None, } } @@ -108,10 +113,12 @@ impl Style { Style::Editorial => "editorial", Style::Modular => "modular", Style::Poster => "poster", + Style::Edge => "edge", } } - /// The accent colour when none is given: a deep blue, green or brown (a poster's page). + /// The accent colour when none is given: a deep blue, green or brown (a poster's page), or an + /// edge sheet's brick red, which reads on a light paper and on a dark one. pub(in crate::cmd::layout) fn accent(self) -> Rgba { match self { Style::Classic => Rgba::rgb(0x2B, 0x26, 0x20), @@ -120,6 +127,7 @@ impl Style { Style::Editorial => Rgba::rgb(0x1F, 0x2D, 0x4D), Style::Modular => Rgba::rgb(0x2F, 0x6B, 0x4F), Style::Poster => Rgba::rgb(0x3A, 0x26, 0x18), + Style::Edge => Rgba::rgb(0xB4, 0x43, 0x2E), } } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index b8c40b015a..96fb406e33 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -103,6 +103,9 @@ mod layout_title; #[path = "tests/layout_removed_layer.rs"] mod layout_removed_layer; +#[path = "tests/layout_edge.rs"] +mod layout_edge; + #[path = "tests/sde_connections.rs"] mod sde_connections; diff --git a/crates/engine/src/tests/layout_edge.rs b/crates/engine/src/tests/layout_edge.rs new file mode 100644 index 0000000000..43e51df0c3 --- /dev/null +++ b/crates/engine/src/tests/layout_edge.rs @@ -0,0 +1,200 @@ +//! `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. + +use super::*; +use rustgis_map::Rgba; +use rustgis_map::layout::{Element, ElementKind, Layout}; + +const PIAUI: [f64; 4] = [-46.8, -11.6, -38.5, -2.2]; +const INK: Rgba = Rgba::rgb(0x2B, 0x26, 0x20); +const SOFT: Rgba = Rgba::rgb(0x5E, 0x55, 0x47); +const LIGHT_INK: Rgba = Rgba::rgb(0xF2, 0xEE, 0xE6); +const LIGHT_SOFT: Rgba = Rgba::rgb(0xCF, 0xC6, 0xB8); + +/// An edge sheet of Piauí with every text of the footer, `extra`'s parameters over these. +fn edge(s: &mut Session, extra: Value) -> Result { + let mut p = json!({"profile": "a4-portrait", "style": "edge", "extent": PIAUI, "title": "PIAUÍ", + "subtitle": "Vegetation trend, 2001–2025", "sources": ["Boundaries: IBGE 2022"], "note": "Significant cells only."}); + for (k, v) in extra.as_object().unwrap() { + p[k] = v.clone(); + } + s.run("layout.publication", &p) +} + +fn last(s: &Session) -> &Layout { + s.project.layouts.last().unwrap() +} + +fn find<'a>(l: &'a Layout, name: &str) -> Option<&'a Element> { + l.elements.iter().find(|e| e.name == name) +} + +fn named<'a>(l: &'a Layout, name: &str) -> &'a Element { + find(l, name).unwrap_or_else(|| panic!("no {name}")) +} + +fn text_colour(l: &Layout, name: &str) -> Rgba { + match &named(l, name).kind { + ElementKind::Text { color, .. } => *color, + k => panic!("{name}: {k:?}"), + } +} + +/// The map reaches both sides of the page with no border, nothing boxes the page or the footer, +/// and a thin rule parts the map from the footer. +fn assert_edge_to_edge(l: &Layout, what: &str) { + let frame = named(l, "Map Frame"); + assert_eq!((frame.x, frame.w), (0.0, l.width), "{what}"); + let ElementKind::MapFrame { border_width, .. } = &frame.kind else { panic!() }; + assert_eq!(*border_width, 0.0, "{what}"); + for gone in ["Frame", "Sources Box", "Reference Box"] { + assert!(find(l, gone).is_none(), "{what}: {gone}"); + } + let rule = named(l, "Footer Rule"); + assert!(matches!(rule.kind, ElementKind::Line { .. }), "{what}"); + assert!(rule.y >= frame.y + frame.h, "{what}: the rule is under the map"); + for name in ["Sources Heading", "Sources", "Reference Heading", "Reference", "Note", "Author"] { + assert!(named(l, name).y >= rule.y, "{what}: {name} is under the rule"); + } + for e in &l.elements { + assert!( + e.x >= -1e-6 && e.y >= -1e-6 && e.x + e.w <= l.width + 1e-6 && e.y + e.h <= l.height + 1e-6, + "{what}: {} leaves the page", + e.name + ); + } +} + +#[test] +fn an_edge_sheet_runs_its_map_from_side_to_side() { + let mut s = world(); + let r = edge(&mut s, json!({})).unwrap(); + assert_eq!(r["style"], "edge"); + let l = last(&s); + assert_edge_to_edge(l, "a4"); + assert_eq!(l.paper, None); + assert_eq!(text_colour(l, "Title"), INK); + assert!(find(l, "Kicker").is_none()); +} + +#[test] +fn an_edge_sheet_fits_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"})).unwrap_or_else(|e| panic!("{}: {e}", profile.id)); + assert_edge_to_edge(last(&s), profile.id); + } +} + +#[test] +fn a_light_paper_keeps_dark_texts_and_a_dark_one_turns_them_light() { + for (paper, ink, soft) in [("#F4EFE6", INK, SOFT), ("#0B1B2B", LIGHT_INK, LIGHT_SOFT)] { + let mut s = world(); + edge(&mut s, json!({"paper": paper})).unwrap(); + let l = last(&s); + assert_eq!(l.paper, Rgba::from_hex(&paper[1..]), "{paper}"); + for name in ["Title", "Sources Heading", "Reference Heading"] { + assert_eq!(text_colour(l, name), ink, "{paper}: {name}"); + } + for name in ["Subtitle", "Sources", "Reference", "Note", "Author"] { + assert_eq!(text_colour(l, name), soft, "{paper}: {name}"); + } + assert_edge_to_edge(l, paper); + } +} + +#[test] +fn a_null_paper_is_a_white_page() { + let mut s = world(); + edge(&mut s, json!({"paper": null})).unwrap(); + assert_eq!(last(&s).paper, None); + assert_eq!(text_colour(last(&s), "Title"), INK); +} + +#[test] +fn a_paper_that_is_no_opaque_colour_is_refused() { + let mut s = world(); + for paper in [json!("#12"), json!("red"), json!("#0B1B2B80"), json!(5)] { + let e = edge(&mut s, json!({"paper": paper})).unwrap_err(); + assert!(e.contains("paper"), "{paper}: {e}"); + } + assert!(s.project.layouts.is_empty()); +} + +#[test] +fn a_kicker_sits_over_the_title_in_spaced_capitals_of_the_accent() { + for (extra, accent) in [(json!({}), Rgba::rgb(0xB4, 0x43, 0x2E)), (json!({"accent": "#1F6F8B"}), Rgba::rgb(0x1F, 0x6F, 0x8B))] { + let mut s = world(); + let mut p = json!({"kicker": "Día 22"}); + if let Some(a) = extra.get("accent") { + p["accent"] = a.clone(); + } + edge(&mut s, p).unwrap(); + let l = last(&s); + let (kicker, title) = (named(l, "Kicker"), named(l, "Title")); + assert!(kicker.y + kicker.h <= title.y + 1e-6); + let ElementKind::Text { text, color, letter_spacing, .. } = &kicker.kind else { panic!() }; + assert_eq!(text, "DÍA 22"); + assert_eq!(*color, accent); + assert!(*letter_spacing > 0.0); + } +} + +#[test] +fn a_long_kicker_wraps_within_the_page() { + let mut s = world(); + edge(&mut s, json!({"profile": "a5-portrait", "kicker": "thirty day map challenge ".repeat(8)})).unwrap(); + let l = last(&s); + let (kicker, title) = (named(l, "Kicker"), named(l, "Title")); + let ElementKind::Text { text, .. } = &kicker.kind else { panic!() }; + assert!(text.contains('\n'), "{text}"); + assert!(kicker.x + kicker.w <= l.width && kicker.y + kicker.h <= title.y + 1e-6); +} + +#[test] +fn a_sheet_with_no_header_starts_its_map_at_the_top_margin() { + let mut s = world(); + s.run("layout.publication", &json!({"profile": "a4-portrait", "style": "edge", "extent": PIAUI})).unwrap(); + let l = last(&s); + for gone in ["Kicker", "Title", "Subtitle"] { + assert!(find(l, gone).is_none(), "{gone}"); + } + let frame = named(l, "Map Frame"); + assert!(frame.y <= 15.0 + 1e-6, "{}", frame.y); +} + +#[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")] { + 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}"); + } + for extra in [json!({}), json!({"style": "edge"})] { + let mut p = json!({"extent": PIAUI, "profile": "figure-1col", key: value}); + if let Some(style) = extra.get("style") { + p["style"] = style.clone(); + } + let e = s.run("layout.publication", &p).unwrap_err(); + assert!(e.contains(key), "{p}: {e}"); + } + } + assert!(s.project.layouts.is_empty()); +} + +#[test] +fn a_figure_leaves_the_edge_style_to_its_caption() { + let mut s = world(); + let r = s.run("layout.publication", &json!({"extent": PIAUI, "profile": "figure-1col", "style": "edge"})).unwrap(); + assert!(r["warnings"].to_string().contains("style \\\"edge\\\""), "{r}"); +} + +#[test] +fn a_duplicated_edge_sheet_keeps_its_paper() { + let mut s = world(); + edge(&mut s, json!({"paper": "#0B1B2B"})).unwrap(); + s.run("layout.duplicate", &json!({})).unwrap(); + assert_eq!(s.project.layouts.len(), 2); + assert_eq!(last(&s).paper, Some(Rgba::rgb(0x0B, 0x1B, 0x2B))); +} diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 275d34f3f7..3e8370911a 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -179,9 +179,9 @@ fn field_width(ui: &egui::Ui) -> f32 { /// The wizard's width, where the screen has room for it. const WIDTH: f32 = 380.0; -/// The height every step takes: the style step's six styles and their descriptions, with room +/// The height every step takes: the style step's seven styles and their descriptions, with room /// for the rounding a high-density screen adds to each line. -const STEP_HEIGHT: f32 = 320.0; +const STEP_HEIGHT: f32 = 365.0; /// Shows the wizard while it is open; Create runs `layout.publication` as the menu does, and the /// wizard stays open on a layout the command refuses. diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 6d765a917e..22c0ee6529 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -1268,6 +1268,7 @@ pub(crate) fn publication_style(id: &str) -> Option<(&'static str, &'static str) "editorial" => (tl!("Editorial"), tl!("A large serif title; the note, the locator and the legend in a column at the right.")), "modular" => (tl!("Modular"), tl!("Cards on a light page: the map, the locator and the legend each in one.")), "poster" => (tl!("Poster"), tl!("The page in colour, the title in light text and the map in a light card.")), + "edge" => (tl!("Edge"), tl!("The map from side to side of the page; a kicker and title over it, the footer under a thin rule.")), _ => return None, }) } diff --git a/docs/getting-started.md b/docs/getting-started.md index fbdfe29334..edf90c18fb 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -35,7 +35,7 @@ sample again. **Settings › Start-up › Start With** chooses what opens next t adds a web tile layer, and its **Celestial Bodies** take the map to the Moon or Mars. Right-drag (or ++ctrl++-drag) turns and tilts the map; click the north arrow to reset it. 6. **Share.** **Publish › Export Map** saves a PNG with labels and a scale bar. **Home › New - Layout** offers page sizes and **Publication Layout** presets for sheets (in one of six styles) and figures. + Layout** offers page sizes and **Publication Layout** presets for sheets (in one of seven styles) and figures. Choose a page size for a page with a map frame, legend, north arrow and scale bar. **Project › Save As** writes a `.rgis` project. diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 3eb0cf486e..0d02c8b5f0 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -186,9 +186,15 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu corners on a light page: the map in one, the locator and the legend in one each beside it, the sources and reference in tinted ones under them; `"poster"` colours the whole page, sets the title and subtitle in light text across the top, the map in a light card and the footer - in darker blocks with amber headings. `"accent"` (`#RRGGBB`) colours the band, the panel's - tint, the headings and rules, and a poster's page (a deep brown, green or blue by default). - A figure leaves the style to its caption. In the menu, each sheet opens a list of the six + 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). + 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). - Every element is an ordinary one, to move or restyle afterwards. The command returns element From fa2bf3a6174ee8a32e8fa713b5b7f587f2046b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 06:06:18 -0500 Subject: [PATCH 2/5] fix(layout): a white edge paper is kept as no colour, and cover the style's map-token texts (#3104) --- .../engine/src/cmd/layout/publication/mod.rs | 3 +- .../src/cmd/layout/publication/sheet.rs | 3 +- crates/engine/src/tests/layout_edge.rs | 30 +++++++++++++++++++ crates/engine/src/tests/layout_title.rs | 6 ++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index 2d7dcf09ed..c65368ddea 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -150,7 +150,8 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu if let Some(k) = ["paper", "kicker"].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\"")); } - let paper = crate::cmd::opaque_color(p, "paper")?.flatten(); + // White is the page's own colour, kept as none, as `layout.page` keeps it. + let paper = crate::cmd::opaque_color(p, "paper")?.flatten().filter(|c| *c != Rgba::rgb(0xFF, 0xFF, 0xFF)); let kicker = one("kicker")?; // Where the coverage grid the placement searches is written as an image (#1379). let coverage_path = match p.get("coverage") { diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index 2982d637c8..cd83797c1e 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -118,7 +118,8 @@ impl Style { } /// The accent colour when none is given: a deep blue, green or brown (a poster's page), or an - /// edge sheet's brick red, which reads on a light paper and on a dark one. + /// edge sheet's brick red, strong on a light paper and fainter on a dark one, where `"accent"` + /// picks a lighter one. pub(in crate::cmd::layout) fn accent(self) -> Rgba { match self { Style::Classic => Rgba::rgb(0x2B, 0x26, 0x20), diff --git a/crates/engine/src/tests/layout_edge.rs b/crates/engine/src/tests/layout_edge.rs index 43e51df0c3..840a1c56d8 100644 --- a/crates/engine/src/tests/layout_edge.rs +++ b/crates/engine/src/tests/layout_edge.rs @@ -111,6 +111,13 @@ fn a_null_paper_is_a_white_page() { assert_eq!(text_colour(last(&s), "Title"), INK); } +#[test] +fn a_white_paper_is_stored_as_none_as_layout_page_stores_it() { + let mut s = world(); + edge(&mut s, json!({"paper": "#FFFFFF"})).unwrap(); + assert_eq!(last(&s).paper, None); +} + #[test] fn a_paper_that_is_no_opaque_colour_is_refused() { let mut s = world(); @@ -151,6 +158,21 @@ fn a_long_kicker_wraps_within_the_page() { assert!(kicker.x + kicker.w <= l.width && kicker.y + kicker.h <= title.y + 1e-6); } +/// A kicker naming the map is kept as typed and wraps as it is drawn, so it follows a rename. +#[test] +fn a_kicker_with_the_map_token_keeps_it_and_wraps_as_drawn() { + let mut s = world(); + s.run("map.rename", &json!({"name": "a very long location map name ".repeat(5)})).unwrap(); + edge(&mut s, json!({"profile": "a5-portrait", "kicker": "{map}"})).unwrap(); + let l = last(&s); + let (kicker, title) = (named(l, "Kicker"), named(l, "Title")); + let ElementKind::Text { text, wrap, .. } = &kicker.kind else { panic!() }; + assert_eq!((text.as_str(), *wrap), ("{map}", true)); + // More than one line's height, and clear of the title. + assert!(kicker.h > 2.0 * crate::render::layout::line_pitch_mm(9.0 * l.width / 210.0), "{}", kicker.h); + assert!(kicker.y + kicker.h <= title.y + 1e-6); +} + #[test] fn a_sheet_with_no_header_starts_its_map_at_the_top_margin() { let mut s = world(); @@ -190,6 +212,14 @@ fn a_figure_leaves_the_edge_style_to_its_caption() { assert!(r["warnings"].to_string().contains("style \\\"edge\\\""), "{r}"); } +#[test] +fn an_edge_sheet_is_one_undo_step() { + let mut s = world(); + edge(&mut s, json!({})).unwrap(); + s.run("edit.undo", &Value::Null).unwrap(); + assert!(s.project.layouts.is_empty()); +} + #[test] fn a_duplicated_edge_sheet_keeps_its_paper() { let mut s = world(); diff --git a/crates/engine/src/tests/layout_title.rs b/crates/engine/src/tests/layout_title.rs index 974552bb40..c534d4f660 100644 --- a/crates/engine/src/tests/layout_title.rs +++ b/crates/engine/src/tests/layout_title.rs @@ -115,7 +115,7 @@ fn a_map_name_wider_than_the_title_wraps_as_drawn_and_follows_a_rename() { let mut s = world(); s.run("map.rename", &json!({"name": LONG})).unwrap(); let extent = json!([-46.8, -11.6, -38.5, -2.2]); - for (li, style) in ["classic", "banner", "panel", "editorial", "modular", "poster"].into_iter().enumerate() { + for (li, style) in ["classic", "banner", "panel", "editorial", "modular", "poster", "edge"].into_iter().enumerate() { let r = s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": extent, "title": "{map}", "style": style})).unwrap(); assert_eq!(stored(&s, li, "Title"), "{map}", "{style}"); @@ -132,8 +132,8 @@ fn a_map_name_wider_than_the_title_wraps_as_drawn_and_follows_a_rename() { assert_eq!(drawn_lines(&s, 0, "Title"), ["Location map"]); // A name that fits needs no wrapping. s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": extent, "title": "{map}"})).unwrap(); - assert_eq!(stored(&s, 6, "Title"), "{map}"); - assert!(!wraps(&s, 6, "Title")); + assert_eq!(stored(&s, 7, "Title"), "{map}"); + assert!(!wraps(&s, 7, "Title")); } /// Words whose advance and ink differ by enough to move a line break. From 0c5feb1d828cf4eeee2ec4b536354377fbbd4a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 06:19:40 -0500 Subject: [PATCH 3/5] docs(layout): say what an edge sheet's default accent does (#3104) --- crates/engine/src/cmd/layout/publication/sheet.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index cd83797c1e..a8217e918a 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -118,8 +118,7 @@ impl Style { } /// The accent colour when none is given: a deep blue, green or brown (a poster's page), or an - /// edge sheet's brick red, strong on a light paper and fainter on a dark one, where `"accent"` - /// picks a lighter one. + /// edge sheet's brick red, the same on a light paper and on a dark one. pub(in crate::cmd::layout) fn accent(self) -> Rgba { match self { Style::Classic => Rgba::rgb(0x2B, 0x26, 0x20), From 7a0efa929d5c36c46599cc80a3af5250b9d4d978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 06:20:19 -0500 Subject: [PATCH 4/5] refactor(layout): name an edge sheet's page colour apart from the surrounds' paper (#3104) --- crates/engine/src/cmd/layout/publication/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index c65368ddea..78b863dbee 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -151,7 +151,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu 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 paper = crate::cmd::opaque_color(p, "paper")?.flatten().filter(|c| *c != Rgba::rgb(0xFF, 0xFF, 0xFF)); + let page_colour = crate::cmd::opaque_color(p, "paper")?.flatten().filter(|c| *c != Rgba::rgb(0xFF, 0xFF, 0xFF)); let kicker = one("kicker")?; // Where the coverage grid the placement searches is written as an image (#1379). let coverage_path = match p.get("coverage") { @@ -547,8 +547,8 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu // 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. - let dark = - paper.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 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) }; let mut y = m + pad; if let Some(t) = &kicker { @@ -854,7 +854,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let given = crate::cmd::within("name", "a layout's name", ps(p, "name").unwrap_or("Publication").trim(), crate::cmd::MAX_NAME)?; let (name, name_cut) = unique_name(s, "New Publication Layout", "the name given", &given); let mut l = Layout::new(name.clone(), w, h); - (l.decimal_comma, l.paper) = (comma, paper); + (l.decimal_comma, l.paper) = (comma, page_colour); let (over, under): (Vec<_>, Vec<_>) = page_wide.into_iter().partition(|e| e.3); for (n, r, kind, _) in under { l.add(&n, r, kind); From 8b09d4f72bfe105181959ca957f03de81ba8c042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 06:35:13 -0500 Subject: [PATCH 5/5] refactor(layout): measure the kicker's spacing with the layout's points per millimetre (#3104) --- crates/engine/src/cmd/layout/publication/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index 78b863dbee..2058824483 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -555,7 +555,8 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let pt = 9.0 * k; // Letter spacing in points, and the millimetres it adds to each character. let spacing = 0.18 * pt; - let added = spacing * 1.33 * 25.4 / 96.0; + // 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)); let width = |x: &str| { let x = drawn(x);