Don't panic when replacement glyph is not found (#4542)

I wanted to implement a font picker that loads all system fonts but ran
into panics due to missing glyphs. Falling back to an empty glyph when
none of the fallback glyphs are available avoids the panic.
This commit is contained in:
Ryan Bluth 2024-05-27 05:53:06 -04:00 committed by GitHub
parent 34672bc1bb
commit f0cbb18943
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 3 deletions

View File

@ -370,9 +370,11 @@ impl Font {
.glyph_info_no_cache_or_fallback(PRIMARY_REPLACEMENT_CHAR)
.or_else(|| slf.glyph_info_no_cache_or_fallback(FALLBACK_REPLACEMENT_CHAR))
.unwrap_or_else(|| {
panic!(
"Failed to find replacement characters {PRIMARY_REPLACEMENT_CHAR:?} or {FALLBACK_REPLACEMENT_CHAR:?}"
)
#[cfg(feature = "log")]
log::warn!(
"Failed to find replacement characters {PRIMARY_REPLACEMENT_CHAR:?} or {FALLBACK_REPLACEMENT_CHAR:?}. Will use empty glyph."
);
(0, GlyphInfo::default())
});
slf.replacement_glyph = replacement_glyph;