Skip to content

Commit

Permalink
Move ascent out of GlyphInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 18, 2023
1 parent ceb8723 commit d272027
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
16 changes: 8 additions & 8 deletions crates/epaint/src/text/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ pub struct GlyphInfo {
/// Unit: points.
pub advance_width: f32,

/// `ascent` value from the font metrics.
/// this is the distance from the top to the baseline.
///
/// Unit: points.
pub ascent: f32,

/// Texture coordinates.
pub uv_rect: UvRect,
}
Expand All @@ -59,7 +53,6 @@ impl Default for GlyphInfo {
Self {
id: ab_glyph::GlyphId(0),
advance_width: 0.0,
ascent: 0.0,
uv_rect: Default::default(),
}
}
Expand Down Expand Up @@ -255,6 +248,14 @@ impl FontImpl {
self.pixels_per_point
}

/// This is the distance from the top to the baseline.
///
/// Unit: points.
#[inline(always)]
pub fn ascent(&self) -> f32 {
self.ascent
}

fn allocate_glyph(&self, glyph_id: ab_glyph::GlyphId) -> GlyphInfo {
assert!(glyph_id.0 != 0);
use ab_glyph::{Font as _, ScaleFont};
Expand Down Expand Up @@ -305,7 +306,6 @@ impl FontImpl {
GlyphInfo {
id: glyph_id,
advance_width: advance_width_in_points,
ascent: self.ascent,
uv_rect,
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/epaint/src/text/text_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn layout_section(
chr,
pos: pos2(paragraph.cursor_x, f32::NAN),
size: vec2(glyph_info.advance_width, line_height),
ascent: glyph_info.ascent,
ascent: font_impl.map_or(0.0, |font| font.ascent()), // Failure to find the font here would be weird
uv_rect: glyph_info.uv_rect,
section_index,
});
Expand Down Expand Up @@ -359,7 +359,6 @@ fn replace_last_glyph_with_overflow_character(
let (font_impl, glyph_info) = font.glyph_info_and_font_impl(last_glyph.chr);
last_glyph.size = vec2(glyph_info.advance_width, line_height);
last_glyph.uv_rect = glyph_info.uv_rect;
last_glyph.ascent = glyph_info.ascent;

// reapply kerning
last_glyph.pos.x += extra_letter_spacing
Expand Down

0 comments on commit d272027

Please sign in to comment.