read_fonts/generated/
generated_ankr.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Ankr<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.glyph_data_table_offset_byte_range().end
11 }
12 fn min_table_bytes(&self) -> &'a [u8] {
13 let range = self.min_byte_range();
14 self.data.as_bytes().get(range).unwrap_or_default()
15 }
16}
17
18impl TopLevelTable for Ankr<'_> {
19 const TAG: Tag = Tag::new(b"ankr");
21}
22
23impl<'a> FontRead<'a> for Ankr<'a> {
24 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
25 #[allow(clippy::absurd_extreme_comparisons)]
26 if data.len() < Self::MIN_SIZE {
27 return Err(ReadError::OutOfBounds);
28 }
29 Ok(Self { data })
30 }
31}
32
33#[derive(Clone)]
35pub struct Ankr<'a> {
36 data: FontData<'a>,
37}
38
39#[allow(clippy::needless_lifetimes)]
40impl<'a> Ankr<'a> {
41 pub const MIN_SIZE: usize =
42 (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
43 basic_table_impls!(impl_the_methods);
44
45 pub fn version(&self) -> u16 {
47 let range = self.version_byte_range();
48 self.data.read_at(range.start).ok().unwrap()
49 }
50
51 pub fn flags(&self) -> u16 {
53 let range = self.flags_byte_range();
54 self.data.read_at(range.start).ok().unwrap()
55 }
56
57 pub fn lookup_table_offset(&self) -> Offset32 {
61 let range = self.lookup_table_offset_byte_range();
62 self.data.read_at(range.start).ok().unwrap()
63 }
64
65 pub fn lookup_table(&self) -> Result<LookupU16<'a>, ReadError> {
67 let data = self.data;
68 self.lookup_table_offset().resolve(data)
69 }
70
71 pub fn glyph_data_table_offset(&self) -> u32 {
73 let range = self.glyph_data_table_offset_byte_range();
74 self.data.read_at(range.start).ok().unwrap()
75 }
76
77 pub fn version_byte_range(&self) -> Range<usize> {
78 let start = 0;
79 start..start + u16::RAW_BYTE_LEN
80 }
81
82 pub fn flags_byte_range(&self) -> Range<usize> {
83 let start = self.version_byte_range().end;
84 start..start + u16::RAW_BYTE_LEN
85 }
86
87 pub fn lookup_table_offset_byte_range(&self) -> Range<usize> {
88 let start = self.flags_byte_range().end;
89 start..start + Offset32::RAW_BYTE_LEN
90 }
91
92 pub fn glyph_data_table_offset_byte_range(&self) -> Range<usize> {
93 let start = self.lookup_table_offset_byte_range().end;
94 start..start + u32::RAW_BYTE_LEN
95 }
96}
97
98const _: () = assert!(FontData::default_data_long_enough(Ankr::MIN_SIZE));
99
100impl Default for Ankr<'_> {
101 fn default() -> Self {
102 Self {
103 data: FontData::default_table_data(),
104 }
105 }
106}
107
108#[cfg(feature = "experimental_traverse")]
109impl<'a> SomeTable<'a> for Ankr<'a> {
110 fn type_name(&self) -> &str {
111 "Ankr"
112 }
113 fn get_field(&self, idx: usize) -> Option<Field<'a>> {
114 match idx {
115 0usize => Some(Field::new("version", self.version())),
116 1usize => Some(Field::new("flags", self.flags())),
117 2usize => Some(Field::new(
118 "lookup_table_offset",
119 FieldType::offset(self.lookup_table_offset(), self.lookup_table()),
120 )),
121 3usize => Some(Field::new(
122 "glyph_data_table_offset",
123 self.glyph_data_table_offset(),
124 )),
125 _ => None,
126 }
127 }
128}
129
130#[cfg(feature = "experimental_traverse")]
131#[allow(clippy::needless_lifetimes)]
132impl<'a> std::fmt::Debug for Ankr<'a> {
133 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
134 (self as &dyn SomeTable<'a>).fmt(f)
135 }
136}
137
138impl<'a> MinByteRange<'a> for GlyphDataEntry<'a> {
139 fn min_byte_range(&self) -> Range<usize> {
140 0..self.anchor_points_byte_range().end
141 }
142 fn min_table_bytes(&self) -> &'a [u8] {
143 let range = self.min_byte_range();
144 self.data.as_bytes().get(range).unwrap_or_default()
145 }
146}
147
148impl<'a> FontRead<'a> for GlyphDataEntry<'a> {
149 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
150 #[allow(clippy::absurd_extreme_comparisons)]
151 if data.len() < Self::MIN_SIZE {
152 return Err(ReadError::OutOfBounds);
153 }
154 Ok(Self { data })
155 }
156}
157
158#[derive(Clone)]
159pub struct GlyphDataEntry<'a> {
160 data: FontData<'a>,
161}
162
163#[allow(clippy::needless_lifetimes)]
164impl<'a> GlyphDataEntry<'a> {
165 pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
166 basic_table_impls!(impl_the_methods);
167
168 pub fn num_points(&self) -> u32 {
170 let range = self.num_points_byte_range();
171 self.data.read_at(range.start).ok().unwrap()
172 }
173
174 pub fn anchor_points(&self) -> &'a [AnchorPoint] {
176 let range = self.anchor_points_byte_range();
177 self.data.read_array(range).ok().unwrap_or_default()
178 }
179
180 pub fn num_points_byte_range(&self) -> Range<usize> {
181 let start = 0;
182 start..start + u32::RAW_BYTE_LEN
183 }
184
185 pub fn anchor_points_byte_range(&self) -> Range<usize> {
186 let num_points = self.num_points();
187 let start = self.num_points_byte_range().end;
188 start..start + (num_points as usize).saturating_mul(AnchorPoint::RAW_BYTE_LEN)
189 }
190}
191
192const _: () = assert!(FontData::default_data_long_enough(GlyphDataEntry::MIN_SIZE));
193
194impl Default for GlyphDataEntry<'_> {
195 fn default() -> Self {
196 Self {
197 data: FontData::default_table_data(),
198 }
199 }
200}
201
202#[cfg(feature = "experimental_traverse")]
203impl<'a> SomeTable<'a> for GlyphDataEntry<'a> {
204 fn type_name(&self) -> &str {
205 "GlyphDataEntry"
206 }
207 fn get_field(&self, idx: usize) -> Option<Field<'a>> {
208 match idx {
209 0usize => Some(Field::new("num_points", self.num_points())),
210 1usize => Some(Field::new(
211 "anchor_points",
212 traversal::FieldType::array_of_records(
213 stringify!(AnchorPoint),
214 self.anchor_points(),
215 self.offset_data(),
216 ),
217 )),
218 _ => None,
219 }
220 }
221}
222
223#[cfg(feature = "experimental_traverse")]
224#[allow(clippy::needless_lifetimes)]
225impl<'a> std::fmt::Debug for GlyphDataEntry<'a> {
226 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
227 (self as &dyn SomeTable<'a>).fmt(f)
228 }
229}
230
231#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
233#[repr(C)]
234#[repr(packed)]
235pub struct AnchorPoint {
236 pub x: BigEndian<i16>,
237 pub y: BigEndian<i16>,
238}
239
240impl AnchorPoint {
241 pub fn x(&self) -> i16 {
242 self.x.get()
243 }
244
245 pub fn y(&self) -> i16 {
246 self.y.get()
247 }
248}
249
250impl FixedSize for AnchorPoint {
251 const RAW_BYTE_LEN: usize = i16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN;
252}
253
254#[cfg(feature = "experimental_traverse")]
255impl<'a> SomeRecord<'a> for AnchorPoint {
256 fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
257 RecordResolver {
258 name: "AnchorPoint",
259 get_field: Box::new(move |idx, _data| match idx {
260 0usize => Some(Field::new("x", self.x())),
261 1usize => Some(Field::new("y", self.y())),
262 _ => None,
263 }),
264 data,
265 }
266 }
267}