Closed
Conversation
The font matcher only checked bold/italic symbolic traits, taking the first match from CoreText's arbitrary enumeration order. For families with width variants (e.g. Monaspace Neon NF has Regular, SemiWide, and Wide variants), this could select the wrong variant -- "Wide Medium" instead of "Regular". Score candidates by width distance from normal (0.0) and weight distance from target, preferring the closest match. Also add diagnostic logging: on first encounter of a font family, log all available variants with their weight/width/bold/italic traits, then log each selected variant with its advance width. Visible with ALACRITTY_LOG=info or ALACRITTY_LOG=debug.
Author
|
Note on approach: DirectWrite handles this natively via |
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
get_matching_face()selecting wrong font variant for families with width variants on macOSProblem
The font matcher only checked bold/italic symbolic traits and took the first match from CoreText's arbitrary enumeration order. For families with width variants (e.g. Monaspace Neon NF which has Regular, SemiWide, and Wide variants for each weight), this selected the wrong variant.
Example with Monaspace Neon NF (42 variants):
This caused cell width inflation (24.880px vs correct 19.840px) and visually wrong font rendering.
Fix
Replace the first-match approach in
get_matching_face()with a scoring system that:width_penalty * 10.0 + weight_penaltywidth_penalty: distance from normal width (0.0 in CoreText's normalized scale)weight_penalty: distance from target weight (0.0 for normal, 0.4 for bold)This matches the behavior of FreeType/fontconfig (Linux) and DirectWrite (Windows), which already handle width correctly:
fc_font_sort()which considers widthFontStretch::NormalDiagnostic logging
On first encounter of a font family, logs all available variants with their normalized weight, width, and symbolic bold/italic traits. Then logs each selected variant with its advance width.
Visible with
ALACRITTY_LOG=info(orALACRITTY_LOG=debug):Platform scope
macOS only. The other backends already handle this correctly.