pub struct TextMetrics {
pub font_size_px: f64,
pub letter_spacing_px: f64,
pub text_transform: TextTransform,
pub monospace: bool,
}Expand description
Text-shaping parameters that influence the rendered width of a label.
TextMetrics is how layout code feeds theme typography into the width
estimator so margins, tick spacing, label strategy, legend packing, and
truncation all see the same width the SVG renderer will eventually paint.
The default is calibrated to Theme::default(): a 12px sans-serif face
with no letter spacing and no text transform. measure_text(text, default)
is therefore guaranteed to return exactly the legacy
approximate_text_width(text) value — this is the backward-compatibility
contract that keeps the pre-theme-hooks golden snapshots byte-identical.
Fields§
§font_size_px: f64Rendered font size in pixels.
letter_spacing_px: f64Extra CSS letter-spacing in pixels applied between glyphs.
text_transform: TextTransformtext-transform that will be applied by the renderer.
monospace: boolWhether the rendered font is a monospace face. Monospace glyphs are noticeably wider than the sans-serif calibration; this flag lets the measurement apply a per-character width correction.
Implementations§
Source§impl TextMetrics
impl TextMetrics
Sourcepub fn is_legacy_default(&self) -> bool
pub fn is_legacy_default(&self) -> bool
True when these metrics exactly match the legacy calibration. When
true, measure_text short-circuits to approximate_text_width so
layout output is bit-for-bit identical to the pre-3.1 behavior.
Sourcepub fn from_theme_tick_value(theme: &Theme) -> Self
pub fn from_theme_tick_value(theme: &Theme) -> Self
Build TextMetrics for numeric tick labels from a theme.
Returns the legacy-default metrics (byte-identical to
approximate_text_width) when every relevant field on theme matches
Theme::default(). Any divergence flips the layout path to the full
measure_text measurement.
Sourcepub fn from_theme_axis_label(theme: &Theme) -> Self
pub fn from_theme_axis_label(theme: &Theme) -> Self
Build TextMetrics for axis/category labels from a theme.
Sourcepub fn from_theme_legend(theme: &Theme) -> Self
pub fn from_theme_legend(theme: &Theme) -> Self
Build TextMetrics for legend labels from a theme.
Sourcepub fn from_theme_title(theme: &Theme) -> Self
pub fn from_theme_title(theme: &Theme) -> Self
Build TextMetrics for the chart title from a theme.
Trait Implementations§
Source§impl Clone for TextMetrics
impl Clone for TextMetrics
Source§fn clone(&self) -> TextMetrics
fn clone(&self) -> TextMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more