Skip to content

Conversation

danielwe
Copy link
Contributor

@danielwe danielwe commented Sep 22, 2025

This is my final set of fixes to the font patcher/icon scaling code. It builds on #8563 and there's not much reason to pay attention here until that one has been reviewed (the unique changes in this PR only touch the two nerd_font_* files and face.zig; the other 7 files in the diff are just #8563). However, I wanted to make sure the full set of changes/fixes I propose are out in the open, such that any substantial edits by maintainers (like in #7953) can take into account the full context.

I think this and the related patches should be considered fixes, not features, so I hope they can be considered for a 1.2.x release.

This PR fixes some bugs in the extraction of scale and alignment rules from the font_patcher script. Roughly in order of importance:

  • Nerd fonts apply an offset to some codepoint ranges when extracting glyphs from their original font (e.g., Font Awesome) and placing them in a Nerd Font. Rules are specified in terms of the former codepoints, but must be applied to the latter. This offset was previously not taken into account, so rules were applied to the wrong glyphs, and some glyphs that should have rules didn't get any.
  • Previously, the rules from every single patch set was included, but the embedded Symbols Only font doesn't contain all of them. Most importantly, there's a legacy patch set that only exists for historical reasons and is never used anymore, which was overwriting some other rules because of overlapping codepoint ranges. Also, the Symbols Only font contains no box drawing characters, so those rules should not be included. With this PR, irrelevant patch sets are filtered out.
  • Some patch sets specify overlapping codepoint ranges, though in reality the original fonts don't actually cover the full ranges and the overlaps just imply that they're filling each other's gaps. During font patching, the presence/absence of a glyph at each codepoint in the original font takes care of the ambiguity. Since we don't have that information, we need to hardcode which patch set "wins" for each case (it's not always the latest set in the list). Luckily, there are only two cases.
  • Many glyphs belong to scale groups that should be scaled and aligned as a unit. However, in font_patcher, the scale group is not used for horizontal alignment, unless the entire scale group has a single advance width (remember, the original symbol fonts are not monospace). This PR adds a bool flag alignment_horizontal_grouped to implement this rule.

There are some additional tweaks to ensure that each codepoint actually gets the rule it's supposed to when it belongs to multiple scale groups or patch sets, and to avoid setting rules for codepoints that don't exist in the embedded font.

@danielwe danielwe requested review from a team as code owners September 22, 2025 22:40
@danielwe
Copy link
Contributor Author

danielwe commented Sep 23, 2025

Fixes #8842

Specifically, the second bullet point above is the ticket. The scaling rules for box drawing characters needs to be excluded, since these codepoints are not present in the symbols only embedded font. The rules end up applying to glyphs that don't need them and that they weren't designed for.

Also fixes #8335

@00-kat 00-kat added the font Issue within the font stack (typically src/font) label Sep 23, 2025
@danielwe danielwe changed the title Final font patcher fixes fix(font): Final font patcher fixes Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
font Issue within the font stack (typically src/font)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants