Skip to main content

write_fonts/generated/
generated_vhea.rs

1// THIS FILE IS AUTOGENERATED.
2// Any changes to this file will be overwritten.
3// For more information about how codegen works, see font-codegen/README.md
4
5#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8/// The [vhea](https://docs.microsoft.com/en-us/typography/opentype/spec/vhea) Vertical Header Table
9#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Vhea {
12    /// The major/minor version (1, 0 or 1, 1)
13    pub version: Version16Dot16,
14    /// Typographic ascent.
15    pub ascender: FWord,
16    /// Typographic descent.
17    pub descender: FWord,
18    /// Typographic line gap. Negative LineGap values are treated as
19    /// zero in some legacy platform implementations.
20    pub line_gap: FWord,
21    /// Maximum advance height value in 'vmtx' table.
22    pub advance_height_max: UfWord,
23    /// Minimum top sidebearing value in 'vmtx' table for glyphs with
24    /// contours (empty glyphs should be ignored).
25    pub min_top_side_bearing: FWord,
26    /// Minimum bottom sidebearing value
27    pub min_bottom_side_bearing: FWord,
28    /// Defined as max( tsb + (yMax-yMin)).
29    pub y_max_extent: FWord,
30    /// Used to calculate the slope of the cursor (rise/run); 1 for
31    /// vertical caret, 0 for horizontal.
32    pub caret_slope_rise: i16,
33    /// 0 for vertical caret, 1 for horizontal.
34    pub caret_slope_run: i16,
35    /// The amount by which a slanted highlight on a glyph needs to be
36    /// shifted to produce the best appearance. Set to 0 for
37    /// non-slanted fonts
38    pub caret_offset: i16,
39    /// Number of advance heights in the vertical metrics (`vmtx`) table.
40    pub number_of_long_ver_metrics: u16,
41}
42
43impl Default for Vhea {
44    fn default() -> Self {
45        Self {
46            version: Version16Dot16::VERSION_1_1,
47            ascender: Default::default(),
48            descender: Default::default(),
49            line_gap: Default::default(),
50            advance_height_max: Default::default(),
51            min_top_side_bearing: Default::default(),
52            min_bottom_side_bearing: Default::default(),
53            y_max_extent: Default::default(),
54            caret_slope_rise: Default::default(),
55            caret_slope_run: Default::default(),
56            caret_offset: Default::default(),
57            number_of_long_ver_metrics: Default::default(),
58        }
59    }
60}
61
62impl Vhea {
63    /// Construct a new `Vhea`
64    #[allow(clippy::too_many_arguments)]
65    pub fn new(
66        ascender: FWord,
67        descender: FWord,
68        line_gap: FWord,
69        advance_height_max: UfWord,
70        min_top_side_bearing: FWord,
71        min_bottom_side_bearing: FWord,
72        y_max_extent: FWord,
73        caret_slope_rise: i16,
74        caret_slope_run: i16,
75        caret_offset: i16,
76        number_of_long_ver_metrics: u16,
77    ) -> Self {
78        Self {
79            ascender,
80            descender,
81            line_gap,
82            advance_height_max,
83            min_top_side_bearing,
84            min_bottom_side_bearing,
85            y_max_extent,
86            caret_slope_rise,
87            caret_slope_run,
88            caret_offset,
89            number_of_long_ver_metrics,
90            ..Default::default()
91        }
92    }
93}
94
95impl FontWrite for Vhea {
96    #[allow(clippy::unnecessary_cast)]
97    fn write_into(&self, writer: &mut TableWriter) {
98        self.version.write_into(writer);
99        self.ascender.write_into(writer);
100        self.descender.write_into(writer);
101        self.line_gap.write_into(writer);
102        self.advance_height_max.write_into(writer);
103        self.min_top_side_bearing.write_into(writer);
104        self.min_bottom_side_bearing.write_into(writer);
105        self.y_max_extent.write_into(writer);
106        self.caret_slope_rise.write_into(writer);
107        self.caret_slope_run.write_into(writer);
108        self.caret_offset.write_into(writer);
109        (0 as i16).write_into(writer);
110        (0 as i16).write_into(writer);
111        (0 as i16).write_into(writer);
112        (0 as i16).write_into(writer);
113        (0 as i16).write_into(writer);
114        self.number_of_long_ver_metrics.write_into(writer);
115    }
116    fn table_type(&self) -> TableType {
117        TableType::TopLevel(Vhea::TAG)
118    }
119}
120
121impl Validate for Vhea {
122    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
123}
124
125impl TopLevelTable for Vhea {
126    const TAG: Tag = Tag::new(b"vhea");
127}
128
129impl<'a> FromObjRef<read_fonts::tables::vhea::Vhea<'a>> for Vhea {
130    fn from_obj_ref(obj: &read_fonts::tables::vhea::Vhea<'a>, _: FontData) -> Self {
131        Vhea {
132            version: obj.version(),
133            ascender: obj.ascender(),
134            descender: obj.descender(),
135            line_gap: obj.line_gap(),
136            advance_height_max: obj.advance_height_max(),
137            min_top_side_bearing: obj.min_top_side_bearing(),
138            min_bottom_side_bearing: obj.min_bottom_side_bearing(),
139            y_max_extent: obj.y_max_extent(),
140            caret_slope_rise: obj.caret_slope_rise(),
141            caret_slope_run: obj.caret_slope_run(),
142            caret_offset: obj.caret_offset(),
143            number_of_long_ver_metrics: obj.number_of_long_ver_metrics(),
144        }
145    }
146}
147
148#[allow(clippy::needless_lifetimes)]
149impl<'a> FromTableRef<read_fonts::tables::vhea::Vhea<'a>> for Vhea {}
150
151impl ReadArgs for Vhea {
152    type Args = ();
153}
154
155impl<'a> FontRead<'a> for Vhea {
156    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
157        <read_fonts::tables::vhea::Vhea as FontRead>::read(data).map(|x| x.to_owned_table())
158    }
159}