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
6 changes: 3 additions & 3 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub fn commands() -> Vec<C> {
r##""valign"?: "top"|"middle"|"bottom" (text, dynamicText: where its block of lines sits down its box; default top; a block taller than its box is drawn from the top, its last lines left out, which a warning says; refused for other kinds), "##,
r##""lineSpacing"?: 0.5 to 3 (text, dynamicText: the distance between its lines, a multiple of the usual; default 1; refused outside that range, and for other kinds), "##,
r##""case"?: "none"|"upper"|"lower" (text, dynamicText: drawn in upper or lower case once its dynamic text is filled in, its text kept as typed; default none; refused for other kinds), "##,
r##""font"?: "sans"|"serif"|an installed font family's name, as labels.fonts lists them (text, dynamicText, and a northArrow's N; a family not installed here is drawn in its fallback, and a serif where none is installed in the sans, with a warning; refused for other kinds), "##,
r##""font"?: "sans"|"serif"|an installed font family's name, as labels.fonts lists them (text, dynamicText, a northArrow's N and a scaleBar's labels; a family not installed here is drawn in its fallback, and a serif where none is installed in the sans, with a warning; refused for other kinds), "##,
r##""fallback"?: "sans"|"serif" (a named font's, where it isn't installed; default its own class, else sans), "##,
r##""title"?: legend title (default "Legend"); chart: its own title ("" for none; default: its field, or the statistic of its field by the group); profile: written over its curve ("" for none; default its layer's name), "##,
r##""subtitle"?: text (legend: one line under its title, at the rows' text size, up to 200 characters; "" for none, the default; refused for other kinds), "##,
Expand Down Expand Up @@ -327,8 +327,8 @@ pub fn commands() -> Vec<C> {
r##""valign"?, "##,
r##""lineSpacing"?, "##,
r##""case"? (text, as in layout.addElement; null leaves each as it is; refused for other elements), "##,
r##""font"?: "sans"|"serif"|an installed font family's name (text, dynamicText, a northArrow's N), "##,
r##""fallback"?: "sans"|"serif" (text, dynamicText, a northArrow's N, as in layout.addElement; refused for other elements), "##,
r##""font"?: "sans"|"serif"|an installed font family's name (text, dynamicText, a northArrow's N, a scaleBar's labels), "##,
r##""fallback"?: "sans"|"serif" (text, dynamicText, a northArrow's N, a scaleBar's labels, as in layout.addElement; refused for other elements), "##,
r##""title"? (legend, colorbar; chart: its own title ("" for none; null giving it the title it is given again)), "##,
r##""subtitle"?: text (legend, as in layout.addElement; "" takes it away, null leaves it as it is), "##,
r##""allClasses"?: bool (legend), "##,
Expand Down
9 changes: 7 additions & 2 deletions crates/engine/src/cmd/layout/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
}
// A family is a text's: refused elsewhere, as a legend's left-out layers are, so a script
// doesn't take it as applied.
if !matches!(kind, "text" | "dynamicText" | "northArrow") && gives_font(p) {
if !matches!(kind, "text" | "dynamicText" | "northArrow" | "scaleBar") && gives_font(p) {
return Err(ONLY_TEXT_FONT.into());
}
if kind != "rectangle" && p.get("radius").is_some_and(|v| !v.is_null()) {
Expand Down Expand Up @@ -802,6 +802,9 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
ElementKind::NorthArrow { font, font_name, .. } if gives_font(p) => {
font_warning(*font, font_name.as_deref(), p.get("fallback").is_some_and(|v| !v.is_null()), (true, false))
}
ElementKind::ScaleBar { font, font_name, .. } if gives_font(p) => {
font_warning(*font, font_name.as_deref(), p.get("fallback").is_some_and(|v| !v.is_null()), (false, false))
}
_ => None,
};
// A colorbar with nothing to show says why, as a notice the app shows.
Expand Down Expand Up @@ -1133,6 +1136,8 @@ const ADD_SCALE_BAR_KEYS: &[&str] = &[
"textSize",
"color",
"fill",
"font",
"fallback",
];

/// Keys read by `layout.addElement` for a legend (#3074).
Expand Down Expand Up @@ -1667,7 +1672,7 @@ mod tests {
// Every key a kind reads, each given a value it takes.
let calls = [
json!({"kind": "northArrow", "layout": 0, "frame": frame, "x": 10, "y": 10, "w": 15, "h": 20, "style": "compass", "fill": "#112233", "outline": "#445566", "font": "sans", "fallback": null, "background": {"fill": "#FFFFFF"}}),
json!({"kind": "scaleBar", "frame": frame, "x": 10, "y": 10, "w": 60, "h": 12, "style": "stepped", "units": "miles", "divisions": 3, "subdivisions": 2, "divisionsBeforeZero": 1, "labelPosition": "below", "unitLabel": "mi", "unitLabelPosition": "afterBar", "fit": "adjustWidth", "decimals": 1, "textSize": 9, "color": "#112233", "fill": "#FFFFFF"}),
json!({"kind": "scaleBar", "frame": frame, "x": 10, "y": 10, "w": 60, "h": 12, "style": "stepped", "units": "miles", "divisions": 3, "subdivisions": 2, "divisionsBeforeZero": 1, "labelPosition": "below", "unitLabel": "mi", "unitLabelPosition": "afterBar", "fit": "adjustWidth", "decimals": 1, "textSize": 9, "color": "#112233", "fill": "#FFFFFF", "font": "sans", "fallback": null}),
json!({"kind": "legend", "frame": frame, "title": "T", "allClasses": true, "hideOther": true, "showNoData": true, "exclude": [], "layerOrder": [], "columns": 2, "labels": {}, "textSize": 8, "fit": "adjustSize", "showLayerNames": false, "showCounts": true, "sizes": "nested", "color": "#112233"}),
json!({"kind": "colorbar", "frame": frame, "title": "T", "orientation": "vertical", "ticks": 3, "tickSide": "left", "reverse": true, "color": "#112233"}),
json!({"kind": "text", "text": "A", "size": 14, "color": "#112233", "bold": true, "italic": true, "align": "center", "letterSpacing": 1, "font": "Some Family", "fallback": "serif", "rotation": 90, "wrap": true, "valign": "middle", "lineSpacing": 1.5, "case": "upper", "name": "ignored"}),
Expand Down
6 changes: 3 additions & 3 deletions crates/engine/src/cmd/layout/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use super::*;

/// What an export of a layout whose texts or north arrows name installed families is told while the app is still
/// indexing the fonts (its first seconds; the app's exports don't wait for them): those texts
/// What an export of a layout whose texts, north arrows or scale bars name installed families is told
/// while the app is still indexing the fonts (its first seconds; the app's exports don't wait for them): those texts
/// are drawn in their fallbacks. A script or the command line indexes them at once.
pub(in crate::cmd::layout) fn named_fonts_unread(layout: &Layout) -> Option<&'static str> {
let named = layout.elements.iter().any(|e| e.kind.named_font().is_some());
(named && rustgis_render::families::available().is_none()).then_some(
"the installed fonts are still being read, so texts and north arrows in a named font family are drawn in their fallback: export again in a moment",
"the installed fonts are still being read, so texts, north arrows and scale bars in a named font family are drawn in their fallback: export again in a moment",
)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/layout/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pub(in crate::cmd::layout) fn frame_view_changed(s: &mut Session, li: usize, fra
/// box as wide as `before` (what it was measured from before the change: its frame, bar and text)
/// is measured again: one set by hand keeps its width. A change to the text under the bar or to
/// anything of the bar's that changes its labels or their room (its units, divisions, text size,
/// subdivisions, divisions before zero, labels, unit label and where it sits, decimals or fit)
/// subdivisions, divisions before zero, labels, unit label and where it sits, decimals, fit or font)
/// measures it again too, with every setting the bar has. A box that would then cover the legend,
/// locator or north arrow, which it didn't, stays as it was, which is said.
pub(in crate::cmd::layout) fn refit_scale_box(s: &mut Session, li: usize, before: &BoxBasis) {
Expand Down
6 changes: 4 additions & 2 deletions crates/engine/src/cmd/layout/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ pub(in crate::cmd) fn say_unfitted_legends_in(
/// What a scale bar is given that changes its labels (#2581): its text size (`null` included, which
/// gives the default back), its units and divisions, which change what they say, and its details,
/// which change its rows, its labels and the room they have (`null` included: a unit label given
/// back is its abbreviation again).
pub(in crate::cmd::layout) const BAR_FIT_KEYS: [&str; 10] = [
/// back is its abbreviation again), and the font they are measured in.
pub(in crate::cmd::layout) const BAR_FIT_KEYS: [&str; 12] = [
"textSize",
"units",
"divisions",
Expand All @@ -274,6 +274,8 @@ pub(in crate::cmd::layout) const BAR_FIT_KEYS: [&str; 10] = [
"unitLabelPosition",
"decimals",
"fit",
"font",
"fallback",
];

/// The `"columns"` a legend is given, refused outside 1 to [`MAX_LEGEND_COLUMNS`]: the one reader
Expand Down
5 changes: 3 additions & 2 deletions crates/engine/src/cmd/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ pub(crate) fn text_block_settings(p: &Value, current: (TextVAlign, f64, TextCase
}

/// What a `font` given for an element that draws no text of a chosen family is told.
pub(in crate::cmd::layout) const ONLY_TEXT_FONT: &str = "only text elements and north arrows take a font or a fallback";
pub(in crate::cmd::layout) const ONLY_TEXT_FONT: &str = "only text elements, north arrows and scale bars take a font or a fallback";

/// Whether `p` gives a `font` or a `fallback`, which only text elements and north arrows take.
/// Whether `p` gives a `font` or a `fallback`, which only text elements, north arrows and
/// scale bars take.
pub(in crate::cmd::layout) fn gives_font(p: &Value) -> bool {
["font", "fallback"].iter().any(|k| p.get(*k).is_some_and(|v| !v.is_null()))
}
Expand Down
15 changes: 11 additions & 4 deletions crates/engine/src/cmd/layout/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ pub(in crate::cmd::layout) fn restyle(kind: &ElementKind, p: &Value) -> Result<O
unit_label_position,
decimals,
fit,
font,
font_name,
} => {
if SCALE_BAR_LOOK_KEYS.iter().chain(SCALE_BAR_KEYS.iter()).all(|k| p.get(k).is_none()) {
let keys = SCALE_BAR_LOOK_KEYS.iter().chain(SCALE_BAR_KEYS.iter()).chain(["font", "fallback"].iter());
if keys.into_iter().all(|k| p.get(k).is_none()) {
return Ok(None);
}
let style = match given_name(p, "style", "alternating, stepped or line")? {
Expand Down Expand Up @@ -122,6 +125,7 @@ pub(in crate::cmd::layout) fn restyle(kind: &ElementKind, p: &Value) -> Result<O
}
Some(_) => return Err("unitLabel is text, or null for the unit's abbreviation".into()),
};
let (font, font_name) = text_font(p, (*font, font_name.clone()))?;
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
Ok(Some(ElementKind::ScaleBar {
frame: *frame,
units,
Expand All @@ -137,6 +141,8 @@ pub(in crate::cmd::layout) fn restyle(kind: &ElementKind, p: &Value) -> Result<O
unit_label_position,
decimals,
fit,
font,
font_name,
}))
}
ElementKind::Rectangle { fill, outline, width, dash, .. } | ElementKind::Ellipse { fill, outline, width, dash } => {
Expand Down Expand Up @@ -398,8 +404,8 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
Some(ElementKind::Text { italic, align, letter_spacing, font, font_name, .. }) => {
Some((text_style(p, *italic, *align, *letter_spacing)?, text_font(p, (*font, font_name.clone()))?))
}
// A north arrow's are read with its look, by `restyle`.
Some(ElementKind::NorthArrow { .. }) => None,
// A north arrow's and a scale bar's are read with their look, by `restyle`.
Some(ElementKind::NorthArrow { .. } | ElementKind::ScaleBar { .. }) => None,
_ if gives_font(p) => return Err(ONLY_TEXT_FONT.into()),
_ => None,
};
Expand Down Expand Up @@ -428,10 +434,11 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
Some(ElementKind::Text { bold, .. }) => b(p, "bold").unwrap_or(*bold),
_ => false,
};
// The family asked for: a text's, or a north arrow's, whose `N` is bold.
// The family asked for: a text's, a north arrow's, whose `N` is bold, or a scale bar's.
let asked = match (&new_text_style, &restyled) {
(Some(((italic, _, _), (f, n))), _) => Some((*f, n.as_deref(), (bold_now, *italic))),
(None, Some(ElementKind::NorthArrow { font, font_name, .. })) => Some((*font, font_name.as_deref(), (true, false))),
(None, Some(ElementKind::ScaleBar { font, font_name, .. })) => Some((*font, font_name.as_deref(), (false, false))),
_ => None,
};
let font_told = asked
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub const CAPABILITIES: &[&str] = &[
"layout-table-look",
"layout-colorbar-labels",
"layout-north-arrow-font",
"layout-scale-bar-font",
"field-generation",
"field-package",
FIELD_CONFLICTS,
Expand Down
Loading
Loading