1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Math<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.math_variants_offset_byte_range().end
11 }
12 fn min_table_bytes(&self) -> &'a [u8] {
13 let range = self.min_byte_range();
14 self.offset_data().as_bytes().get(range).unwrap_or_default()
15 }
16}
17
18impl TopLevelTable for Math<'_> {
19 const TAG: Tag = Tag::new(b"MATH");
21}
22
23impl ReadArgs for Math<'_> {
24 type Args = ();
25}
26
27impl<'a> FontRead<'a> for Math<'a> {
28 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29 #[allow(clippy::absurd_extreme_comparisons)]
30 if data.len() < Self::MIN_SIZE {
31 return Err(ReadError::OutOfBounds);
32 }
33 let Some(data) = TableDataRef::new(data.as_bytes()) else {
34 return Err(ReadError::OutOfBounds);
35 };
36 Ok(Self { data })
37 }
38}
39
40#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42#[repr(C, packed)]
43#[doc(hidden)]
44pub struct MathFixedHeader {
45 pub version: BigEndian<MajorMinor>,
46 pub math_constants_offset: BigEndian<Offset16>,
47 pub math_glyph_info_offset: BigEndian<Offset16>,
48 pub math_variants_offset: BigEndian<Offset16>,
49}
50
51#[allow(clippy::absurd_extreme_comparisons)]
52const _: () = assert!(std::mem::size_of::<MathFixedHeader>() <= Math::MIN_SIZE);
53
54#[derive(Clone)]
56pub struct Math<'a> {
57 data: TableDataRef<'a, MathFixedHeader>,
58}
59
60#[allow(clippy::needless_lifetimes)]
61impl<'a> Math<'a> {
62 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
63 + Offset16::RAW_BYTE_LEN
64 + Offset16::RAW_BYTE_LEN
65 + Offset16::RAW_BYTE_LEN);
66 basic_table_impls!(impl_the_methods);
67
68 pub fn version(&self) -> MajorMinor {
70 self.data.header().version.get()
71 }
72
73 pub fn math_constants_offset(&self) -> Offset16 {
75 self.data.header().math_constants_offset.get()
76 }
77
78 pub fn math_constants(&self) -> Result<MathConstants<'a>, ReadError> {
80 let data = self.offset_data();
81 self.math_constants_offset().resolve(data)
82 }
83
84 pub fn math_glyph_info_offset(&self) -> Offset16 {
86 self.data.header().math_glyph_info_offset.get()
87 }
88
89 pub fn math_glyph_info(&self) -> Result<MathGlyphInfo<'a>, ReadError> {
91 let data = self.offset_data();
92 self.math_glyph_info_offset().resolve(data)
93 }
94
95 pub fn math_variants_offset(&self) -> Offset16 {
97 self.data.header().math_variants_offset.get()
98 }
99
100 pub fn math_variants(&self) -> Result<MathVariants<'a>, ReadError> {
102 let data = self.offset_data();
103 self.math_variants_offset().resolve(data)
104 }
105
106 pub fn version_byte_range(&self) -> Range<usize> {
107 let start = 0usize;
108 let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
109 start..end
110 }
111
112 pub fn math_constants_offset_byte_range(&self) -> Range<usize> {
113 let start = self.version_byte_range().end;
114 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
115 start..end
116 }
117
118 pub fn math_glyph_info_offset_byte_range(&self) -> Range<usize> {
119 let start = self.math_constants_offset_byte_range().end;
120 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
121 start..end
122 }
123
124 pub fn math_variants_offset_byte_range(&self) -> Range<usize> {
125 let start = self.math_glyph_info_offset_byte_range().end;
126 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
127 start..end
128 }
129}
130
131const _: () = assert!(FontData::default_data_long_enough(Math::MIN_SIZE));
132
133impl Default for Math<'_> {
134 fn default() -> Self {
135 Self {
136 data: TableDataRef::new(FontData::default_table_data().as_bytes())
137 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
138 }
139 }
140}
141
142#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
147#[repr(C)]
148#[repr(packed)]
149pub struct MathValueRecord {
150 pub value: BigEndian<FWord>,
152 pub device_offset: BigEndian<Nullable<Offset16>>,
156}
157
158impl MathValueRecord {
159 pub fn value(&self) -> FWord {
161 self.value.get()
162 }
163
164 pub fn device_offset(&self) -> Nullable<Offset16> {
168 self.device_offset.get()
169 }
170
171 pub fn device<'a>(
178 &self,
179 data: FontData<'a>,
180 ) -> Option<Result<DeviceOrVariationIndex<'a>, ReadError>> {
181 self.device_offset().resolve(data)
182 }
183}
184
185impl FixedSize for MathValueRecord {
186 const RAW_BYTE_LEN: usize = FWord::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
187}
188
189impl<'a> MinByteRange<'a> for MathConstants<'a> {
190 fn min_byte_range(&self) -> Range<usize> {
191 0..self.radical_degree_bottom_raise_percent_byte_range().end
192 }
193 fn min_table_bytes(&self) -> &'a [u8] {
194 let range = self.min_byte_range();
195 self.offset_data().as_bytes().get(range).unwrap_or_default()
196 }
197}
198
199impl ReadArgs for MathConstants<'_> {
200 type Args = ();
201}
202
203impl<'a> FontRead<'a> for MathConstants<'a> {
204 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
205 #[allow(clippy::absurd_extreme_comparisons)]
206 if data.len() < Self::MIN_SIZE {
207 return Err(ReadError::OutOfBounds);
208 }
209 let Some(data) = TableDataRef::new(data.as_bytes()) else {
210 return Err(ReadError::OutOfBounds);
211 };
212 Ok(Self { data })
213 }
214}
215
216#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
218#[repr(C, packed)]
219#[doc(hidden)]
220pub struct MathConstantsFixedHeader {
221 pub script_percent_scale_down: BigEndian<i16>,
222 pub script_script_percent_scale_down: BigEndian<i16>,
223 pub delimited_sub_formula_min_height: BigEndian<UfWord>,
224 pub display_operator_min_height: BigEndian<UfWord>,
225 pub math_leading: MathValueRecord,
226 pub axis_height: MathValueRecord,
227 pub accent_base_height: MathValueRecord,
228 pub flattened_accent_base_height: MathValueRecord,
229 pub subscript_shift_down: MathValueRecord,
230 pub subscript_top_max: MathValueRecord,
231 pub subscript_baseline_drop_min: MathValueRecord,
232 pub superscript_shift_up: MathValueRecord,
233 pub superscript_shift_up_cramped: MathValueRecord,
234 pub superscript_bottom_min: MathValueRecord,
235 pub superscript_baseline_drop_max: MathValueRecord,
236 pub sub_superscript_gap_min: MathValueRecord,
237 pub superscript_bottom_max_with_subscript: MathValueRecord,
238 pub space_after_script: MathValueRecord,
239 pub upper_limit_gap_min: MathValueRecord,
240 pub upper_limit_baseline_rise_min: MathValueRecord,
241 pub lower_limit_gap_min: MathValueRecord,
242 pub lower_limit_baseline_drop_min: MathValueRecord,
243 pub stack_top_shift_up: MathValueRecord,
244 pub stack_top_display_style_shift_up: MathValueRecord,
245 pub stack_bottom_shift_down: MathValueRecord,
246 pub stack_bottom_display_style_shift_down: MathValueRecord,
247 pub stack_gap_min: MathValueRecord,
248 pub stack_display_style_gap_min: MathValueRecord,
249 pub stretch_stack_top_shift_up: MathValueRecord,
250 pub stretch_stack_bottom_shift_down: MathValueRecord,
251 pub stretch_stack_gap_above_min: MathValueRecord,
252 pub stretch_stack_gap_below_min: MathValueRecord,
253 pub fraction_numerator_shift_up: MathValueRecord,
254 pub fraction_numerator_display_style_shift_up: MathValueRecord,
255 pub fraction_denominator_shift_down: MathValueRecord,
256 pub fraction_denominator_display_style_shift_down: MathValueRecord,
257 pub fraction_numerator_gap_min: MathValueRecord,
258 pub fraction_num_display_style_gap_min: MathValueRecord,
259 pub fraction_rule_thickness: MathValueRecord,
260 pub fraction_denominator_gap_min: MathValueRecord,
261 pub fraction_denom_display_style_gap_min: MathValueRecord,
262 pub skewed_fraction_horizontal_gap: MathValueRecord,
263 pub skewed_fraction_vertical_gap: MathValueRecord,
264 pub overbar_vertical_gap: MathValueRecord,
265 pub overbar_rule_thickness: MathValueRecord,
266 pub overbar_extra_ascender: MathValueRecord,
267 pub underbar_vertical_gap: MathValueRecord,
268 pub underbar_rule_thickness: MathValueRecord,
269 pub underbar_extra_descender: MathValueRecord,
270 pub radical_vertical_gap: MathValueRecord,
271 pub radical_display_style_vertical_gap: MathValueRecord,
272 pub radical_rule_thickness: MathValueRecord,
273 pub radical_extra_ascender: MathValueRecord,
274 pub radical_kern_before_degree: MathValueRecord,
275 pub radical_kern_after_degree: MathValueRecord,
276 pub radical_degree_bottom_raise_percent: BigEndian<i16>,
277}
278
279#[allow(clippy::absurd_extreme_comparisons)]
280const _: () = assert!(std::mem::size_of::<MathConstantsFixedHeader>() <= MathConstants::MIN_SIZE);
281
282#[derive(Clone)]
284pub struct MathConstants<'a> {
285 data: TableDataRef<'a, MathConstantsFixedHeader>,
286}
287
288#[allow(clippy::needless_lifetimes)]
289impl<'a> MathConstants<'a> {
290 pub const MIN_SIZE: usize = (i16::RAW_BYTE_LEN
291 + i16::RAW_BYTE_LEN
292 + UfWord::RAW_BYTE_LEN
293 + UfWord::RAW_BYTE_LEN
294 + MathValueRecord::RAW_BYTE_LEN
295 + MathValueRecord::RAW_BYTE_LEN
296 + MathValueRecord::RAW_BYTE_LEN
297 + MathValueRecord::RAW_BYTE_LEN
298 + MathValueRecord::RAW_BYTE_LEN
299 + MathValueRecord::RAW_BYTE_LEN
300 + MathValueRecord::RAW_BYTE_LEN
301 + MathValueRecord::RAW_BYTE_LEN
302 + MathValueRecord::RAW_BYTE_LEN
303 + MathValueRecord::RAW_BYTE_LEN
304 + MathValueRecord::RAW_BYTE_LEN
305 + MathValueRecord::RAW_BYTE_LEN
306 + MathValueRecord::RAW_BYTE_LEN
307 + MathValueRecord::RAW_BYTE_LEN
308 + MathValueRecord::RAW_BYTE_LEN
309 + MathValueRecord::RAW_BYTE_LEN
310 + MathValueRecord::RAW_BYTE_LEN
311 + MathValueRecord::RAW_BYTE_LEN
312 + MathValueRecord::RAW_BYTE_LEN
313 + MathValueRecord::RAW_BYTE_LEN
314 + MathValueRecord::RAW_BYTE_LEN
315 + MathValueRecord::RAW_BYTE_LEN
316 + MathValueRecord::RAW_BYTE_LEN
317 + MathValueRecord::RAW_BYTE_LEN
318 + MathValueRecord::RAW_BYTE_LEN
319 + MathValueRecord::RAW_BYTE_LEN
320 + MathValueRecord::RAW_BYTE_LEN
321 + MathValueRecord::RAW_BYTE_LEN
322 + MathValueRecord::RAW_BYTE_LEN
323 + MathValueRecord::RAW_BYTE_LEN
324 + MathValueRecord::RAW_BYTE_LEN
325 + MathValueRecord::RAW_BYTE_LEN
326 + MathValueRecord::RAW_BYTE_LEN
327 + MathValueRecord::RAW_BYTE_LEN
328 + MathValueRecord::RAW_BYTE_LEN
329 + MathValueRecord::RAW_BYTE_LEN
330 + MathValueRecord::RAW_BYTE_LEN
331 + MathValueRecord::RAW_BYTE_LEN
332 + MathValueRecord::RAW_BYTE_LEN
333 + MathValueRecord::RAW_BYTE_LEN
334 + MathValueRecord::RAW_BYTE_LEN
335 + MathValueRecord::RAW_BYTE_LEN
336 + MathValueRecord::RAW_BYTE_LEN
337 + MathValueRecord::RAW_BYTE_LEN
338 + MathValueRecord::RAW_BYTE_LEN
339 + MathValueRecord::RAW_BYTE_LEN
340 + MathValueRecord::RAW_BYTE_LEN
341 + MathValueRecord::RAW_BYTE_LEN
342 + MathValueRecord::RAW_BYTE_LEN
343 + MathValueRecord::RAW_BYTE_LEN
344 + MathValueRecord::RAW_BYTE_LEN
345 + i16::RAW_BYTE_LEN);
346 basic_table_impls!(impl_the_methods);
347
348 pub fn script_percent_scale_down(&self) -> i16 {
350 self.data.header().script_percent_scale_down.get()
351 }
352
353 pub fn script_script_percent_scale_down(&self) -> i16 {
356 self.data.header().script_script_percent_scale_down.get()
357 }
358
359 pub fn delimited_sub_formula_min_height(&self) -> UfWord {
362 self.data.header().delimited_sub_formula_min_height.get()
363 }
364
365 pub fn display_operator_min_height(&self) -> UfWord {
369 self.data.header().display_operator_min_height.get()
370 }
371
372 pub fn math_leading(&self) -> &'a MathValueRecord {
375 &self.data.header().math_leading
376 }
377
378 pub fn axis_height(&self) -> &'a MathValueRecord {
380 &self.data.header().axis_height
381 }
382
383 pub fn accent_base_height(&self) -> &'a MathValueRecord {
386 &self.data.header().accent_base_height
387 }
388
389 pub fn flattened_accent_base_height(&self) -> &'a MathValueRecord {
392 &self.data.header().flattened_accent_base_height
393 }
394
395 pub fn subscript_shift_down(&self) -> &'a MathValueRecord {
397 &self.data.header().subscript_shift_down
398 }
399
400 pub fn subscript_top_max(&self) -> &'a MathValueRecord {
403 &self.data.header().subscript_top_max
404 }
405
406 pub fn subscript_baseline_drop_min(&self) -> &'a MathValueRecord {
409 &self.data.header().subscript_baseline_drop_min
410 }
411
412 pub fn superscript_shift_up(&self) -> &'a MathValueRecord {
414 &self.data.header().superscript_shift_up
415 }
416
417 pub fn superscript_shift_up_cramped(&self) -> &'a MathValueRecord {
419 &self.data.header().superscript_shift_up_cramped
420 }
421
422 pub fn superscript_bottom_min(&self) -> &'a MathValueRecord {
425 &self.data.header().superscript_bottom_min
426 }
427
428 pub fn superscript_baseline_drop_max(&self) -> &'a MathValueRecord {
431 &self.data.header().superscript_baseline_drop_max
432 }
433
434 pub fn sub_superscript_gap_min(&self) -> &'a MathValueRecord {
436 &self.data.header().sub_superscript_gap_min
437 }
438
439 pub fn superscript_bottom_max_with_subscript(&self) -> &'a MathValueRecord {
443 &self.data.header().superscript_bottom_max_with_subscript
444 }
445
446 pub fn space_after_script(&self) -> &'a MathValueRecord {
448 &self.data.header().space_after_script
449 }
450
451 pub fn upper_limit_gap_min(&self) -> &'a MathValueRecord {
454 &self.data.header().upper_limit_gap_min
455 }
456
457 pub fn upper_limit_baseline_rise_min(&self) -> &'a MathValueRecord {
460 &self.data.header().upper_limit_baseline_rise_min
461 }
462
463 pub fn lower_limit_gap_min(&self) -> &'a MathValueRecord {
466 &self.data.header().lower_limit_gap_min
467 }
468
469 pub fn lower_limit_baseline_drop_min(&self) -> &'a MathValueRecord {
472 &self.data.header().lower_limit_baseline_drop_min
473 }
474
475 pub fn stack_top_shift_up(&self) -> &'a MathValueRecord {
477 &self.data.header().stack_top_shift_up
478 }
479
480 pub fn stack_top_display_style_shift_up(&self) -> &'a MathValueRecord {
483 &self.data.header().stack_top_display_style_shift_up
484 }
485
486 pub fn stack_bottom_shift_down(&self) -> &'a MathValueRecord {
488 &self.data.header().stack_bottom_shift_down
489 }
490
491 pub fn stack_bottom_display_style_shift_down(&self) -> &'a MathValueRecord {
494 &self.data.header().stack_bottom_display_style_shift_down
495 }
496
497 pub fn stack_gap_min(&self) -> &'a MathValueRecord {
500 &self.data.header().stack_gap_min
501 }
502
503 pub fn stack_display_style_gap_min(&self) -> &'a MathValueRecord {
506 &self.data.header().stack_display_style_gap_min
507 }
508
509 pub fn stretch_stack_top_shift_up(&self) -> &'a MathValueRecord {
511 &self.data.header().stretch_stack_top_shift_up
512 }
513
514 pub fn stretch_stack_bottom_shift_down(&self) -> &'a MathValueRecord {
516 &self.data.header().stretch_stack_bottom_shift_down
517 }
518
519 pub fn stretch_stack_gap_above_min(&self) -> &'a MathValueRecord {
522 &self.data.header().stretch_stack_gap_above_min
523 }
524
525 pub fn stretch_stack_gap_below_min(&self) -> &'a MathValueRecord {
528 &self.data.header().stretch_stack_gap_below_min
529 }
530
531 pub fn fraction_numerator_shift_up(&self) -> &'a MathValueRecord {
533 &self.data.header().fraction_numerator_shift_up
534 }
535
536 pub fn fraction_numerator_display_style_shift_up(&self) -> &'a MathValueRecord {
538 &self.data.header().fraction_numerator_display_style_shift_up
539 }
540
541 pub fn fraction_denominator_shift_down(&self) -> &'a MathValueRecord {
543 &self.data.header().fraction_denominator_shift_down
544 }
545
546 pub fn fraction_denominator_display_style_shift_down(&self) -> &'a MathValueRecord {
548 &self
549 .data
550 .header()
551 .fraction_denominator_display_style_shift_down
552 }
553
554 pub fn fraction_numerator_gap_min(&self) -> &'a MathValueRecord {
557 &self.data.header().fraction_numerator_gap_min
558 }
559
560 pub fn fraction_num_display_style_gap_min(&self) -> &'a MathValueRecord {
563 &self.data.header().fraction_num_display_style_gap_min
564 }
565
566 pub fn fraction_rule_thickness(&self) -> &'a MathValueRecord {
568 &self.data.header().fraction_rule_thickness
569 }
570
571 pub fn fraction_denominator_gap_min(&self) -> &'a MathValueRecord {
574 &self.data.header().fraction_denominator_gap_min
575 }
576
577 pub fn fraction_denom_display_style_gap_min(&self) -> &'a MathValueRecord {
580 &self.data.header().fraction_denom_display_style_gap_min
581 }
582
583 pub fn skewed_fraction_horizontal_gap(&self) -> &'a MathValueRecord {
586 &self.data.header().skewed_fraction_horizontal_gap
587 }
588
589 pub fn skewed_fraction_vertical_gap(&self) -> &'a MathValueRecord {
592 &self.data.header().skewed_fraction_vertical_gap
593 }
594
595 pub fn overbar_vertical_gap(&self) -> &'a MathValueRecord {
597 &self.data.header().overbar_vertical_gap
598 }
599
600 pub fn overbar_rule_thickness(&self) -> &'a MathValueRecord {
602 &self.data.header().overbar_rule_thickness
603 }
604
605 pub fn overbar_extra_ascender(&self) -> &'a MathValueRecord {
607 &self.data.header().overbar_extra_ascender
608 }
609
610 pub fn underbar_vertical_gap(&self) -> &'a MathValueRecord {
612 &self.data.header().underbar_vertical_gap
613 }
614
615 pub fn underbar_rule_thickness(&self) -> &'a MathValueRecord {
617 &self.data.header().underbar_rule_thickness
618 }
619
620 pub fn underbar_extra_descender(&self) -> &'a MathValueRecord {
622 &self.data.header().underbar_extra_descender
623 }
624
625 pub fn radical_vertical_gap(&self) -> &'a MathValueRecord {
627 &self.data.header().radical_vertical_gap
628 }
629
630 pub fn radical_display_style_vertical_gap(&self) -> &'a MathValueRecord {
633 &self.data.header().radical_display_style_vertical_gap
634 }
635
636 pub fn radical_rule_thickness(&self) -> &'a MathValueRecord {
638 &self.data.header().radical_rule_thickness
639 }
640
641 pub fn radical_extra_ascender(&self) -> &'a MathValueRecord {
643 &self.data.header().radical_extra_ascender
644 }
645
646 pub fn radical_kern_before_degree(&self) -> &'a MathValueRecord {
649 &self.data.header().radical_kern_before_degree
650 }
651
652 pub fn radical_kern_after_degree(&self) -> &'a MathValueRecord {
654 &self.data.header().radical_kern_after_degree
655 }
656
657 pub fn radical_degree_bottom_raise_percent(&self) -> i16 {
660 self.data.header().radical_degree_bottom_raise_percent.get()
661 }
662
663 pub fn script_percent_scale_down_byte_range(&self) -> Range<usize> {
664 let start = 0usize;
665 let end = start.saturating_add(i16::RAW_BYTE_LEN);
666 start..end
667 }
668
669 pub fn script_script_percent_scale_down_byte_range(&self) -> Range<usize> {
670 let start = self.script_percent_scale_down_byte_range().end;
671 let end = start.saturating_add(i16::RAW_BYTE_LEN);
672 start..end
673 }
674
675 pub fn delimited_sub_formula_min_height_byte_range(&self) -> Range<usize> {
676 let start = self.script_script_percent_scale_down_byte_range().end;
677 let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
678 start..end
679 }
680
681 pub fn display_operator_min_height_byte_range(&self) -> Range<usize> {
682 let start = self.delimited_sub_formula_min_height_byte_range().end;
683 let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
684 start..end
685 }
686
687 pub fn math_leading_byte_range(&self) -> Range<usize> {
688 let start = self.display_operator_min_height_byte_range().end;
689 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
690 start..end
691 }
692
693 pub fn axis_height_byte_range(&self) -> Range<usize> {
694 let start = self.math_leading_byte_range().end;
695 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
696 start..end
697 }
698
699 pub fn accent_base_height_byte_range(&self) -> Range<usize> {
700 let start = self.axis_height_byte_range().end;
701 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
702 start..end
703 }
704
705 pub fn flattened_accent_base_height_byte_range(&self) -> Range<usize> {
706 let start = self.accent_base_height_byte_range().end;
707 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
708 start..end
709 }
710
711 pub fn subscript_shift_down_byte_range(&self) -> Range<usize> {
712 let start = self.flattened_accent_base_height_byte_range().end;
713 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
714 start..end
715 }
716
717 pub fn subscript_top_max_byte_range(&self) -> Range<usize> {
718 let start = self.subscript_shift_down_byte_range().end;
719 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
720 start..end
721 }
722
723 pub fn subscript_baseline_drop_min_byte_range(&self) -> Range<usize> {
724 let start = self.subscript_top_max_byte_range().end;
725 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
726 start..end
727 }
728
729 pub fn superscript_shift_up_byte_range(&self) -> Range<usize> {
730 let start = self.subscript_baseline_drop_min_byte_range().end;
731 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
732 start..end
733 }
734
735 pub fn superscript_shift_up_cramped_byte_range(&self) -> Range<usize> {
736 let start = self.superscript_shift_up_byte_range().end;
737 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
738 start..end
739 }
740
741 pub fn superscript_bottom_min_byte_range(&self) -> Range<usize> {
742 let start = self.superscript_shift_up_cramped_byte_range().end;
743 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
744 start..end
745 }
746
747 pub fn superscript_baseline_drop_max_byte_range(&self) -> Range<usize> {
748 let start = self.superscript_bottom_min_byte_range().end;
749 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
750 start..end
751 }
752
753 pub fn sub_superscript_gap_min_byte_range(&self) -> Range<usize> {
754 let start = self.superscript_baseline_drop_max_byte_range().end;
755 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
756 start..end
757 }
758
759 pub fn superscript_bottom_max_with_subscript_byte_range(&self) -> Range<usize> {
760 let start = self.sub_superscript_gap_min_byte_range().end;
761 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
762 start..end
763 }
764
765 pub fn space_after_script_byte_range(&self) -> Range<usize> {
766 let start = self.superscript_bottom_max_with_subscript_byte_range().end;
767 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
768 start..end
769 }
770
771 pub fn upper_limit_gap_min_byte_range(&self) -> Range<usize> {
772 let start = self.space_after_script_byte_range().end;
773 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
774 start..end
775 }
776
777 pub fn upper_limit_baseline_rise_min_byte_range(&self) -> Range<usize> {
778 let start = self.upper_limit_gap_min_byte_range().end;
779 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
780 start..end
781 }
782
783 pub fn lower_limit_gap_min_byte_range(&self) -> Range<usize> {
784 let start = self.upper_limit_baseline_rise_min_byte_range().end;
785 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
786 start..end
787 }
788
789 pub fn lower_limit_baseline_drop_min_byte_range(&self) -> Range<usize> {
790 let start = self.lower_limit_gap_min_byte_range().end;
791 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
792 start..end
793 }
794
795 pub fn stack_top_shift_up_byte_range(&self) -> Range<usize> {
796 let start = self.lower_limit_baseline_drop_min_byte_range().end;
797 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
798 start..end
799 }
800
801 pub fn stack_top_display_style_shift_up_byte_range(&self) -> Range<usize> {
802 let start = self.stack_top_shift_up_byte_range().end;
803 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
804 start..end
805 }
806
807 pub fn stack_bottom_shift_down_byte_range(&self) -> Range<usize> {
808 let start = self.stack_top_display_style_shift_up_byte_range().end;
809 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
810 start..end
811 }
812
813 pub fn stack_bottom_display_style_shift_down_byte_range(&self) -> Range<usize> {
814 let start = self.stack_bottom_shift_down_byte_range().end;
815 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
816 start..end
817 }
818
819 pub fn stack_gap_min_byte_range(&self) -> Range<usize> {
820 let start = self.stack_bottom_display_style_shift_down_byte_range().end;
821 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
822 start..end
823 }
824
825 pub fn stack_display_style_gap_min_byte_range(&self) -> Range<usize> {
826 let start = self.stack_gap_min_byte_range().end;
827 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
828 start..end
829 }
830
831 pub fn stretch_stack_top_shift_up_byte_range(&self) -> Range<usize> {
832 let start = self.stack_display_style_gap_min_byte_range().end;
833 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
834 start..end
835 }
836
837 pub fn stretch_stack_bottom_shift_down_byte_range(&self) -> Range<usize> {
838 let start = self.stretch_stack_top_shift_up_byte_range().end;
839 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
840 start..end
841 }
842
843 pub fn stretch_stack_gap_above_min_byte_range(&self) -> Range<usize> {
844 let start = self.stretch_stack_bottom_shift_down_byte_range().end;
845 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
846 start..end
847 }
848
849 pub fn stretch_stack_gap_below_min_byte_range(&self) -> Range<usize> {
850 let start = self.stretch_stack_gap_above_min_byte_range().end;
851 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
852 start..end
853 }
854
855 pub fn fraction_numerator_shift_up_byte_range(&self) -> Range<usize> {
856 let start = self.stretch_stack_gap_below_min_byte_range().end;
857 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
858 start..end
859 }
860
861 pub fn fraction_numerator_display_style_shift_up_byte_range(&self) -> Range<usize> {
862 let start = self.fraction_numerator_shift_up_byte_range().end;
863 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
864 start..end
865 }
866
867 pub fn fraction_denominator_shift_down_byte_range(&self) -> Range<usize> {
868 let start = self
869 .fraction_numerator_display_style_shift_up_byte_range()
870 .end;
871 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
872 start..end
873 }
874
875 pub fn fraction_denominator_display_style_shift_down_byte_range(&self) -> Range<usize> {
876 let start = self.fraction_denominator_shift_down_byte_range().end;
877 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
878 start..end
879 }
880
881 pub fn fraction_numerator_gap_min_byte_range(&self) -> Range<usize> {
882 let start = self
883 .fraction_denominator_display_style_shift_down_byte_range()
884 .end;
885 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
886 start..end
887 }
888
889 pub fn fraction_num_display_style_gap_min_byte_range(&self) -> Range<usize> {
890 let start = self.fraction_numerator_gap_min_byte_range().end;
891 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
892 start..end
893 }
894
895 pub fn fraction_rule_thickness_byte_range(&self) -> Range<usize> {
896 let start = self.fraction_num_display_style_gap_min_byte_range().end;
897 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
898 start..end
899 }
900
901 pub fn fraction_denominator_gap_min_byte_range(&self) -> Range<usize> {
902 let start = self.fraction_rule_thickness_byte_range().end;
903 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
904 start..end
905 }
906
907 pub fn fraction_denom_display_style_gap_min_byte_range(&self) -> Range<usize> {
908 let start = self.fraction_denominator_gap_min_byte_range().end;
909 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
910 start..end
911 }
912
913 pub fn skewed_fraction_horizontal_gap_byte_range(&self) -> Range<usize> {
914 let start = self.fraction_denom_display_style_gap_min_byte_range().end;
915 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
916 start..end
917 }
918
919 pub fn skewed_fraction_vertical_gap_byte_range(&self) -> Range<usize> {
920 let start = self.skewed_fraction_horizontal_gap_byte_range().end;
921 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
922 start..end
923 }
924
925 pub fn overbar_vertical_gap_byte_range(&self) -> Range<usize> {
926 let start = self.skewed_fraction_vertical_gap_byte_range().end;
927 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
928 start..end
929 }
930
931 pub fn overbar_rule_thickness_byte_range(&self) -> Range<usize> {
932 let start = self.overbar_vertical_gap_byte_range().end;
933 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
934 start..end
935 }
936
937 pub fn overbar_extra_ascender_byte_range(&self) -> Range<usize> {
938 let start = self.overbar_rule_thickness_byte_range().end;
939 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
940 start..end
941 }
942
943 pub fn underbar_vertical_gap_byte_range(&self) -> Range<usize> {
944 let start = self.overbar_extra_ascender_byte_range().end;
945 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
946 start..end
947 }
948
949 pub fn underbar_rule_thickness_byte_range(&self) -> Range<usize> {
950 let start = self.underbar_vertical_gap_byte_range().end;
951 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
952 start..end
953 }
954
955 pub fn underbar_extra_descender_byte_range(&self) -> Range<usize> {
956 let start = self.underbar_rule_thickness_byte_range().end;
957 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
958 start..end
959 }
960
961 pub fn radical_vertical_gap_byte_range(&self) -> Range<usize> {
962 let start = self.underbar_extra_descender_byte_range().end;
963 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
964 start..end
965 }
966
967 pub fn radical_display_style_vertical_gap_byte_range(&self) -> Range<usize> {
968 let start = self.radical_vertical_gap_byte_range().end;
969 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
970 start..end
971 }
972
973 pub fn radical_rule_thickness_byte_range(&self) -> Range<usize> {
974 let start = self.radical_display_style_vertical_gap_byte_range().end;
975 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
976 start..end
977 }
978
979 pub fn radical_extra_ascender_byte_range(&self) -> Range<usize> {
980 let start = self.radical_rule_thickness_byte_range().end;
981 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
982 start..end
983 }
984
985 pub fn radical_kern_before_degree_byte_range(&self) -> Range<usize> {
986 let start = self.radical_extra_ascender_byte_range().end;
987 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
988 start..end
989 }
990
991 pub fn radical_kern_after_degree_byte_range(&self) -> Range<usize> {
992 let start = self.radical_kern_before_degree_byte_range().end;
993 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
994 start..end
995 }
996
997 pub fn radical_degree_bottom_raise_percent_byte_range(&self) -> Range<usize> {
998 let start = self.radical_kern_after_degree_byte_range().end;
999 let end = start.saturating_add(i16::RAW_BYTE_LEN);
1000 start..end
1001 }
1002}
1003
1004const _: () = assert!(FontData::default_data_long_enough(MathConstants::MIN_SIZE));
1005
1006impl Default for MathConstants<'_> {
1007 fn default() -> Self {
1008 Self {
1009 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1010 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1011 }
1012 }
1013}
1014
1015impl<'a> MinByteRange<'a> for MathGlyphInfo<'a> {
1016 fn min_byte_range(&self) -> Range<usize> {
1017 0..self.math_kern_info_offset_byte_range().end
1018 }
1019 fn min_table_bytes(&self) -> &'a [u8] {
1020 let range = self.min_byte_range();
1021 self.offset_data().as_bytes().get(range).unwrap_or_default()
1022 }
1023}
1024
1025impl ReadArgs for MathGlyphInfo<'_> {
1026 type Args = ();
1027}
1028
1029impl<'a> FontRead<'a> for MathGlyphInfo<'a> {
1030 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1031 #[allow(clippy::absurd_extreme_comparisons)]
1032 if data.len() < Self::MIN_SIZE {
1033 return Err(ReadError::OutOfBounds);
1034 }
1035 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1036 return Err(ReadError::OutOfBounds);
1037 };
1038 Ok(Self { data })
1039 }
1040}
1041
1042#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1044#[repr(C, packed)]
1045#[doc(hidden)]
1046pub struct MathGlyphInfoFixedHeader {
1047 pub math_italics_correction_info_offset: BigEndian<Nullable<Offset16>>,
1048 pub math_top_accent_attachment_offset: BigEndian<Nullable<Offset16>>,
1049 pub extended_shape_coverage_offset: BigEndian<Nullable<Offset16>>,
1050 pub math_kern_info_offset: BigEndian<Nullable<Offset16>>,
1051}
1052
1053#[allow(clippy::absurd_extreme_comparisons)]
1054const _: () = assert!(std::mem::size_of::<MathGlyphInfoFixedHeader>() <= MathGlyphInfo::MIN_SIZE);
1055
1056#[derive(Clone)]
1058pub struct MathGlyphInfo<'a> {
1059 data: TableDataRef<'a, MathGlyphInfoFixedHeader>,
1060}
1061
1062#[allow(clippy::needless_lifetimes)]
1063impl<'a> MathGlyphInfo<'a> {
1064 pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN
1065 + Offset16::RAW_BYTE_LEN
1066 + Offset16::RAW_BYTE_LEN
1067 + Offset16::RAW_BYTE_LEN);
1068 basic_table_impls!(impl_the_methods);
1069
1070 pub fn math_italics_correction_info_offset(&self) -> Nullable<Offset16> {
1073 self.data.header().math_italics_correction_info_offset.get()
1074 }
1075
1076 pub fn math_italics_correction_info(
1078 &self,
1079 ) -> Option<Result<MathItalicsCorrectionInfo<'a>, ReadError>> {
1080 let data = self.offset_data();
1081 self.math_italics_correction_info_offset().resolve(data)
1082 }
1083
1084 pub fn math_top_accent_attachment_offset(&self) -> Nullable<Offset16> {
1087 self.data.header().math_top_accent_attachment_offset.get()
1088 }
1089
1090 pub fn math_top_accent_attachment(
1092 &self,
1093 ) -> Option<Result<MathTopAccentAttachment<'a>, ReadError>> {
1094 let data = self.offset_data();
1095 self.math_top_accent_attachment_offset().resolve(data)
1096 }
1097
1098 pub fn extended_shape_coverage_offset(&self) -> Nullable<Offset16> {
1101 self.data.header().extended_shape_coverage_offset.get()
1102 }
1103
1104 pub fn extended_shape_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
1106 let data = self.offset_data();
1107 self.extended_shape_coverage_offset().resolve(data)
1108 }
1109
1110 pub fn math_kern_info_offset(&self) -> Nullable<Offset16> {
1113 self.data.header().math_kern_info_offset.get()
1114 }
1115
1116 pub fn math_kern_info(&self) -> Option<Result<MathKernInfo<'a>, ReadError>> {
1118 let data = self.offset_data();
1119 self.math_kern_info_offset().resolve(data)
1120 }
1121
1122 pub fn math_italics_correction_info_offset_byte_range(&self) -> Range<usize> {
1123 let start = 0usize;
1124 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1125 start..end
1126 }
1127
1128 pub fn math_top_accent_attachment_offset_byte_range(&self) -> Range<usize> {
1129 let start = self.math_italics_correction_info_offset_byte_range().end;
1130 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1131 start..end
1132 }
1133
1134 pub fn extended_shape_coverage_offset_byte_range(&self) -> Range<usize> {
1135 let start = self.math_top_accent_attachment_offset_byte_range().end;
1136 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1137 start..end
1138 }
1139
1140 pub fn math_kern_info_offset_byte_range(&self) -> Range<usize> {
1141 let start = self.extended_shape_coverage_offset_byte_range().end;
1142 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1143 start..end
1144 }
1145}
1146
1147const _: () = assert!(FontData::default_data_long_enough(MathGlyphInfo::MIN_SIZE));
1148
1149impl Default for MathGlyphInfo<'_> {
1150 fn default() -> Self {
1151 Self {
1152 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1153 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1154 }
1155 }
1156}
1157
1158impl<'a> MinByteRange<'a> for MathItalicsCorrectionInfo<'a> {
1159 fn min_byte_range(&self) -> Range<usize> {
1160 0..self.italics_correction_byte_range().end
1161 }
1162 fn min_table_bytes(&self) -> &'a [u8] {
1163 let range = self.min_byte_range();
1164 self.offset_data().as_bytes().get(range).unwrap_or_default()
1165 }
1166}
1167
1168impl ReadArgs for MathItalicsCorrectionInfo<'_> {
1169 type Args = ();
1170}
1171
1172impl<'a> FontRead<'a> for MathItalicsCorrectionInfo<'a> {
1173 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1174 #[allow(clippy::absurd_extreme_comparisons)]
1175 if data.len() < Self::MIN_SIZE {
1176 return Err(ReadError::OutOfBounds);
1177 }
1178 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1179 return Err(ReadError::OutOfBounds);
1180 };
1181 Ok(Self { data })
1182 }
1183}
1184
1185#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1187#[repr(C, packed)]
1188#[doc(hidden)]
1189pub struct MathItalicsCorrectionInfoFixedHeader {
1190 pub coverage_offset: BigEndian<Offset16>,
1191 pub italics_correction_count: BigEndian<u16>,
1192}
1193
1194#[allow(clippy::absurd_extreme_comparisons)]
1195const _: () = assert!(
1196 std::mem::size_of::<MathItalicsCorrectionInfoFixedHeader>()
1197 <= MathItalicsCorrectionInfo::MIN_SIZE
1198);
1199
1200#[derive(Clone)]
1202pub struct MathItalicsCorrectionInfo<'a> {
1203 data: TableDataRef<'a, MathItalicsCorrectionInfoFixedHeader>,
1204}
1205
1206#[allow(clippy::needless_lifetimes)]
1207impl<'a> MathItalicsCorrectionInfo<'a> {
1208 pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1209 basic_table_impls!(impl_the_methods);
1210
1211 pub fn coverage_offset(&self) -> Offset16 {
1214 self.data.header().coverage_offset.get()
1215 }
1216
1217 pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1219 let data = self.offset_data();
1220 self.coverage_offset().resolve(data)
1221 }
1222
1223 pub fn italics_correction_count(&self) -> u16 {
1226 self.data.header().italics_correction_count.get()
1227 }
1228
1229 pub fn italics_correction(&self) -> &'a [MathValueRecord] {
1232 let range = self.italics_correction_byte_range();
1233 self.offset_data()
1234 .read_array(range)
1235 .ok()
1236 .unwrap_or_default()
1237 }
1238
1239 pub fn coverage_offset_byte_range(&self) -> Range<usize> {
1240 let start = 0usize;
1241 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1242 start..end
1243 }
1244
1245 pub fn italics_correction_count_byte_range(&self) -> Range<usize> {
1246 let start = self.coverage_offset_byte_range().end;
1247 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1248 start..end
1249 }
1250
1251 pub fn italics_correction_byte_range(&self) -> Range<usize> {
1252 let italics_correction_count = self.italics_correction_count();
1253 let start = self.italics_correction_count_byte_range().end;
1254 let end = start.saturating_add(
1255 (transforms::to_usize(italics_correction_count))
1256 .saturating_mul(MathValueRecord::RAW_BYTE_LEN),
1257 );
1258 start..end
1259 }
1260}
1261
1262const _: () = assert!(FontData::default_data_long_enough(
1263 MathItalicsCorrectionInfo::MIN_SIZE
1264));
1265
1266impl Default for MathItalicsCorrectionInfo<'_> {
1267 fn default() -> Self {
1268 Self {
1269 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1270 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1271 }
1272 }
1273}
1274
1275impl<'a> MinByteRange<'a> for MathTopAccentAttachment<'a> {
1276 fn min_byte_range(&self) -> Range<usize> {
1277 0..self.top_accent_attachment_byte_range().end
1278 }
1279 fn min_table_bytes(&self) -> &'a [u8] {
1280 let range = self.min_byte_range();
1281 self.offset_data().as_bytes().get(range).unwrap_or_default()
1282 }
1283}
1284
1285impl ReadArgs for MathTopAccentAttachment<'_> {
1286 type Args = ();
1287}
1288
1289impl<'a> FontRead<'a> for MathTopAccentAttachment<'a> {
1290 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1291 #[allow(clippy::absurd_extreme_comparisons)]
1292 if data.len() < Self::MIN_SIZE {
1293 return Err(ReadError::OutOfBounds);
1294 }
1295 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1296 return Err(ReadError::OutOfBounds);
1297 };
1298 Ok(Self { data })
1299 }
1300}
1301
1302#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1304#[repr(C, packed)]
1305#[doc(hidden)]
1306pub struct MathTopAccentAttachmentFixedHeader {
1307 pub top_accent_coverage_offset: BigEndian<Offset16>,
1308 pub top_accent_attachment_count: BigEndian<u16>,
1309}
1310
1311#[allow(clippy::absurd_extreme_comparisons)]
1312const _: () = assert!(
1313 std::mem::size_of::<MathTopAccentAttachmentFixedHeader>() <= MathTopAccentAttachment::MIN_SIZE
1314);
1315
1316#[derive(Clone)]
1318pub struct MathTopAccentAttachment<'a> {
1319 data: TableDataRef<'a, MathTopAccentAttachmentFixedHeader>,
1320}
1321
1322#[allow(clippy::needless_lifetimes)]
1323impl<'a> MathTopAccentAttachment<'a> {
1324 pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1325 basic_table_impls!(impl_the_methods);
1326
1327 pub fn top_accent_coverage_offset(&self) -> Offset16 {
1330 self.data.header().top_accent_coverage_offset.get()
1331 }
1332
1333 pub fn top_accent_coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1335 let data = self.offset_data();
1336 self.top_accent_coverage_offset().resolve(data)
1337 }
1338
1339 pub fn top_accent_attachment_count(&self) -> u16 {
1342 self.data.header().top_accent_attachment_count.get()
1343 }
1344
1345 pub fn top_accent_attachment(&self) -> &'a [MathValueRecord] {
1348 let range = self.top_accent_attachment_byte_range();
1349 self.offset_data()
1350 .read_array(range)
1351 .ok()
1352 .unwrap_or_default()
1353 }
1354
1355 pub fn top_accent_coverage_offset_byte_range(&self) -> Range<usize> {
1356 let start = 0usize;
1357 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1358 start..end
1359 }
1360
1361 pub fn top_accent_attachment_count_byte_range(&self) -> Range<usize> {
1362 let start = self.top_accent_coverage_offset_byte_range().end;
1363 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1364 start..end
1365 }
1366
1367 pub fn top_accent_attachment_byte_range(&self) -> Range<usize> {
1368 let top_accent_attachment_count = self.top_accent_attachment_count();
1369 let start = self.top_accent_attachment_count_byte_range().end;
1370 let end = start.saturating_add(
1371 (transforms::to_usize(top_accent_attachment_count))
1372 .saturating_mul(MathValueRecord::RAW_BYTE_LEN),
1373 );
1374 start..end
1375 }
1376}
1377
1378const _: () = assert!(FontData::default_data_long_enough(
1379 MathTopAccentAttachment::MIN_SIZE
1380));
1381
1382impl Default for MathTopAccentAttachment<'_> {
1383 fn default() -> Self {
1384 Self {
1385 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1386 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1387 }
1388 }
1389}
1390
1391impl<'a> MinByteRange<'a> for MathKernInfo<'a> {
1392 fn min_byte_range(&self) -> Range<usize> {
1393 0..self.math_kern_info_records_byte_range().end
1394 }
1395 fn min_table_bytes(&self) -> &'a [u8] {
1396 let range = self.min_byte_range();
1397 self.offset_data().as_bytes().get(range).unwrap_or_default()
1398 }
1399}
1400
1401impl ReadArgs for MathKernInfo<'_> {
1402 type Args = ();
1403}
1404
1405impl<'a> FontRead<'a> for MathKernInfo<'a> {
1406 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1407 #[allow(clippy::absurd_extreme_comparisons)]
1408 if data.len() < Self::MIN_SIZE {
1409 return Err(ReadError::OutOfBounds);
1410 }
1411 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1412 return Err(ReadError::OutOfBounds);
1413 };
1414 Ok(Self { data })
1415 }
1416}
1417
1418#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1420#[repr(C, packed)]
1421#[doc(hidden)]
1422pub struct MathKernInfoFixedHeader {
1423 pub math_kern_coverage_offset: BigEndian<Offset16>,
1424 pub math_kern_count: BigEndian<u16>,
1425}
1426
1427#[allow(clippy::absurd_extreme_comparisons)]
1428const _: () = assert!(std::mem::size_of::<MathKernInfoFixedHeader>() <= MathKernInfo::MIN_SIZE);
1429
1430#[derive(Clone)]
1432pub struct MathKernInfo<'a> {
1433 data: TableDataRef<'a, MathKernInfoFixedHeader>,
1434}
1435
1436#[allow(clippy::needless_lifetimes)]
1437impl<'a> MathKernInfo<'a> {
1438 pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1439 basic_table_impls!(impl_the_methods);
1440
1441 pub fn math_kern_coverage_offset(&self) -> Offset16 {
1444 self.data.header().math_kern_coverage_offset.get()
1445 }
1446
1447 pub fn math_kern_coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1449 let data = self.offset_data();
1450 self.math_kern_coverage_offset().resolve(data)
1451 }
1452
1453 pub fn math_kern_count(&self) -> u16 {
1456 self.data.header().math_kern_count.get()
1457 }
1458
1459 pub fn math_kern_info_records(&self) -> &'a [MathKernInfoRecord] {
1461 let range = self.math_kern_info_records_byte_range();
1462 self.offset_data()
1463 .read_array(range)
1464 .ok()
1465 .unwrap_or_default()
1466 }
1467
1468 pub fn math_kern_coverage_offset_byte_range(&self) -> Range<usize> {
1469 let start = 0usize;
1470 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1471 start..end
1472 }
1473
1474 pub fn math_kern_count_byte_range(&self) -> Range<usize> {
1475 let start = self.math_kern_coverage_offset_byte_range().end;
1476 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1477 start..end
1478 }
1479
1480 pub fn math_kern_info_records_byte_range(&self) -> Range<usize> {
1481 let math_kern_count = self.math_kern_count();
1482 let start = self.math_kern_count_byte_range().end;
1483 let end = start.saturating_add(
1484 (transforms::to_usize(math_kern_count))
1485 .saturating_mul(MathKernInfoRecord::RAW_BYTE_LEN),
1486 );
1487 start..end
1488 }
1489}
1490
1491const _: () = assert!(FontData::default_data_long_enough(MathKernInfo::MIN_SIZE));
1492
1493impl Default for MathKernInfo<'_> {
1494 fn default() -> Self {
1495 Self {
1496 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1497 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1498 }
1499 }
1500}
1501
1502#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
1506#[repr(C)]
1507#[repr(packed)]
1508pub struct MathKernInfoRecord {
1509 pub top_right_math_kern_offset: BigEndian<Nullable<Offset16>>,
1512 pub top_left_math_kern_offset: BigEndian<Nullable<Offset16>>,
1515 pub bottom_right_math_kern_offset: BigEndian<Nullable<Offset16>>,
1518 pub bottom_left_math_kern_offset: BigEndian<Nullable<Offset16>>,
1521}
1522
1523impl MathKernInfoRecord {
1524 pub fn top_right_math_kern_offset(&self) -> Nullable<Offset16> {
1527 self.top_right_math_kern_offset.get()
1528 }
1529
1530 pub fn top_right_math_kern<'a>(
1536 &self,
1537 data: FontData<'a>,
1538 ) -> Option<Result<MathKern<'a>, ReadError>> {
1539 self.top_right_math_kern_offset().resolve(data)
1540 }
1541
1542 pub fn top_left_math_kern_offset(&self) -> Nullable<Offset16> {
1545 self.top_left_math_kern_offset.get()
1546 }
1547
1548 pub fn top_left_math_kern<'a>(
1554 &self,
1555 data: FontData<'a>,
1556 ) -> Option<Result<MathKern<'a>, ReadError>> {
1557 self.top_left_math_kern_offset().resolve(data)
1558 }
1559
1560 pub fn bottom_right_math_kern_offset(&self) -> Nullable<Offset16> {
1563 self.bottom_right_math_kern_offset.get()
1564 }
1565
1566 pub fn bottom_right_math_kern<'a>(
1572 &self,
1573 data: FontData<'a>,
1574 ) -> Option<Result<MathKern<'a>, ReadError>> {
1575 self.bottom_right_math_kern_offset().resolve(data)
1576 }
1577
1578 pub fn bottom_left_math_kern_offset(&self) -> Nullable<Offset16> {
1581 self.bottom_left_math_kern_offset.get()
1582 }
1583
1584 pub fn bottom_left_math_kern<'a>(
1590 &self,
1591 data: FontData<'a>,
1592 ) -> Option<Result<MathKern<'a>, ReadError>> {
1593 self.bottom_left_math_kern_offset().resolve(data)
1594 }
1595}
1596
1597impl FixedSize for MathKernInfoRecord {
1598 const RAW_BYTE_LEN: usize = Offset16::RAW_BYTE_LEN
1599 + Offset16::RAW_BYTE_LEN
1600 + Offset16::RAW_BYTE_LEN
1601 + Offset16::RAW_BYTE_LEN;
1602}
1603
1604impl<'a> MinByteRange<'a> for MathKern<'a> {
1605 fn min_byte_range(&self) -> Range<usize> {
1606 0..self.kern_values_byte_range().end
1607 }
1608 fn min_table_bytes(&self) -> &'a [u8] {
1609 let range = self.min_byte_range();
1610 self.offset_data().as_bytes().get(range).unwrap_or_default()
1611 }
1612}
1613
1614impl ReadArgs for MathKern<'_> {
1615 type Args = ();
1616}
1617
1618impl<'a> FontRead<'a> for MathKern<'a> {
1619 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1620 #[allow(clippy::absurd_extreme_comparisons)]
1621 if data.len() < Self::MIN_SIZE {
1622 return Err(ReadError::OutOfBounds);
1623 }
1624 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1625 return Err(ReadError::OutOfBounds);
1626 };
1627 Ok(Self { data })
1628 }
1629}
1630
1631#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1633#[repr(C, packed)]
1634#[doc(hidden)]
1635pub struct MathKernFixedHeader {
1636 pub height_count: BigEndian<u16>,
1637}
1638
1639#[allow(clippy::absurd_extreme_comparisons)]
1640const _: () = assert!(std::mem::size_of::<MathKernFixedHeader>() <= MathKern::MIN_SIZE);
1641
1642#[derive(Clone)]
1644pub struct MathKern<'a> {
1645 data: TableDataRef<'a, MathKernFixedHeader>,
1646}
1647
1648#[allow(clippy::needless_lifetimes)]
1649impl<'a> MathKern<'a> {
1650 pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
1651 basic_table_impls!(impl_the_methods);
1652
1653 pub fn height_count(&self) -> u16 {
1655 self.data.header().height_count.get()
1656 }
1657
1658 pub fn correction_height(&self) -> &'a [MathValueRecord] {
1661 let range = self.correction_height_byte_range();
1662 self.offset_data()
1663 .read_array(range)
1664 .ok()
1665 .unwrap_or_default()
1666 }
1667
1668 pub fn kern_values(&self) -> &'a [MathValueRecord] {
1673 let range = self.kern_values_byte_range();
1674 self.offset_data()
1675 .read_array(range)
1676 .ok()
1677 .unwrap_or_default()
1678 }
1679
1680 pub fn height_count_byte_range(&self) -> Range<usize> {
1681 let start = 0usize;
1682 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1683 start..end
1684 }
1685
1686 pub fn correction_height_byte_range(&self) -> Range<usize> {
1687 let height_count = self.height_count();
1688 let start = self.height_count_byte_range().end;
1689 let end = start.saturating_add(
1690 (transforms::to_usize(height_count)).saturating_mul(MathValueRecord::RAW_BYTE_LEN),
1691 );
1692 start..end
1693 }
1694
1695 pub fn kern_values_byte_range(&self) -> Range<usize> {
1696 let height_count = self.height_count();
1697 let start = self.correction_height_byte_range().end;
1698 let end = start.saturating_add(
1699 (transforms::add(height_count, 1_usize)).saturating_mul(MathValueRecord::RAW_BYTE_LEN),
1700 );
1701 start..end
1702 }
1703}
1704
1705const _: () = assert!(FontData::default_data_long_enough(MathKern::MIN_SIZE));
1706
1707impl Default for MathKern<'_> {
1708 fn default() -> Self {
1709 Self {
1710 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1711 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1712 }
1713 }
1714}
1715
1716impl<'a> MinByteRange<'a> for MathVariants<'a> {
1717 fn min_byte_range(&self) -> Range<usize> {
1718 0..self.horiz_glyph_construction_offsets_byte_range().end
1719 }
1720 fn min_table_bytes(&self) -> &'a [u8] {
1721 let range = self.min_byte_range();
1722 self.offset_data().as_bytes().get(range).unwrap_or_default()
1723 }
1724}
1725
1726impl ReadArgs for MathVariants<'_> {
1727 type Args = ();
1728}
1729
1730impl<'a> FontRead<'a> for MathVariants<'a> {
1731 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1732 #[allow(clippy::absurd_extreme_comparisons)]
1733 if data.len() < Self::MIN_SIZE {
1734 return Err(ReadError::OutOfBounds);
1735 }
1736 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1737 return Err(ReadError::OutOfBounds);
1738 };
1739 Ok(Self { data })
1740 }
1741}
1742
1743#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1745#[repr(C, packed)]
1746#[doc(hidden)]
1747pub struct MathVariantsFixedHeader {
1748 pub min_connector_overlap: BigEndian<UfWord>,
1749 pub vert_glyph_coverage_offset: BigEndian<Nullable<Offset16>>,
1750 pub horiz_glyph_coverage_offset: BigEndian<Nullable<Offset16>>,
1751 pub vert_glyph_count: BigEndian<u16>,
1752 pub horiz_glyph_count: BigEndian<u16>,
1753}
1754
1755#[allow(clippy::absurd_extreme_comparisons)]
1756const _: () = assert!(std::mem::size_of::<MathVariantsFixedHeader>() <= MathVariants::MIN_SIZE);
1757
1758#[derive(Clone)]
1760pub struct MathVariants<'a> {
1761 data: TableDataRef<'a, MathVariantsFixedHeader>,
1762}
1763
1764#[allow(clippy::needless_lifetimes)]
1765impl<'a> MathVariants<'a> {
1766 pub const MIN_SIZE: usize = (UfWord::RAW_BYTE_LEN
1767 + Offset16::RAW_BYTE_LEN
1768 + Offset16::RAW_BYTE_LEN
1769 + u16::RAW_BYTE_LEN
1770 + u16::RAW_BYTE_LEN);
1771 basic_table_impls!(impl_the_methods);
1772
1773 pub fn min_connector_overlap(&self) -> UfWord {
1776 self.data.header().min_connector_overlap.get()
1777 }
1778
1779 pub fn vert_glyph_coverage_offset(&self) -> Nullable<Offset16> {
1782 self.data.header().vert_glyph_coverage_offset.get()
1783 }
1784
1785 pub fn vert_glyph_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
1787 let data = self.offset_data();
1788 self.vert_glyph_coverage_offset().resolve(data)
1789 }
1790
1791 pub fn horiz_glyph_coverage_offset(&self) -> Nullable<Offset16> {
1794 self.data.header().horiz_glyph_coverage_offset.get()
1795 }
1796
1797 pub fn horiz_glyph_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
1799 let data = self.offset_data();
1800 self.horiz_glyph_coverage_offset().resolve(data)
1801 }
1802
1803 pub fn vert_glyph_count(&self) -> u16 {
1807 self.data.header().vert_glyph_count.get()
1808 }
1809
1810 pub fn horiz_glyph_count(&self) -> u16 {
1814 self.data.header().horiz_glyph_count.get()
1815 }
1816
1817 pub fn vert_glyph_construction_offsets(&self) -> &'a [BigEndian<Offset16>] {
1820 let range = self.vert_glyph_construction_offsets_byte_range();
1821 self.offset_data()
1822 .read_array(range)
1823 .ok()
1824 .unwrap_or_default()
1825 }
1826
1827 pub fn vert_glyph_constructions(
1829 &self,
1830 ) -> ArrayOfOffsets<'a, MathGlyphConstruction<'a>, Offset16> {
1831 let data = self.offset_data();
1832 let offsets = self.vert_glyph_construction_offsets();
1833 ArrayOfOffsets::new(offsets, data, ())
1834 }
1835
1836 pub fn horiz_glyph_construction_offsets(&self) -> &'a [BigEndian<Offset16>] {
1839 let range = self.horiz_glyph_construction_offsets_byte_range();
1840 self.offset_data()
1841 .read_array(range)
1842 .ok()
1843 .unwrap_or_default()
1844 }
1845
1846 pub fn horiz_glyph_constructions(
1848 &self,
1849 ) -> ArrayOfOffsets<'a, MathGlyphConstruction<'a>, Offset16> {
1850 let data = self.offset_data();
1851 let offsets = self.horiz_glyph_construction_offsets();
1852 ArrayOfOffsets::new(offsets, data, ())
1853 }
1854
1855 pub fn min_connector_overlap_byte_range(&self) -> Range<usize> {
1856 let start = 0usize;
1857 let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
1858 start..end
1859 }
1860
1861 pub fn vert_glyph_coverage_offset_byte_range(&self) -> Range<usize> {
1862 let start = self.min_connector_overlap_byte_range().end;
1863 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1864 start..end
1865 }
1866
1867 pub fn horiz_glyph_coverage_offset_byte_range(&self) -> Range<usize> {
1868 let start = self.vert_glyph_coverage_offset_byte_range().end;
1869 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1870 start..end
1871 }
1872
1873 pub fn vert_glyph_count_byte_range(&self) -> Range<usize> {
1874 let start = self.horiz_glyph_coverage_offset_byte_range().end;
1875 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1876 start..end
1877 }
1878
1879 pub fn horiz_glyph_count_byte_range(&self) -> Range<usize> {
1880 let start = self.vert_glyph_count_byte_range().end;
1881 let end = start.saturating_add(u16::RAW_BYTE_LEN);
1882 start..end
1883 }
1884
1885 pub fn vert_glyph_construction_offsets_byte_range(&self) -> Range<usize> {
1886 let vert_glyph_count = self.vert_glyph_count();
1887 let start = self.horiz_glyph_count_byte_range().end;
1888 let end = start.saturating_add(
1889 (transforms::to_usize(vert_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
1890 );
1891 start..end
1892 }
1893
1894 pub fn horiz_glyph_construction_offsets_byte_range(&self) -> Range<usize> {
1895 let horiz_glyph_count = self.horiz_glyph_count();
1896 let start = self.vert_glyph_construction_offsets_byte_range().end;
1897 let end = start.saturating_add(
1898 (transforms::to_usize(horiz_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
1899 );
1900 start..end
1901 }
1902}
1903
1904const _: () = assert!(FontData::default_data_long_enough(MathVariants::MIN_SIZE));
1905
1906impl Default for MathVariants<'_> {
1907 fn default() -> Self {
1908 Self {
1909 data: TableDataRef::new(FontData::default_table_data().as_bytes())
1910 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1911 }
1912 }
1913}
1914
1915impl<'a> MinByteRange<'a> for MathGlyphConstruction<'a> {
1916 fn min_byte_range(&self) -> Range<usize> {
1917 0..self.math_glyph_variant_records_byte_range().end
1918 }
1919 fn min_table_bytes(&self) -> &'a [u8] {
1920 let range = self.min_byte_range();
1921 self.offset_data().as_bytes().get(range).unwrap_or_default()
1922 }
1923}
1924
1925impl ReadArgs for MathGlyphConstruction<'_> {
1926 type Args = ();
1927}
1928
1929impl<'a> FontRead<'a> for MathGlyphConstruction<'a> {
1930 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1931 #[allow(clippy::absurd_extreme_comparisons)]
1932 if data.len() < Self::MIN_SIZE {
1933 return Err(ReadError::OutOfBounds);
1934 }
1935 let Some(data) = TableDataRef::new(data.as_bytes()) else {
1936 return Err(ReadError::OutOfBounds);
1937 };
1938 Ok(Self { data })
1939 }
1940}
1941
1942#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1944#[repr(C, packed)]
1945#[doc(hidden)]
1946pub struct MathGlyphConstructionFixedHeader {
1947 pub glyph_assembly_offset: BigEndian<Nullable<Offset16>>,
1948 pub variant_count: BigEndian<u16>,
1949}
1950
1951#[allow(clippy::absurd_extreme_comparisons)]
1952const _: () = assert!(
1953 std::mem::size_of::<MathGlyphConstructionFixedHeader>() <= MathGlyphConstruction::MIN_SIZE
1954);
1955
1956#[derive(Clone)]
1958pub struct MathGlyphConstruction<'a> {
1959 data: TableDataRef<'a, MathGlyphConstructionFixedHeader>,
1960}
1961
1962#[allow(clippy::needless_lifetimes)]
1963impl<'a> MathGlyphConstruction<'a> {
1964 pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1965 basic_table_impls!(impl_the_methods);
1966
1967 pub fn glyph_assembly_offset(&self) -> Nullable<Offset16> {
1970 self.data.header().glyph_assembly_offset.get()
1971 }
1972
1973 pub fn glyph_assembly(&self) -> Option<Result<GlyphAssembly<'a>, ReadError>> {
1975 let data = self.offset_data();
1976 self.glyph_assembly_offset().resolve(data)
1977 }
1978
1979 pub fn variant_count(&self) -> u16 {
1981 self.data.header().variant_count.get()
1982 }
1983
1984 pub fn math_glyph_variant_records(&self) -> &'a [MathGlyphVariantRecord] {
1986 let range = self.math_glyph_variant_records_byte_range();
1987 self.offset_data()
1988 .read_array(range)
1989 .ok()
1990 .unwrap_or_default()
1991 }
1992
1993 pub fn glyph_assembly_offset_byte_range(&self) -> Range<usize> {
1994 let start = 0usize;
1995 let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1996 start..end
1997 }
1998
1999 pub fn variant_count_byte_range(&self) -> Range<usize> {
2000 let start = self.glyph_assembly_offset_byte_range().end;
2001 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2002 start..end
2003 }
2004
2005 pub fn math_glyph_variant_records_byte_range(&self) -> Range<usize> {
2006 let variant_count = self.variant_count();
2007 let start = self.variant_count_byte_range().end;
2008 let end = start.saturating_add(
2009 (transforms::to_usize(variant_count))
2010 .saturating_mul(MathGlyphVariantRecord::RAW_BYTE_LEN),
2011 );
2012 start..end
2013 }
2014}
2015
2016const _: () = assert!(FontData::default_data_long_enough(
2017 MathGlyphConstruction::MIN_SIZE
2018));
2019
2020impl Default for MathGlyphConstruction<'_> {
2021 fn default() -> Self {
2022 Self {
2023 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2024 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2025 }
2026 }
2027}
2028
2029#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
2031#[repr(C)]
2032#[repr(packed)]
2033pub struct MathGlyphVariantRecord {
2034 pub variant_glyph: BigEndian<GlyphId16>,
2036 pub advance_measurement: BigEndian<UfWord>,
2039}
2040
2041impl MathGlyphVariantRecord {
2042 pub fn variant_glyph(&self) -> GlyphId16 {
2044 self.variant_glyph.get()
2045 }
2046
2047 pub fn advance_measurement(&self) -> UfWord {
2050 self.advance_measurement.get()
2051 }
2052}
2053
2054impl FixedSize for MathGlyphVariantRecord {
2055 const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN + UfWord::RAW_BYTE_LEN;
2056}
2057
2058impl<'a> MinByteRange<'a> for GlyphAssembly<'a> {
2059 fn min_byte_range(&self) -> Range<usize> {
2060 0..self.part_records_byte_range().end
2061 }
2062 fn min_table_bytes(&self) -> &'a [u8] {
2063 let range = self.min_byte_range();
2064 self.offset_data().as_bytes().get(range).unwrap_or_default()
2065 }
2066}
2067
2068impl ReadArgs for GlyphAssembly<'_> {
2069 type Args = ();
2070}
2071
2072impl<'a> FontRead<'a> for GlyphAssembly<'a> {
2073 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2074 #[allow(clippy::absurd_extreme_comparisons)]
2075 if data.len() < Self::MIN_SIZE {
2076 return Err(ReadError::OutOfBounds);
2077 }
2078 let Some(data) = TableDataRef::new(data.as_bytes()) else {
2079 return Err(ReadError::OutOfBounds);
2080 };
2081 Ok(Self { data })
2082 }
2083}
2084
2085#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2087#[repr(C, packed)]
2088#[doc(hidden)]
2089pub struct GlyphAssemblyFixedHeader {
2090 pub italics_correction: MathValueRecord,
2091 pub part_count: BigEndian<u16>,
2092}
2093
2094#[allow(clippy::absurd_extreme_comparisons)]
2095const _: () = assert!(std::mem::size_of::<GlyphAssemblyFixedHeader>() <= GlyphAssembly::MIN_SIZE);
2096
2097#[derive(Clone)]
2099pub struct GlyphAssembly<'a> {
2100 data: TableDataRef<'a, GlyphAssemblyFixedHeader>,
2101}
2102
2103#[allow(clippy::needless_lifetimes)]
2104impl<'a> GlyphAssembly<'a> {
2105 pub const MIN_SIZE: usize = (MathValueRecord::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2106 basic_table_impls!(impl_the_methods);
2107
2108 pub fn italics_correction(&self) -> &'a MathValueRecord {
2111 &self.data.header().italics_correction
2112 }
2113
2114 pub fn part_count(&self) -> u16 {
2116 self.data.header().part_count.get()
2117 }
2118
2119 pub fn part_records(&self) -> &'a [GlyphPartRecord] {
2122 let range = self.part_records_byte_range();
2123 self.offset_data()
2124 .read_array(range)
2125 .ok()
2126 .unwrap_or_default()
2127 }
2128
2129 pub fn italics_correction_byte_range(&self) -> Range<usize> {
2130 let start = 0usize;
2131 let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
2132 start..end
2133 }
2134
2135 pub fn part_count_byte_range(&self) -> Range<usize> {
2136 let start = self.italics_correction_byte_range().end;
2137 let end = start.saturating_add(u16::RAW_BYTE_LEN);
2138 start..end
2139 }
2140
2141 pub fn part_records_byte_range(&self) -> Range<usize> {
2142 let part_count = self.part_count();
2143 let start = self.part_count_byte_range().end;
2144 let end = start.saturating_add(
2145 (transforms::to_usize(part_count)).saturating_mul(GlyphPartRecord::RAW_BYTE_LEN),
2146 );
2147 start..end
2148 }
2149}
2150
2151const _: () = assert!(FontData::default_data_long_enough(GlyphAssembly::MIN_SIZE));
2152
2153impl Default for GlyphAssembly<'_> {
2154 fn default() -> Self {
2155 Self {
2156 data: TableDataRef::new(FontData::default_table_data().as_bytes())
2157 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2158 }
2159 }
2160}
2161
2162#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
2164#[repr(C)]
2165#[repr(packed)]
2166pub struct GlyphPartRecord {
2167 pub glyph_id: BigEndian<GlyphId16>,
2169 pub start_connector_length: BigEndian<UfWord>,
2172 pub end_connector_length: BigEndian<UfWord>,
2175 pub full_advance: BigEndian<UfWord>,
2178 pub part_flags: BigEndian<PartFlags>,
2180}
2181
2182impl GlyphPartRecord {
2183 pub fn glyph_id(&self) -> GlyphId16 {
2185 self.glyph_id.get()
2186 }
2187
2188 pub fn start_connector_length(&self) -> UfWord {
2191 self.start_connector_length.get()
2192 }
2193
2194 pub fn end_connector_length(&self) -> UfWord {
2197 self.end_connector_length.get()
2198 }
2199
2200 pub fn full_advance(&self) -> UfWord {
2203 self.full_advance.get()
2204 }
2205
2206 pub fn part_flags(&self) -> PartFlags {
2208 self.part_flags.get()
2209 }
2210}
2211
2212impl FixedSize for GlyphPartRecord {
2213 const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN
2214 + UfWord::RAW_BYTE_LEN
2215 + UfWord::RAW_BYTE_LEN
2216 + UfWord::RAW_BYTE_LEN
2217 + PartFlags::RAW_BYTE_LEN;
2218}
2219
2220#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
2222#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2223#[repr(transparent)]
2224pub struct PartFlags {
2225 bits: u16,
2226}
2227
2228impl PartFlags {
2229 pub const EXTENDER_FLAG: Self = Self { bits: 0x0001 };
2231}
2232
2233impl PartFlags {
2234 #[inline]
2236 pub const fn empty() -> Self {
2237 Self { bits: 0 }
2238 }
2239
2240 #[inline]
2242 pub const fn all() -> Self {
2243 Self {
2244 bits: Self::EXTENDER_FLAG.bits,
2245 }
2246 }
2247
2248 #[inline]
2250 pub const fn bits(&self) -> u16 {
2251 self.bits
2252 }
2253
2254 #[inline]
2257 pub const fn from_bits(bits: u16) -> Option<Self> {
2258 if (bits & !Self::all().bits()) == 0 {
2259 Some(Self { bits })
2260 } else {
2261 None
2262 }
2263 }
2264
2265 #[inline]
2268 pub const fn from_bits_truncate(bits: u16) -> Self {
2269 Self {
2270 bits: bits & Self::all().bits,
2271 }
2272 }
2273
2274 #[inline]
2276 pub const fn is_empty(&self) -> bool {
2277 self.bits() == Self::empty().bits()
2278 }
2279
2280 #[inline]
2282 pub const fn intersects(&self, other: Self) -> bool {
2283 !(Self {
2284 bits: self.bits & other.bits,
2285 })
2286 .is_empty()
2287 }
2288
2289 #[inline]
2291 pub const fn contains(&self, other: Self) -> bool {
2292 (self.bits & other.bits) == other.bits
2293 }
2294
2295 #[inline]
2297 pub fn insert(&mut self, other: Self) {
2298 self.bits |= other.bits;
2299 }
2300
2301 #[inline]
2303 pub fn remove(&mut self, other: Self) {
2304 self.bits &= !other.bits;
2305 }
2306
2307 #[inline]
2309 pub fn toggle(&mut self, other: Self) {
2310 self.bits ^= other.bits;
2311 }
2312
2313 #[inline]
2324 #[must_use]
2325 pub const fn intersection(self, other: Self) -> Self {
2326 Self {
2327 bits: self.bits & other.bits,
2328 }
2329 }
2330
2331 #[inline]
2342 #[must_use]
2343 pub const fn union(self, other: Self) -> Self {
2344 Self {
2345 bits: self.bits | other.bits,
2346 }
2347 }
2348
2349 #[inline]
2362 #[must_use]
2363 pub const fn difference(self, other: Self) -> Self {
2364 Self {
2365 bits: self.bits & !other.bits,
2366 }
2367 }
2368}
2369
2370impl std::ops::BitOr for PartFlags {
2371 type Output = Self;
2372
2373 #[inline]
2375 fn bitor(self, other: PartFlags) -> Self {
2376 Self {
2377 bits: self.bits | other.bits,
2378 }
2379 }
2380}
2381
2382impl std::ops::BitOrAssign for PartFlags {
2383 #[inline]
2385 fn bitor_assign(&mut self, other: Self) {
2386 self.bits |= other.bits;
2387 }
2388}
2389
2390impl std::ops::BitXor for PartFlags {
2391 type Output = Self;
2392
2393 #[inline]
2395 fn bitxor(self, other: Self) -> Self {
2396 Self {
2397 bits: self.bits ^ other.bits,
2398 }
2399 }
2400}
2401
2402impl std::ops::BitXorAssign for PartFlags {
2403 #[inline]
2405 fn bitxor_assign(&mut self, other: Self) {
2406 self.bits ^= other.bits;
2407 }
2408}
2409
2410impl std::ops::BitAnd for PartFlags {
2411 type Output = Self;
2412
2413 #[inline]
2415 fn bitand(self, other: Self) -> Self {
2416 Self {
2417 bits: self.bits & other.bits,
2418 }
2419 }
2420}
2421
2422impl std::ops::BitAndAssign for PartFlags {
2423 #[inline]
2425 fn bitand_assign(&mut self, other: Self) {
2426 self.bits &= other.bits;
2427 }
2428}
2429
2430impl std::ops::Sub for PartFlags {
2431 type Output = Self;
2432
2433 #[inline]
2435 fn sub(self, other: Self) -> Self {
2436 Self {
2437 bits: self.bits & !other.bits,
2438 }
2439 }
2440}
2441
2442impl std::ops::SubAssign for PartFlags {
2443 #[inline]
2445 fn sub_assign(&mut self, other: Self) {
2446 self.bits &= !other.bits;
2447 }
2448}
2449
2450impl std::ops::Not for PartFlags {
2451 type Output = Self;
2452
2453 #[inline]
2455 fn not(self) -> Self {
2456 Self { bits: !self.bits } & Self::all()
2457 }
2458}
2459
2460impl std::fmt::Debug for PartFlags {
2461 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2462 let members: &[(&str, Self)] = &[("EXTENDER_FLAG", Self::EXTENDER_FLAG)];
2463 let mut first = true;
2464 for (name, value) in members {
2465 if self.contains(*value) {
2466 if !first {
2467 f.write_str(" | ")?;
2468 }
2469 first = false;
2470 f.write_str(name)?;
2471 }
2472 }
2473 if first {
2474 f.write_str("(empty)")?;
2475 }
2476 Ok(())
2477 }
2478}
2479
2480impl std::fmt::Binary for PartFlags {
2481 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2482 std::fmt::Binary::fmt(&self.bits, f)
2483 }
2484}
2485
2486impl std::fmt::Octal for PartFlags {
2487 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2488 std::fmt::Octal::fmt(&self.bits, f)
2489 }
2490}
2491
2492impl std::fmt::LowerHex for PartFlags {
2493 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2494 std::fmt::LowerHex::fmt(&self.bits, f)
2495 }
2496}
2497
2498impl std::fmt::UpperHex for PartFlags {
2499 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2500 std::fmt::UpperHex::fmt(&self.bits, f)
2501 }
2502}
2503
2504impl font_types::Scalar for PartFlags {
2505 type Raw = <u16 as font_types::Scalar>::Raw;
2506 fn to_raw(self) -> Self::Raw {
2507 self.bits().to_raw()
2508 }
2509 fn from_raw(raw: Self::Raw) -> Self {
2510 let t = <u16>::from_raw(raw);
2511 Self::from_bits_truncate(t)
2512 }
2513}