You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(layout): choose the font of a scale bar's labels - #3491
A layout scale bar's numbers and unit were always drawn in the sans-serif. They now take a font, as a text element's and a north arrow's do.
layout.addElement and layout.update accept font (sans, serif or an installed family's name) and fallback on a scale bar, read by the same text_font a text uses. A family that isn't installed is kept, drawn in its fallback, and said in the same warning.
Format › Scale Bar gets the Font and Fallback rows of a text (textform::font_rows).
The labels are measured in that face wherever the bar is sized (its inset, its fitted length, its cut or shortened unit label, its fitted box and the off-page check) and drawn in it on the page and in PNG, PDF and SVG exports. An export made while the installed fonts are still being read warns about scale bars too.
A publication's scale bar box is measured again when the bar's font changes.
A family that isn't installed no longer widens the Format pane: its name is cut with an ellipsis in the Font list, which the text and north arrow panes share.
Both fields are saved only when changed, under a new layout-scale-bar-font capability, so an older version refuses the project instead of dropping them. Saved layout.addElement, layout.import, report.existingTemplate, project.openText and script steps require it too; a saved layout.update names no element kind, so an older version refuses it when the step runs. A scale bar saved before draws and saves as it did.
layout.publication's scaleBar object doesn't take a font: the font is set in the element's properties.
Surfaces: the desktop and web Format pane, and the layout.addElement / layout.update commands with their parameter help (scripts, tasks, Python, Assistant and MCP). The ribbon, the phone app and the publication wizard don't change.
Testing
New tests in crates/engine/src/tests/layout_scale_font.rs (default saves nothing, serif, a family not installed with and without fallback, an installed family, bad values refused with nothing changed, undo, save and reload, a publication's scale box following the font), in crates/render/src/layout/tests.rs (labels drawn and measured in the face, the off-page check judged in it) and in crates/ui-egui/src/layoutview/tests.rs (the Font row, and a missing family not widening the pane). The publication box, off-page and pane tests were seen failing before their fixes.
scale_bar_font_capability_follows_saved_layouts_and_commands, with the fixture layout_scale_bar_font.rgis.
Existing tests updated: the assertions that expected a scale bar to refuse a font now use a rectangle, and the scale bar's key list in cmd/layout/elements.rs gains font and fallback.
cargo fmt --check, workspace clippy, doctests, the layering check and cargo xtask schema --check pass. Full nextest: 11665 of 11674 passed; the 9 failures are outside this change: 7 in rustgis-geolibre and line_strokes_editor_edits_one_class fail on this machine without it, and the timing test browse_lists_thousands_of_plugins_quickly passes when run again on its own. The last two fixes were then checked with their targeted tests and clippy of their crates.
Before and after captured with the ui_shot example: the sans-serif page exports byte for byte the same as before.
UI evidence
Format › Scale Bar, before and after (a serif chosen):
The exported scale bar in the sans-serif and in the serif (300 dpi, cropped). A label that would touch its neighbour is left out, as before, so another face can keep other labels:
No actionable comments were generated in the recent review.
Walkthrough
Scale bars now support font and fallback settings through layout commands and the Format pane. Rendering and measurement use the selected face. Project capability checks identify saved layouts and command inputs that use non-Sans scale-bar fonts.
Changes: Scale-bar font support
Layer / File(s)
Summary
Font model and layout commands crates/map/src/layout/elements.rs, crates/engine/src/cmd/layout/*, crates/engine/src/tests.rs, crates/engine/src/tests/layout_*font.rs
Scale bars store font settings. layout.addElement and layout.update accept font and fallback options, and font warnings cover scale bars. Tests cover defaults, named fonts, fallbacks, validation, serialization, and undo behavior.
Font-aware measurement and rendering crates/render/src/layout/*, crates/engine/src/tests/layout_scale_font.rs, docs/user-guide/layouts.md
Scale-bar labels and unit text use the selected face for drawing, measurement, and clipping checks. Tests cover serif labels and publication-layout sizing. The guide documents font options and box-size warnings.
The layout-scale-bar-font capability is registered and required for applicable non-Sans scale-bar fonts in saved layouts and command inputs. Tests and schema fixtures cover capability detection.
Format pane controls crates/ui-egui/src/layoutview/format/scalebar.rs, crates/ui-egui/src/layoutview/tests.rs, crates/ui-egui/src/textform.rs
The Format pane exposes scale-bar font controls. The font-family combo box truncates long selected names. Tests cover font selection, undo, and long unavailable names.
sequenceDiagram
participant LayoutCommand
participant ScaleBar
participant Renderer
participant BarOptions
LayoutCommand->>ScaleBar: store resolved font settings
Renderer->>BarOptions: derive face from scale-bar settings
BarOptions-->>Renderer: provide face for layout
Renderer->>Renderer: measure and draw labels with that face
Loading
Possibly related PRs
opengeos/RustGIS#3471: Adds font and fallback support for north-arrow labels using shared font controls and capability checks.
opengeos/RustGIS#949: Adds the named-font and fallback behavior that this change also uses for scale bars.
opengeos/RustGIS#2660: Updates scale-bar label sizing and publication remeasurement in the same sizing path.
Suggested reviewers:giswqs
Merge Risk: Minimal · up to 40bd1
This change adds per-scale-bar font and fallback settings, with a capability guard so older versions refuse projects that use them. No actionable merge-blocking risk was identified in the supplied material.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a font choice for scale bar labels in the layout feature. The changeset adds per-scale-bar font and fallback settings in the Format pane, the layout commands, renderin…
Description check
The description follows the template. It has a Summary that states what changes and why. It has a Testing section that lists new tests, the commands run, and the failures outside the change. It has a …
Linked Issues check
[#3468] asks for a per-scale-bar font (sans, serif, or an installed family) and fallback (sans or serif). The whole-PR summary, from merge base 556f704 to head 40bd108, shows each coding o…
Out of Scope Changes check
Each changed area maps to an objective of [#3468]: engine command and update paths, capability and project-save gating, render measurement and drawing, the Format pane rows, the refit_scale_box reme…
Full details: Title check
Explanation
The title names the main change: a font choice for scale bar labels in the layout feature. The changeset adds per-scale-bar font and fallback settings in the Format pane, the layout commands, rendering, measurement, and the new capability. The title is specific and concise, and it matches the primary change.
Full details: Description check
Explanation
The description follows the template. It has a Summary that states what changes and why. It has a Testing section that lists new tests, the commands run, and the failures outside the change. It has a UI evidence section with before and after screenshots. It links the related issue (Closes #3468). The UI evidence section replaces the 'No visible UI change' line, which is correct because this PR changes visible UI.
Full details: Linked Issues check
Explanation
[#3468] asks for a per-scale-bar font (sans, serif, or an installed family) and fallback (sans or serif). The whole-PR summary, from merge base 556f704 to head 40bd108, shows each coding objective implemented. (1) Commands: cmd/layout/elements.rs and update.rs accept font and fallback for scale bars. BAR_FIT_KEYS in legend.rs lists both keys. (2) Model: crates/map/src/layout/elements.rs adds font: FontFamily and font_name to ScaleBar. (3) Missing family: named_fonts_unread in export.rs covers scale bars and warns that they draw in the fallback. (4) Drawing and measurement: render/src/layout/scale_bar.rs and losses.rs use the bar's face for labels, unit text, inset and fitted box. refit_scale_box remeasures on font change, which covers the publication placement. (5) Persistence: layout-scale-bar-font is added to project.rs, project_capabilities.rs and the schema. Only changed fields are saved. The fixture layout_scale_bar_font.rgis covers this. (6) Format pane: ui-egui/.../format/scalebar.rs shows the shared font rows. Tests cover engine save/reload and undo, render drawing and off-page checks, and the Format row. The issue's coding requirements are all covered. No non-coding objective applies. I did not open the source hunks in this pass. This assessment relies on the PR summary and the stated test coverage.
Full details: Out of Scope Changes check
Explanation
Each changed area maps to an objective of [#3468]: engine command and update paths, capability and project-save gating, render measurement and drawing, the Format pane rows, the refit_scale_box remeasure, schema and docs, and tests and fixture. The shared ui-egui/src/textform.rs change (ellipsis for long family names) also affects the text and north arrow panes. The PR description states this effect, and the issue's Format row needs it. The publication scaleBar object takes no font. The issue does not require one, and the PR states this. The ribbon, phone app and publication wizard are unchanged, as the PR states. No change without a connection to the issue was found. Source hunks were not opened in this pass, so this rests on the summary.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit sets the labels in serif, Then checks each measure, neat and brief. The numbers fit; the unit stays, The bar draws true in varied ways. One tap, one undo, fonts return, While rabbit ears review and learn.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: 8f92ae99-82f8-4b9a-9346-d23e2e97764c
Commits
Reviewing files that changed from the base of the PR and between 467da3c and 40bd108.
Files selected for processing: 1
crates/render/src/layout/tests.rs
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.
I read the full diff, the staged AGENTS.md, and the surrounding code for the paths it touches. I could not build or run the tests (no shell in this review), so everything below comes from reading the code. The PR's claimed test results are not verified here.
Prior review threads: none exist on this PR, so there were no earlier concerns to skip.
Bugs
Locked scale bar can be reset with null (medium-high confidence, inline comment posted at update.rs:128).font: null or fallback: null on a locked bar is not refused, because null_resets does not list font or fallback for a scale bar. The lock check therefore never fires. The PR's docs say a locked bar refuses changes "null included", so this contradicts them. The same gap already exists for text and north-arrow fonts, so the fix may belong in null_resets for all three.
Security
None found. Font names go through the existing de_font and text_font validation, and the new capability checks parse with the same guards as the north-arrow ones.
Performance
Extra project parse on project.openText (low confidence, minor).command_uses_scale_bar_font calls text_gives_font, which runs Project::from_json on any text containing "font". A project text that also needs the north-arrow capability is now parsed twice. The capability loop already re-parses per check, so this follows an existing pattern and adds one more parse rather than a new cost. Memoizing the parse would remove it.
Quality
Serif-dependent tests can pass without running.a_publication_scale_box_follows_the_bars_font and a_scale_bars_labels_are_drawn_and_measured_in_its_face return early when no serif is installed, and the assert_ne! in the engine test is also conditional on that. On a runner without a serif font, the new coverage silently does nothing. This follows the existing font-test pattern, so I did not raise it as a defect.
Element-kind schema not checked.project.schema.json has no ScaleBar entry, and the PR only adds the capability string, which matches the north-arrow change. I did not find a missing schema update.
AGENTS.md
No rule breaks found. The checks I made:
layout.update, layout.addElement, layout.import, report.existingTemplate, project.openText and script.run are all covered by the capability.
The font and fallback keys are in the scale bar's key lists.
The Format pane's font row mirrors the north arrow's.
The export warning is updated.
The UI test and the rendering tests exist.
The docs are updated.
Twins checked: the north-arrow font path (layout.addElement, layout.update, named_font, the export warning, project.openText, layout.import), and the overlay and wasm twins, which this change does not touch.
Rendering checks: draw_label matches text_at's Left, Center and Right anchoring; styled_at and text_at both anchor on the line's middle; Face is Copy; the remaining measure( calls in bar_layout use its face-aware local closure.
Change size
Compared with main (merge base 556f704 to PR head 467da3c). Sizes are file sizes, not line counts.
The extra parse on project.openText follows the one-parse-per-capability pattern the checks already use; sharing the parse is a change to that dispatch, not to this font.
The serif-dependent tests return early without a serif, as the sibling font tests do.
project.schema.json needs only the capability string, as for the north arrow.
The failed Web app (wasm32) job stopped while downloading Trunk (curl: (22) The requested URL returned error: 618), after the wasm build had finished; it needs a re-run.
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).
I read the whole diff, the prior review thread, and the surrounding code for the lock path, the font helpers, the render text functions, the capability dispatch, the Format pane and the schema. I found no bugs or security problems. One quality point is posted inline.
Bugs
None found. I checked these and they hold:
Locked bar and null font/fallback. The prior thread is answered by the author. text_font treats a null font or fallback as "not given" and returns the current pair, so it can't change a locked bar. Non-null values do reach the lock check. Confidence high.
Glyph placement. For the default face, styled_at and draw_label place glyphs exactly as text_at did: sans_beside returns None and the centre/left/right offsets match. Confidence medium-high, since I reasoned it from the code and did not run it.
Measurement face. Every scale bar measurement goes through the face-aware measure closure. The cut helpers (last_label, shortened) receive that closure. Unit labels are only ever Left or Center, so the Right branch in the off-page check is unreachable. Confidence high.
Publication path. Publication scale bars don't list font/fallback in their keys, so they can't reach the new restyle branch. Confidence high.
Security
None found.
Performance
Low confidence, not posted inline: text_gives_font re-parses a project.openText text that mentions "font" once more for the scale bar capability, on top of the north arrow's parse and the other capability checks. This is a small, bounded cost on project open and does not justify a change now.
Quality
Posted inline (crates/render/src/layout/tests.rs:6953): the serif-dependent tests return early when no serif face is installed, so they can pass without checking anything. The same applies to a_publication_scale_box_follows_the_bars_font and a_scale_bars_label_off_the_page_is_judged_in_its_face. Confidence medium, since I can't see the CI image's font set.
AGENTS.md
None found. I checked the capability, fixture, schema and docs rules; the command-surface snapshot and the row and memory limits; and the error-string and tl! usage. No new background work was added. The change is synchronous text measurement inside layout.update, and the PR does not add a long loop.
Twins checked: the scale bar capability dispatch mirrors the north arrow's in layout.addElement, layout.import, report.existingTemplate, project.openText and script.run, with the same deliberate omission of layout.update. Overlay tools and the wasm/desktop cfg pairs are not touched by this diff. The shared font_rows gains .truncate(), which also changes the text and north arrow panes; the PR body says this is intended.
Prior reviews
1 earlier concern left alone: the null font lock-bypass thread. It is answered by the PR author, and I verified the answer against text_font and null_resets.
Change size
Compared: the whole PR against main (merge base 556f704 to PR head 40bd108).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A layout scale bar's numbers and unit were always drawn in the sans-serif. They now take a font, as a text element's and a north arrow's do.
layout.addElementandlayout.updateacceptfont(sans,serifor an installed family's name) andfallbackon a scale bar, read by the sametext_fonta text uses. A family that isn't installed is kept, drawn in its fallback, and said in the samewarning.textform::font_rows).layout-scale-bar-fontcapability, so an older version refuses the project instead of dropping them. Savedlayout.addElement,layout.import,report.existingTemplate,project.openTextand script steps require it too; a savedlayout.updatenames no element kind, so an older version refuses it when the step runs. A scale bar saved before draws and saves as it did.layout.publication'sscaleBarobject doesn't take a font: the font is set in the element's properties.Surfaces: the desktop and web Format pane, and the
layout.addElement/layout.updatecommands with their parameter help (scripts, tasks, Python, Assistant and MCP). The ribbon, the phone app and the publication wizard don't change.Testing
crates/engine/src/tests/layout_scale_font.rs(default saves nothing, serif, a family not installed with and withoutfallback, an installed family, bad values refused with nothing changed, undo, save and reload, a publication's scale box following the font), incrates/render/src/layout/tests.rs(labels drawn and measured in the face, the off-page check judged in it) and incrates/ui-egui/src/layoutview/tests.rs(the Font row, and a missing family not widening the pane). The publication box, off-page and pane tests were seen failing before their fixes.scale_bar_font_capability_follows_saved_layouts_and_commands, with the fixturelayout_scale_bar_font.rgis.cmd/layout/elements.rsgainsfontandfallback.cargo fmt --check, workspace clippy, doctests, the layering check andcargo xtask schema --checkpass. Fullnextest: 11665 of 11674 passed; the 9 failures are outside this change: 7 inrustgis-geolibreandline_strokes_editor_edits_one_classfail on this machine without it, and the timing testbrowse_lists_thousands_of_plugins_quicklypasses when run again on its own. The last two fixes were then checked with their targeted tests and clippy of their crates.ui_shotexample: the sans-serif page exports byte for byte the same as before.UI evidence
Format › Scale Bar, before and after (a serif chosen):
The exported scale bar in the sans-serif and in the serif (300 dpi, cropped). A label that would touch its neighbour is left out, as before, so another face can keep other labels:
A family that isn't installed:
Related issue
Closes #3468
Summary by CodeRabbit