perf: minimize the performance impact of text decoration

Boxed the decoration data to go from 40b to 8b.
The performance is almost unchanged for text without decoration.
This commit is contained in:
Hojjat 2026-02-24 14:52:04 -07:00 committed by Jeremy Soller
parent 6ef1ccbeed
commit 78665aab3b
4 changed files with 78 additions and 53 deletions

View file

@ -253,14 +253,31 @@ impl TextDecoration {
overline_color_opt: None,
}
}
pub const fn has_decoration(&self) -> bool {
!matches!(self.underline, UnderlineStyle::None) || self.strikethrough || self.overline
}
}
/// Offset and thickness for a text decoration line, in EM units.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct DecorationMetrics {
/// Offset from baseline in EM units
pub offset: f32,
/// Thickness in EM units
pub thickness: f32,
}
#[derive(Clone, Debug, PartialEq)]
pub struct GlyphDecorationData {
/// The text decoration configuration from the user
pub text_decoration: TextDecoration,
/// Underline offset and thickness from the font
pub underline_metrics: DecorationMetrics,
/// Strikethrough offset and thickness from the font
pub strikethrough_metrics: DecorationMetrics,
}
/// Text attributes
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Attrs<'a> {