-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,8 @@ pub struct FontImpl { | |
pixels_per_point: f32, | ||
glyph_info_cache: RwLock<ahash::HashMap<char, GlyphInfo>>, // TODO(emilk): standard Mutex | ||
atlas: Arc<Mutex<TextureAtlas>>, | ||
|
||
fallbacks: [char; 2], | ||
} | ||
|
||
impl FontImpl { | ||
|
@@ -132,6 +134,7 @@ impl FontImpl { | |
pixels_per_point, | ||
glyph_info_cache: Default::default(), | ||
atlas, | ||
fallbacks: tweak.fallbacks.unwrap_or(['◻', '?']), | ||
} | ||
} | ||
|
||
|
@@ -363,20 +366,23 @@ impl Font { | |
glyph_info_cache: Default::default(), | ||
}; | ||
|
||
const PRIMARY_REPLACEMENT_CHAR: char = '◻'; // white medium square | ||
const FALLBACK_REPLACEMENT_CHAR: char = '?'; // fallback for the fallback | ||
|
||
let replacement_glyph = slf | ||
.glyph_info_no_cache_or_fallback(PRIMARY_REPLACEMENT_CHAR) | ||
.or_else(|| slf.glyph_info_no_cache_or_fallback(FALLBACK_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)) | ||
}) | ||
}) | ||
.unwrap_or_else(|| { | ||
#[cfg(feature = "log")] | ||
log::warn!( | ||
"Failed to find replacement characters {PRIMARY_REPLACEMENT_CHAR:?} or {FALLBACK_REPLACEMENT_CHAR:?}. Will use empty glyph." | ||
); | ||
log::warn!("Failed to find replacement characters. Will use empty glyph."); | ||
(0, GlyphInfo::default()) | ||
}); | ||
slf.replacement_glyph = replacement_glyph; | ||
|
||
slf | ||
} | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Well, |
||
} | ||
|
||
/// Can we display all the glyphs in this text? | ||
|
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?