diff --git a/crates/epaint/src/text/font.rs b/crates/epaint/src/text/font.rs index 8fc6e9efc6d..3b601847b3a 100644 --- a/crates/epaint/src/text/font.rs +++ b/crates/epaint/src/text/font.rs @@ -468,6 +468,18 @@ impl Font { (Some(font_impl), glyph_info) } + pub(crate) fn ascent(&self) -> f32 { + if self.fonts.is_empty() { + self.row_height + } else { + let mut max_ascent = 0.0; + for font in &self.fonts { + max_ascent = f32::max(max_ascent, font.ascent()); + } + max_ascent + } + } + fn glyph_info_no_cache_or_fallback(&mut self, c: char) -> Option<(FontIndex, GlyphInfo)> { for (font_index, font_impl) in self.fonts.iter().enumerate() { if let Some(glyph_info) = font_impl.glyph_info(c) { diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 96dd067582d..41b4630c72a 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -172,7 +172,7 @@ fn layout_section( chr, pos: pos2(paragraph.cursor_x, f32::NAN), size: vec2(glyph_info.advance_width, line_height), - ascent: font_impl.map_or(0.0, |font| font.ascent()), // Failure to find the font here would be weird + ascent: font.ascent(), uv_rect: glyph_info.uv_rect, section_index, }); @@ -392,7 +392,7 @@ fn replace_last_glyph_with_overflow_character( chr: overflow_character, pos: pos2(x, f32::NAN), size: vec2(replacement_glyph_info.advance_width, line_height), - ascent: font_impl.map_or(0.0, |font| font.ascent()), // Failure to find the font here would be weird + ascent: font.ascent(), uv_rect: replacement_glyph_info.uv_rect, section_index, }); @@ -404,13 +404,13 @@ fn replace_last_glyph_with_overflow_character( let x = 0.0; // TODO(emilk): heed paragraph leading_space 😬 - let (font_impl, replacement_glyph_info) = font.font_impl_and_glyph_info(overflow_character); + let (_, replacement_glyph_info) = font.font_impl_and_glyph_info(overflow_character); row.glyphs.push(Glyph { chr: overflow_character, pos: pos2(x, f32::NAN), size: vec2(replacement_glyph_info.advance_width, line_height), - ascent: font_impl.map_or(0.0, |font| font.ascent()), // Failure to find the font here would be weird + ascent: font.ascent(), uv_rect: replacement_glyph_info.uv_rect, section_index, });