Skip to main content

ass_renderer/layout/
metrics.rs

1//! Text metrics for layout calculations
2
3/// Text metrics for layout calculations
4#[derive(Debug, Clone)]
5pub struct TextMetrics {
6    pub width: f32,
7    pub height: f32,
8    pub ascent: f32,
9    pub descent: f32,
10    pub line_gap: f32,
11    pub baseline: f32,
12}
13
14impl TextMetrics {
15    /// Create from shaped text
16    pub fn from_shaped(shaped: &crate::pipeline::shaping::ShapedText) -> Self {
17        // ShapedText has width, height, and baseline
18        // We'll estimate ascent/descent from height and baseline
19        let ascent = shaped.baseline;
20        let descent = shaped.height - shaped.baseline;
21
22        Self {
23            width: shaped.width,
24            height: shaped.height,
25            ascent,
26            descent,
27            line_gap: 0.0, // Not available in ShapedText
28            baseline: shaped.baseline,
29        }
30    }
31
32    /// Create with estimated values
33    pub fn estimated(width: f32, height: f32) -> Self {
34        Self {
35            width,
36            height,
37            ascent: height * 0.8,
38            descent: height * 0.2,
39            line_gap: height * 0.1,
40            baseline: height * 0.8,
41        }
42    }
43}