diff --git a/crates/assistant/skills/print-layout/SKILL.md b/crates/assistant/skills/print-layout/SKILL.md index 0f2567be78..f425af5356 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. `"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 b655b5697b..7a47d4928f 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? 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? 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 3007d3005f..7f0d3ab8cc 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -84,7 +84,9 @@ pub fn commands() -> Vec { r#""grid"?: "none" (no grid on the map frame, and no label strips inside it) | {a frame grid's options as layout.addElement takes them: type, crs, step, short, mgrs, color, width, labels, labelSize, style, tickLength, format, hemisphere, edges, labelOrientation; a graticule takes no crs, short or mgrs, a measured grid no format or hemisphere} over the default graticule (its step by the extent, labelled left and bottom, on a sheet all round); the label strips follow its labels, edges and labelSize (in points as given, not scaled with the sheet), and without a graticule the default reference names none and {grid} in a text reads "—", "#, r#""scaleBar"?: "none" | {a scale bar's options as layout.update takes them: style, units, divisions, color, fill, textSize, decimals, subdivisions, divisionsBeforeZero, labelPosition, unitLabel, unitLabelPosition, fit; textSize in points as given, not scaled with the sheet} (none on a globe shown whole, whatever is asked), "#, 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 fdd5fd6d22..6d4b4aea88 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -59,7 +59,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)) @@ -135,7 +137,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())?; @@ -144,6 +146,14 @@ 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\"")); + } + // 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")?; // 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, @@ -194,7 +204,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)) @@ -309,8 +319,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 @@ -340,8 +351,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; @@ -354,11 +367,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"), @@ -545,6 +560,65 @@ 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 = 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 { + let pt = 9.0 * k; + // Letter spacing in points, and the millimetres it adds to each character. + let spacing = 0.18 * pt; + // 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); + 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 @@ -795,7 +869,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, 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); @@ -816,7 +890,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..a8217e918a 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, 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), @@ -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 ff4406b903..cc2b71c2e0 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/layout_publication_parts.rs"] mod layout_publication_parts; diff --git a/crates/engine/src/tests/layout_edge.rs b/crates/engine/src/tests/layout_edge.rs new file mode 100644 index 0000000000..840a1c56d8 --- /dev/null +++ b/crates/engine/src/tests/layout_edge.rs @@ -0,0 +1,230 @@ +//! `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_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(); + 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); +} + +/// 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(); + 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 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(); + 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/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. diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 3d8a806404..59c8acbf22 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -186,9 +186,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, their outlines and descriptions, +/// The height every step takes: the style step's seven styles, their outlines and descriptions, /// with room for the rounding a high-density screen adds to each line. -const STEP_HEIGHT: f32 = 360.0; +const STEP_HEIGHT: f32 = 415.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/publicationwizard/style.rs b/crates/ui-egui/src/publicationwizard/style.rs index f56bd18554..121c2b03c4 100644 --- a/crates/ui-egui/src/publicationwizard/style.rs +++ b/crates/ui-egui/src/publicationwizard/style.rs @@ -49,7 +49,7 @@ const INK: egui::Color32 = egui::Color32::from_gray(150); /// a style keeps for its locator and legend, after `layout.publication`'s arrangement of the style /// (`cmd/layout/publication`), with `accent` where the sheet takes it, which Classic's nowhere /// does. A locator or legend over the map isn't drawn: its corner follows the data. An outline, not -/// the sheet: laying the real one out six times on every change would run the placement six times +/// the sheet: laying the real one out for every style on every change would run the placement that many times /// (#2850). fn outline(style: &str, page: egui::Rect, accent: egui::Color32) -> Vec { use egui::{Color32, CornerRadius, Shape, Stroke, StrokeKind}; @@ -120,6 +120,20 @@ fn outline(style: &str, page: egui::Rect, accent: egui::Color32) -> Vec { + s.push(fill(at(0.08, 0.04, 0.3, 0.025), accent)); + s.push(fill(at(0.08, 0.085, 0.55, 0.05), ink)); + s.push(fill(at(0.08, 0.155, 0.4, 0.025), ink)); + s.push(fill(at(0.0, 0.21, 1.0, 0.6), map)); + s.push(Shape::line_segment( + [at(0.08, 0.85, 0.84, 0.0).left_top(), at(0.08, 0.85, 0.84, 0.0).right_top()], + Stroke::new(0.5, rule), + )); + for x in [0.08, 0.52] { + s.push(fill(at(x, 0.875, 0.3, 0.025), ink)); + s.push(fill(at(x, 0.92, 0.24, 0.025), ink)); + } + } // Classic, which takes the accent nowhere, and a style added without an outline of its own. _ => { s.push(fill(at(0.3, 0.04, 0.4, 0.04), ink)); @@ -241,6 +255,17 @@ mod tests { assert!(marks.iter().any(|r| r.left() > map.right() && r.bottom() <= map.top()), "column rule {marks:?}"); } + /// Edge's sheet: the map from one side of the page to the other, the kicker in the accent + /// above it. + #[test] + fn edges_outline_runs_its_map_from_side_to_side_under_its_kicker() { + let map = map_of("edge"); + assert_eq!((map.left(), map.right()), (0.0, 1.0), "{map:?}"); + let marks: Vec = boxes("edge").into_iter().filter(|(_, c)| *c == RED).map(|(r, _)| r).collect(); + assert_eq!(marks.len(), 1, "{marks:?}"); + assert!(marks[0].bottom() <= map.top(), "{marks:?}"); + } + /// Modular's sheet: the map's card at the left, the locator's and the legend's cards at its /// right, one over the other. #[test] 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 b41453a1bf..da8ef676b6 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -199,9 +199,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