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 let end = start + u16::RAW_BYTE_LEN;
80 start..end
81 }
82
83 pub fn flags_byte_range(&self) -> Range<usize> {
84 let start = self.version_byte_range().end;
85 let end = start + u16::RAW_BYTE_LEN;
86 start..end
87 }
88
89 pub fn lookup_table_offset_byte_range(&self) -> Range<usize> {
90 let start = self.flags_byte_range().end;
91 let end = start + Offset32::RAW_BYTE_LEN;
92 start..end
93 }
94
95 pub fn glyph_data_table_offset_byte_range(&self) -> Range<usize> {
96 let start = self.lookup_table_offset_byte_range().end;
97 let end = start + u32::RAW_BYTE_LEN;
98 start..end
99 }
100}
101
102const _: () = assert!(FontData::default_data_long_enough(Ankr::MIN_SIZE));
103
104impl Default for Ankr<'_> {
105 fn default() -> Self {
106 Self {
107 data: FontData::default_table_data(),
108 }
109 }
110}
111
112#[cfg(feature = "experimental_traverse")]
113impl<'a> SomeTable<'a> for Ankr<'a> {
114 fn type_name(&self) -> &str {
115 "Ankr"
116 }
117 fn get_field(&self, idx: usize) -> Option<Field<'a>> {
118 match idx {
119 0usize => Some(Field::new("version", self.version())),
120 1usize => Some(Field::new("flags", self.flags())),
121 2usize => Some(Field::new(
122 "lookup_table_offset",
123 FieldType::offset(self.lookup_table_offset(), self.lookup_table()),
124 )),
125 3usize => Some(Field::new(
126 "glyph_data_table_offset",
127 self.glyph_data_table_offset(),
128 )),
129 _ => None,
130 }
131 }
132}
133
134#[cfg(feature = "experimental_traverse")]
135#[allow(clippy::needless_lifetimes)]
136impl<'a> std::fmt::Debug for Ankr<'a> {
137 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
138 (self as &dyn SomeTable<'a>).fmt(f)
139 }
140}
141
142impl<'a> MinByteRange<'a> for GlyphDataEntry<'a> {
143 fn min_byte_range(&self) -> Range<usize> {
144 0..self.anchor_points_byte_range().end
145 }
146 fn min_table_bytes(&self) -> &'a [u8] {
147 let range = self.min_byte_range();
148 self.data.as_bytes().get(range).unwrap_or_default()
149 }
150}
151
152impl<'a> FontRead<'a> for GlyphDataEntry<'a> {
153 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
154 #[allow(clippy::absurd_extreme_comparisons)]
155 if data.len() < Self::MIN_SIZE {
156 return Err(ReadError::OutOfBounds);
157 }
158 Ok(Self { data })
159 }
160}
161
162#[derive(Clone)]
163pub struct GlyphDataEntry<'a> {
164 data: FontData<'a>,
165}
166
167#[allow(clippy::needless_lifetimes)]
168impl<'a> GlyphDataEntry<'a> {
169 pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
170 basic_table_impls!(impl_the_methods);
171
172 pub fn num_points(&self) -> u32 {
174 let range = self.num_points_byte_range();
175 self.data.read_at(range.start).ok().unwrap()
176 }
177
178 pub fn anchor_points(&self) -> &'a [AnchorPoint] {
180 let range = self.anchor_points_byte_range();
181 self.data.read_array(range).ok().unwrap_or_default()
182 }
183
184 pub fn num_points_byte_range(&self) -> Range<usize> {
185 let start = 0;
186 let end = start + u32::RAW_BYTE_LEN;
187 start..end
188 }
189
190 pub fn anchor_points_byte_range(&self) -> Range<usize> {
191 let num_points = self.num_points();
192 let start = self.num_points_byte_range().end;
193 let end =
194 start + (transforms::to_usize(num_points)).saturating_mul(AnchorPoint::RAW_BYTE_LEN);
195 start..end
196 }
197}
198
199const _: () = assert!(FontData::default_data_long_enough(GlyphDataEntry::MIN_SIZE));
200
201impl Default for GlyphDataEntry<'_> {
202 fn default() -> Self {
203 Self {
204 data: FontData::default_table_data(),
205 }
206 }
207}
208
209#[cfg(feature = "experimental_traverse")]
210impl<'a> SomeTable<'a> for GlyphDataEntry<'a> {
211 fn type_name(&self) -> &str {
212 "GlyphDataEntry"
213 }
214 fn get_field(&self, idx: usize) -> Option<Field<'a>> {
215 match idx {
216 0usize => Some(Field::new("num_points", self.num_points())),
217 1usize => Some(Field::new(
218 "anchor_points",
219 traversal::FieldType::array_of_records(
220 stringify!(AnchorPoint),
221 self.anchor_points(),
222 self.offset_data(),
223 ),
224 )),
225 _ => None,
226 }
227 }
228}
229
230#[cfg(feature = "experimental_traverse")]
231#[allow(clippy::needless_lifetimes)]
232impl<'a> std::fmt::Debug for GlyphDataEntry<'a> {
233 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
234 (self as &dyn SomeTable<'a>).fmt(f)
235 }
236}
237
238#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
240#[repr(C)]
241#[repr(packed)]
242pub struct AnchorPoint {
243 pub x: BigEndian<i16>,
244 pub y: BigEndian<i16>,
245}
246
247impl AnchorPoint {
248 pub fn x(&self) -> i16 {
249 self.x.get()
250 }
251
252 pub fn y(&self) -> i16 {
253 self.y.get()
254 }
255}
256
257impl FixedSize for AnchorPoint {
258 const RAW_BYTE_LEN: usize = i16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN;
259}
260
261#[cfg(feature = "experimental_traverse")]
262impl<'a> SomeRecord<'a> for AnchorPoint {
263 fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
264 RecordResolver {
265 name: "AnchorPoint",
266 get_field: Box::new(move |idx, _data| match idx {
267 0usize => Some(Field::new("x", self.x())),
268 1usize => Some(Field::new("y", self.y())),
269 _ => None,
270 }),
271 data,
272 }
273 }
274}