1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// THIS FILE IS AUTOGENERATED.
// Any changes to this file will be overwritten.
// For more information about how codegen works, see font-codegen/README.md

#[allow(unused_imports)]
use crate::codegen_prelude::*;

/// [hhea](https://docs.microsoft.com/en-us/typography/opentype/spec/hhea) Horizontal Header Table
#[derive(Clone, Debug, Default)]
pub struct Hhea {
    /// Typographic ascent.
    pub ascender: FWord,
    /// Typographic descent.
    pub descender: FWord,
    /// Typographic line gap. Negative LineGap values are treated as
    /// zero in some legacy platform implementations.
    pub line_gap: FWord,
    /// Maximum advance width value in 'hmtx' table.
    pub advance_width_max: UfWord,
    /// Minimum left sidebearing value in 'hmtx' table for glyphs with
    /// contours (empty glyphs should be ignored).
    pub min_left_side_bearing: FWord,
    /// Minimum right sidebearing value; calculated as min(aw - (lsb +
    /// xMax - xMin)) for glyphs with contours (empty glyphs should be ignored).
    pub min_right_side_bearing: FWord,
    /// Max(lsb + (xMax-xMin))
    pub x_max_extent: FWord,
    /// Used to calculate the slope of the cursor (rise/run); 1 for
    /// vertical caret, 0 for horizontal.
    pub caret_slope_rise: i16,
    /// 0 for vertical caret, 1 for horizontal.
    pub caret_slope_run: i16,
    /// The amount by which a slanted highlight on a glyph needs to be
    /// shifted to produce the best appearance. Set to 0 for
    /// non-slanted fonts
    pub caret_offset: i16,
    /// Number of LongMetric entries in 'hmtx'/'vmtx' table
    pub number_of_long_metrics: u16,
}

impl Hhea {
    /// Construct a new `Hhea`
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        ascender: FWord,
        descender: FWord,
        line_gap: FWord,
        advance_width_max: UfWord,
        min_left_side_bearing: FWord,
        min_right_side_bearing: FWord,
        x_max_extent: FWord,
        caret_slope_rise: i16,
        caret_slope_run: i16,
        caret_offset: i16,
        number_of_long_metrics: u16,
    ) -> Self {
        Self {
            ascender,
            descender,
            line_gap,
            advance_width_max,
            min_left_side_bearing,
            min_right_side_bearing,
            x_max_extent,
            caret_slope_rise,
            caret_slope_run,
            caret_offset,
            number_of_long_metrics,
        }
    }
}

impl FontWrite for Hhea {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        (MajorMinor::VERSION_1_0 as MajorMinor).write_into(writer);
        self.ascender.write_into(writer);
        self.descender.write_into(writer);
        self.line_gap.write_into(writer);
        self.advance_width_max.write_into(writer);
        self.min_left_side_bearing.write_into(writer);
        self.min_right_side_bearing.write_into(writer);
        self.x_max_extent.write_into(writer);
        self.caret_slope_rise.write_into(writer);
        self.caret_slope_run.write_into(writer);
        self.caret_offset.write_into(writer);
        (0 as i16).write_into(writer);
        (0 as i16).write_into(writer);
        (0 as i16).write_into(writer);
        (0 as i16).write_into(writer);
        (0 as i16).write_into(writer);
        self.number_of_long_metrics.write_into(writer);
    }
    fn name(&self) -> &'static str {
        "Hhea"
    }
}

impl Validate for Hhea {
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}

impl TopLevelTable for Hhea {
    const TAG: Tag = Tag::new(b"hhea");
}

impl<'a> FromObjRef<read_fonts::tables::hhea::Hhea<'a>> for Hhea {
    fn from_obj_ref(obj: &read_fonts::tables::hhea::Hhea<'a>, _: FontData) -> Self {
        Hhea {
            ascender: obj.ascender(),
            descender: obj.descender(),
            line_gap: obj.line_gap(),
            advance_width_max: obj.advance_width_max(),
            min_left_side_bearing: obj.min_left_side_bearing(),
            min_right_side_bearing: obj.min_right_side_bearing(),
            x_max_extent: obj.x_max_extent(),
            caret_slope_rise: obj.caret_slope_rise(),
            caret_slope_run: obj.caret_slope_run(),
            caret_offset: obj.caret_offset(),
            number_of_long_metrics: obj.number_of_long_metrics(),
        }
    }
}

impl<'a> FromTableRef<read_fonts::tables::hhea::Hhea<'a>> for Hhea {}

impl<'a> FontRead<'a> for Hhea {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::tables::hhea::Hhea as FontRead>::read(data).map(|x| x.to_owned_table())
    }
}