Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
let room_side = if labelled.left || labelled.right { LABEL_ROOM_SIDE * strip_scale } else { 0.0 };
let room_end = if labelled.top || labelled.bottom { LABEL_ROOM_END * strip_scale } else { 0.0 };
let reference = reference.unwrap_or_else(|| {
let line = if step.is_some() { "Datum: {datum} · Graticule: {grid}" } else { "Datum: {datum}" };
vec!["Projection: {projection}".into(), line.into()]
let [projection_line, datum_and_grid] = PUBLICATION_DEFAULT_REFERENCE;
let line = if step.is_some() { datum_and_grid } else { "Datum: {datum}" };
vec![projection_line.into(), line.into()]
});
let step_said = step.map_or_else(|| "—".to_string(), step_text);
let fill = |t: &str| t.replace("{projection}", &projection).replace("{datum}", &datum).replace("{grid}", &step_said);
Expand Down Expand Up @@ -266,7 +267,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
// lines in `body_pt`, `tw` wide. Each one's elements keep their names (`Sources`, `Reference`)
// whatever its heading reads, the heading filled and wrapped like the rest.
let sections = |tw: f64, head_pt: f64, body_pt: f64| -> Vec<(&'static str, Broken, Broken)> {
[("Sources", heading(0, "Sources"), &sources), ("Reference", heading(1, "Cartographic reference"), &reference)]
[("Sources", heading(0, PUBLICATION_HEADINGS[0]), &sources), ("Reference", heading(1, PUBLICATION_HEADINGS[1]), &reference)]
.into_iter()
.filter(|(.., texts)| !texts.is_empty())
.map(|(name, head, texts)| {
Expand Down
12 changes: 12 additions & 0 deletions crates/engine/src/cmd/layout/publication/sheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ pub const PUBLICATION_STYLES: &[(&str, &str)] = &[
/// with today's date when the layout is drawn).
pub const PUBLICATION_DEFAULT_CREDIT: &str = "Made with RustGIS · {date}";

/// The headings of a publication's sources and cartographic reference when `"headings"` doesn't
/// give them.
pub const PUBLICATION_HEADINGS: [&str; 2] = ["Sources", "Cartographic reference"];

/// The cartographic reference's lines when `"reference"` isn't given, on a sheet with a graticule
/// (`{projection}`, `{datum}` and `{grid}` are filled with the sheet's). Without one the command
/// writes the datum alone in place of the second.
pub const PUBLICATION_DEFAULT_REFERENCE: [&str; 2] = ["Projection: {projection}", "Datum: {datum} · Graticule: {grid}"];

/// The most texts a publication layout takes in one list, such as its sources.
pub const MAX_PUBLICATION_LINES: usize = 50;

/// The longest text a publication layout takes in one field, in characters.
pub const MAX_PUBLICATION_TEXT: usize = 2000;

Expand Down
8 changes: 4 additions & 4 deletions crates/engine/src/cmd/layout/publication/texts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ pub(crate) fn datum_of(def: &str) -> Option<String> {
param("+R=").map(|_| "a sphere".into())
}

/// Texts given as one or a list (up to 50), each of at most [`MAX_PUBLICATION_TEXT`] characters: a
/// longer one is refused, not cut.
/// Texts given as one or a list (up to [`MAX_PUBLICATION_LINES`]), each of at most
/// [`MAX_PUBLICATION_TEXT`] characters: a longer one is refused, not cut.
pub(in crate::cmd::layout) fn texts_of(p: &Value, k: &str) -> Result<Option<Vec<String>>, String> {
let within = |t: &str| crate::cmd::within(k, "a publication layout's text", t, MAX_PUBLICATION_TEXT);
match p.get(k) {
None | Some(Value::Null) => Ok(None),
Some(Value::String(t)) => Ok(Some(vec![within(t)?])),
Some(Value::Array(a)) if a.len() <= 50 => a
Some(Value::Array(a)) if a.len() <= MAX_PUBLICATION_LINES => a
.iter()
.map(|v| v.as_str().ok_or_else(|| format!("{k} is a text or a list of texts")).and_then(within))
.collect::<Result<_, _>>()
.map(Some),
Some(_) => Err(format!("{k} is a text or a list of up to 50 texts")),
Some(_) => Err(format!("{k} is a text or a list of up to {MAX_PUBLICATION_LINES} texts")),
}
}

Expand Down
5 changes: 5 additions & 0 deletions crates/ui-egui/src/publicationwizard/accent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,25 @@ mod tests {
// Go back to Style while still ticked and switch to Poster: accent follows Poster.
click(&mut h, "Back");
click(&mut h, "Back");
click(&mut h, "Back");
h.get_by_label("Poster").click();
h.run_steps(2);
assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(poster), "re-seeded to Poster");
// Unticking on Poster must not remember Banner's or Poster's default as a custom colour.
click(&mut h, "Next");
click(&mut h, "Next");
click(&mut h, "Next");
h.get_by_label("Pick a colour of your own").click();
h.run_steps(2);
assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, None);
click(&mut h, "Back");
click(&mut h, "Back");
click(&mut h, "Back");
h.get_by_label("Editorial").click();
h.run_steps(2);
click(&mut h, "Next");
click(&mut h, "Next");
click(&mut h, "Next");
h.get_by_label("Pick a colour of your own").click();
h.run_steps(2);
assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(editorial), "starts from Editorial");
Expand All @@ -135,6 +139,7 @@ mod tests {
h.state_mut().dialogs.publication.as_mut().unwrap().accent = Some(red);
click(&mut h, "Back");
click(&mut h, "Back");
click(&mut h, "Back");
h.get_by_label("Banner").click();
h.run_steps(2);
assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(red), "custom colour kept");
Expand Down
Loading
Loading