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