euv_core/font/measurer/trait.rs
1use super::*;
2
3/// Pluggable text measurement interface enabling deterministic cross-platform text layout.
4pub trait TextMeasurer {
5 /// Measures and wraps `text` under `style` within an optional `max_width` constraint.
6 ///
7 /// # Arguments
8 ///
9 /// - `&Self` - Text measurer reference.
10 /// - `&str` - UTF-8 text to lay out.
11 /// - `TextStyle` - Typography style parameters.
12 /// - `Option<f32>` - Optional maximum line width in logical pixels.
13 ///
14 /// # Returns
15 ///
16 /// - `TextLayoutResult` - Wrapped lines and aggregate bounding box.
17 fn measure(&self, text: &str, style: TextStyle, max_width: Option<f32>) -> TextLayoutResult;
18
19 /// Measures only the aggregate bounding box of `text` under `style` within an optional `max_width` constraint.
20 ///
21 /// # Arguments
22 ///
23 /// - `&Self` - Text measurer reference.
24 /// - `&str` - UTF-8 text to measure.
25 /// - `TextStyle` - Typography style parameters.
26 /// - `Option<f32>` - Optional maximum line width in logical pixels.
27 ///
28 /// # Returns
29 ///
30 /// - `Size` - Aggregate bounding box without requiring callers to materialize wrapped lines.
31 fn measure_size(&self, text: &str, style: TextStyle, max_width: Option<f32>) -> Size {
32 self.measure(text, style, max_width).get_size()
33 }
34}