Skip to content

Fix: list and render installed system fonts (#4) - #9

Merged
h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
justinjohn0306:fix/system-fonts-in-list
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
justinjohn0306:fix/system-fonts-in-list

Conversation

@justinjohn0306

Copy link
Copy Markdown
Contributor

Summary

Fixes #4. The font dropdown listed a hardcoded 17 names and cells always rendered in the built-in role font, so a font installed on the machine could not be listed or chosen. Opening an XLSX that used an installed font showed the text correctly (the file's font resolved), but the user could not pick any installed font from the UI.

Root cause

Two defects in crates/ui-egui, both from one constraint:

  1. The font combo iterated ribbon::FONTS, a fixed array of 17 names. Nothing enumerated the machine's fonts.
  2. theme::cell_family reduced any name to one of 8 pre-bound roles, so a chosen name would have rendered as the Calibri fallback regardless.

The reason it was hardcoded: egui panics when asked for a FontFamily::Name that was never bound to font data (epaint text/fonts.rs:1025). Only the 8 built-in roles were ever bound. So a fix must both list installed families and register their bytes.

Changes

  • New crates/ui-egui/src/fonts.rs — scans the platform font folders, reads each file's name table with skrifa to catalog families/weights/styles. skrifa is already compiled transitively through epaint at the same 0.44 version, so it adds no new build. Damaged or non-font files and symlink loops yield nothing, never a panic. The scan runs on a background thread; families() (non-blocking) feeds the combos: the standard names first, then installed families A–Z.
  • Binding — theme::font_definitions(used) binds the workbook's installed fonts as egui families keyed fnt:{family}:{b|n}{i|n}, each chained to egui's default proportional fonts so emoji/odd glyphs still render. A global bound-family registry is the safety gate; cell_family returns the installed family only when it is bound, else the previous bucketing, so it never names an unbound family.
  • Wiring (lib.rs) — setup_context starts the scan; logic() rebinds when the workbook's (uid, revision) changes, with a one-frame skip-paint gate (egui activates new definitions on the next pass), reusing the existing startup fonts_ready pattern.
  • wasm — everything no-ops; the list stays the standard set.

Follows the sibling-app house pattern (slidecraft/wordcraft crates/fonts): hand-rolled platform scan + skrifa name-table reads, no new font-discovery dependency.

Testing

  • cargo xtask ci — all 7 steps pass (fmt, clippy -D warnings, tests, assets, layers, wasm, parity)
  • New regression tests: scanner over a temp dir with real font bytes (epaint_default_fonts), damaged/non-font files yield nothing, folder-listed-twice read once, symlink loop terminates; cell_family fuzz proves arbitrary names never return an unbound family; binding a family binds all four roles with data behind every chained key
  • Loaded an existing XLSX and confirmed its fonts appear in the list and render; picked an installed font and confirmed cells render in it
  • Rendered the Home tab offscreen — no regression

Notes

To get the gate green I also fixed pre-existing clippy lints in untouched crates (core, numfmt, functions, engine): the local toolchain's clippy is newer than whatever last linted the tree and no rust-toolchain.toml is pinned. Confirmed pre-existing via git stash on pristine main. These are behavior-preserving; one was a genuine dead-code bug (|| true in engine/src/cmd/file.rs and ui-egui/src/grid.rs). Pinning a toolchain would be the real fix, left out of scope here.

The font dropdown showed a hardcoded 17-name list and cells always
rendered in the built-in Calibri/role font, so a font installed on the
machine could not be listed or chosen. Both trace to one constraint:
egui panics when asked for a FontFamily::Name that was never bound to
font data, so only the 8 built-in roles were ever bound.

Scan the platform font folders for installed families (a bounded read of
each file's name table via skrifa, already compiled transitively through
epaint), bind the faces a workbook actually uses into egui as
fnt:{family}:{b|n}{i|n} roles chained to the defaults, and offer the
installed families in the font combos after the standard set. cell_family
returns the installed role when it is bound, else the previous bucketing,
so it never names an unbound family. The scan runs in the background and
the first frame that rebinds skips painting, like the existing startup
gate. Native only; wasm keeps the standard list.

Incidental: newer local clippy flagged pre-existing lints in untouched
crates (no toolchain is pinned); fixed behavior-preservingly so the gate
passes.
@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thank you — the scanning design is sound (background thread, name table only, unbound-family panic guard, symlink-loop tests). It needs a rebase onto the font-fallback work landing now (#38 → #31 → #104), and: (1) bind_faces builds [face, regular] + default without the CJK/Thai/Hebrew fallback keys, so CJK in a cell set to an installed Latin font reverts to tofu — please append the fallback chain; (2) cache font bytes: every used-font change rebuilds font_definitions and re-reads all files (incl. ~20 MB CJK files), and bind_faces reads before its dedupe check; (3) the scan fs::reads whole files up to 64 MB — reading the header/name table is enough; (4) drop the duplicated clippy changes (already on main). The process-global BOUND registry is also fragile with multiple egui contexts in one process (kittest/snapshot).

If you haven't already, please come join us on Discord: https://discord.gg/artcraft — happy to talk any of this through there.

… per-language font set and fallback faces; only families that survive drop_unparseable_fonts count as bound; a language switch rebinds them (review fix-up for storytold#9)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 4dca02c into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Merged — thank you for the contribution! (I merged main into your branch: workbook fonts now bind on top of main's per-language font set and CJK/Thai/Hebrew fallback faces, only families that survive #277's unparseable-font check count as bound, and switching the interface language rebinds them.)

If you haven't already, come join us on the ArtCraft Discord: https://discord.gg/artcraft

mo2menmuhamed added a commit to mo2menmuhamed/gridcraft that referenced this pull request Oct 12, 2026
…a bar

- General-aligned text whose first letter is Arabic or Hebrew sits on the
  right of its cell and spills left, like Excel's default "Context" reading
  order (`bidi::starts_rtl`, UAX storytold#9 P2-P3). Right-to-left sheets are
  mirrored as a whole and already put it there, so they are unchanged.
- Sheet tab names and the formula bar (when not editing) are laid out by
  `bidi::layout_job`, so an Arabic sheet name or cell content reads right to
  left with its numbers in order.

While editing, the cell editor and formula bar still show text left to
right: egui's TextEdit maps the caret, clicks and selection onto glyphs in
stored order, and reordering them would put the caret on the wrong letter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hasan-sdaif added a commit to hasan-sdaif/gridcraft that referenced this pull request Oct 13, 2026
egui 0.36 lays a label's runs left to right and runs no bidi over them
(its text code still carries TODO(emilk): heed bidi characters), so an
Arabic label read with its words in reverse order: each word was shaped
correctly once one of the theme's Arabic faces covered its glyphs, but
it was drawn at the wrong end of the line. Arabic's translations are now
handed out in visual order (i18n/bidi.rs, UAX storytold#9 with an RTL base via
unicode-bidi, cached per label): the runs left to right as a right-to-
left reader meets them, the letters inside each run in logical order
because harfrust reverses the run itself, brackets mirrored — the pairs
of BidiMirroring.txt, guillemets included. What a user types keeps its
logical order, and a headless layout test pins the order the labels
come out in, so it cannot regress.

The dictionary also translates the seventeen strings that landed on
main since the branch began (the page margins, the recent-files ages,
"Enable AutoComplete for cell values", "100%"), and drops eight stray
RLM marks (epaint strips bidi controls as invisible; the pass makes
them unnecessary).
hasan-sdaif added a commit to hasan-sdaif/gridcraft that referenced this pull request Oct 13, 2026
UAX storytold#9 L2 reverses a right-to-left level's runs, and a `{placeholder}`
sitting between Arabic words came out reversed (`}n{`) — the reordering
was treating the label's own syntax as text, so the fill could no
longer find it. Each placeholder now rides through the pass as one
private-use character (restored afterwards, per placeholder, so a
reordered sentence still finds its own), and curly brackets are left
out of the mirror table for the same reason: BidiMirroring.txt pairs
them, but in an interface label they are almost always a placeholder's
own syntax. Found by replaying the whole catalog through a Python
UAX storytold#9 replica of the pass.
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.

System fonts on pc do not load in fonts list

3 participants