use crate::font::GlyphData;
pub struct PageMetrics {
pub width: u32,
pub height: u32,
pub scale: f64,
pub baseline_y: f64,
}
pub fn compute_metrics(glyphs: &[GlyphData], font_size: u32, units_per_em: u16) -> PageMetrics {
let upem = if units_per_em == 0 { 1 } else { units_per_em };
let scale = font_size as f64 / upem as f64;
let total_advance: f64 = glyphs.iter().map(|g| g.advance_width as f64).sum();
let width = (total_advance * scale).ceil() as u32;
let height = (font_size as f64 * 1.5).ceil() as u32;
let baseline_y = font_size as f64 * 1.1;
PageMetrics {
width,
height,
scale,
baseline_y,
}
}
pub fn transform_point(x: f32, y: f32, scale: f64, offset_x: f64, baseline_y: f64) -> (f64, f64) {
let sx = x as f64 * scale + offset_x;
let sy = -(y as f64) * scale + baseline_y;
(sx, sy)
}