Skip to content

Fonts: bound workbook families fall back to the interface chain (no CJK tofu) - #2408

Open
dantehe729 wants to merge 1 commit into
storytold:mainfrom
dantehe729:fix/bound-font-cjk-fallback
Open

dantehe729 wants to merge 1 commit into
storytold:mainfrom
dantehe729:fix/bound-font-cjk-fallback

Conversation

@dantehe729

@dantehe729 dantehe729 commented Oct 24, 2026 •

Copy link
Copy Markdown

Summary

Once the installed-font scan actually runs (#974), every workbook font that gets bound draws Chinese, Japanese, Korean, Thai and Hebrew text as tofu, including plain Latin families such as Calibri.

font_definitions_with bound the workbook families before FontFamily::Proportional was replaced with the UI chain. bind_faces appends the Proportional chain as the fallback, so at that point it still appended egui's default chain (Ubuntu-Light, NotoEmoji-Regular, emoji-icon-font), which has no script faces. A cell in Calibri holding 满分小学霸 双11销售盘点 rendered the digits and nothing else.

This change binds the workbook families after the Proportional chain becomes the UI chain. Each bound family then ends with sys-cell and the script fallback faces (sys-cjk-han-zh, sys-cjk-han-ja, sys-cjk-hangul, sys-thai, sys-hebrew, sys-symbols), the same as the built-in roles.

On main the binding never runs, because nothing starts the scan in the apps (#974). So this bug only shows up together with #974, #1179 or #1931. The fix is independent of those PRs and works with any of them.

Changes

  • theme::font_definitions_with resolves used to (name, faces) pairs and calls a new private font_definitions_binding, which binds them after the Proportional chain is set. The change is mechanical: the binding loop moves below the UI-chain step.

  • New test a_bound_workbook_font_falls_back_to_the_interface_chain: it binds a temporary Ubuntu face and asserts that all four role chains end with the UI chain. It fails with the old order:

    fnt:Ubuntu:nn: ["fnt-src:…Ubuntu-Light.ttf:0", "Ubuntu-Light", "NotoEmoji-Regular", "emoji-icon-font"]
    should end with the UI chain ["sys-ui", "Ubuntu-Light", "NotoEmoji-Regular", "emoji-icon-font", "sys-cell",
    "sys-cjk-han-zh", "sys-cjk-han-ja", "sys-cjk-hangul", "sys-thai", "sys-hebrew", "sys-symbols"]
    

    It passes with this change.

Validation (Windows 10, Simplified Chinese fonts)

  • I ran the desktop app with the scan started, as in Fonts: start the installed-font scan in the app (installed fonts were never listed or rendered) #974, plus this fix. Cells set in Calibri, 微软雅黑, 方正兰亭粗黑简体, 京东正黑体, 宋体 and 楷体 all render their Chinese text in the expected face. Without this fix, all of them showed tofu.
  • cargo fmt --all -- --check
  • cargo clippy -p gridcraft-ui-egui --all-targets -- -D warnings
  • cargo test -p gridcraft-ui-egui --lib -- theme:: fonts::: 32 passed.
  • cargo check -p gridcraft-ui-egui --target wasm32-unknown-unknown

I did not run the full cargo xtask ci locally, because the whole ui-egui suite takes more than 30 minutes on this machine. CI will cover the rest.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved font fallback for workbook text so it follows the interface’s font fallback settings. This helps text using Ubuntu font styles display more consistently when a character is unavailable in the selected font.

…JK tofu)

font_definitions_with bound the workbook's installed families before the
Proportional chain became the UI chain, so bind_faces appended egui's
Latin-only default chain: once the font scan runs (storytold#974), a cell in any
bound family (even Calibri) drew Chinese, Japanese, Korean, Thai and Hebrew
as tofu. Bind them after the UI chain is in place, so each bound family ends
with the cell font and the script fallback faces like the built-in roles.

Regression test: a_bound_workbook_font_falls_back_to_the_interface_chain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 24, 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 b8771d5 and 395c7c5.

Files selected for processing: 1
  • crates/ui-egui/src/theme.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

The font-definition path now binds installed workbook font faces after setting the proportional family to the UI chain. A test checks that all four Ubuntu style-role chains end with the UI chain.

Changes: Workbook font binding

Layer / File(s) Summary
Bind workbook faces with the UI chain
crates/ui-egui/src/theme.rs
The font-definition path collects installed workbook faces and binds them after setting the proportional family to the UI chain. A test checks the UI chain on all four Ubuntu style roles.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: justinjohn0306

Merge Risk: Minimal · up to 395c7

Workbook fonts are set up to inherit the UI fallback chain. No issue identified here calls for delaying the merge.

Architecture risk: Medium · up to 395c7

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/ui-egui/src/theme.rs: font_definitions_with now collects installed workbook families and their faces, then passes them to the new private font_definitions_binding helper.
  • observed — Modified behavior in crates/ui-egui/src/theme.rs: Removed the earlier loop that bound installed workbook families before interface-family fallback adjustments.
  • observed — Modified behavior in crates/ui-egui/src/theme.rs: Installed workbook faces are now bound after the proportional family is set to the UI chain, passing each collected family and its faces to bind_faces.
  • observed — Modified behavior in crates/ui-egui/src/theme.rs: Added a test that creates a temporary Ubuntu face, builds definitions for Chinese, and checks that all four bound Ubuntu style-role chains end with the UI chain; it restores the standard bound roles and removes the temporary directory.

Reliability and maintainability

  • inferred — Risk-relevant change factors for crates: blast_radius_1; direct_dependents_1
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly states the main change: bound workbook font families now fall back to the interface chain to prevent CJK tofu.
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.
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.

@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 head of the diff: fonts bound to workbook families fall back to the interface chain, so there is no CJK tofu. The theme gathers the installed families among those used, gets their faces and passes them to font_definitions_binding, which builds the definitions with the interface fallback after each bound family. A family that the workbook names and the machine has should still draw its own glyphs, with CJK taken from the fallback chain only for missing characters, as Excel does. The fallback chain is the same one as in gridcraft#2324 (Khmer) and the related PRs, so the order of the chain should be decided once. Building font definitions for every used family is expensive, so the result should be cached until the set of used families changes. I have not run it, and no exact-head CI result exists for this head. Nothing was run.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

Aimarmndz added a commit to Aimarmndz/gridcraft that referenced this pull request Nov 2, 2026
From @RockerHX's review: Arial, Tahoma and Verdana, each regular, bold,
italic and bold italic, must end with the interface chain of their
weight (ui-bold for bold roles, ui otherwise) and draw "中文ABC2026".
It covers the CJK fallback order of storytold#2408 as well as storytold#2035. It's a
separate test binary because it runs the process-wide font scan.

On macOS 27 all 12 roles are checked and pass; with font_setup.rs and
fonts.rs from main it fails with "fnt:Arial:nn must inherit ui".

Co-authored-by: RockerHX <5380764+RockerHX@users.noreply.github.com>

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.

2 participants