Try to improve support for .notdef glyphs through FontTweak#4644
Open
Warpten wants to merge 1 commit intoemilk:mainfrom
Open
Try to improve support for .notdef glyphs through FontTweak#4644Warpten wants to merge 1 commit intoemilk:mainfrom
FontTweak#4644Warpten wants to merge 1 commit intoemilk:mainfrom
Conversation
Warpten
commented
Jun 9, 2024
| /// Can we display this glyph? | ||
| pub fn has_glyph(&mut self, c: char) -> bool { | ||
| self.glyph_info(c) != self.replacement_glyph // TODO(emilk): this is a false negative if the user asks about the replacement character itself 🤦♂️ | ||
| self.glyph_info_no_cache_or_fallback(c).is_some() |
Author
There was a problem hiding this comment.
This seemed a nice "bonus" to-do solving, slightly unrelated to the issue at hand; I'm suspecting there's a reason you chose not to do this in the first place?
Owner
There was a problem hiding this comment.
Well, glyph_info_no_cache_or_fallback doesn't use the cache, so it is marginally slower.
Owner
|
When would you want to have a different replacement char? |
Author
emilk
reviewed
Jun 23, 2024
Comment on lines
+369
to
+380
| // For each font, find the first available fallback character | ||
| slf.replacement_glyph = slf | ||
| .fonts | ||
| .iter() | ||
| .enumerate() | ||
| .find_map(|(font_index, font_impl)| { | ||
| font_impl.fallbacks.iter().find_map(|chr| { | ||
| font_impl | ||
| .glyph_info(*chr) | ||
| .map(|glyph_info| (font_index, glyph_info)) | ||
| }) | ||
| }) |
Owner
There was a problem hiding this comment.
Why not call glyph_info_no_cache_or_fallback here like before?
13 tasks
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.

The idea consists of adding
fallbacksto theFontTweakstructure, which then get used in egui'sFont(actually a wrapper over multipleFontImpl) to identify fallback characters. We look through each wrappedFontImpl, stopping in the first fallback character we found, defaulting to the empty glyph if none is found.Example output when replacing the user font by

MaterialSymbolsSharpin the egui custom font example:Note that as it is (mostly due to my very limited understanding of fonts in general), this isn't enough to load .notdef properly, even with a user-definied fallback character set. I suspect this however has to do with
ttf_parserseemingly not actually loading .notdef.