Repository navigation
Fix: list and render installed system fonts (#4) - #9
Conversation
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.
|
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) 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>
|
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 |
…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>
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).
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.
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:ribbon::FONTS, a fixed array of 17 names. Nothing enumerated the machine's fonts.theme::cell_familyreduced 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::Namethat was never bound to font data (epainttext/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
crates/ui-egui/src/fonts.rs— scans the platform font folders, reads each file'snametable with skrifa to catalog families/weights/styles. skrifa is already compiled transitively through epaint at the same0.44version, 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.theme::font_definitions(used)binds the workbook's installed fonts as egui families keyedfnt:{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_familyreturns the installed family only when it is bound, else the previous bucketing, so it never names an unbound family.lib.rs) —setup_contextstarts 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 startupfonts_readypattern.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)epaint_default_fonts), damaged/non-font files yield nothing, folder-listed-twice read once, symlink loop terminates;cell_familyfuzz proves arbitrary names never return an unbound family; binding a family binds all four roles with data behind every chained keyNotes
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 norust-toolchain.tomlis pinned. Confirmed pre-existing viagit stashon pristinemain. These are behavior-preserving; one was a genuine dead-code bug (|| trueinengine/src/cmd/file.rsandui-egui/src/grid.rs). Pinning a toolchain would be the real fix, left out of scope here.