Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust fallback font size to match glyph scale of primary font #3029

Open
kdien opened this issue Dec 20, 2024 · 4 comments
Open

Adjust fallback font size to match glyph scale of primary font #3029

kdien opened this issue Dec 20, 2024 · 4 comments
Labels
font Issue within the font stack (typically src/font)

Comments

@kdien
Copy link

kdien commented Dec 20, 2024

Certain fonts are just smaller by default, meaning I'd need to increase the font size for them to "look" the same with others. Examples are Inconsolata, Ubuntu Mono, Dank Mono, etc.

When using these fonts with the increased size, the built-in nerd font icons become bigger (makes sense since they follow the configured size) and hence look very disproportionate to the text.

(Reference Discord conversation: https://discord.com/channels/1005603569187160125/1319693664846348288)

@mitchellh
Copy link
Contributor

@qwerasd205 do you mind adding some additions details to this? It's unclear from the issue here what the actual bug or feature request or what this is. I think the title is likely wrong.

@mitchellh mitchellh added needs-confirmation A reproduction has been reported, but the bug hasn't been confirmed or reproduced by a maintainer. font Issue within the font stack (typically src/font) labels Dec 20, 2024
@qwerasd205
Copy link
Collaborator

It is something I plan to get around to some time soon- it's more of a feature request than a bug, since it's just to alleviate some undesirable but expected behavior. The idea is font-size-adjust-style adjustment of fallback font sizes to better harmonize them with the primary (configured) font, which among other things would have the effect of appropriately scaling the nerd font icons (though we would have to, and should anyway, separate the embedded nerd font icons in to a separate icons-only nerd font, rather than the patched JB mono we have right now).

If you wanna change this issue to be about that then "adjust fallback font size to match glyph scale of primary font" or something along those lines would be a better title.

@mitchellh mitchellh changed the title Disproportionate icon size for smaller fonts Adjust fallback font size to match glyph scale of primary font Dec 22, 2024
@mitchellh mitchellh removed the needs-confirmation A reproduction has been reported, but the bug hasn't been confirmed or reproduced by a maintainer. label Dec 22, 2024
@mitchellh
Copy link
Contributor

Got it thanks. I'm going to rename this issue and mark it as a feature then because I think its working fine, but an improvement on it can make it work better.

@mitchellh
Copy link
Contributor

Related: #3939

mitchellh added a commit that referenced this issue Jan 8, 2025
This refactor enables two very significant improvements to our font
handling, which I will be implementing next:
1. Automatically adjust size of fallback faces to better align with the
primary face, a la CSS
[`font-size-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size-adjust).
[^1]
2. Move glyph resizing/positioning out of GPU-land and in to
`renderGlyph` and apply alignment/resizing rules from the nerd fonts
patcher[^2] to the glyphs at rasterization time, so that we can ensure
exact cell fits and swap out our embedded JB Mono with an unpatched
version with a separate dedicated symbols-only nerd font.

In addition to being necessary prep work for those two changes, this PR
is also a minor but real stand-alone improvement. By only computing the
cell metrics for our primary font, we avoid a *lot* of wasted work when
loading fallback fonts, and also avoid that being a source of load
errors, which we don't yet handle gracefully[^3].

To validate this PR I've run the full set of font backend tests locally
on my Mac with no failures, and did a sanity check of running Ghostty
with both renderers and with CoreText and FreeType font backends and
then `cat`ing a file that requires fallback fonts to render, and
everything looks correct.

[^1]: #3029

[^2]: The alignment and resizing rules for the nerd font symbols are
defined in the patcher
[here](https://github.com/ryanoasis/nerd-fonts/blob/6d0b8ba05af0d1380905aee1a136c1dedf71c1db/font-patcher#L866-L1151)

[^3]: #2991
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

No branches or pull requests

3 participants