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