Skip to content

Commit 5f9f063

Browse files
committed
[TTF] Add centralized logic to determine a font’s line height
1 parent 9fa8613 commit 5f9f063

File tree

1 file changed

+10
-0
lines changed
  • rust_programs/ttf_renderer/src

1 file changed

+10
-0
lines changed

rust_programs/ttf_renderer/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ impl Font {
9898
Some(glyph_index) => self.glyphs.get(glyph_index.0),
9999
}
100100
}
101+
102+
pub fn scaled_line_height(&self, font_size: Size) -> isize {
103+
let scale_factor = font_size.height as f64 / self.units_per_em as f64;
104+
// TODO(PT): A 'scale' method for the layout metrics as a whole, similar to the glyph metrics
105+
let scaled_ascent = self.global_layout_metrics.ascent as f64 * scale_factor;
106+
let scaled_descent = self.global_layout_metrics.descent as f64 * scale_factor;
107+
let scaled_line_gap = self.global_layout_metrics.line_gap as f64 * scale_factor;
108+
let scaled_line_height = scaled_ascent - scaled_descent + scaled_line_gap;
109+
scaled_line_height as isize
110+
}
101111
}
102112

103113
pub fn parse(font_data: &[u8]) -> Font {

0 commit comments

Comments
 (0)