-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Try to improve support for .notdef glyphs through FontTweak
#4644
base: master
Are you sure you want to change the base?
Conversation
@@ -434,7 +440,7 @@ impl Font { | |||
|
|||
/// 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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, glyph_info_no_cache_or_fallback
doesn't use the cache, so it is marginally slower.
When would you want to have a different replacement char? |
// 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)) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call glyph_info_no_cache_or_fallback
here like before?
The idea consists of adding
fallbacks
to theFontTweak
structure, 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
MaterialSymbolsSharp
in 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_parser
seemingly not actually loading .notdef.