read_fonts/generated/
generated_maxp.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Maxp<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.num_glyphs_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 Maxp<'_> {
19 const TAG: Tag = Tag::new(b"maxp");
21}
22
23impl<'a> FontRead<'a> for Maxp<'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 Maxp<'a> {
36 data: FontData<'a>,
37}
38
39#[allow(clippy::needless_lifetimes)]
40impl<'a> Maxp<'a> {
41 pub const MIN_SIZE: usize = (Version16Dot16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
42 basic_table_impls!(impl_the_methods);
43
44 pub fn version(&self) -> Version16Dot16 {
46 let range = self.version_byte_range();
47 self.data.read_at(range.start).ok().unwrap()
48 }
49
50 pub fn num_glyphs(&self) -> u16 {
52 let range = self.num_glyphs_byte_range();
53 self.data.read_at(range.start).ok().unwrap()
54 }
55
56 pub fn max_points(&self) -> Option<u16> {
58 let range = self.max_points_byte_range();
59 (!range.is_empty())
60 .then(|| self.data.read_at(range.start).ok())
61 .flatten()
62 }
63
64 pub fn max_contours(&self) -> Option<u16> {
66 let range = self.max_contours_byte_range();
67 (!range.is_empty())
68 .then(|| self.data.read_at(range.start).ok())
69 .flatten()
70 }
71
72 pub fn max_composite_points(&self) -> Option<u16> {
74 let range = self.max_composite_points_byte_range();
75 (!range.is_empty())
76 .then(|| self.data.read_at(range.start).ok())
77 .flatten()
78 }
79
80 pub fn max_composite_contours(&self) -> Option<u16> {
82 let range = self.max_composite_contours_byte_range();
83 (!range.is_empty())
84 .then(|| self.data.read_at(range.start).ok())
85 .flatten()
86 }
87
88 pub fn max_zones(&self) -> Option<u16> {
91 let range = self.max_zones_byte_range();
92 (!range.is_empty())
93 .then(|| self.data.read_at(range.start).ok())
94 .flatten()
95 }
96
97 pub fn max_twilight_points(&self) -> Option<u16> {
99 let range = self.max_twilight_points_byte_range();
100 (!range.is_empty())
101 .then(|| self.data.read_at(range.start).ok())
102 .flatten()
103 }
104
105 pub fn max_storage(&self) -> Option<u16> {
107 let range = self.max_storage_byte_range();
108 (!range.is_empty())
109 .then(|| self.data.read_at(range.start).ok())
110 .flatten()
111 }
112
113 pub fn max_function_defs(&self) -> Option<u16> {
115 let range = self.max_function_defs_byte_range();
116 (!range.is_empty())
117 .then(|| self.data.read_at(range.start).ok())
118 .flatten()
119 }
120
121 pub fn max_instruction_defs(&self) -> Option<u16> {
123 let range = self.max_instruction_defs_byte_range();
124 (!range.is_empty())
125 .then(|| self.data.read_at(range.start).ok())
126 .flatten()
127 }
128
129 pub fn max_stack_elements(&self) -> Option<u16> {
133 let range = self.max_stack_elements_byte_range();
134 (!range.is_empty())
135 .then(|| self.data.read_at(range.start).ok())
136 .flatten()
137 }
138
139 pub fn max_size_of_instructions(&self) -> Option<u16> {
141 let range = self.max_size_of_instructions_byte_range();
142 (!range.is_empty())
143 .then(|| self.data.read_at(range.start).ok())
144 .flatten()
145 }
146
147 pub fn max_component_elements(&self) -> Option<u16> {
150 let range = self.max_component_elements_byte_range();
151 (!range.is_empty())
152 .then(|| self.data.read_at(range.start).ok())
153 .flatten()
154 }
155
156 pub fn max_component_depth(&self) -> Option<u16> {
158 let range = self.max_component_depth_byte_range();
159 (!range.is_empty())
160 .then(|| self.data.read_at(range.start).ok())
161 .flatten()
162 }
163
164 pub fn version_byte_range(&self) -> Range<usize> {
165 let start = 0;
166 start..start + Version16Dot16::RAW_BYTE_LEN
167 }
168
169 pub fn num_glyphs_byte_range(&self) -> Range<usize> {
170 let start = self.version_byte_range().end;
171 start..start + u16::RAW_BYTE_LEN
172 }
173
174 pub fn max_points_byte_range(&self) -> Range<usize> {
175 let start = self.num_glyphs_byte_range().end;
176 start
177 ..(self.version().compatible((1u16, 0u16)))
178 .then(|| start + u16::RAW_BYTE_LEN)
179 .unwrap_or(start)
180 }
181
182 pub fn max_contours_byte_range(&self) -> Range<usize> {
183 let start = self.max_points_byte_range().end;
184 start
185 ..(self.version().compatible((1u16, 0u16)))
186 .then(|| start + u16::RAW_BYTE_LEN)
187 .unwrap_or(start)
188 }
189
190 pub fn max_composite_points_byte_range(&self) -> Range<usize> {
191 let start = self.max_contours_byte_range().end;
192 start
193 ..(self.version().compatible((1u16, 0u16)))
194 .then(|| start + u16::RAW_BYTE_LEN)
195 .unwrap_or(start)
196 }
197
198 pub fn max_composite_contours_byte_range(&self) -> Range<usize> {
199 let start = self.max_composite_points_byte_range().end;
200 start
201 ..(self.version().compatible((1u16, 0u16)))
202 .then(|| start + u16::RAW_BYTE_LEN)
203 .unwrap_or(start)
204 }
205
206 pub fn max_zones_byte_range(&self) -> Range<usize> {
207 let start = self.max_composite_contours_byte_range().end;
208 start
209 ..(self.version().compatible((1u16, 0u16)))
210 .then(|| start + u16::RAW_BYTE_LEN)
211 .unwrap_or(start)
212 }
213
214 pub fn max_twilight_points_byte_range(&self) -> Range<usize> {
215 let start = self.max_zones_byte_range().end;
216 start
217 ..(self.version().compatible((1u16, 0u16)))
218 .then(|| start + u16::RAW_BYTE_LEN)
219 .unwrap_or(start)
220 }
221
222 pub fn max_storage_byte_range(&self) -> Range<usize> {
223 let start = self.max_twilight_points_byte_range().end;
224 start
225 ..(self.version().compatible((1u16, 0u16)))
226 .then(|| start + u16::RAW_BYTE_LEN)
227 .unwrap_or(start)
228 }
229
230 pub fn max_function_defs_byte_range(&self) -> Range<usize> {
231 let start = self.max_storage_byte_range().end;
232 start
233 ..(self.version().compatible((1u16, 0u16)))
234 .then(|| start + u16::RAW_BYTE_LEN)
235 .unwrap_or(start)
236 }
237
238 pub fn max_instruction_defs_byte_range(&self) -> Range<usize> {
239 let start = self.max_function_defs_byte_range().end;
240 start
241 ..(self.version().compatible((1u16, 0u16)))
242 .then(|| start + u16::RAW_BYTE_LEN)
243 .unwrap_or(start)
244 }
245
246 pub fn max_stack_elements_byte_range(&self) -> Range<usize> {
247 let start = self.max_instruction_defs_byte_range().end;
248 start
249 ..(self.version().compatible((1u16, 0u16)))
250 .then(|| start + u16::RAW_BYTE_LEN)
251 .unwrap_or(start)
252 }
253
254 pub fn max_size_of_instructions_byte_range(&self) -> Range<usize> {
255 let start = self.max_stack_elements_byte_range().end;
256 start
257 ..(self.version().compatible((1u16, 0u16)))
258 .then(|| start + u16::RAW_BYTE_LEN)
259 .unwrap_or(start)
260 }
261
262 pub fn max_component_elements_byte_range(&self) -> Range<usize> {
263 let start = self.max_size_of_instructions_byte_range().end;
264 start
265 ..(self.version().compatible((1u16, 0u16)))
266 .then(|| start + u16::RAW_BYTE_LEN)
267 .unwrap_or(start)
268 }
269
270 pub fn max_component_depth_byte_range(&self) -> Range<usize> {
271 let start = self.max_component_elements_byte_range().end;
272 start
273 ..(self.version().compatible((1u16, 0u16)))
274 .then(|| start + u16::RAW_BYTE_LEN)
275 .unwrap_or(start)
276 }
277}
278
279#[cfg(feature = "experimental_traverse")]
280impl<'a> SomeTable<'a> for Maxp<'a> {
281 fn type_name(&self) -> &str {
282 "Maxp"
283 }
284 fn get_field(&self, idx: usize) -> Option<Field<'a>> {
285 match idx {
286 0usize => Some(Field::new("version", self.version())),
287 1usize => Some(Field::new("num_glyphs", self.num_glyphs())),
288 2usize if self.version().compatible((1u16, 0u16)) => {
289 Some(Field::new("max_points", self.max_points().unwrap()))
290 }
291 3usize if self.version().compatible((1u16, 0u16)) => {
292 Some(Field::new("max_contours", self.max_contours().unwrap()))
293 }
294 4usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
295 "max_composite_points",
296 self.max_composite_points().unwrap(),
297 )),
298 5usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
299 "max_composite_contours",
300 self.max_composite_contours().unwrap(),
301 )),
302 6usize if self.version().compatible((1u16, 0u16)) => {
303 Some(Field::new("max_zones", self.max_zones().unwrap()))
304 }
305 7usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
306 "max_twilight_points",
307 self.max_twilight_points().unwrap(),
308 )),
309 8usize if self.version().compatible((1u16, 0u16)) => {
310 Some(Field::new("max_storage", self.max_storage().unwrap()))
311 }
312 9usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
313 "max_function_defs",
314 self.max_function_defs().unwrap(),
315 )),
316 10usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
317 "max_instruction_defs",
318 self.max_instruction_defs().unwrap(),
319 )),
320 11usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
321 "max_stack_elements",
322 self.max_stack_elements().unwrap(),
323 )),
324 12usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
325 "max_size_of_instructions",
326 self.max_size_of_instructions().unwrap(),
327 )),
328 13usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
329 "max_component_elements",
330 self.max_component_elements().unwrap(),
331 )),
332 14usize if self.version().compatible((1u16, 0u16)) => Some(Field::new(
333 "max_component_depth",
334 self.max_component_depth().unwrap(),
335 )),
336 _ => None,
337 }
338 }
339}
340
341#[cfg(feature = "experimental_traverse")]
342#[allow(clippy::needless_lifetimes)]
343impl<'a> std::fmt::Debug for Maxp<'a> {
344 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
345 (self as &dyn SomeTable<'a>).fmt(f)
346 }
347}