mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Handle having no fonts (missing "default_fonts" feature) without a crash
This commit is contained in:
@@ -215,7 +215,7 @@ impl Font {
|
|||||||
fonts,
|
fonts,
|
||||||
characters: RwLock::new(None),
|
characters: RwLock::new(None),
|
||||||
replacement_glyph: Default::default(),
|
replacement_glyph: Default::default(),
|
||||||
pixels_per_point: 0.0,
|
pixels_per_point: 1.0,
|
||||||
row_height: 0.0,
|
row_height: 0.0,
|
||||||
glyph_info_cache: Default::default(),
|
glyph_info_cache: Default::default(),
|
||||||
};
|
};
|
||||||
@@ -318,10 +318,13 @@ impl Font {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn glyph_info_and_font_impl(&self, c: char) -> (&FontImpl, GlyphInfo) {
|
pub(crate) fn glyph_info_and_font_impl(&self, c: char) -> (Option<&FontImpl>, GlyphInfo) {
|
||||||
|
if self.fonts.is_empty() {
|
||||||
|
return (None, self.replacement_glyph.1);
|
||||||
|
}
|
||||||
let (font_index, glyph_info) = self.glyph_info(c);
|
let (font_index, glyph_info) = self.glyph_info(c);
|
||||||
let font_impl = &self.fonts[font_index];
|
let font_impl = &self.fonts[font_index];
|
||||||
(font_impl, glyph_info)
|
(Some(font_impl), glyph_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_info_no_cache_or_fallback(&self, c: char) -> Option<(FontIndex, GlyphInfo)> {
|
fn glyph_info_no_cache_or_fallback(&self, c: char) -> Option<(FontIndex, GlyphInfo)> {
|
||||||
|
|||||||
@@ -72,8 +72,10 @@ fn layout_section(
|
|||||||
paragraph.empty_paragraph_height = font_height; // TODO: replace this hack with actually including `\n` in the glyphs?
|
paragraph.empty_paragraph_height = font_height; // TODO: replace this hack with actually including `\n` in the glyphs?
|
||||||
} else {
|
} else {
|
||||||
let (font_impl, glyph_info) = font.glyph_info_and_font_impl(chr);
|
let (font_impl, glyph_info) = font.glyph_info_and_font_impl(chr);
|
||||||
if let Some(last_glyph_id) = last_glyph_id {
|
if let Some(font_impl) = font_impl {
|
||||||
paragraph.cursor_x += font_impl.pair_kerning(last_glyph_id, glyph_info.id)
|
if let Some(last_glyph_id) = last_glyph_id {
|
||||||
|
paragraph.cursor_x += font_impl.pair_kerning(last_glyph_id, glyph_info.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paragraph.glyphs.push(Glyph {
|
paragraph.glyphs.push(Glyph {
|
||||||
|
|||||||
Reference in New Issue
Block a user