Repository navigation
feat(viewer): draw text the embedded font lacks with host fonts - #442
Merged
Merged
Conversation
The thumbnail label and the attention banner now draw characters that Geist Medium lacks, such as CJK, Arabic and Hebrew, with the first host font that has them. fontdb reads the fontconfig font directories in pure Rust on the first such character, so Latin text never scans them. unicode-bidi orders right-to-left runs, and swash joins Arabic letters. Only characters no host font draws become an ellipsis. Closes #421
Keep owned bytes for retained host fonts, so a font file that shrinks later cannot crash the viewer with SIGBUS. Mirror paired punctuation in right-to-left runs, pick a font that draws a whole cluster, and treat default ignorable code points as text that needs no font. Prefer the CJK face of the locale's region, and strip bidi controls from attention messages.
find_cluster now searches only loaded fonts, and font_of first loads the characters the embedded font lacks with one batched find_all. Many distinct clusters that no font covers no longer scan the host fonts once each. The marks test also requires nonzero glyph ids.
Layout now loads every character the embedded font lacks with one scan, so the one-scan bound holds for any caller, not only after displayable.
A right-to-left run draws a mirrored character, such as U+220B for U+2208, that the text itself may not contain, so each one cost its own host scan.
…1-31 fontdb uses ttf-parser to read installed host fonts; the advisory names no vulnerability. Replacement is tracked in #443.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The native viewer draws its text with one embedded font, Geist Medium, which lacks CJK, Arabic, Hebrew, Greek, Thai, Devanagari and more. A character Geist cannot draw is now drawn with the first host font that has it. Geist stays the primary font. The attention banner (an agent's
request_takeovermessage) and the thumbnail label use the fallback, and the ellipsis from #367 now stands only for characters no host font can draw.How it works.
fallback.rsfinds host fonts through fontdb in pure Rust, with no bundled font and no new C runtime library (lddon the release binary shows only libc, libm and libgcc_s). The font directories fontconfig names are scanned once, on the first character Geist lacks, so Latin text never pays for it. Laying out a text costs at most one scan, including the mirrored characters that right-to-left runs draw. A font the viewer keeps is read into memory when first chosen, so a font file truncated later cannot crash the viewer. The scan itself still maps each file only while it reads it. Text is ordered with unicode-bidi: pure Arabic or Hebrew reads right to left with joined forms, and brackets in right-to-left runs are mirrored. A combining mark takes a loaded font that draws its whole cluster. Default-ignorable characters, such as U+FE0F, never become an ellipsis. CJK faces prefer the region named inLC_ALL,LC_CTYPEorLANG. Bidi control characters are stripped from the attention message, so U+202E cannot reverse what the human reads; the host already refuses format characters in takeover messages, so this is defense in depth.Closes #421
ldd; live test421/before-live-test.log("cjk: label ink 0" on the old code)421/qa-*.png,421/round2/qa-*.png,421/round3/after-*.png421/round2/before/,421/round3/before-test.log,421/round4/,421/round5/421/round3/qa-before.log,421/round3/qa-after.logEvidence paths are under
~/.pickforge/investigations/on the review host.Memory: a kept face is read whole, and for a TTC that is the whole collection. On the QA host the CJK face is
NotoSansCJK-Medium.ttc, so a CJK label raised the viewer from 19.6 MB to 38.3 MB, and the warning sign, which also comes from that file, costs the same (421/round2/rss.txt). Before, these bytes were shared page cache through a map; now they are private heap, read once per viewer.CI's rust job has no CJK or Arabic fonts, so those host-font tests skip there; the scan, locale, retain and bidi tests do not need host fonts.
Reviews. Sol round 1: 6/10 (SIGBUS on a truncated mapped font, bracket mirroring, combining marks). Fable round 1: 8/10 (variation selectors, CJK region, bidi controls in the banner). All six were fixed in 972607f, each with a test. Round 2: Sol 9/10 (test nit), Fable 8/10 (one scan per uncovered cluster could stall the UI about 5 s, and the override QA shot was missing), fixed in 866b01f. Fable round 3: 8/10, the one-scan bound relied on callers; 36c69df moves the batch into layout. Sol round 4: 5/10, mirrored characters were not in the batch; fixed in 54ca515. Sol round 5: 10/10, no findings.
Declined: right alignment of right-to-left banners, the "Sans" family name heuristic, CI font packages, and skipping visible format characters such as U+0600 in the batch (that would draw them as empty boxes). Follow-ups from QA: #438 (the banner wrap can split a base character from its mark) and #439 (a mark that no font draws together with its base shows as an empty box).
Checks: full vitest coverage run with the desktop, window, wait, browser and viewer requirements on at 30e4811 (191 files, 3427 passed, 4 skipped) and
PICKFORGE_REQUIRE_XVFB=1 cargo test --workspace --locked(342 passed). After the last two viewer commits: cargo fmt, clippy with-D warnings, the workspace cargo tests (342 passed) and the three native viewer vitest files (34 passed). eabe1d2 merges main, which changed only TypeScript. PickCheck 0.4.0 against main is clean, and a local gitleaks scan of the branch is clean.Dependency audit:
fontdbbrings inttf-parser0.25, which RUSTSEC-2026-0192 marks as unmaintained (no known vulnerability). 0be90fe adds anosv-scanner.tomlexception with a reason and an expiry of 2027-01-31, as that file requires. #443 tracks moving host font discovery offttf-parserbefore then. A localosv-scanner scan source --recursive ./is clean.