diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-13 21:39:38 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-13 21:40:06 +0100 |
| commit | 880b1847bd4170ce80be5781c2163ba085cdcaff (patch) | |
| tree | 3fbfdb70cb04c4922f0ec9e3f29f2c63d11d753b /src/font/mod.rs | |
| parent | cb3c263c4a67f4d361dbdb5048a1c073bd1fff96 (diff) | |
Derive `Cast` for enums
Diffstat (limited to 'src/font/mod.rs')
| -rw-r--r-- | src/font/mod.rs | 38 |
1 files changed, 4 insertions, 34 deletions
diff --git a/src/font/mod.rs b/src/font/mod.rs index 94ec170e..bfb790bb 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use ttf_parser::GlyphId; -use crate::eval::{cast_from_value, cast_to_value, Value}; +use crate::eval::Cast; use crate::geom::Em; use crate::util::Buffer; @@ -231,12 +231,9 @@ pub struct LineMetrics { } /// Identifies a vertical metric of a font. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)] pub enum VerticalFontMetric { - /// The typographic ascender. - /// - /// Corresponds to the typographic ascender from the `OS/2` table if present - /// and falls back to the ascender from the `hhea` table otherwise. + /// The font's ascender, which typically exceeds the height of all glyphs. Ascender, /// The approximate height of uppercase letters. CapHeight, @@ -244,33 +241,6 @@ pub enum VerticalFontMetric { XHeight, /// The baseline on which the letters rest. Baseline, - /// The typographic descender. - /// - /// Corresponds to the typographic descender from the `OS/2` table if - /// present and falls back to the descender from the `hhea` table otherwise. - Descender, -} - -cast_from_value! { - VerticalFontMetric, - /// The font's ascender, which typically exceeds the height of all glyphs. - "ascender" => Self::Ascender, - /// The approximate height of uppercase letters. - "cap-height" => Self::CapHeight, - /// The approximate height of non-ascending lowercase letters. - "x-height" => Self::XHeight, - /// The baseline on which the letters rest. - "baseline" => Self::Baseline, /// The font's ascender, which typically exceeds the depth of all glyphs. - "descender" => Self::Descender, -} - -cast_to_value! { - v: VerticalFontMetric => Value::from(match v { - VerticalFontMetric::Ascender => "ascender", - VerticalFontMetric::CapHeight => "cap-height", - VerticalFontMetric::XHeight => "x-height", - VerticalFontMetric::Baseline => "baseline" , - VerticalFontMetric::Descender => "descender", - }) + Descender, } |
