sugarloaf: preserve matched CoreText font faces - #1963
Open
aymanbagabas wants to merge 2 commits into
Open
aymanbagabas wants to merge 2 commits into
aymanbagabas wants to merge 2 commits into
Conversation
CoreText selects the requested named face, but reopening its file loads the first descriptor. Variable fonts can therefore render regular and bold text with the same thin face. Retain the matched CoreText handle through font loading. Keep explicit weight overrides and the existing path-based loader for fallback fonts. Add a regression test with bundled Cascadia Code variable fonts. Cover regular, bold, italic, bold italic, distinct glyph masks, and an explicit weight override. Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Coverage checks and advance measurements still reopen the first face instead of using the retained rendering face.
Review effort: Balanced
Findings: 1
What changed in this PR
Preserves matched CoreText font faces on macOS so named variable-font styles survive loading.
Changes:
- Loads matched font handles directly while retaining path-based fallback loading.
- Adds regression coverage for named styles, distinct glyph masks, and explicit weight overrides.
| File | Description |
|---|---|
| sugarloaf/src/font/mod.rs | Retains matched handles and adds variable-font regression coverage. |
| sugarloaf/src/font/macos.rs | Returns the matched handle alongside its path. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| } | ||
| } | ||
| info!("Font '{family}' matched via CoreText at {}", path.display()); | ||
| FindResult::Found(FontData::from_handle_macos(handle, path, slot, &font_spec)) |
Prefer the retained CoreText handle for glyph coverage, advance measurement, and primary-font cascade selection. Keep path and byte fallbacks when no handle is stored. Add a collection-face regression test that checks coverage and advances against the selected face rather than descriptor zero. Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
This branch has not been deployed
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.

Summary
Fix identical regular and bold text on macOS with named variable-font styles.
CoreText selects the requested face, but Rio keeps only its file path. The loader then reopens the file and selects its first descriptor. With JetBrains Mono, both Medium and Bold resolve to the same variable-font file and reopen as Thin.
Retain the matched CoreText handle through font loading instead. This preserves the selected style, variable axes, and collection face. Explicit weight overrides still apply. The existing path-based loader remains available for fallback fonts.
Before:
After:
Reproduction
With the variable version of JetBrains Mono installed, configure:
Run:
Before this fix, both styles use Thin and produce identical glyph pixels. After this fix, they use the requested Medium and Bold faces.
Testing
cargo test -q -p sugarloaf --lib font::: 80 tests passed on macOS.cargo build -q -p rioterm: passed.git diff --check: passed.