Skip to content

fix: start system font scan during language-aware context setup - #2640

Open
Karloss1234 wants to merge 1 commit into
storytold:mainfrom
Karloss1234:fix/system-font-scan
Open

Karloss1234 wants to merge 1 commit into
storytold:mainfrom
Karloss1234:fix/system-font-scan

Conversation

@Karloss1234

@Karloss1234 Karloss1234 commented Oct 26, 2026 •

Copy link
Copy Markdown

Problem

On Linux, GridCraft was not rendering installed system fonts such as Arial, Calibri, Courier New, and Times New Roman correctly. Bold and italic variants were also affected.

The font scanner was never started during the normal desktop startup path.

Root cause

fonts::start_scan() was called by setup_context(), but the desktop application uses setup_context_for_language() instead.

Consequently, the background font scan never started, leaving system font families unavailable to the renderer.

Fix

Call fonts::start_scan() from setup_context_for_language().

The scanner uses OnceLock, so repeated calls are safe.

Verification

Tested on Kubuntu 26.04. Before the fix, the font scan never completed because it was not started. After the fix, installed system fonts were discovered and registered, and normal, bold, and italic rendering worked correctly.

Summary by CodeRabbit

  • Improvements
    • The app now scans available system fonts when setting up language-specific fonts and themes.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 3daed92 and 567cc7a.

Files selected for processing: 1
  • crates/ui-egui/src/app.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

SheetApp::setup_context_for_language now starts the machine-font scan before installing language-specific fonts and applying the theme.

Changes: Language-aware font setup

Layer / File(s) Summary
Start font scan during setup
crates/ui-egui/src/app.rs
setup_context_for_language starts font scanning before it sets font definitions and applies the theme.

Priority: Normal

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix

Possibly related PRs

  • storytold/gridcraft#2714: Adds Linux fontconfig discovery and Arabic fallback, which can use the scan started during language-aware setup.
  • storytold/gridcraft#2275: Adds installed-font cataloging for the snapshot example, addressing a similar missing-scan path.
  • storytold/gridcraft#581: Adds desktop system-font support for Indian-script interface languages, which uses system-font discovery.

Suggested reviewers: dylanmtaylor

Merge Risk: Minimal · up to 567cc

The change restores font scanning for language-aware startup without introducing an established merge-blocking risk.

Security architecture risk: Minimal · up to 567cc

The change activates existing local-font discovery during language-aware startup. It adds no caller-selected scan path or additional privileges, and preserves the existing safeguards for repeated initialization and font publication. No material security regression was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The exposure change is activation of existing local-font parsing for native language-aware callers, under the application process’s filesystem authority. Influence over scanned content depends on local filesystem or process-environment control; the changed method supplies no document-derived scan path. On wasm, start_scan initiates no background work.

Trust Boundaries and Controls

  • observed — The existing scanner filters font extensions, checks file metadata against a 64 MiB size threshold before reading, caps retained family aliases at 16 per face, and deduplicates visited directories. These controls remain in place on the newly activated path; they do not establish a total scan-resource bound.

Resilience and Maintainability Implications

  • observed — If the catalog is not published, the completion gate prevents workbook-font rebinding while initial language-font installation proceeds independently. The change preserves this separation between initial rendering setup and background discovery.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: starting the system font scan during language-aware context setup.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@Karloss1234

Copy link
Copy Markdown
Author

CodeRabbit identified #2229 as a potentially related issue.

This fix may also resolve that report, since the root cause appears to be the same: setup_context_for_language() does not initiate the installed-font scan.

I reproduced the problem on Kubuntu 26.04 and Fedora 44. After adding fonts::start_scan(), installed Microsoft fonts were correctly discovered and rendered, including their bold and italic variants.

@Karloss1234

Copy link
Copy Markdown
Author

This fix also addresses the root cause of the Calibri rendering problem I previously reported in #1815.

My original assumption was that Calibri needed improved rendering at 100% zoom. Further investigation showed that the installed font wasn't being loaded, and GridCraft was displaying a substitute font instead. This PR fixes the font substitution Problem.

@Harrison-Booth

Copy link
Copy Markdown
Contributor

Review notes (not a formal review) on head 567cc7a.

Checked

  • Read the one-line diff. On current main, fonts::start_scan() is called only from SheetApp::setup_context (crates/ui-egui/src/app.rs), and setup_context has no caller in apps/ or crates/; the desktop app (apps/gridcraft/src/main.rs, creation callback), the web app (apps/gridcraft-web/src/web.rs) and start_font_setup (app/fonts.rs) all go through setup_context_for_language. So nothing on main starts the scan, and faces_of reads catalog_now(), which stays None until a scan has run: that matches the description.
  • start_scan is guarded by a static OnceLock and does nothing on wasm, so the extra call from the web app and the repeated call from start_font_setup are harmless.
  • cargo fmt --all -- --check passes on the PR head. The branch is 15 commits behind main but touches only that line.

Not checked

  • I did not run the tests or the app, and did not reproduce the missing-font symptom on Linux; the Kubuntu/Fedora results are the author's.

@Karloss1234

Copy link
Copy Markdown
Author

Additional evidence: I have also tested standard GridCraft v0.13.0 on a native Windows installation running from an SSD where the same font discovery issue occurs, so the issue is not specific to Linux (Kubuntu or Fedora).

I haven't tested this PR Font Scan solution with the Windows installation. This PR solution has been tested successfully in GridCraft v0.13.0 on Kubuntu and Fedora.

I am surprised that no one else has noticed that GridCraft only displays three different fonts across a selection of 17 fonts. The three displayed fonts are fallback fonts because there is no system font scan on GridCraft Startup (Calibri and Arial are identical etc). With this PR there are 17 visibly different and correct fonts. Does no one install/test the desktop version of GridCraft?

@Harrison-Booth

Copy link
Copy Markdown
Contributor

Additional evidence: I have also tested standard GridCraft v0.13.0 on a native Windows installation running from an SSD where the same font discovery issue occurs, so the issue is not specific to Linux (Kubuntu or Fedora).

I haven't tested this PR Font Scan solution with the Windows installation. This PR solution has been tested successfully in GridCraft v0.13.0 on Kubuntu and Fedora.

I am surprised that no one else has noticed that GridCraft only displays three different fonts across a selection of 17 fonts. The three displayed fonts are fallback fonts because there is no system font scan on GridCraft Startup (Calibri and Arial are identical etc). With this PR there are 17 visibly different and correct fonts. Does no one install/test the desktop version of GridCraft?

This is a good callout - to be fair I typically always run the default font in whichever I'm in (GridCraft or Excel)... but would be a good thing to test regularly to make sure this system is running. Thanks for calling it out.

@Karloss1234

Karloss1234 commented Oct 31, 2026 •

Copy link
Copy Markdown
Author

It would be great if this PR could be reviewed and, if appropriate, merged. I'd like to build on these changes to investigate and improve some of the remaining font-rendering issues, but it would be helpful to have this font-discovery work confirmed first. v0.14.2 has been tested. Thanks!
I find that this PR enables all but one standard font to work perfectly. Calibri bold and Italics also work perfectly.
The one font with an issue is the default Calibri Regular font. It sits high in the cell and small (with or without this PR implemented). It seems to be a separate bug which I don't want to invest/waste time on fixing without this PR being formally reviewed/accepted.
Thanks again.

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReviewerA — source-read COMMENT (not an approval)

I read the whole diff: one line calling fonts::start_scan() in setup_context_for_language. start_scan is guarded by a OnceLock, so a second call is a no-op, and it is a no-op on wasm. That looks safe. Please add a note or test showing the scan now starts before the first language-specific font lookup (the stated bug), since nothing in the diff proves the ordering.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval.

Status: waiting_author.

This branch has not been deployed

No deployments
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.

3 participants