write_fonts/generated/
generated_head.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
8pub use read_fonts::tables::head::MacStyle;
9
10impl FontWrite for MacStyle {
11    fn write_into(&self, writer: &mut TableWriter) {
12        writer.write_slice(&self.bits().to_be_bytes())
13    }
14}
15
16/// The [head](https://docs.microsoft.com/en-us/typography/opentype/spec/head)
17/// (font header) table.
18#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20pub struct Head {
21    /// Set by font manufacturer.
22    pub font_revision: Fixed,
23    /// To compute: set it to 0, sum the entire font as uint32, then
24    /// store 0xB1B0AFBA - sum. If the font is used as a component in a
25    /// font collection file, the value of this field will be
26    /// invalidated by changes to the file structure and font table
27    /// directory, and must be ignored.
28    pub checksum_adjustment: u32,
29    /// Set to 0x5F0F3CF5.
30    pub magic_number: u32,
31    /// See the flags enum
32    pub flags: u16,
33    /// Set to a value from 16 to 16384. Any value in this range is
34    /// valid. In fonts that have TrueType outlines, a power of 2 is
35    /// recommended as this allows performance optimizations in some
36    /// rasterizers.
37    pub units_per_em: u16,
38    /// Number of seconds since 12:00 midnight that started January 1st
39    /// 1904 in GMT/UTC time zone.
40    pub created: LongDateTime,
41    /// Number of seconds since 12:00 midnight that started January 1st
42    /// 1904 in GMT/UTC time zone.
43    pub modified: LongDateTime,
44    /// Minimum x coordinate across all glyph bounding boxes.
45    pub x_min: i16,
46    /// Minimum y coordinate across all glyph bounding boxes.
47    pub y_min: i16,
48    /// Maximum x coordinate across all glyph bounding boxes.
49    pub x_max: i16,
50    /// Maximum y coordinate across all glyph bounding boxes.
51    pub y_max: i16,
52    /// Bits identifying the font's style; see [MacStyle]
53    pub mac_style: MacStyle,
54    /// Smallest readable size in pixels.
55    pub lowest_rec_ppem: u16,
56    /// Deprecated (Set to 2).
57    pub font_direction_hint: i16,
58    /// 0 for short offsets (Offset16), 1 for long (Offset32).
59    pub index_to_loc_format: i16,
60}
61
62impl Default for Head {
63    fn default() -> Self {
64        Self {
65            font_revision: Default::default(),
66            checksum_adjustment: Default::default(),
67            magic_number: 0x5F0F3CF5,
68            flags: Default::default(),
69            units_per_em: Default::default(),
70            created: Default::default(),
71            modified: Default::default(),
72            x_min: Default::default(),
73            y_min: Default::default(),
74            x_max: Default::default(),
75            y_max: Default::default(),
76            mac_style: Default::default(),
77            lowest_rec_ppem: Default::default(),
78            font_direction_hint: 2,
79            index_to_loc_format: Default::default(),
80        }
81    }
82}
83
84impl Head {
85    /// Construct a new `Head`
86    #[allow(clippy::too_many_arguments)]
87    pub fn new(
88        font_revision: Fixed,
89        checksum_adjustment: u32,
90        flags: u16,
91        units_per_em: u16,
92        created: LongDateTime,
93        modified: LongDateTime,
94        x_min: i16,
95        y_min: i16,
96        x_max: i16,
97        y_max: i16,
98        mac_style: MacStyle,
99        lowest_rec_ppem: u16,
100        index_to_loc_format: i16,
101    ) -> Self {
102        Self {
103            font_revision,
104            checksum_adjustment,
105            flags,
106            units_per_em,
107            created,
108            modified,
109            x_min,
110            y_min,
111            x_max,
112            y_max,
113            mac_style,
114            lowest_rec_ppem,
115            index_to_loc_format,
116            ..Default::default()
117        }
118    }
119}
120
121impl FontWrite for Head {
122    #[allow(clippy::unnecessary_cast)]
123    fn write_into(&self, writer: &mut TableWriter) {
124        (MajorMinor::VERSION_1_0 as MajorMinor).write_into(writer);
125        self.font_revision.write_into(writer);
126        self.checksum_adjustment.write_into(writer);
127        self.magic_number.write_into(writer);
128        self.flags.write_into(writer);
129        self.units_per_em.write_into(writer);
130        self.created.write_into(writer);
131        self.modified.write_into(writer);
132        self.x_min.write_into(writer);
133        self.y_min.write_into(writer);
134        self.x_max.write_into(writer);
135        self.y_max.write_into(writer);
136        self.mac_style.write_into(writer);
137        self.lowest_rec_ppem.write_into(writer);
138        self.font_direction_hint.write_into(writer);
139        self.index_to_loc_format.write_into(writer);
140        (0 as i16).write_into(writer);
141    }
142    fn table_type(&self) -> TableType {
143        TableType::TopLevel(Head::TAG)
144    }
145}
146
147impl Validate for Head {
148    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
149}
150
151impl TopLevelTable for Head {
152    const TAG: Tag = Tag::new(b"head");
153}
154
155impl<'a> FromObjRef<read_fonts::tables::head::Head<'a>> for Head {
156    fn from_obj_ref(obj: &read_fonts::tables::head::Head<'a>, _: FontData) -> Self {
157        Head {
158            font_revision: obj.font_revision(),
159            checksum_adjustment: obj.checksum_adjustment(),
160            magic_number: obj.magic_number(),
161            flags: obj.flags(),
162            units_per_em: obj.units_per_em(),
163            created: obj.created(),
164            modified: obj.modified(),
165            x_min: obj.x_min(),
166            y_min: obj.y_min(),
167            x_max: obj.x_max(),
168            y_max: obj.y_max(),
169            mac_style: obj.mac_style(),
170            lowest_rec_ppem: obj.lowest_rec_ppem(),
171            font_direction_hint: obj.font_direction_hint(),
172            index_to_loc_format: obj.index_to_loc_format(),
173        }
174    }
175}
176
177#[allow(clippy::needless_lifetimes)]
178impl<'a> FromTableRef<read_fonts::tables::head::Head<'a>> for Head {}
179
180impl<'a> FontRead<'a> for Head {
181    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
182        <read_fonts::tables::head::Head as FontRead>::read(data).map(|x| x.to_owned_table())
183    }
184}