-
Notifications
You must be signed in to change notification settings - Fork 690
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
Graceful handling of font files that fail to load (invalid font tables, bad format, etc.) #2991
Comments
|
The crash seems like a separate bug that should be fixed. |
I renamed the issue slightly in case anyone browsing our issue list is confused by this. I don't know if the rename helped but I didn't want people to think we didn't handle non-existent fonts. This issue is about fonts that exist that are invalid for whatever reason and we haven't programmed a way to handle it. |
This issue caused font rendering to break for me when printing Thai numerals 1 because Ghostty would fall back to a bitmap font 2 which are not supported, even though I would have also had TrueType font with Thai glyphs (Noto Sans Thai) to fall back to. To reproduce:
or $ ghostty +show-face --cp=0xE57
Unable to get face: error.CopyTableError After the printf ghostty would log something like this (the warning about CopyTableError was repeatedly printed every ~0.5 seconds or so after the fallback was found):
To work around the issue you can explicitly choose a font that has the glyph: $ ghostty --font-family="Noto Sans Thai" +show-face --cp=0xE57
U+E57 « ๗ » found in face “Noto Sans Thai”. this can also be specified as a secondary font in
Footnotes
|
We do not currently support bitmap fonts in a real capacity, and they often are missing some tables which we currently rely on for metrics, and we don't handle the metrics calculations failing gracefully right now. This needs to be fixed for the fontconfig discovery mechanism as well, so this does NOT close issue #2168 (it fixes the problem on macOS but not linux). This greatly alleviates the effect of #2991 since most cases I've seen that be a problem have been the accidental loading of a bitmap font; but the underlying issue still exists.
I can confirm its an issue with unicode bitmap font rendering as it crashes with Cozette. |
This should be mitigated significantly with #3550 on macOS. This prevents macOS from using CoreText in the fallback chain (or any chain really). This will be part of 1.0.1. |
Removing this issue from 1.0.1 since the mitigation is in place. Keeping the issue open to address more robustly in the future. |
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
We need to handle bad fonts (corrupted, or unsupported due to missing tables) better. Currently they cause rendering issues when they appear as fallbacks and they cause straight up crashes when set as the primary font. We need to handle this gracefully, and the font discovery mechanism(s) need to be updated to exclude bitmap fonts.
The text was updated successfully, but these errors were encountered: