Skip to content

Commit 6f7d389

Browse files
committed
[TTF] GlyphMetrics can be scaled to a desired font size
1 parent 5f9f063 commit 6f7d389

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

rust_programs/ttf_renderer/src/metrics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ impl GlyphMetrics {
145145
(self.top_side_bearing as f64 * scale_y) as isize,
146146
)
147147
}
148+
149+
pub fn scale_to_font_size(&self, font_units_per_em: usize, font_size: &Size) -> Self {
150+
// TrueType fonts are scaled with reference to the height / point size.
151+
let scale_factor = font_size.height as f64 / (font_units_per_em as f64);
152+
self.scale(scale_factor, scale_factor)
153+
}
148154
}
149155

150156
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)