Skip to content

feat(layout): choose the font of a scale bar's labels - #3491

Merged
jgregoriorincon merged 6 commits into
opengeos:mainfrom
jgregoriorincon:feat/3468-scale-bar-font
Nov 30, 2026
Merged

jgregoriorincon merged 6 commits into
opengeos:mainfrom
jgregoriorincon:feat/3468-scale-bar-font

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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.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):

3468-format-before-after.png

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:

3468-bar-sans-serif.png

A family that isn't installed:

3468-font-note.png

Related issue

Closes #3468

Summary by CodeRabbit

  • New Features
    • Scale bars now support font and fallback settings for their numbers and unit labels.
    • Labels are measured and rendered using the selected font, helping layouts account for label size.
    • Projects using non-default scale-bar fonts now declare a compatibility requirement so older versions can identify unsupported settings.
  • Bug Fixes
    • Long font names are truncated in narrow formatting panels instead of expanding the field column.
  • Documentation
    • Updated layout guidance to cover scale-bar fonts, fallbacks, and label-fitting behavior.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.
Project capability detection
crates/engine/src/project.rs, crates/engine/src/project_capabilities.rs, schema/*, docs/maintaining.md
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.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed [#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 Passed 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.

Share

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.

Comment thread crates/engine/src/cmd/layout/update.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code 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.

Measure Value
Files changed 23 (added 2, modified 21, removed 0, renamed 0)
Size before 5.57 MB
Size after 5.59 MB
Total size change +24.7 KB
Path Before After Change
crates/engine/src/tests/layout_scale_font.rs 0 B 6.8 KB +6.8 KB
crates/engine/src/project_capabilities.rs 274.0 KB 280.3 KB +5.0 KB
crates/render/src/layout/tests.rs 483.0 KB 486.4 KB +3.5 KB
crates/ui-egui/src/layoutview/tests.rs 216.5 KB 219.9 KB +3.4 KB
schema/fixtures/layout_scale_bar_font.rgis 0 B 1.5 KB +1.5 KB
crates/render/src/layout/scale_bar.rs 33.7 KB 34.7 KB +1.0 KB
crates/map/src/layout/elements.rs 56.5 KB 57.4 KB +866 B
docs/maintaining.md 36.8 KB 37.4 KB +579 B
crates/ui-egui/src/layoutview/format/scalebar.rs 9.3 KB 9.8 KB +535 B
crates/engine/src/cmd/layout/update.rs 50.9 KB 51.3 KB +435 B
crates/engine/src/cmd/layout/elements.rs 81.2 KB 81.5 KB +280 B
docs/user-guide/layouts.md 101.4 KB 101.6 KB +206 B
crates/engine/src/tests.rs 3.8 MB 3.8 MB +126 B
crates/ui-egui/src/textform.rs 35.9 KB 36.0 KB +109 B
crates/render/src/layout/losses.rs 24.1 KB 24.1 KB +66 B
schema/project.schema.json 39.5 KB 39.5 KB +64 B
crates/engine/src/cmd/layout/legend.rs 34.5 KB 34.6 KB +63 B
crates/engine/src/cmd/layout.rs 62.8 KB 62.9 KB +62 B
crates/engine/src/project.rs 157.7 KB 157.7 KB +29 B
crates/engine/src/cmd/layout/text.rs 23.5 KB 23.5 KB +28 B

@jgregoriorincon

Copy link
Copy Markdown
Contributor Author

On the review summary's other points, no change:

  • 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-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3491/
Web app https://preview.rustgis.app/pr-3491/app/
Commit 40bd108

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).

Comment thread crates/render/src/layout/tests.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

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).

Measure Value
Files changed 23 (added 2, modified 21, removed 0, renamed 0)
Size before 5.57 MB
Size after 5.59 MB
Total size change +24.7 KB
File Before After Change
crates/engine/src/tests/layout_scale_font.rs 0 B 6.8 KB +6.8 KB
crates/engine/src/project_capabilities.rs 274.0 KB 279.1 KB +5.0 KB
crates/render/src/layout/tests.rs 482.8 KB 486.4 KB +3.6 KB
crates/ui-egui/src/layoutview/tests.rs 216.5 KB 219.9 KB +3.4 KB
schema/fixtures/layout_scale_bar_font.rgis 0 B 1.5 KB +1.5 KB
crates/render/src/layout/scale_bar.rs 33.7 KB 34.7 KB +1.0 KB
crates/map/src/layout/elements.rs 56.5 KB 57.4 KB +866 B
docs/maintaining.md 36.8 KB 37.4 KB +579 B
crates/ui-egui/src/layoutview/format/scalebar.rs 9.3 KB 9.8 KB +535 B
crates/engine/src/cmd/layout/update.rs 50.9 KB 51.3 KB +435 B
crates/engine/src/cmd/layout/elements.rs 81.2 KB 81.5 KB +280 B
docs/user-guide/layouts.md 101.4 KB 101.6 KB +206 B
crates/engine/src/tests.rs 3.83 MB 3.83 MB +126 B
crates/ui-egui/src/textform.rs 35.9 KB 36.0 KB +109 B
crates/render/src/layout/losses.rs 24.1 KB 24.1 KB +66 B
schema/project.schema.json 39.5 KB 39.5 KB +64 B
crates/engine/src/cmd/layout/legend.rs 34.5 KB 34.6 KB +63 B
crates/engine/src/cmd/layout.rs 62.8 KB 62.9 KB +62 B
crates/engine/src/project.rs 157.7 KB 157.7 KB +29 B
crates/engine/src/cmd/layout/text.rs 23.5 KB 23.6 KB +28 B

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Nov 30, 2026
Merged via the queue into opengeos:main with commit 1fc44f9 Nov 30, 2026
30 checks passed
@jgregoriorincon
jgregoriorincon deleted the feat/3468-scale-bar-font branch November 30, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Layout scale bar: choose the font of its labels

1 participant