1#[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#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
25#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
26pub struct Head {
27 pub font_revision: Fixed,
29 pub checksum_adjustment: u32,
35 pub magic_number: u32,
37 pub flags: Flags,
39 pub units_per_em: u16,
44 pub created: LongDateTime,
47 pub modified: LongDateTime,
50 pub x_min: i16,
52 pub y_min: i16,
54 pub x_max: i16,
56 pub y_max: i16,
58 pub mac_style: MacStyle,
60 pub lowest_rec_ppem: u16,
62 pub font_direction_hint: i16,
64 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 #[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}