1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Maxp {
12 pub num_glyphs: u16,
14 pub max_points: Option<u16>,
16 pub max_contours: Option<u16>,
18 pub max_composite_points: Option<u16>,
20 pub max_composite_contours: Option<u16>,
22 pub max_zones: Option<u16>,
25 pub max_twilight_points: Option<u16>,
27 pub max_storage: Option<u16>,
29 pub max_function_defs: Option<u16>,
31 pub max_instruction_defs: Option<u16>,
33 pub max_stack_elements: Option<u16>,
37 pub max_size_of_instructions: Option<u16>,
39 pub max_component_elements: Option<u16>,
42 pub max_component_depth: Option<u16>,
44}
45
46impl Maxp {
47 pub fn new(num_glyphs: u16) -> Self {
49 Self {
50 num_glyphs,
51 ..Default::default()
52 }
53 }
54}
55
56impl FontWrite for Maxp {
57 #[allow(clippy::unnecessary_cast)]
58 fn write_into(&self, writer: &mut TableWriter) {
59 let version = self.compute_version() as Version16Dot16;
60 version.write_into(writer);
61 self.num_glyphs.write_into(writer);
62 version.compatible((1u16, 0u16)).then(|| {
63 self.max_points
64 .as_ref()
65 .expect("missing conditional field should have failed validation")
66 .write_into(writer)
67 });
68 version.compatible((1u16, 0u16)).then(|| {
69 self.max_contours
70 .as_ref()
71 .expect("missing conditional field should have failed validation")
72 .write_into(writer)
73 });
74 version.compatible((1u16, 0u16)).then(|| {
75 self.max_composite_points
76 .as_ref()
77 .expect("missing conditional field should have failed validation")
78 .write_into(writer)
79 });
80 version.compatible((1u16, 0u16)).then(|| {
81 self.max_composite_contours
82 .as_ref()
83 .expect("missing conditional field should have failed validation")
84 .write_into(writer)
85 });
86 version.compatible((1u16, 0u16)).then(|| {
87 self.max_zones
88 .as_ref()
89 .expect("missing conditional field should have failed validation")
90 .write_into(writer)
91 });
92 version.compatible((1u16, 0u16)).then(|| {
93 self.max_twilight_points
94 .as_ref()
95 .expect("missing conditional field should have failed validation")
96 .write_into(writer)
97 });
98 version.compatible((1u16, 0u16)).then(|| {
99 self.max_storage
100 .as_ref()
101 .expect("missing conditional field should have failed validation")
102 .write_into(writer)
103 });
104 version.compatible((1u16, 0u16)).then(|| {
105 self.max_function_defs
106 .as_ref()
107 .expect("missing conditional field should have failed validation")
108 .write_into(writer)
109 });
110 version.compatible((1u16, 0u16)).then(|| {
111 self.max_instruction_defs
112 .as_ref()
113 .expect("missing conditional field should have failed validation")
114 .write_into(writer)
115 });
116 version.compatible((1u16, 0u16)).then(|| {
117 self.max_stack_elements
118 .as_ref()
119 .expect("missing conditional field should have failed validation")
120 .write_into(writer)
121 });
122 version.compatible((1u16, 0u16)).then(|| {
123 self.max_size_of_instructions
124 .as_ref()
125 .expect("missing conditional field should have failed validation")
126 .write_into(writer)
127 });
128 version.compatible((1u16, 0u16)).then(|| {
129 self.max_component_elements
130 .as_ref()
131 .expect("missing conditional field should have failed validation")
132 .write_into(writer)
133 });
134 version.compatible((1u16, 0u16)).then(|| {
135 self.max_component_depth
136 .as_ref()
137 .expect("missing conditional field should have failed validation")
138 .write_into(writer)
139 });
140 }
141 fn table_type(&self) -> TableType {
142 TableType::TopLevel(Maxp::TAG)
143 }
144}
145
146impl Validate for Maxp {
147 fn validate_impl(&self, ctx: &mut ValidationCtx) {
148 ctx.in_table("Maxp", |ctx| {
149 let version: Version16Dot16 = self.compute_version();
150 ctx.in_field("max_points", |ctx| {
151 if version.compatible((1u16, 0u16)) && self.max_points.is_none() {
152 ctx.report(format!("field must be present for version {version}"));
153 }
154 });
155 ctx.in_field("max_contours", |ctx| {
156 if version.compatible((1u16, 0u16)) && self.max_contours.is_none() {
157 ctx.report(format!("field must be present for version {version}"));
158 }
159 });
160 ctx.in_field("max_composite_points", |ctx| {
161 if version.compatible((1u16, 0u16)) && self.max_composite_points.is_none() {
162 ctx.report(format!("field must be present for version {version}"));
163 }
164 });
165 ctx.in_field("max_composite_contours", |ctx| {
166 if version.compatible((1u16, 0u16)) && self.max_composite_contours.is_none() {
167 ctx.report(format!("field must be present for version {version}"));
168 }
169 });
170 ctx.in_field("max_zones", |ctx| {
171 if version.compatible((1u16, 0u16)) && self.max_zones.is_none() {
172 ctx.report(format!("field must be present for version {version}"));
173 }
174 });
175 ctx.in_field("max_twilight_points", |ctx| {
176 if version.compatible((1u16, 0u16)) && self.max_twilight_points.is_none() {
177 ctx.report(format!("field must be present for version {version}"));
178 }
179 });
180 ctx.in_field("max_storage", |ctx| {
181 if version.compatible((1u16, 0u16)) && self.max_storage.is_none() {
182 ctx.report(format!("field must be present for version {version}"));
183 }
184 });
185 ctx.in_field("max_function_defs", |ctx| {
186 if version.compatible((1u16, 0u16)) && self.max_function_defs.is_none() {
187 ctx.report(format!("field must be present for version {version}"));
188 }
189 });
190 ctx.in_field("max_instruction_defs", |ctx| {
191 if version.compatible((1u16, 0u16)) && self.max_instruction_defs.is_none() {
192 ctx.report(format!("field must be present for version {version}"));
193 }
194 });
195 ctx.in_field("max_stack_elements", |ctx| {
196 if version.compatible((1u16, 0u16)) && self.max_stack_elements.is_none() {
197 ctx.report(format!("field must be present for version {version}"));
198 }
199 });
200 ctx.in_field("max_size_of_instructions", |ctx| {
201 if version.compatible((1u16, 0u16)) && self.max_size_of_instructions.is_none() {
202 ctx.report(format!("field must be present for version {version}"));
203 }
204 });
205 ctx.in_field("max_component_elements", |ctx| {
206 if version.compatible((1u16, 0u16)) && self.max_component_elements.is_none() {
207 ctx.report(format!("field must be present for version {version}"));
208 }
209 });
210 ctx.in_field("max_component_depth", |ctx| {
211 if version.compatible((1u16, 0u16)) && self.max_component_depth.is_none() {
212 ctx.report(format!("field must be present for version {version}"));
213 }
214 });
215 })
216 }
217}
218
219impl TopLevelTable for Maxp {
220 const TAG: Tag = Tag::new(b"maxp");
221}
222
223impl<'a> FromObjRef<read_fonts::tables::maxp::Maxp<'a>> for Maxp {
224 fn from_obj_ref(obj: &read_fonts::tables::maxp::Maxp<'a>, _: FontData) -> Self {
225 Maxp {
226 num_glyphs: obj.num_glyphs(),
227 max_points: obj.max_points(),
228 max_contours: obj.max_contours(),
229 max_composite_points: obj.max_composite_points(),
230 max_composite_contours: obj.max_composite_contours(),
231 max_zones: obj.max_zones(),
232 max_twilight_points: obj.max_twilight_points(),
233 max_storage: obj.max_storage(),
234 max_function_defs: obj.max_function_defs(),
235 max_instruction_defs: obj.max_instruction_defs(),
236 max_stack_elements: obj.max_stack_elements(),
237 max_size_of_instructions: obj.max_size_of_instructions(),
238 max_component_elements: obj.max_component_elements(),
239 max_component_depth: obj.max_component_depth(),
240 }
241 }
242}
243
244#[allow(clippy::needless_lifetimes)]
245impl<'a> FromTableRef<read_fonts::tables::maxp::Maxp<'a>> for Maxp {}
246
247impl ReadArgs for Maxp {
248 type Args = ();
249}
250
251impl<'a> FontRead<'a> for Maxp {
252 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
253 <read_fonts::tables::maxp::Maxp as FontRead>::read(data).map(|x| x.to_owned_table())
254 }
255}
256
257#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
259#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
260pub struct MaxpExtended {
261 pub num_glyphs: Uint24,
263 pub max_points: Option<u16>,
265 pub max_contours: Option<u16>,
267 pub max_composite_points: Option<u16>,
269 pub max_composite_contours: Option<u16>,
271 pub max_zones: Option<u16>,
273 pub max_twilight_points: Option<u16>,
275 pub max_storage: Option<u16>,
277 pub max_function_defs: Option<u16>,
279 pub max_instruction_defs: Option<u16>,
281 pub max_stack_elements: Option<u16>,
283 pub max_size_of_instructions: Option<u16>,
285 pub max_component_elements: Option<u16>,
287 pub max_component_depth: Option<u16>,
289}
290
291impl MaxpExtended {
292 pub fn new(num_glyphs: Uint24) -> Self {
294 Self {
295 num_glyphs,
296 ..Default::default()
297 }
298 }
299}
300
301impl FontWrite for MaxpExtended {
302 #[allow(clippy::unnecessary_cast)]
303 fn write_into(&self, writer: &mut TableWriter) {
304 let version = self.compute_version() as Version16Dot16;
305 version.write_into(writer);
306 self.num_glyphs.write_into(writer);
307 version.compatible((1u16, 0u16)).then(|| {
308 self.max_points
309 .as_ref()
310 .expect("missing conditional field should have failed validation")
311 .write_into(writer)
312 });
313 version.compatible((1u16, 0u16)).then(|| {
314 self.max_contours
315 .as_ref()
316 .expect("missing conditional field should have failed validation")
317 .write_into(writer)
318 });
319 version.compatible((1u16, 0u16)).then(|| {
320 self.max_composite_points
321 .as_ref()
322 .expect("missing conditional field should have failed validation")
323 .write_into(writer)
324 });
325 version.compatible((1u16, 0u16)).then(|| {
326 self.max_composite_contours
327 .as_ref()
328 .expect("missing conditional field should have failed validation")
329 .write_into(writer)
330 });
331 version.compatible((1u16, 0u16)).then(|| {
332 self.max_zones
333 .as_ref()
334 .expect("missing conditional field should have failed validation")
335 .write_into(writer)
336 });
337 version.compatible((1u16, 0u16)).then(|| {
338 self.max_twilight_points
339 .as_ref()
340 .expect("missing conditional field should have failed validation")
341 .write_into(writer)
342 });
343 version.compatible((1u16, 0u16)).then(|| {
344 self.max_storage
345 .as_ref()
346 .expect("missing conditional field should have failed validation")
347 .write_into(writer)
348 });
349 version.compatible((1u16, 0u16)).then(|| {
350 self.max_function_defs
351 .as_ref()
352 .expect("missing conditional field should have failed validation")
353 .write_into(writer)
354 });
355 version.compatible((1u16, 0u16)).then(|| {
356 self.max_instruction_defs
357 .as_ref()
358 .expect("missing conditional field should have failed validation")
359 .write_into(writer)
360 });
361 version.compatible((1u16, 0u16)).then(|| {
362 self.max_stack_elements
363 .as_ref()
364 .expect("missing conditional field should have failed validation")
365 .write_into(writer)
366 });
367 version.compatible((1u16, 0u16)).then(|| {
368 self.max_size_of_instructions
369 .as_ref()
370 .expect("missing conditional field should have failed validation")
371 .write_into(writer)
372 });
373 version.compatible((1u16, 0u16)).then(|| {
374 self.max_component_elements
375 .as_ref()
376 .expect("missing conditional field should have failed validation")
377 .write_into(writer)
378 });
379 version.compatible((1u16, 0u16)).then(|| {
380 self.max_component_depth
381 .as_ref()
382 .expect("missing conditional field should have failed validation")
383 .write_into(writer)
384 });
385 }
386 fn table_type(&self) -> TableType {
387 TableType::TopLevel(MaxpExtended::TAG)
388 }
389}
390
391impl Validate for MaxpExtended {
392 fn validate_impl(&self, ctx: &mut ValidationCtx) {
393 ctx.in_table("MaxpExtended", |ctx| {
394 let version: Version16Dot16 = self.compute_version();
395 ctx.in_field("max_points", |ctx| {
396 if version.compatible((1u16, 0u16)) && self.max_points.is_none() {
397 ctx.report(format!("field must be present for version {version}"));
398 }
399 });
400 ctx.in_field("max_contours", |ctx| {
401 if version.compatible((1u16, 0u16)) && self.max_contours.is_none() {
402 ctx.report(format!("field must be present for version {version}"));
403 }
404 });
405 ctx.in_field("max_composite_points", |ctx| {
406 if version.compatible((1u16, 0u16)) && self.max_composite_points.is_none() {
407 ctx.report(format!("field must be present for version {version}"));
408 }
409 });
410 ctx.in_field("max_composite_contours", |ctx| {
411 if version.compatible((1u16, 0u16)) && self.max_composite_contours.is_none() {
412 ctx.report(format!("field must be present for version {version}"));
413 }
414 });
415 ctx.in_field("max_zones", |ctx| {
416 if version.compatible((1u16, 0u16)) && self.max_zones.is_none() {
417 ctx.report(format!("field must be present for version {version}"));
418 }
419 });
420 ctx.in_field("max_twilight_points", |ctx| {
421 if version.compatible((1u16, 0u16)) && self.max_twilight_points.is_none() {
422 ctx.report(format!("field must be present for version {version}"));
423 }
424 });
425 ctx.in_field("max_storage", |ctx| {
426 if version.compatible((1u16, 0u16)) && self.max_storage.is_none() {
427 ctx.report(format!("field must be present for version {version}"));
428 }
429 });
430 ctx.in_field("max_function_defs", |ctx| {
431 if version.compatible((1u16, 0u16)) && self.max_function_defs.is_none() {
432 ctx.report(format!("field must be present for version {version}"));
433 }
434 });
435 ctx.in_field("max_instruction_defs", |ctx| {
436 if version.compatible((1u16, 0u16)) && self.max_instruction_defs.is_none() {
437 ctx.report(format!("field must be present for version {version}"));
438 }
439 });
440 ctx.in_field("max_stack_elements", |ctx| {
441 if version.compatible((1u16, 0u16)) && self.max_stack_elements.is_none() {
442 ctx.report(format!("field must be present for version {version}"));
443 }
444 });
445 ctx.in_field("max_size_of_instructions", |ctx| {
446 if version.compatible((1u16, 0u16)) && self.max_size_of_instructions.is_none() {
447 ctx.report(format!("field must be present for version {version}"));
448 }
449 });
450 ctx.in_field("max_component_elements", |ctx| {
451 if version.compatible((1u16, 0u16)) && self.max_component_elements.is_none() {
452 ctx.report(format!("field must be present for version {version}"));
453 }
454 });
455 ctx.in_field("max_component_depth", |ctx| {
456 if version.compatible((1u16, 0u16)) && self.max_component_depth.is_none() {
457 ctx.report(format!("field must be present for version {version}"));
458 }
459 });
460 })
461 }
462}
463
464impl TopLevelTable for MaxpExtended {
465 const TAG: Tag = Tag::new(b"MAXP");
466}
467
468impl<'a> FromObjRef<read_fonts::tables::maxp::MaxpExtended<'a>> for MaxpExtended {
469 fn from_obj_ref(obj: &read_fonts::tables::maxp::MaxpExtended<'a>, _: FontData) -> Self {
470 MaxpExtended {
471 num_glyphs: obj.num_glyphs(),
472 max_points: obj.max_points(),
473 max_contours: obj.max_contours(),
474 max_composite_points: obj.max_composite_points(),
475 max_composite_contours: obj.max_composite_contours(),
476 max_zones: obj.max_zones(),
477 max_twilight_points: obj.max_twilight_points(),
478 max_storage: obj.max_storage(),
479 max_function_defs: obj.max_function_defs(),
480 max_instruction_defs: obj.max_instruction_defs(),
481 max_stack_elements: obj.max_stack_elements(),
482 max_size_of_instructions: obj.max_size_of_instructions(),
483 max_component_elements: obj.max_component_elements(),
484 max_component_depth: obj.max_component_depth(),
485 }
486 }
487}
488
489#[allow(clippy::needless_lifetimes)]
490impl<'a> FromTableRef<read_fonts::tables::maxp::MaxpExtended<'a>> for MaxpExtended {}
491
492impl ReadArgs for MaxpExtended {
493 type Args = ();
494}
495
496impl<'a> FontRead<'a> for MaxpExtended {
497 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
498 <read_fonts::tables::maxp::MaxpExtended as FontRead>::read(data).map(|x| x.to_owned_table())
499 }
500}