accessibility_tree/style/values/
fonts.rs

1use super::{EarlyCascadeContext, EarlyFromSpecified, Length, SpecifiedLength, SpecifiedValue};
2
3#[derive(Copy, Clone)]
4pub struct FontSize(pub Length);
5
6impl From<Length> for FontSize {
7    fn from(l: Length) -> Self {
8        FontSize(l)
9    }
10}
11
12impl SpecifiedValue for FontSize {
13    type SpecifiedValue = SpecifiedLength;
14}
15
16impl EarlyFromSpecified for FontSize {
17    fn early_from_specified(s: &SpecifiedLength, context: &EarlyCascadeContext) -> Self {
18        FontSize(match s {
19            SpecifiedLength::Absolute(px) => *px,
20            SpecifiedLength::Em(value) => context.inherited.font.font_size.0 * *value,
21        })
22    }
23}
24
25pub type Em = crate::primitives::Length<crate::fonts::Em>;
26
27impl std::ops::Mul<Em> for FontSize {
28    type Output = Length;
29    fn mul(self, other: Em) -> Length {
30        self.0 * other.0
31    }
32}
33
34impl std::ops::Div<FontSize> for Length {
35    type Output = Em;
36
37    fn div(self, other: FontSize) -> Em {
38        Em::new(self.px / other.0.px)
39    }
40}