Coverage Report

Created: 2026-12-01 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.47.0/generated/generated_math.rs
Line
Count
Source
1
// THIS FILE IS AUTOGENERATED.
2
// Any changes to this file will be overwritten.
3
// For more information about how codegen works, see font-codegen/README.md
4
5
#[allow(unused_imports)]
6
use crate::codegen_prelude::*;
7
8
impl<'a> MinByteRange<'a> for Math<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.math_variants_offset_byte_range().end
11
0
    }
12
0
    fn min_table_bytes(&self) -> &'a [u8] {
13
0
        let range = self.min_byte_range();
14
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
15
0
    }
16
}
17
18
impl TopLevelTable for Math<'_> {
19
    /// `MATH`
20
    const TAG: Tag = Tag::new(b"MATH");
21
}
22
23
impl ReadArgs for Math<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Math<'a> {
28
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
0
        if data.len() < Self::MIN_SIZE {
31
0
            return Err(ReadError::OutOfBounds);
32
0
        }
33
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
0
        Ok(Self { data })
37
0
    }
38
}
39
40
/// The fields at the start of the table, which are read directly.
41
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42
#[repr(C, packed)]
43
#[doc(hidden)]
44
pub 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)]
52
const _: () = assert!(std::mem::size_of::<MathFixedHeader>() <= Math::MIN_SIZE);
53
54
/// The [MATH](https://learn.microsoft.com/en-us/typography/opentype/spec/math) table
55
#[derive(Clone)]
56
pub struct Math<'a> {
57
    data: TableDataRef<'a, MathFixedHeader>,
58
}
59
60
#[allow(clippy::needless_lifetimes)]
61
impl<'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
    /// (major, minor) Version for the MATH table (1,0)
69
0
    pub fn version(&self) -> MajorMinor {
70
0
        self.data.header().version.get()
71
0
    }
72
73
    /// Offset to MathConstants table, from beginning of MATH table.
74
0
    pub fn math_constants_offset(&self) -> Offset16 {
75
0
        self.data.header().math_constants_offset.get()
76
0
    }
77
78
    /// Attempt to resolve [`math_constants_offset`][Self::math_constants_offset].
79
0
    pub fn math_constants(&self) -> Result<MathConstants<'a>, ReadError> {
80
0
        let data = self.offset_data();
81
0
        self.math_constants_offset().resolve(data)
82
0
    }
83
84
    /// Offset to MathGlyphInfo table, from beginning of MATH table.
85
0
    pub fn math_glyph_info_offset(&self) -> Offset16 {
86
0
        self.data.header().math_glyph_info_offset.get()
87
0
    }
88
89
    /// Attempt to resolve [`math_glyph_info_offset`][Self::math_glyph_info_offset].
90
0
    pub fn math_glyph_info(&self) -> Result<MathGlyphInfo<'a>, ReadError> {
91
0
        let data = self.offset_data();
92
0
        self.math_glyph_info_offset().resolve(data)
93
0
    }
94
95
    /// Offset to MathVariants table, from beginning of MATH table.
96
0
    pub fn math_variants_offset(&self) -> Offset16 {
97
0
        self.data.header().math_variants_offset.get()
98
0
    }
99
100
    /// Attempt to resolve [`math_variants_offset`][Self::math_variants_offset].
101
0
    pub fn math_variants(&self) -> Result<MathVariants<'a>, ReadError> {
102
0
        let data = self.offset_data();
103
0
        self.math_variants_offset().resolve(data)
104
0
    }
105
106
0
    pub fn version_byte_range(&self) -> Range<usize> {
107
0
        let start = 0usize;
108
0
        let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
109
0
        start..end
110
0
    }
111
112
0
    pub fn math_constants_offset_byte_range(&self) -> Range<usize> {
113
0
        let start = self.version_byte_range().end;
114
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
115
0
        start..end
116
0
    }
117
118
0
    pub fn math_glyph_info_offset_byte_range(&self) -> Range<usize> {
119
0
        let start = self.math_constants_offset_byte_range().end;
120
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
121
0
        start..end
122
0
    }
123
124
0
    pub fn math_variants_offset_byte_range(&self) -> Range<usize> {
125
0
        let start = self.math_glyph_info_offset_byte_range().end;
126
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
127
0
        start..end
128
0
    }
129
}
130
131
const _: () = assert!(FontData::default_data_long_enough(Math::MIN_SIZE));
132
133
impl Default for Math<'_> {
134
0
    fn default() -> Self {
135
        Self {
136
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
137
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
138
        }
139
0
    }
140
}
141
142
/// [MathValueRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathvaluerecord)
143
///
144
/// The device offset is measured from the beginning of the table that contains
145
/// the record, not from the record itself.
146
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
147
#[repr(C)]
148
#[repr(packed)]
149
pub struct MathValueRecord {
150
    /// The X or Y value in design units.
151
    pub value: BigEndian<FWord>,
152
    /// Offset to the Device table (non-variable font) / VariationIndex table
153
    /// (variable font) for this value, from the beginning of the parent table.
154
    /// May be NULL.
155
    pub device_offset: BigEndian<Nullable<Offset16>>,
156
}
157
158
impl MathValueRecord {
159
    /// The X or Y value in design units.
160
0
    pub fn value(&self) -> FWord {
161
0
        self.value.get()
162
0
    }
163
164
    /// Offset to the Device table (non-variable font) / VariationIndex table
165
    /// (variable font) for this value, from the beginning of the parent table.
166
    /// May be NULL.
167
0
    pub fn device_offset(&self) -> Nullable<Offset16> {
168
0
        self.device_offset.get()
169
0
    }
170
171
    /// Offset to the Device table (non-variable font) / VariationIndex table
172
    /// (variable font) for this value, from the beginning of the parent table.
173
    /// May be NULL.
174
    ///
175
    /// The `data` argument should be retrieved from the parent table
176
    /// By calling its `offset_data` method.
177
0
    pub fn device<'a>(
178
0
        &self,
179
0
        data: FontData<'a>,
180
0
    ) -> Option<Result<DeviceOrVariationIndex<'a>, ReadError>> {
181
0
        self.device_offset().resolve(data)
182
0
    }
183
}
184
185
impl FixedSize for MathValueRecord {
186
    const RAW_BYTE_LEN: usize = FWord::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
187
}
188
189
impl<'a> MinByteRange<'a> for MathConstants<'a> {
190
0
    fn min_byte_range(&self) -> Range<usize> {
191
0
        0..self.radical_degree_bottom_raise_percent_byte_range().end
192
0
    }
193
0
    fn min_table_bytes(&self) -> &'a [u8] {
194
0
        let range = self.min_byte_range();
195
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
196
0
    }
197
}
198
199
impl ReadArgs for MathConstants<'_> {
200
    type Args = ();
201
}
202
203
impl<'a> FontRead<'a> for MathConstants<'a> {
204
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
205
        #[allow(clippy::absurd_extreme_comparisons)]
206
0
        if data.len() < Self::MIN_SIZE {
207
0
            return Err(ReadError::OutOfBounds);
208
0
        }
209
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
210
0
            return Err(ReadError::OutOfBounds);
211
        };
212
0
        Ok(Self { data })
213
0
    }
214
}
215
216
/// The fields at the start of the table, which are read directly.
217
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
218
#[repr(C, packed)]
219
#[doc(hidden)]
220
pub 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)]
280
const _: () = assert!(std::mem::size_of::<MathConstantsFixedHeader>() <= MathConstants::MIN_SIZE);
281
282
/// [MathConstants](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathconstants-table)
283
#[derive(Clone)]
284
pub struct MathConstants<'a> {
285
    data: TableDataRef<'a, MathConstantsFixedHeader>,
286
}
287
288
#[allow(clippy::needless_lifetimes)]
289
impl<'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
    /// Percentage of scaling down for level 1 superscripts and subscripts.
349
0
    pub fn script_percent_scale_down(&self) -> i16 {
350
0
        self.data.header().script_percent_scale_down.get()
351
0
    }
352
353
    /// Percentage of scaling down for level 2 (scriptScript) superscripts and
354
    /// subscripts.
355
0
    pub fn script_script_percent_scale_down(&self) -> i16 {
356
0
        self.data.header().script_script_percent_scale_down.get()
357
0
    }
358
359
    /// Minimum height required for a delimited expression (contained within
360
    /// parentheses, etc.) to be treated as a sub-formula.
361
0
    pub fn delimited_sub_formula_min_height(&self) -> UfWord {
362
0
        self.data.header().delimited_sub_formula_min_height.get()
363
0
    }
364
365
    /// Minimum height of n-ary operators (such as integral and summation) for
366
    /// formulas in display mode (that is, appearing as standalone page
367
    /// elements, not embedded inline within text).
368
0
    pub fn display_operator_min_height(&self) -> UfWord {
369
0
        self.data.header().display_operator_min_height.get()
370
0
    }
371
372
    /// White space to be left between math formulas to ensure proper line
373
    /// spacing.
374
0
    pub fn math_leading(&self) -> &'a MathValueRecord {
375
0
        &self.data.header().math_leading
376
0
    }
377
378
    /// Axis height of the font.
379
0
    pub fn axis_height(&self) -> &'a MathValueRecord {
380
0
        &self.data.header().axis_height
381
0
    }
382
383
    /// Maximum (ink) height of accent base that does not require raising the
384
    /// accents.
385
0
    pub fn accent_base_height(&self) -> &'a MathValueRecord {
386
0
        &self.data.header().accent_base_height
387
0
    }
388
389
    /// Maximum (ink) height of accent base that does not require flattening the
390
    /// accents.
391
0
    pub fn flattened_accent_base_height(&self) -> &'a MathValueRecord {
392
0
        &self.data.header().flattened_accent_base_height
393
0
    }
394
395
    /// The standard shift down applied to subscript elements.
396
0
    pub fn subscript_shift_down(&self) -> &'a MathValueRecord {
397
0
        &self.data.header().subscript_shift_down
398
0
    }
399
400
    /// Maximum allowed height of the (ink) top of subscripts that does not
401
    /// require moving subscripts further down.
402
0
    pub fn subscript_top_max(&self) -> &'a MathValueRecord {
403
0
        &self.data.header().subscript_top_max
404
0
    }
405
406
    /// Minimum allowed drop of the baseline of subscripts relative to the (ink)
407
    /// bottom of the base.
408
0
    pub fn subscript_baseline_drop_min(&self) -> &'a MathValueRecord {
409
0
        &self.data.header().subscript_baseline_drop_min
410
0
    }
411
412
    /// Standard shift up applied to superscript elements.
413
0
    pub fn superscript_shift_up(&self) -> &'a MathValueRecord {
414
0
        &self.data.header().superscript_shift_up
415
0
    }
416
417
    /// Standard shift of superscripts relative to the base, in cramped style.
418
0
    pub fn superscript_shift_up_cramped(&self) -> &'a MathValueRecord {
419
0
        &self.data.header().superscript_shift_up_cramped
420
0
    }
421
422
    /// Minimum allowed height of the (ink) bottom of superscripts that does not
423
    /// require moving subscripts further up.
424
0
    pub fn superscript_bottom_min(&self) -> &'a MathValueRecord {
425
0
        &self.data.header().superscript_bottom_min
426
0
    }
427
428
    /// Maximum allowed drop of the baseline of superscripts relative to the
429
    /// (ink) top of the base.
430
0
    pub fn superscript_baseline_drop_max(&self) -> &'a MathValueRecord {
431
0
        &self.data.header().superscript_baseline_drop_max
432
0
    }
433
434
    /// Minimum gap between the superscript and subscript ink.
435
0
    pub fn sub_superscript_gap_min(&self) -> &'a MathValueRecord {
436
0
        &self.data.header().sub_superscript_gap_min
437
0
    }
438
439
    /// The maximum level to which the (ink) bottom of superscript can be
440
    /// pushed to increase the gap between superscript and subscript, before
441
    /// subscript starts being moved down.
442
0
    pub fn superscript_bottom_max_with_subscript(&self) -> &'a MathValueRecord {
443
0
        &self.data.header().superscript_bottom_max_with_subscript
444
0
    }
445
446
    /// Extra white space to be added after each subscript and superscript.
447
0
    pub fn space_after_script(&self) -> &'a MathValueRecord {
448
0
        &self.data.header().space_after_script
449
0
    }
450
451
    /// Minimum gap between the (ink) bottom of the upper limit, and the (ink)
452
    /// top of the base operator.
453
0
    pub fn upper_limit_gap_min(&self) -> &'a MathValueRecord {
454
0
        &self.data.header().upper_limit_gap_min
455
0
    }
456
457
    /// Minimum distance between baseline of upper limit and (ink) top of the
458
    /// base operator.
459
0
    pub fn upper_limit_baseline_rise_min(&self) -> &'a MathValueRecord {
460
0
        &self.data.header().upper_limit_baseline_rise_min
461
0
    }
462
463
    /// Minimum gap between (ink) top of the lower limit, and (ink) bottom of
464
    /// the base operator.
465
0
    pub fn lower_limit_gap_min(&self) -> &'a MathValueRecord {
466
0
        &self.data.header().lower_limit_gap_min
467
0
    }
468
469
    /// Minimum distance between baseline of the lower limit and (ink) bottom of
470
    /// the base operator.
471
0
    pub fn lower_limit_baseline_drop_min(&self) -> &'a MathValueRecord {
472
0
        &self.data.header().lower_limit_baseline_drop_min
473
0
    }
474
475
    /// Standard shift up applied to the top element of a stack.
476
0
    pub fn stack_top_shift_up(&self) -> &'a MathValueRecord {
477
0
        &self.data.header().stack_top_shift_up
478
0
    }
479
480
    /// Standard shift up applied to the top element of a stack in display
481
    /// style.
482
0
    pub fn stack_top_display_style_shift_up(&self) -> &'a MathValueRecord {
483
0
        &self.data.header().stack_top_display_style_shift_up
484
0
    }
485
486
    /// Standard shift down applied to the bottom element of a stack.
487
0
    pub fn stack_bottom_shift_down(&self) -> &'a MathValueRecord {
488
0
        &self.data.header().stack_bottom_shift_down
489
0
    }
490
491
    /// Standard shift down applied to the bottom element of a stack in display
492
    /// style.
493
0
    pub fn stack_bottom_display_style_shift_down(&self) -> &'a MathValueRecord {
494
0
        &self.data.header().stack_bottom_display_style_shift_down
495
0
    }
496
497
    /// Minimum gap between (ink) bottom of the top element of a stack, and the
498
    /// (ink) top of the bottom element.
499
0
    pub fn stack_gap_min(&self) -> &'a MathValueRecord {
500
0
        &self.data.header().stack_gap_min
501
0
    }
502
503
    /// Minimum gap between (ink) bottom of the top element of a stack, and the
504
    /// (ink) top of the bottom element in display style.
505
0
    pub fn stack_display_style_gap_min(&self) -> &'a MathValueRecord {
506
0
        &self.data.header().stack_display_style_gap_min
507
0
    }
508
509
    /// Standard shift up applied to the top element of the stretch stack.
510
0
    pub fn stretch_stack_top_shift_up(&self) -> &'a MathValueRecord {
511
0
        &self.data.header().stretch_stack_top_shift_up
512
0
    }
513
514
    /// Standard shift down applied to the bottom element of the stretch stack.
515
0
    pub fn stretch_stack_bottom_shift_down(&self) -> &'a MathValueRecord {
516
0
        &self.data.header().stretch_stack_bottom_shift_down
517
0
    }
518
519
    /// Minimum gap between the ink of the stretched element, and the (ink)
520
    /// bottom of the element above.
521
0
    pub fn stretch_stack_gap_above_min(&self) -> &'a MathValueRecord {
522
0
        &self.data.header().stretch_stack_gap_above_min
523
0
    }
524
525
    /// Minimum gap between the ink of the stretched element, and the (ink) top
526
    /// of the element below.
527
0
    pub fn stretch_stack_gap_below_min(&self) -> &'a MathValueRecord {
528
0
        &self.data.header().stretch_stack_gap_below_min
529
0
    }
530
531
    /// Standard shift up applied to the numerator.
532
0
    pub fn fraction_numerator_shift_up(&self) -> &'a MathValueRecord {
533
0
        &self.data.header().fraction_numerator_shift_up
534
0
    }
535
536
    /// Standard shift up applied to the numerator in display style.
537
0
    pub fn fraction_numerator_display_style_shift_up(&self) -> &'a MathValueRecord {
538
0
        &self.data.header().fraction_numerator_display_style_shift_up
539
0
    }
540
541
    /// Standard shift down applied to the denominator.
542
0
    pub fn fraction_denominator_shift_down(&self) -> &'a MathValueRecord {
543
0
        &self.data.header().fraction_denominator_shift_down
544
0
    }
545
546
    /// Standard shift down applied to the denominator in display style.
547
0
    pub fn fraction_denominator_display_style_shift_down(&self) -> &'a MathValueRecord {
548
0
        &self
549
0
            .data
550
0
            .header()
551
0
            .fraction_denominator_display_style_shift_down
552
0
    }
553
554
    /// Minimum tolerated gap between the (ink) bottom of the numerator and the
555
    /// ink of the fraction bar.
556
0
    pub fn fraction_numerator_gap_min(&self) -> &'a MathValueRecord {
557
0
        &self.data.header().fraction_numerator_gap_min
558
0
    }
559
560
    /// Minimum tolerated gap between the (ink) bottom of the numerator and the
561
    /// ink of the fraction bar in display style.
562
0
    pub fn fraction_num_display_style_gap_min(&self) -> &'a MathValueRecord {
563
0
        &self.data.header().fraction_num_display_style_gap_min
564
0
    }
565
566
    /// Thickness of the fraction bar.
567
0
    pub fn fraction_rule_thickness(&self) -> &'a MathValueRecord {
568
0
        &self.data.header().fraction_rule_thickness
569
0
    }
570
571
    /// Minimum tolerated gap between the ink of the fraction bar and the (ink)
572
    /// top of the denominator.
573
0
    pub fn fraction_denominator_gap_min(&self) -> &'a MathValueRecord {
574
0
        &self.data.header().fraction_denominator_gap_min
575
0
    }
576
577
    /// Minimum tolerated gap between the ink of the fraction bar and the (ink)
578
    /// top of the denominator in display style.
579
0
    pub fn fraction_denom_display_style_gap_min(&self) -> &'a MathValueRecord {
580
0
        &self.data.header().fraction_denom_display_style_gap_min
581
0
    }
582
583
    /// Horizontal distance between the top and bottom elements of a skewed
584
    /// fraction.
585
0
    pub fn skewed_fraction_horizontal_gap(&self) -> &'a MathValueRecord {
586
0
        &self.data.header().skewed_fraction_horizontal_gap
587
0
    }
588
589
    /// Vertical distance between the ink of the top and bottom elements of a
590
    /// skewed fraction.
591
0
    pub fn skewed_fraction_vertical_gap(&self) -> &'a MathValueRecord {
592
0
        &self.data.header().skewed_fraction_vertical_gap
593
0
    }
594
595
    /// Distance between the overbar and the (ink) top of he base.
596
0
    pub fn overbar_vertical_gap(&self) -> &'a MathValueRecord {
597
0
        &self.data.header().overbar_vertical_gap
598
0
    }
599
600
    /// Thickness of overbar.
601
0
    pub fn overbar_rule_thickness(&self) -> &'a MathValueRecord {
602
0
        &self.data.header().overbar_rule_thickness
603
0
    }
604
605
    /// Extra white space reserved above the overbar.
606
0
    pub fn overbar_extra_ascender(&self) -> &'a MathValueRecord {
607
0
        &self.data.header().overbar_extra_ascender
608
0
    }
609
610
    /// Distance between underbar and (ink) bottom of the base.
611
0
    pub fn underbar_vertical_gap(&self) -> &'a MathValueRecord {
612
0
        &self.data.header().underbar_vertical_gap
613
0
    }
614
615
    /// Thickness of underbar.
616
0
    pub fn underbar_rule_thickness(&self) -> &'a MathValueRecord {
617
0
        &self.data.header().underbar_rule_thickness
618
0
    }
619
620
    /// Extra white space reserved below the underbar.
621
0
    pub fn underbar_extra_descender(&self) -> &'a MathValueRecord {
622
0
        &self.data.header().underbar_extra_descender
623
0
    }
624
625
    /// Space between the (ink) top of the expression and the bar over it.
626
0
    pub fn radical_vertical_gap(&self) -> &'a MathValueRecord {
627
0
        &self.data.header().radical_vertical_gap
628
0
    }
629
630
    /// Space between the (ink) top of the expression and the bar over it in
631
    /// display style.
632
0
    pub fn radical_display_style_vertical_gap(&self) -> &'a MathValueRecord {
633
0
        &self.data.header().radical_display_style_vertical_gap
634
0
    }
635
636
    /// Thickness of the radical rule.
637
0
    pub fn radical_rule_thickness(&self) -> &'a MathValueRecord {
638
0
        &self.data.header().radical_rule_thickness
639
0
    }
640
641
    /// Extra white space reserved above the radical.
642
0
    pub fn radical_extra_ascender(&self) -> &'a MathValueRecord {
643
0
        &self.data.header().radical_extra_ascender
644
0
    }
645
646
    /// Extra horizontal kern before the degree of a radical, if such is
647
    /// present.
648
0
    pub fn radical_kern_before_degree(&self) -> &'a MathValueRecord {
649
0
        &self.data.header().radical_kern_before_degree
650
0
    }
651
652
    /// Negative kern after the degree of a radical, if such is present.
653
0
    pub fn radical_kern_after_degree(&self) -> &'a MathValueRecord {
654
0
        &self.data.header().radical_kern_after_degree
655
0
    }
656
657
    /// Height of the bottom of the radical degree, if such is present, in
658
    /// proportion to the ascender of the radical sign.
659
0
    pub fn radical_degree_bottom_raise_percent(&self) -> i16 {
660
0
        self.data.header().radical_degree_bottom_raise_percent.get()
661
0
    }
662
663
0
    pub fn script_percent_scale_down_byte_range(&self) -> Range<usize> {
664
0
        let start = 0usize;
665
0
        let end = start.saturating_add(i16::RAW_BYTE_LEN);
666
0
        start..end
667
0
    }
668
669
0
    pub fn script_script_percent_scale_down_byte_range(&self) -> Range<usize> {
670
0
        let start = self.script_percent_scale_down_byte_range().end;
671
0
        let end = start.saturating_add(i16::RAW_BYTE_LEN);
672
0
        start..end
673
0
    }
674
675
0
    pub fn delimited_sub_formula_min_height_byte_range(&self) -> Range<usize> {
676
0
        let start = self.script_script_percent_scale_down_byte_range().end;
677
0
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
678
0
        start..end
679
0
    }
680
681
0
    pub fn display_operator_min_height_byte_range(&self) -> Range<usize> {
682
0
        let start = self.delimited_sub_formula_min_height_byte_range().end;
683
0
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
684
0
        start..end
685
0
    }
686
687
0
    pub fn math_leading_byte_range(&self) -> Range<usize> {
688
0
        let start = self.display_operator_min_height_byte_range().end;
689
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
690
0
        start..end
691
0
    }
692
693
0
    pub fn axis_height_byte_range(&self) -> Range<usize> {
694
0
        let start = self.math_leading_byte_range().end;
695
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
696
0
        start..end
697
0
    }
698
699
0
    pub fn accent_base_height_byte_range(&self) -> Range<usize> {
700
0
        let start = self.axis_height_byte_range().end;
701
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
702
0
        start..end
703
0
    }
704
705
0
    pub fn flattened_accent_base_height_byte_range(&self) -> Range<usize> {
706
0
        let start = self.accent_base_height_byte_range().end;
707
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
708
0
        start..end
709
0
    }
710
711
0
    pub fn subscript_shift_down_byte_range(&self) -> Range<usize> {
712
0
        let start = self.flattened_accent_base_height_byte_range().end;
713
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
714
0
        start..end
715
0
    }
716
717
0
    pub fn subscript_top_max_byte_range(&self) -> Range<usize> {
718
0
        let start = self.subscript_shift_down_byte_range().end;
719
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
720
0
        start..end
721
0
    }
722
723
0
    pub fn subscript_baseline_drop_min_byte_range(&self) -> Range<usize> {
724
0
        let start = self.subscript_top_max_byte_range().end;
725
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
726
0
        start..end
727
0
    }
728
729
0
    pub fn superscript_shift_up_byte_range(&self) -> Range<usize> {
730
0
        let start = self.subscript_baseline_drop_min_byte_range().end;
731
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
732
0
        start..end
733
0
    }
734
735
0
    pub fn superscript_shift_up_cramped_byte_range(&self) -> Range<usize> {
736
0
        let start = self.superscript_shift_up_byte_range().end;
737
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
738
0
        start..end
739
0
    }
740
741
0
    pub fn superscript_bottom_min_byte_range(&self) -> Range<usize> {
742
0
        let start = self.superscript_shift_up_cramped_byte_range().end;
743
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
744
0
        start..end
745
0
    }
746
747
0
    pub fn superscript_baseline_drop_max_byte_range(&self) -> Range<usize> {
748
0
        let start = self.superscript_bottom_min_byte_range().end;
749
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
750
0
        start..end
751
0
    }
752
753
0
    pub fn sub_superscript_gap_min_byte_range(&self) -> Range<usize> {
754
0
        let start = self.superscript_baseline_drop_max_byte_range().end;
755
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
756
0
        start..end
757
0
    }
758
759
0
    pub fn superscript_bottom_max_with_subscript_byte_range(&self) -> Range<usize> {
760
0
        let start = self.sub_superscript_gap_min_byte_range().end;
761
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
762
0
        start..end
763
0
    }
764
765
0
    pub fn space_after_script_byte_range(&self) -> Range<usize> {
766
0
        let start = self.superscript_bottom_max_with_subscript_byte_range().end;
767
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
768
0
        start..end
769
0
    }
770
771
0
    pub fn upper_limit_gap_min_byte_range(&self) -> Range<usize> {
772
0
        let start = self.space_after_script_byte_range().end;
773
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
774
0
        start..end
775
0
    }
776
777
0
    pub fn upper_limit_baseline_rise_min_byte_range(&self) -> Range<usize> {
778
0
        let start = self.upper_limit_gap_min_byte_range().end;
779
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
780
0
        start..end
781
0
    }
782
783
0
    pub fn lower_limit_gap_min_byte_range(&self) -> Range<usize> {
784
0
        let start = self.upper_limit_baseline_rise_min_byte_range().end;
785
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
786
0
        start..end
787
0
    }
788
789
0
    pub fn lower_limit_baseline_drop_min_byte_range(&self) -> Range<usize> {
790
0
        let start = self.lower_limit_gap_min_byte_range().end;
791
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
792
0
        start..end
793
0
    }
794
795
0
    pub fn stack_top_shift_up_byte_range(&self) -> Range<usize> {
796
0
        let start = self.lower_limit_baseline_drop_min_byte_range().end;
797
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
798
0
        start..end
799
0
    }
800
801
0
    pub fn stack_top_display_style_shift_up_byte_range(&self) -> Range<usize> {
802
0
        let start = self.stack_top_shift_up_byte_range().end;
803
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
804
0
        start..end
805
0
    }
806
807
0
    pub fn stack_bottom_shift_down_byte_range(&self) -> Range<usize> {
808
0
        let start = self.stack_top_display_style_shift_up_byte_range().end;
809
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
810
0
        start..end
811
0
    }
812
813
0
    pub fn stack_bottom_display_style_shift_down_byte_range(&self) -> Range<usize> {
814
0
        let start = self.stack_bottom_shift_down_byte_range().end;
815
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
816
0
        start..end
817
0
    }
818
819
0
    pub fn stack_gap_min_byte_range(&self) -> Range<usize> {
820
0
        let start = self.stack_bottom_display_style_shift_down_byte_range().end;
821
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
822
0
        start..end
823
0
    }
824
825
0
    pub fn stack_display_style_gap_min_byte_range(&self) -> Range<usize> {
826
0
        let start = self.stack_gap_min_byte_range().end;
827
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
828
0
        start..end
829
0
    }
830
831
0
    pub fn stretch_stack_top_shift_up_byte_range(&self) -> Range<usize> {
832
0
        let start = self.stack_display_style_gap_min_byte_range().end;
833
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
834
0
        start..end
835
0
    }
836
837
0
    pub fn stretch_stack_bottom_shift_down_byte_range(&self) -> Range<usize> {
838
0
        let start = self.stretch_stack_top_shift_up_byte_range().end;
839
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
840
0
        start..end
841
0
    }
842
843
0
    pub fn stretch_stack_gap_above_min_byte_range(&self) -> Range<usize> {
844
0
        let start = self.stretch_stack_bottom_shift_down_byte_range().end;
845
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
846
0
        start..end
847
0
    }
848
849
0
    pub fn stretch_stack_gap_below_min_byte_range(&self) -> Range<usize> {
850
0
        let start = self.stretch_stack_gap_above_min_byte_range().end;
851
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
852
0
        start..end
853
0
    }
854
855
0
    pub fn fraction_numerator_shift_up_byte_range(&self) -> Range<usize> {
856
0
        let start = self.stretch_stack_gap_below_min_byte_range().end;
857
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
858
0
        start..end
859
0
    }
860
861
0
    pub fn fraction_numerator_display_style_shift_up_byte_range(&self) -> Range<usize> {
862
0
        let start = self.fraction_numerator_shift_up_byte_range().end;
863
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
864
0
        start..end
865
0
    }
866
867
0
    pub fn fraction_denominator_shift_down_byte_range(&self) -> Range<usize> {
868
0
        let start = self
869
0
            .fraction_numerator_display_style_shift_up_byte_range()
870
0
            .end;
871
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
872
0
        start..end
873
0
    }
874
875
0
    pub fn fraction_denominator_display_style_shift_down_byte_range(&self) -> Range<usize> {
876
0
        let start = self.fraction_denominator_shift_down_byte_range().end;
877
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
878
0
        start..end
879
0
    }
880
881
0
    pub fn fraction_numerator_gap_min_byte_range(&self) -> Range<usize> {
882
0
        let start = self
883
0
            .fraction_denominator_display_style_shift_down_byte_range()
884
0
            .end;
885
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
886
0
        start..end
887
0
    }
888
889
0
    pub fn fraction_num_display_style_gap_min_byte_range(&self) -> Range<usize> {
890
0
        let start = self.fraction_numerator_gap_min_byte_range().end;
891
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
892
0
        start..end
893
0
    }
894
895
0
    pub fn fraction_rule_thickness_byte_range(&self) -> Range<usize> {
896
0
        let start = self.fraction_num_display_style_gap_min_byte_range().end;
897
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
898
0
        start..end
899
0
    }
900
901
0
    pub fn fraction_denominator_gap_min_byte_range(&self) -> Range<usize> {
902
0
        let start = self.fraction_rule_thickness_byte_range().end;
903
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
904
0
        start..end
905
0
    }
906
907
0
    pub fn fraction_denom_display_style_gap_min_byte_range(&self) -> Range<usize> {
908
0
        let start = self.fraction_denominator_gap_min_byte_range().end;
909
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
910
0
        start..end
911
0
    }
912
913
0
    pub fn skewed_fraction_horizontal_gap_byte_range(&self) -> Range<usize> {
914
0
        let start = self.fraction_denom_display_style_gap_min_byte_range().end;
915
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
916
0
        start..end
917
0
    }
918
919
0
    pub fn skewed_fraction_vertical_gap_byte_range(&self) -> Range<usize> {
920
0
        let start = self.skewed_fraction_horizontal_gap_byte_range().end;
921
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
922
0
        start..end
923
0
    }
924
925
0
    pub fn overbar_vertical_gap_byte_range(&self) -> Range<usize> {
926
0
        let start = self.skewed_fraction_vertical_gap_byte_range().end;
927
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
928
0
        start..end
929
0
    }
930
931
0
    pub fn overbar_rule_thickness_byte_range(&self) -> Range<usize> {
932
0
        let start = self.overbar_vertical_gap_byte_range().end;
933
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
934
0
        start..end
935
0
    }
936
937
0
    pub fn overbar_extra_ascender_byte_range(&self) -> Range<usize> {
938
0
        let start = self.overbar_rule_thickness_byte_range().end;
939
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
940
0
        start..end
941
0
    }
942
943
0
    pub fn underbar_vertical_gap_byte_range(&self) -> Range<usize> {
944
0
        let start = self.overbar_extra_ascender_byte_range().end;
945
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
946
0
        start..end
947
0
    }
948
949
0
    pub fn underbar_rule_thickness_byte_range(&self) -> Range<usize> {
950
0
        let start = self.underbar_vertical_gap_byte_range().end;
951
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
952
0
        start..end
953
0
    }
954
955
0
    pub fn underbar_extra_descender_byte_range(&self) -> Range<usize> {
956
0
        let start = self.underbar_rule_thickness_byte_range().end;
957
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
958
0
        start..end
959
0
    }
960
961
0
    pub fn radical_vertical_gap_byte_range(&self) -> Range<usize> {
962
0
        let start = self.underbar_extra_descender_byte_range().end;
963
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
964
0
        start..end
965
0
    }
966
967
0
    pub fn radical_display_style_vertical_gap_byte_range(&self) -> Range<usize> {
968
0
        let start = self.radical_vertical_gap_byte_range().end;
969
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
970
0
        start..end
971
0
    }
972
973
0
    pub fn radical_rule_thickness_byte_range(&self) -> Range<usize> {
974
0
        let start = self.radical_display_style_vertical_gap_byte_range().end;
975
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
976
0
        start..end
977
0
    }
978
979
0
    pub fn radical_extra_ascender_byte_range(&self) -> Range<usize> {
980
0
        let start = self.radical_rule_thickness_byte_range().end;
981
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
982
0
        start..end
983
0
    }
984
985
0
    pub fn radical_kern_before_degree_byte_range(&self) -> Range<usize> {
986
0
        let start = self.radical_extra_ascender_byte_range().end;
987
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
988
0
        start..end
989
0
    }
990
991
0
    pub fn radical_kern_after_degree_byte_range(&self) -> Range<usize> {
992
0
        let start = self.radical_kern_before_degree_byte_range().end;
993
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
994
0
        start..end
995
0
    }
996
997
0
    pub fn radical_degree_bottom_raise_percent_byte_range(&self) -> Range<usize> {
998
0
        let start = self.radical_kern_after_degree_byte_range().end;
999
0
        let end = start.saturating_add(i16::RAW_BYTE_LEN);
1000
0
        start..end
1001
0
    }
1002
}
1003
1004
const _: () = assert!(FontData::default_data_long_enough(MathConstants::MIN_SIZE));
1005
1006
impl Default for MathConstants<'_> {
1007
0
    fn default() -> Self {
1008
        Self {
1009
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1010
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1011
        }
1012
0
    }
1013
}
1014
1015
impl<'a> MinByteRange<'a> for MathGlyphInfo<'a> {
1016
0
    fn min_byte_range(&self) -> Range<usize> {
1017
0
        0..self.math_kern_info_offset_byte_range().end
1018
0
    }
1019
0
    fn min_table_bytes(&self) -> &'a [u8] {
1020
0
        let range = self.min_byte_range();
1021
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1022
0
    }
1023
}
1024
1025
impl ReadArgs for MathGlyphInfo<'_> {
1026
    type Args = ();
1027
}
1028
1029
impl<'a> FontRead<'a> for MathGlyphInfo<'a> {
1030
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1031
        #[allow(clippy::absurd_extreme_comparisons)]
1032
0
        if data.len() < Self::MIN_SIZE {
1033
0
            return Err(ReadError::OutOfBounds);
1034
0
        }
1035
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1036
0
            return Err(ReadError::OutOfBounds);
1037
        };
1038
0
        Ok(Self { data })
1039
0
    }
1040
}
1041
1042
/// The fields at the start of the table, which are read directly.
1043
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1044
#[repr(C, packed)]
1045
#[doc(hidden)]
1046
pub 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)]
1054
const _: () = assert!(std::mem::size_of::<MathGlyphInfoFixedHeader>() <= MathGlyphInfo::MIN_SIZE);
1055
1056
/// [MathGlyphInfo](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathglyphinfo-table)
1057
#[derive(Clone)]
1058
pub struct MathGlyphInfo<'a> {
1059
    data: TableDataRef<'a, MathGlyphInfoFixedHeader>,
1060
}
1061
1062
#[allow(clippy::needless_lifetimes)]
1063
impl<'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
    /// Offset to MathItalicsCorrectionInfo table, from the beginning of the
1071
    /// MathGlyphInfo table. May be NULL.
1072
0
    pub fn math_italics_correction_info_offset(&self) -> Nullable<Offset16> {
1073
0
        self.data.header().math_italics_correction_info_offset.get()
1074
0
    }
1075
1076
    /// Attempt to resolve [`math_italics_correction_info_offset`][Self::math_italics_correction_info_offset].
1077
0
    pub fn math_italics_correction_info(
1078
0
        &self,
1079
0
    ) -> Option<Result<MathItalicsCorrectionInfo<'a>, ReadError>> {
1080
0
        let data = self.offset_data();
1081
0
        self.math_italics_correction_info_offset().resolve(data)
1082
0
    }
1083
1084
    /// Offset to MathTopAccentAttachment table, from the beginning of the
1085
    /// MathGlyphInfo table. May be NULL.
1086
0
    pub fn math_top_accent_attachment_offset(&self) -> Nullable<Offset16> {
1087
0
        self.data.header().math_top_accent_attachment_offset.get()
1088
0
    }
1089
1090
    /// Attempt to resolve [`math_top_accent_attachment_offset`][Self::math_top_accent_attachment_offset].
1091
0
    pub fn math_top_accent_attachment(
1092
0
        &self,
1093
0
    ) -> Option<Result<MathTopAccentAttachment<'a>, ReadError>> {
1094
0
        let data = self.offset_data();
1095
0
        self.math_top_accent_attachment_offset().resolve(data)
1096
0
    }
1097
1098
    /// Offset to the Coverage table for glyphs with extended shapes, from the
1099
    /// beginning of the MathGlyphInfo table. May be NULL.
1100
0
    pub fn extended_shape_coverage_offset(&self) -> Nullable<Offset16> {
1101
0
        self.data.header().extended_shape_coverage_offset.get()
1102
0
    }
1103
1104
    /// Attempt to resolve [`extended_shape_coverage_offset`][Self::extended_shape_coverage_offset].
1105
0
    pub fn extended_shape_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
1106
0
        let data = self.offset_data();
1107
0
        self.extended_shape_coverage_offset().resolve(data)
1108
0
    }
1109
1110
    /// Offset to the MathKernInfo table, from the beginning of the
1111
    /// MathGlyphInfo table. May be NULL.
1112
0
    pub fn math_kern_info_offset(&self) -> Nullable<Offset16> {
1113
0
        self.data.header().math_kern_info_offset.get()
1114
0
    }
1115
1116
    /// Attempt to resolve [`math_kern_info_offset`][Self::math_kern_info_offset].
1117
0
    pub fn math_kern_info(&self) -> Option<Result<MathKernInfo<'a>, ReadError>> {
1118
0
        let data = self.offset_data();
1119
0
        self.math_kern_info_offset().resolve(data)
1120
0
    }
1121
1122
0
    pub fn math_italics_correction_info_offset_byte_range(&self) -> Range<usize> {
1123
0
        let start = 0usize;
1124
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1125
0
        start..end
1126
0
    }
1127
1128
0
    pub fn math_top_accent_attachment_offset_byte_range(&self) -> Range<usize> {
1129
0
        let start = self.math_italics_correction_info_offset_byte_range().end;
1130
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1131
0
        start..end
1132
0
    }
1133
1134
0
    pub fn extended_shape_coverage_offset_byte_range(&self) -> Range<usize> {
1135
0
        let start = self.math_top_accent_attachment_offset_byte_range().end;
1136
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1137
0
        start..end
1138
0
    }
1139
1140
0
    pub fn math_kern_info_offset_byte_range(&self) -> Range<usize> {
1141
0
        let start = self.extended_shape_coverage_offset_byte_range().end;
1142
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1143
0
        start..end
1144
0
    }
1145
}
1146
1147
const _: () = assert!(FontData::default_data_long_enough(MathGlyphInfo::MIN_SIZE));
1148
1149
impl Default for MathGlyphInfo<'_> {
1150
0
    fn default() -> Self {
1151
        Self {
1152
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1153
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1154
        }
1155
0
    }
1156
}
1157
1158
impl<'a> MinByteRange<'a> for MathItalicsCorrectionInfo<'a> {
1159
0
    fn min_byte_range(&self) -> Range<usize> {
1160
0
        0..self.italics_correction_byte_range().end
1161
0
    }
1162
0
    fn min_table_bytes(&self) -> &'a [u8] {
1163
0
        let range = self.min_byte_range();
1164
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1165
0
    }
1166
}
1167
1168
impl ReadArgs for MathItalicsCorrectionInfo<'_> {
1169
    type Args = ();
1170
}
1171
1172
impl<'a> FontRead<'a> for MathItalicsCorrectionInfo<'a> {
1173
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1174
        #[allow(clippy::absurd_extreme_comparisons)]
1175
0
        if data.len() < Self::MIN_SIZE {
1176
0
            return Err(ReadError::OutOfBounds);
1177
0
        }
1178
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1179
0
            return Err(ReadError::OutOfBounds);
1180
        };
1181
0
        Ok(Self { data })
1182
0
    }
1183
}
1184
1185
/// The fields at the start of the table, which are read directly.
1186
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1187
#[repr(C, packed)]
1188
#[doc(hidden)]
1189
pub struct MathItalicsCorrectionInfoFixedHeader {
1190
    pub coverage_offset: BigEndian<Offset16>,
1191
    pub italics_correction_count: BigEndian<u16>,
1192
}
1193
1194
#[allow(clippy::absurd_extreme_comparisons)]
1195
const _: () = assert!(
1196
    std::mem::size_of::<MathItalicsCorrectionInfoFixedHeader>()
1197
        <= MathItalicsCorrectionInfo::MIN_SIZE
1198
);
1199
1200
/// [MathItalicsCorrectionInfo](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathitalicscorrectioninfo-table)
1201
#[derive(Clone)]
1202
pub struct MathItalicsCorrectionInfo<'a> {
1203
    data: TableDataRef<'a, MathItalicsCorrectionInfoFixedHeader>,
1204
}
1205
1206
#[allow(clippy::needless_lifetimes)]
1207
impl<'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
    /// Offset to the Coverage table, from the beginning of the
1212
    /// MathItalicsCorrectionInfo table.
1213
0
    pub fn coverage_offset(&self) -> Offset16 {
1214
0
        self.data.header().coverage_offset.get()
1215
0
    }
1216
1217
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
1218
0
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1219
0
        let data = self.offset_data();
1220
0
        self.coverage_offset().resolve(data)
1221
0
    }
1222
1223
    /// Number of italics correction values. Should coincide with the number of
1224
    /// covered glyphs.
1225
0
    pub fn italics_correction_count(&self) -> u16 {
1226
0
        self.data.header().italics_correction_count.get()
1227
0
    }
1228
1229
    /// Array of MathValueRecords defining italics correction values for each
1230
    /// covered glyph.
1231
0
    pub fn italics_correction(&self) -> &'a [MathValueRecord] {
1232
0
        let range = self.italics_correction_byte_range();
1233
0
        self.offset_data()
1234
0
            .read_array(range)
1235
0
            .ok()
1236
0
            .unwrap_or_default()
1237
0
    }
1238
1239
0
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
1240
0
        let start = 0usize;
1241
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1242
0
        start..end
1243
0
    }
1244
1245
0
    pub fn italics_correction_count_byte_range(&self) -> Range<usize> {
1246
0
        let start = self.coverage_offset_byte_range().end;
1247
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1248
0
        start..end
1249
0
    }
1250
1251
0
    pub fn italics_correction_byte_range(&self) -> Range<usize> {
1252
0
        let italics_correction_count = self.italics_correction_count();
1253
0
        let start = self.italics_correction_count_byte_range().end;
1254
0
        let end = start.saturating_add(
1255
0
            (transforms::to_usize(italics_correction_count))
1256
0
                .saturating_mul(MathValueRecord::RAW_BYTE_LEN),
1257
        );
1258
0
        start..end
1259
0
    }
1260
}
1261
1262
const _: () = assert!(FontData::default_data_long_enough(
1263
    MathItalicsCorrectionInfo::MIN_SIZE
1264
));
1265
1266
impl Default for MathItalicsCorrectionInfo<'_> {
1267
0
    fn default() -> Self {
1268
        Self {
1269
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1270
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1271
        }
1272
0
    }
1273
}
1274
1275
impl<'a> MinByteRange<'a> for MathTopAccentAttachment<'a> {
1276
0
    fn min_byte_range(&self) -> Range<usize> {
1277
0
        0..self.top_accent_attachment_byte_range().end
1278
0
    }
1279
0
    fn min_table_bytes(&self) -> &'a [u8] {
1280
0
        let range = self.min_byte_range();
1281
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1282
0
    }
1283
}
1284
1285
impl ReadArgs for MathTopAccentAttachment<'_> {
1286
    type Args = ();
1287
}
1288
1289
impl<'a> FontRead<'a> for MathTopAccentAttachment<'a> {
1290
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1291
        #[allow(clippy::absurd_extreme_comparisons)]
1292
0
        if data.len() < Self::MIN_SIZE {
1293
0
            return Err(ReadError::OutOfBounds);
1294
0
        }
1295
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1296
0
            return Err(ReadError::OutOfBounds);
1297
        };
1298
0
        Ok(Self { data })
1299
0
    }
1300
}
1301
1302
/// The fields at the start of the table, which are read directly.
1303
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1304
#[repr(C, packed)]
1305
#[doc(hidden)]
1306
pub 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)]
1312
const _: () = assert!(
1313
    std::mem::size_of::<MathTopAccentAttachmentFixedHeader>() <= MathTopAccentAttachment::MIN_SIZE
1314
);
1315
1316
/// [MathTopAccentAttachment](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathtopaccentattachment-table)
1317
#[derive(Clone)]
1318
pub struct MathTopAccentAttachment<'a> {
1319
    data: TableDataRef<'a, MathTopAccentAttachmentFixedHeader>,
1320
}
1321
1322
#[allow(clippy::needless_lifetimes)]
1323
impl<'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
    /// Offset to the Coverage table, from the beginning of the
1328
    /// MathTopAccentAttachment table.
1329
0
    pub fn top_accent_coverage_offset(&self) -> Offset16 {
1330
0
        self.data.header().top_accent_coverage_offset.get()
1331
0
    }
1332
1333
    /// Attempt to resolve [`top_accent_coverage_offset`][Self::top_accent_coverage_offset].
1334
0
    pub fn top_accent_coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1335
0
        let data = self.offset_data();
1336
0
        self.top_accent_coverage_offset().resolve(data)
1337
0
    }
1338
1339
    /// Number of top accent attachment point values. Should coincide with the
1340
    /// number of covered glyphs.
1341
0
    pub fn top_accent_attachment_count(&self) -> u16 {
1342
0
        self.data.header().top_accent_attachment_count.get()
1343
0
    }
1344
1345
    /// Array of MathValueRecords defining top accent attachment points for each
1346
    /// covered glyph.
1347
0
    pub fn top_accent_attachment(&self) -> &'a [MathValueRecord] {
1348
0
        let range = self.top_accent_attachment_byte_range();
1349
0
        self.offset_data()
1350
0
            .read_array(range)
1351
0
            .ok()
1352
0
            .unwrap_or_default()
1353
0
    }
1354
1355
0
    pub fn top_accent_coverage_offset_byte_range(&self) -> Range<usize> {
1356
0
        let start = 0usize;
1357
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1358
0
        start..end
1359
0
    }
1360
1361
0
    pub fn top_accent_attachment_count_byte_range(&self) -> Range<usize> {
1362
0
        let start = self.top_accent_coverage_offset_byte_range().end;
1363
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1364
0
        start..end
1365
0
    }
1366
1367
0
    pub fn top_accent_attachment_byte_range(&self) -> Range<usize> {
1368
0
        let top_accent_attachment_count = self.top_accent_attachment_count();
1369
0
        let start = self.top_accent_attachment_count_byte_range().end;
1370
0
        let end = start.saturating_add(
1371
0
            (transforms::to_usize(top_accent_attachment_count))
1372
0
                .saturating_mul(MathValueRecord::RAW_BYTE_LEN),
1373
        );
1374
0
        start..end
1375
0
    }
1376
}
1377
1378
const _: () = assert!(FontData::default_data_long_enough(
1379
    MathTopAccentAttachment::MIN_SIZE
1380
));
1381
1382
impl Default for MathTopAccentAttachment<'_> {
1383
0
    fn default() -> Self {
1384
        Self {
1385
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1386
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1387
        }
1388
0
    }
1389
}
1390
1391
impl<'a> MinByteRange<'a> for MathKernInfo<'a> {
1392
0
    fn min_byte_range(&self) -> Range<usize> {
1393
0
        0..self.math_kern_info_records_byte_range().end
1394
0
    }
1395
0
    fn min_table_bytes(&self) -> &'a [u8] {
1396
0
        let range = self.min_byte_range();
1397
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1398
0
    }
1399
}
1400
1401
impl ReadArgs for MathKernInfo<'_> {
1402
    type Args = ();
1403
}
1404
1405
impl<'a> FontRead<'a> for MathKernInfo<'a> {
1406
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1407
        #[allow(clippy::absurd_extreme_comparisons)]
1408
0
        if data.len() < Self::MIN_SIZE {
1409
0
            return Err(ReadError::OutOfBounds);
1410
0
        }
1411
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1412
0
            return Err(ReadError::OutOfBounds);
1413
        };
1414
0
        Ok(Self { data })
1415
0
    }
1416
}
1417
1418
/// The fields at the start of the table, which are read directly.
1419
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1420
#[repr(C, packed)]
1421
#[doc(hidden)]
1422
pub 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)]
1428
const _: () = assert!(std::mem::size_of::<MathKernInfoFixedHeader>() <= MathKernInfo::MIN_SIZE);
1429
1430
/// [MathKernInfo](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathkerninfo-table)
1431
#[derive(Clone)]
1432
pub struct MathKernInfo<'a> {
1433
    data: TableDataRef<'a, MathKernInfoFixedHeader>,
1434
}
1435
1436
#[allow(clippy::needless_lifetimes)]
1437
impl<'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
    /// Offset to the Coverage table, from the beginning of the MathKernInfo
1442
    /// table.
1443
0
    pub fn math_kern_coverage_offset(&self) -> Offset16 {
1444
0
        self.data.header().math_kern_coverage_offset.get()
1445
0
    }
1446
1447
    /// Attempt to resolve [`math_kern_coverage_offset`][Self::math_kern_coverage_offset].
1448
0
    pub fn math_kern_coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1449
0
        let data = self.offset_data();
1450
0
        self.math_kern_coverage_offset().resolve(data)
1451
0
    }
1452
1453
    /// Number of MathKernInfoRecords. Should coincide with the number of
1454
    /// covered glyphs.
1455
0
    pub fn math_kern_count(&self) -> u16 {
1456
0
        self.data.header().math_kern_count.get()
1457
0
    }
1458
1459
    /// Array of MathKernInfoRecords, one for each covered glyph.
1460
0
    pub fn math_kern_info_records(&self) -> &'a [MathKernInfoRecord] {
1461
0
        let range = self.math_kern_info_records_byte_range();
1462
0
        self.offset_data()
1463
0
            .read_array(range)
1464
0
            .ok()
1465
0
            .unwrap_or_default()
1466
0
    }
1467
1468
0
    pub fn math_kern_coverage_offset_byte_range(&self) -> Range<usize> {
1469
0
        let start = 0usize;
1470
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1471
0
        start..end
1472
0
    }
1473
1474
0
    pub fn math_kern_count_byte_range(&self) -> Range<usize> {
1475
0
        let start = self.math_kern_coverage_offset_byte_range().end;
1476
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1477
0
        start..end
1478
0
    }
1479
1480
0
    pub fn math_kern_info_records_byte_range(&self) -> Range<usize> {
1481
0
        let math_kern_count = self.math_kern_count();
1482
0
        let start = self.math_kern_count_byte_range().end;
1483
0
        let end = start.saturating_add(
1484
0
            (transforms::to_usize(math_kern_count))
1485
0
                .saturating_mul(MathKernInfoRecord::RAW_BYTE_LEN),
1486
        );
1487
0
        start..end
1488
0
    }
1489
}
1490
1491
const _: () = assert!(FontData::default_data_long_enough(MathKernInfo::MIN_SIZE));
1492
1493
impl Default for MathKernInfo<'_> {
1494
0
    fn default() -> Self {
1495
        Self {
1496
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1497
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1498
        }
1499
0
    }
1500
}
1501
1502
/// [MathKernInfoRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathkerninforecord)
1503
///
1504
/// The offsets are measured from the beginning of the MathKernInfo table.
1505
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
1506
#[repr(C)]
1507
#[repr(packed)]
1508
pub struct MathKernInfoRecord {
1509
    /// Offset to the MathKern table for the top right corner, from the
1510
    /// beginning of the MathKernInfo table. May be NULL.
1511
    pub top_right_math_kern_offset: BigEndian<Nullable<Offset16>>,
1512
    /// Offset to the MathKern table for the top left corner, from the beginning
1513
    /// of the MathKernInfo table. May be NULL.
1514
    pub top_left_math_kern_offset: BigEndian<Nullable<Offset16>>,
1515
    /// Offset to the MathKern table for the bottom right corner, from the
1516
    /// beginning of the MathKernInfo table. May be NULL.
1517
    pub bottom_right_math_kern_offset: BigEndian<Nullable<Offset16>>,
1518
    /// Offset to the MathKern table for the bottom left corner, from the
1519
    /// beginning of the MathKernInfo table. May be NULL.
1520
    pub bottom_left_math_kern_offset: BigEndian<Nullable<Offset16>>,
1521
}
1522
1523
impl MathKernInfoRecord {
1524
    /// Offset to the MathKern table for the top right corner, from the
1525
    /// beginning of the MathKernInfo table. May be NULL.
1526
0
    pub fn top_right_math_kern_offset(&self) -> Nullable<Offset16> {
1527
0
        self.top_right_math_kern_offset.get()
1528
0
    }
1529
1530
    /// Offset to the MathKern table for the top right corner, from the
1531
    /// beginning of the MathKernInfo table. May be NULL.
1532
    ///
1533
    /// The `data` argument should be retrieved from the parent table
1534
    /// By calling its `offset_data` method.
1535
0
    pub fn top_right_math_kern<'a>(
1536
0
        &self,
1537
0
        data: FontData<'a>,
1538
0
    ) -> Option<Result<MathKern<'a>, ReadError>> {
1539
0
        self.top_right_math_kern_offset().resolve(data)
1540
0
    }
1541
1542
    /// Offset to the MathKern table for the top left corner, from the beginning
1543
    /// of the MathKernInfo table. May be NULL.
1544
0
    pub fn top_left_math_kern_offset(&self) -> Nullable<Offset16> {
1545
0
        self.top_left_math_kern_offset.get()
1546
0
    }
1547
1548
    /// Offset to the MathKern table for the top left corner, from the beginning
1549
    /// of the MathKernInfo table. May be NULL.
1550
    ///
1551
    /// The `data` argument should be retrieved from the parent table
1552
    /// By calling its `offset_data` method.
1553
0
    pub fn top_left_math_kern<'a>(
1554
0
        &self,
1555
0
        data: FontData<'a>,
1556
0
    ) -> Option<Result<MathKern<'a>, ReadError>> {
1557
0
        self.top_left_math_kern_offset().resolve(data)
1558
0
    }
1559
1560
    /// Offset to the MathKern table for the bottom right corner, from the
1561
    /// beginning of the MathKernInfo table. May be NULL.
1562
0
    pub fn bottom_right_math_kern_offset(&self) -> Nullable<Offset16> {
1563
0
        self.bottom_right_math_kern_offset.get()
1564
0
    }
1565
1566
    /// Offset to the MathKern table for the bottom right corner, from the
1567
    /// beginning of the MathKernInfo table. May be NULL.
1568
    ///
1569
    /// The `data` argument should be retrieved from the parent table
1570
    /// By calling its `offset_data` method.
1571
0
    pub fn bottom_right_math_kern<'a>(
1572
0
        &self,
1573
0
        data: FontData<'a>,
1574
0
    ) -> Option<Result<MathKern<'a>, ReadError>> {
1575
0
        self.bottom_right_math_kern_offset().resolve(data)
1576
0
    }
1577
1578
    /// Offset to the MathKern table for the bottom left corner, from the
1579
    /// beginning of the MathKernInfo table. May be NULL.
1580
0
    pub fn bottom_left_math_kern_offset(&self) -> Nullable<Offset16> {
1581
0
        self.bottom_left_math_kern_offset.get()
1582
0
    }
1583
1584
    /// Offset to the MathKern table for the bottom left corner, from the
1585
    /// beginning of the MathKernInfo table. May be NULL.
1586
    ///
1587
    /// The `data` argument should be retrieved from the parent table
1588
    /// By calling its `offset_data` method.
1589
0
    pub fn bottom_left_math_kern<'a>(
1590
0
        &self,
1591
0
        data: FontData<'a>,
1592
0
    ) -> Option<Result<MathKern<'a>, ReadError>> {
1593
0
        self.bottom_left_math_kern_offset().resolve(data)
1594
0
    }
1595
}
1596
1597
impl 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
1604
impl<'a> MinByteRange<'a> for MathKern<'a> {
1605
0
    fn min_byte_range(&self) -> Range<usize> {
1606
0
        0..self.kern_values_byte_range().end
1607
0
    }
1608
0
    fn min_table_bytes(&self) -> &'a [u8] {
1609
0
        let range = self.min_byte_range();
1610
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1611
0
    }
1612
}
1613
1614
impl ReadArgs for MathKern<'_> {
1615
    type Args = ();
1616
}
1617
1618
impl<'a> FontRead<'a> for MathKern<'a> {
1619
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1620
        #[allow(clippy::absurd_extreme_comparisons)]
1621
0
        if data.len() < Self::MIN_SIZE {
1622
0
            return Err(ReadError::OutOfBounds);
1623
0
        }
1624
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1625
0
            return Err(ReadError::OutOfBounds);
1626
        };
1627
0
        Ok(Self { data })
1628
0
    }
1629
}
1630
1631
/// The fields at the start of the table, which are read directly.
1632
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1633
#[repr(C, packed)]
1634
#[doc(hidden)]
1635
pub struct MathKernFixedHeader {
1636
    pub height_count: BigEndian<u16>,
1637
}
1638
1639
#[allow(clippy::absurd_extreme_comparisons)]
1640
const _: () = assert!(std::mem::size_of::<MathKernFixedHeader>() <= MathKern::MIN_SIZE);
1641
1642
/// [MathKern](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathkern-table)
1643
#[derive(Clone)]
1644
pub struct MathKern<'a> {
1645
    data: TableDataRef<'a, MathKernFixedHeader>,
1646
}
1647
1648
#[allow(clippy::needless_lifetimes)]
1649
impl<'a> MathKern<'a> {
1650
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
1651
    basic_table_impls!(impl_the_methods);
1652
1653
    /// Number of heights at which the kern value changes.
1654
0
    pub fn height_count(&self) -> u16 {
1655
0
        self.data.header().height_count.get()
1656
0
    }
1657
1658
    /// Array of correction heights, in design units, sorted from lowest to
1659
    /// highest.
1660
0
    pub fn correction_height(&self) -> &'a [MathValueRecord] {
1661
0
        let range = self.correction_height_byte_range();
1662
0
        self.offset_data()
1663
0
            .read_array(range)
1664
0
            .ok()
1665
0
            .unwrap_or_default()
1666
0
    }
1667
1668
    /// Array of kerning values for different height ranges, in design units.
1669
    ///
1670
    /// There is one more of these than there are correction heights: the first
1671
    /// applies below the first correction height, and the last above the last.
1672
0
    pub fn kern_values(&self) -> &'a [MathValueRecord] {
1673
0
        let range = self.kern_values_byte_range();
1674
0
        self.offset_data()
1675
0
            .read_array(range)
1676
0
            .ok()
1677
0
            .unwrap_or_default()
1678
0
    }
1679
1680
0
    pub fn height_count_byte_range(&self) -> Range<usize> {
1681
0
        let start = 0usize;
1682
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1683
0
        start..end
1684
0
    }
1685
1686
0
    pub fn correction_height_byte_range(&self) -> Range<usize> {
1687
0
        let height_count = self.height_count();
1688
0
        let start = self.height_count_byte_range().end;
1689
0
        let end = start.saturating_add(
1690
0
            (transforms::to_usize(height_count)).saturating_mul(MathValueRecord::RAW_BYTE_LEN),
1691
        );
1692
0
        start..end
1693
0
    }
1694
1695
0
    pub fn kern_values_byte_range(&self) -> Range<usize> {
1696
0
        let height_count = self.height_count();
1697
0
        let start = self.correction_height_byte_range().end;
1698
0
        let end = start.saturating_add(
1699
0
            (transforms::add(height_count, 1_usize)).saturating_mul(MathValueRecord::RAW_BYTE_LEN),
1700
        );
1701
0
        start..end
1702
0
    }
1703
}
1704
1705
const _: () = assert!(FontData::default_data_long_enough(MathKern::MIN_SIZE));
1706
1707
impl Default for MathKern<'_> {
1708
0
    fn default() -> Self {
1709
        Self {
1710
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1711
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1712
        }
1713
0
    }
1714
}
1715
1716
impl<'a> MinByteRange<'a> for MathVariants<'a> {
1717
0
    fn min_byte_range(&self) -> Range<usize> {
1718
0
        0..self.horiz_glyph_construction_offsets_byte_range().end
1719
0
    }
1720
0
    fn min_table_bytes(&self) -> &'a [u8] {
1721
0
        let range = self.min_byte_range();
1722
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1723
0
    }
1724
}
1725
1726
impl ReadArgs for MathVariants<'_> {
1727
    type Args = ();
1728
}
1729
1730
impl<'a> FontRead<'a> for MathVariants<'a> {
1731
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1732
        #[allow(clippy::absurd_extreme_comparisons)]
1733
0
        if data.len() < Self::MIN_SIZE {
1734
0
            return Err(ReadError::OutOfBounds);
1735
0
        }
1736
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1737
0
            return Err(ReadError::OutOfBounds);
1738
        };
1739
0
        Ok(Self { data })
1740
0
    }
1741
}
1742
1743
/// The fields at the start of the table, which are read directly.
1744
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1745
#[repr(C, packed)]
1746
#[doc(hidden)]
1747
pub 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)]
1756
const _: () = assert!(std::mem::size_of::<MathVariantsFixedHeader>() <= MathVariants::MIN_SIZE);
1757
1758
/// [MathVariants](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathvariants-table)
1759
#[derive(Clone)]
1760
pub struct MathVariants<'a> {
1761
    data: TableDataRef<'a, MathVariantsFixedHeader>,
1762
}
1763
1764
#[allow(clippy::needless_lifetimes)]
1765
impl<'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
    /// Minimum overlap of connecting glyphs during glyph construction, in
1774
    /// design units.
1775
0
    pub fn min_connector_overlap(&self) -> UfWord {
1776
0
        self.data.header().min_connector_overlap.get()
1777
0
    }
1778
1779
    /// Offset to the Coverage table for shapes growing in the vertical
1780
    /// direction, from the beginning of the MathVariants table. May be NULL.
1781
0
    pub fn vert_glyph_coverage_offset(&self) -> Nullable<Offset16> {
1782
0
        self.data.header().vert_glyph_coverage_offset.get()
1783
0
    }
1784
1785
    /// Attempt to resolve [`vert_glyph_coverage_offset`][Self::vert_glyph_coverage_offset].
1786
0
    pub fn vert_glyph_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
1787
0
        let data = self.offset_data();
1788
0
        self.vert_glyph_coverage_offset().resolve(data)
1789
0
    }
1790
1791
    /// Offset to the Coverage table for shapes growing in the horizontal
1792
    /// direction, from the beginning of the MathVariants table. May be NULL.
1793
0
    pub fn horiz_glyph_coverage_offset(&self) -> Nullable<Offset16> {
1794
0
        self.data.header().horiz_glyph_coverage_offset.get()
1795
0
    }
1796
1797
    /// Attempt to resolve [`horiz_glyph_coverage_offset`][Self::horiz_glyph_coverage_offset].
1798
0
    pub fn horiz_glyph_coverage(&self) -> Option<Result<CoverageTable<'a>, ReadError>> {
1799
0
        let data = self.offset_data();
1800
0
        self.horiz_glyph_coverage_offset().resolve(data)
1801
0
    }
1802
1803
    /// Number of glyphs for which information is provided for vertically
1804
    /// growing variants. Must be the same as the number of glyph IDs referenced
1805
    /// in the vertical Coverage table.
1806
0
    pub fn vert_glyph_count(&self) -> u16 {
1807
0
        self.data.header().vert_glyph_count.get()
1808
0
    }
1809
1810
    /// Number of glyphs for which information is provided for horizontally
1811
    /// growing variants. Must be the same as the number of glyph IDs referenced
1812
    /// in the horizontal Coverage table.
1813
0
    pub fn horiz_glyph_count(&self) -> u16 {
1814
0
        self.data.header().horiz_glyph_count.get()
1815
0
    }
1816
1817
    /// Array of offsets to MathGlyphConstruction tables, from the beginning of
1818
    /// the MathVariants table, for shapes growing in the vertical direction.
1819
0
    pub fn vert_glyph_construction_offsets(&self) -> &'a [BigEndian<Offset16>] {
1820
0
        let range = self.vert_glyph_construction_offsets_byte_range();
1821
0
        self.offset_data()
1822
0
            .read_array(range)
1823
0
            .ok()
1824
0
            .unwrap_or_default()
1825
0
    }
1826
1827
    /// A dynamically resolving wrapper for [`vert_glyph_construction_offsets`][Self::vert_glyph_construction_offsets].
1828
0
    pub fn vert_glyph_constructions(
1829
0
        &self,
1830
0
    ) -> ArrayOfOffsets<'a, MathGlyphConstruction<'a>, Offset16> {
1831
0
        let data = self.offset_data();
1832
0
        let offsets = self.vert_glyph_construction_offsets();
1833
0
        ArrayOfOffsets::new(offsets, data, ())
1834
0
    }
1835
1836
    /// Array of offsets to MathGlyphConstruction tables, from the beginning of
1837
    /// the MathVariants table, for shapes growing in the horizontal direction.
1838
0
    pub fn horiz_glyph_construction_offsets(&self) -> &'a [BigEndian<Offset16>] {
1839
0
        let range = self.horiz_glyph_construction_offsets_byte_range();
1840
0
        self.offset_data()
1841
0
            .read_array(range)
1842
0
            .ok()
1843
0
            .unwrap_or_default()
1844
0
    }
1845
1846
    /// A dynamically resolving wrapper for [`horiz_glyph_construction_offsets`][Self::horiz_glyph_construction_offsets].
1847
0
    pub fn horiz_glyph_constructions(
1848
0
        &self,
1849
0
    ) -> ArrayOfOffsets<'a, MathGlyphConstruction<'a>, Offset16> {
1850
0
        let data = self.offset_data();
1851
0
        let offsets = self.horiz_glyph_construction_offsets();
1852
0
        ArrayOfOffsets::new(offsets, data, ())
1853
0
    }
1854
1855
0
    pub fn min_connector_overlap_byte_range(&self) -> Range<usize> {
1856
0
        let start = 0usize;
1857
0
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
1858
0
        start..end
1859
0
    }
1860
1861
0
    pub fn vert_glyph_coverage_offset_byte_range(&self) -> Range<usize> {
1862
0
        let start = self.min_connector_overlap_byte_range().end;
1863
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1864
0
        start..end
1865
0
    }
1866
1867
0
    pub fn horiz_glyph_coverage_offset_byte_range(&self) -> Range<usize> {
1868
0
        let start = self.vert_glyph_coverage_offset_byte_range().end;
1869
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1870
0
        start..end
1871
0
    }
1872
1873
0
    pub fn vert_glyph_count_byte_range(&self) -> Range<usize> {
1874
0
        let start = self.horiz_glyph_coverage_offset_byte_range().end;
1875
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1876
0
        start..end
1877
0
    }
1878
1879
0
    pub fn horiz_glyph_count_byte_range(&self) -> Range<usize> {
1880
0
        let start = self.vert_glyph_count_byte_range().end;
1881
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1882
0
        start..end
1883
0
    }
1884
1885
0
    pub fn vert_glyph_construction_offsets_byte_range(&self) -> Range<usize> {
1886
0
        let vert_glyph_count = self.vert_glyph_count();
1887
0
        let start = self.horiz_glyph_count_byte_range().end;
1888
0
        let end = start.saturating_add(
1889
0
            (transforms::to_usize(vert_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
1890
        );
1891
0
        start..end
1892
0
    }
1893
1894
0
    pub fn horiz_glyph_construction_offsets_byte_range(&self) -> Range<usize> {
1895
0
        let horiz_glyph_count = self.horiz_glyph_count();
1896
0
        let start = self.vert_glyph_construction_offsets_byte_range().end;
1897
0
        let end = start.saturating_add(
1898
0
            (transforms::to_usize(horiz_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
1899
        );
1900
0
        start..end
1901
0
    }
1902
}
1903
1904
const _: () = assert!(FontData::default_data_long_enough(MathVariants::MIN_SIZE));
1905
1906
impl Default for MathVariants<'_> {
1907
0
    fn default() -> Self {
1908
        Self {
1909
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1910
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1911
        }
1912
0
    }
1913
}
1914
1915
impl<'a> MinByteRange<'a> for MathGlyphConstruction<'a> {
1916
0
    fn min_byte_range(&self) -> Range<usize> {
1917
0
        0..self.math_glyph_variant_records_byte_range().end
1918
0
    }
1919
0
    fn min_table_bytes(&self) -> &'a [u8] {
1920
0
        let range = self.min_byte_range();
1921
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1922
0
    }
1923
}
1924
1925
impl ReadArgs for MathGlyphConstruction<'_> {
1926
    type Args = ();
1927
}
1928
1929
impl<'a> FontRead<'a> for MathGlyphConstruction<'a> {
1930
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1931
        #[allow(clippy::absurd_extreme_comparisons)]
1932
0
        if data.len() < Self::MIN_SIZE {
1933
0
            return Err(ReadError::OutOfBounds);
1934
0
        }
1935
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1936
0
            return Err(ReadError::OutOfBounds);
1937
        };
1938
0
        Ok(Self { data })
1939
0
    }
1940
}
1941
1942
/// The fields at the start of the table, which are read directly.
1943
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1944
#[repr(C, packed)]
1945
#[doc(hidden)]
1946
pub struct MathGlyphConstructionFixedHeader {
1947
    pub glyph_assembly_offset: BigEndian<Nullable<Offset16>>,
1948
    pub variant_count: BigEndian<u16>,
1949
}
1950
1951
#[allow(clippy::absurd_extreme_comparisons)]
1952
const _: () = assert!(
1953
    std::mem::size_of::<MathGlyphConstructionFixedHeader>() <= MathGlyphConstruction::MIN_SIZE
1954
);
1955
1956
/// [MathGlyphConstruction](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathglyphconstruction-table)
1957
#[derive(Clone)]
1958
pub struct MathGlyphConstruction<'a> {
1959
    data: TableDataRef<'a, MathGlyphConstructionFixedHeader>,
1960
}
1961
1962
#[allow(clippy::needless_lifetimes)]
1963
impl<'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
    /// Offset to the GlyphAssembly table for this shape, from the beginning of
1968
    /// the MathGlyphConstruction table. May be NULL.
1969
0
    pub fn glyph_assembly_offset(&self) -> Nullable<Offset16> {
1970
0
        self.data.header().glyph_assembly_offset.get()
1971
0
    }
1972
1973
    /// Attempt to resolve [`glyph_assembly_offset`][Self::glyph_assembly_offset].
1974
0
    pub fn glyph_assembly(&self) -> Option<Result<GlyphAssembly<'a>, ReadError>> {
1975
0
        let data = self.offset_data();
1976
0
        self.glyph_assembly_offset().resolve(data)
1977
0
    }
1978
1979
    /// Count of glyph growing variants for this glyph.
1980
0
    pub fn variant_count(&self) -> u16 {
1981
0
        self.data.header().variant_count.get()
1982
0
    }
1983
1984
    /// MathGlyphVariantRecords for alternative variants of the base glyph.
1985
0
    pub fn math_glyph_variant_records(&self) -> &'a [MathGlyphVariantRecord] {
1986
0
        let range = self.math_glyph_variant_records_byte_range();
1987
0
        self.offset_data()
1988
0
            .read_array(range)
1989
0
            .ok()
1990
0
            .unwrap_or_default()
1991
0
    }
1992
1993
0
    pub fn glyph_assembly_offset_byte_range(&self) -> Range<usize> {
1994
0
        let start = 0usize;
1995
0
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1996
0
        start..end
1997
0
    }
1998
1999
0
    pub fn variant_count_byte_range(&self) -> Range<usize> {
2000
0
        let start = self.glyph_assembly_offset_byte_range().end;
2001
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2002
0
        start..end
2003
0
    }
2004
2005
0
    pub fn math_glyph_variant_records_byte_range(&self) -> Range<usize> {
2006
0
        let variant_count = self.variant_count();
2007
0
        let start = self.variant_count_byte_range().end;
2008
0
        let end = start.saturating_add(
2009
0
            (transforms::to_usize(variant_count))
2010
0
                .saturating_mul(MathGlyphVariantRecord::RAW_BYTE_LEN),
2011
        );
2012
0
        start..end
2013
0
    }
2014
}
2015
2016
const _: () = assert!(FontData::default_data_long_enough(
2017
    MathGlyphConstruction::MIN_SIZE
2018
));
2019
2020
impl Default for MathGlyphConstruction<'_> {
2021
0
    fn default() -> Self {
2022
        Self {
2023
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
2024
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2025
        }
2026
0
    }
2027
}
2028
2029
/// [MathGlyphVariantRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathglyphvariantrecord)
2030
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
2031
#[repr(C)]
2032
#[repr(packed)]
2033
pub struct MathGlyphVariantRecord {
2034
    /// Glyph ID for the variant.
2035
    pub variant_glyph: BigEndian<GlyphId16>,
2036
    /// Advance width/height, in design units, of the variant, in the direction
2037
    /// of requested glyph extension.
2038
    pub advance_measurement: BigEndian<UfWord>,
2039
}
2040
2041
impl MathGlyphVariantRecord {
2042
    /// Glyph ID for the variant.
2043
0
    pub fn variant_glyph(&self) -> GlyphId16 {
2044
0
        self.variant_glyph.get()
2045
0
    }
2046
2047
    /// Advance width/height, in design units, of the variant, in the direction
2048
    /// of requested glyph extension.
2049
0
    pub fn advance_measurement(&self) -> UfWord {
2050
0
        self.advance_measurement.get()
2051
0
    }
2052
}
2053
2054
impl FixedSize for MathGlyphVariantRecord {
2055
    const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN + UfWord::RAW_BYTE_LEN;
2056
}
2057
2058
impl<'a> MinByteRange<'a> for GlyphAssembly<'a> {
2059
0
    fn min_byte_range(&self) -> Range<usize> {
2060
0
        0..self.part_records_byte_range().end
2061
0
    }
2062
0
    fn min_table_bytes(&self) -> &'a [u8] {
2063
0
        let range = self.min_byte_range();
2064
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2065
0
    }
2066
}
2067
2068
impl ReadArgs for GlyphAssembly<'_> {
2069
    type Args = ();
2070
}
2071
2072
impl<'a> FontRead<'a> for GlyphAssembly<'a> {
2073
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2074
        #[allow(clippy::absurd_extreme_comparisons)]
2075
0
        if data.len() < Self::MIN_SIZE {
2076
0
            return Err(ReadError::OutOfBounds);
2077
0
        }
2078
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2079
0
            return Err(ReadError::OutOfBounds);
2080
        };
2081
0
        Ok(Self { data })
2082
0
    }
2083
}
2084
2085
/// The fields at the start of the table, which are read directly.
2086
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2087
#[repr(C, packed)]
2088
#[doc(hidden)]
2089
pub struct GlyphAssemblyFixedHeader {
2090
    pub italics_correction: MathValueRecord,
2091
    pub part_count: BigEndian<u16>,
2092
}
2093
2094
#[allow(clippy::absurd_extreme_comparisons)]
2095
const _: () = assert!(std::mem::size_of::<GlyphAssemblyFixedHeader>() <= GlyphAssembly::MIN_SIZE);
2096
2097
/// [GlyphAssembly](https://learn.microsoft.com/en-us/typography/opentype/spec/math#glyphassembly-table)
2098
#[derive(Clone)]
2099
pub struct GlyphAssembly<'a> {
2100
    data: TableDataRef<'a, GlyphAssemblyFixedHeader>,
2101
}
2102
2103
#[allow(clippy::needless_lifetimes)]
2104
impl<'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
    /// Italics correction of this GlyphAssembly. Should not depend on the
2109
    /// assembly size.
2110
0
    pub fn italics_correction(&self) -> &'a MathValueRecord {
2111
0
        &self.data.header().italics_correction
2112
0
    }
2113
2114
    /// Number of parts in this assembly.
2115
0
    pub fn part_count(&self) -> u16 {
2116
0
        self.data.header().part_count.get()
2117
0
    }
2118
2119
    /// Array of part records, from left to right (for assemblies that extend
2120
    /// horizontally) or bottom to top (for assemblies that extend vertically).
2121
0
    pub fn part_records(&self) -> &'a [GlyphPartRecord] {
2122
0
        let range = self.part_records_byte_range();
2123
0
        self.offset_data()
2124
0
            .read_array(range)
2125
0
            .ok()
2126
0
            .unwrap_or_default()
2127
0
    }
2128
2129
0
    pub fn italics_correction_byte_range(&self) -> Range<usize> {
2130
0
        let start = 0usize;
2131
0
        let end = start.saturating_add(MathValueRecord::RAW_BYTE_LEN);
2132
0
        start..end
2133
0
    }
2134
2135
0
    pub fn part_count_byte_range(&self) -> Range<usize> {
2136
0
        let start = self.italics_correction_byte_range().end;
2137
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2138
0
        start..end
2139
0
    }
2140
2141
0
    pub fn part_records_byte_range(&self) -> Range<usize> {
2142
0
        let part_count = self.part_count();
2143
0
        let start = self.part_count_byte_range().end;
2144
0
        let end = start.saturating_add(
2145
0
            (transforms::to_usize(part_count)).saturating_mul(GlyphPartRecord::RAW_BYTE_LEN),
2146
        );
2147
0
        start..end
2148
0
    }
2149
}
2150
2151
const _: () = assert!(FontData::default_data_long_enough(GlyphAssembly::MIN_SIZE));
2152
2153
impl Default for GlyphAssembly<'_> {
2154
0
    fn default() -> Self {
2155
        Self {
2156
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
2157
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2158
        }
2159
0
    }
2160
}
2161
2162
/// [GlyphPartRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/math#glyphpartrecord)
2163
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
2164
#[repr(C)]
2165
#[repr(packed)]
2166
pub struct GlyphPartRecord {
2167
    /// Glyph ID for the part.
2168
    pub glyph_id: BigEndian<GlyphId16>,
2169
    /// Advance width/ height, in design units, of the straight bar connector
2170
    /// material at the start of the glyph in the direction of the extension.
2171
    pub start_connector_length: BigEndian<UfWord>,
2172
    /// Advance width/ height, in design units, of the straight bar connector
2173
    /// material at the end of the glyph in the direction of the extension.
2174
    pub end_connector_length: BigEndian<UfWord>,
2175
    /// Full advance width/height for this part in the direction of the
2176
    /// extension, in design units.
2177
    pub full_advance: BigEndian<UfWord>,
2178
    /// Part qualifiers.
2179
    pub part_flags: BigEndian<PartFlags>,
2180
}
2181
2182
impl GlyphPartRecord {
2183
    /// Glyph ID for the part.
2184
0
    pub fn glyph_id(&self) -> GlyphId16 {
2185
0
        self.glyph_id.get()
2186
0
    }
2187
2188
    /// Advance width/ height, in design units, of the straight bar connector
2189
    /// material at the start of the glyph in the direction of the extension.
2190
0
    pub fn start_connector_length(&self) -> UfWord {
2191
0
        self.start_connector_length.get()
2192
0
    }
2193
2194
    /// Advance width/ height, in design units, of the straight bar connector
2195
    /// material at the end of the glyph in the direction of the extension.
2196
0
    pub fn end_connector_length(&self) -> UfWord {
2197
0
        self.end_connector_length.get()
2198
0
    }
2199
2200
    /// Full advance width/height for this part in the direction of the
2201
    /// extension, in design units.
2202
0
    pub fn full_advance(&self) -> UfWord {
2203
0
        self.full_advance.get()
2204
0
    }
2205
2206
    /// Part qualifiers.
2207
0
    pub fn part_flags(&self) -> PartFlags {
2208
0
        self.part_flags.get()
2209
0
    }
2210
}
2211
2212
impl 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
/// Qualifiers for a [`GlyphPartRecord`].
2221
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
2222
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2223
#[repr(transparent)]
2224
pub struct PartFlags {
2225
    bits: u16,
2226
}
2227
2228
impl PartFlags {
2229
    /// If set, the part can be skipped or repeated.
2230
    pub const EXTENDER_FLAG: Self = Self { bits: 0x0001 };
2231
}
2232
2233
impl PartFlags {
2234
    ///  Returns an empty set of flags.
2235
    #[inline]
2236
0
    pub const fn empty() -> Self {
2237
0
        Self { bits: 0 }
2238
0
    }
2239
2240
    /// Returns the set containing all flags.
2241
    #[inline]
2242
0
    pub const fn all() -> Self {
2243
0
        Self {
2244
0
            bits: Self::EXTENDER_FLAG.bits,
2245
0
        }
2246
0
    }
2247
2248
    /// Returns the raw value of the flags currently stored.
2249
    #[inline]
2250
0
    pub const fn bits(&self) -> u16 {
2251
0
        self.bits
2252
0
    }
2253
2254
    /// Convert from underlying bit representation, unless that
2255
    /// representation contains bits that do not correspond to a flag.
2256
    #[inline]
2257
0
    pub const fn from_bits(bits: u16) -> Option<Self> {
2258
0
        if (bits & !Self::all().bits()) == 0 {
2259
0
            Some(Self { bits })
2260
        } else {
2261
0
            None
2262
        }
2263
0
    }
2264
2265
    /// Convert from underlying bit representation, dropping any bits
2266
    /// that do not correspond to flags.
2267
    #[inline]
2268
0
    pub const fn from_bits_truncate(bits: u16) -> Self {
2269
0
        Self {
2270
0
            bits: bits & Self::all().bits,
2271
0
        }
2272
0
    }
2273
2274
    /// Returns `true` if no flags are currently stored.
2275
    #[inline]
2276
0
    pub const fn is_empty(&self) -> bool {
2277
0
        self.bits() == Self::empty().bits()
2278
0
    }
2279
2280
    /// Returns `true` if there are flags common to both `self` and `other`.
2281
    #[inline]
2282
0
    pub const fn intersects(&self, other: Self) -> bool {
2283
0
        !(Self {
2284
0
            bits: self.bits & other.bits,
2285
0
        })
2286
0
        .is_empty()
2287
0
    }
2288
2289
    /// Returns `true` if all of the flags in `other` are contained within `self`.
2290
    #[inline]
2291
0
    pub const fn contains(&self, other: Self) -> bool {
2292
0
        (self.bits & other.bits) == other.bits
2293
0
    }
2294
2295
    /// Inserts the specified flags in-place.
2296
    #[inline]
2297
0
    pub fn insert(&mut self, other: Self) {
2298
0
        self.bits |= other.bits;
2299
0
    }
2300
2301
    /// Removes the specified flags in-place.
2302
    #[inline]
2303
0
    pub fn remove(&mut self, other: Self) {
2304
0
        self.bits &= !other.bits;
2305
0
    }
2306
2307
    /// Toggles the specified flags in-place.
2308
    #[inline]
2309
0
    pub fn toggle(&mut self, other: Self) {
2310
0
        self.bits ^= other.bits;
2311
0
    }
2312
2313
    /// Returns the intersection between the flags in `self` and
2314
    /// `other`.
2315
    ///
2316
    /// Specifically, the returned set contains only the flags which are
2317
    /// present in *both* `self` *and* `other`.
2318
    ///
2319
    /// This is equivalent to using the `&` operator (e.g.
2320
    /// [`ops::BitAnd`]), as in `flags & other`.
2321
    ///
2322
    /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
2323
    #[inline]
2324
    #[must_use]
2325
0
    pub const fn intersection(self, other: Self) -> Self {
2326
0
        Self {
2327
0
            bits: self.bits & other.bits,
2328
0
        }
2329
0
    }
2330
2331
    /// Returns the union of between the flags in `self` and `other`.
2332
    ///
2333
    /// Specifically, the returned set contains all flags which are
2334
    /// present in *either* `self` *or* `other`, including any which are
2335
    /// present in both.
2336
    ///
2337
    /// This is equivalent to using the `|` operator (e.g.
2338
    /// [`ops::BitOr`]), as in `flags | other`.
2339
    ///
2340
    /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
2341
    #[inline]
2342
    #[must_use]
2343
0
    pub const fn union(self, other: Self) -> Self {
2344
0
        Self {
2345
0
            bits: self.bits | other.bits,
2346
0
        }
2347
0
    }
2348
2349
    /// Returns the difference between the flags in `self` and `other`.
2350
    ///
2351
    /// Specifically, the returned set contains all flags present in
2352
    /// `self`, except for the ones present in `other`.
2353
    ///
2354
    /// It is also conceptually equivalent to the "bit-clear" operation:
2355
    /// `flags & !other` (and this syntax is also supported).
2356
    ///
2357
    /// This is equivalent to using the `-` operator (e.g.
2358
    /// [`ops::Sub`]), as in `flags - other`.
2359
    ///
2360
    /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
2361
    #[inline]
2362
    #[must_use]
2363
0
    pub const fn difference(self, other: Self) -> Self {
2364
0
        Self {
2365
0
            bits: self.bits & !other.bits,
2366
0
        }
2367
0
    }
2368
}
2369
2370
impl std::ops::BitOr for PartFlags {
2371
    type Output = Self;
2372
2373
    /// Returns the union of the two sets of flags.
2374
    #[inline]
2375
0
    fn bitor(self, other: PartFlags) -> Self {
2376
0
        Self {
2377
0
            bits: self.bits | other.bits,
2378
0
        }
2379
0
    }
2380
}
2381
2382
impl std::ops::BitOrAssign for PartFlags {
2383
    /// Adds the set of flags.
2384
    #[inline]
2385
0
    fn bitor_assign(&mut self, other: Self) {
2386
0
        self.bits |= other.bits;
2387
0
    }
2388
}
2389
2390
impl std::ops::BitXor for PartFlags {
2391
    type Output = Self;
2392
2393
    /// Returns the left flags, but with all the right flags toggled.
2394
    #[inline]
2395
0
    fn bitxor(self, other: Self) -> Self {
2396
0
        Self {
2397
0
            bits: self.bits ^ other.bits,
2398
0
        }
2399
0
    }
2400
}
2401
2402
impl std::ops::BitXorAssign for PartFlags {
2403
    /// Toggles the set of flags.
2404
    #[inline]
2405
0
    fn bitxor_assign(&mut self, other: Self) {
2406
0
        self.bits ^= other.bits;
2407
0
    }
2408
}
2409
2410
impl std::ops::BitAnd for PartFlags {
2411
    type Output = Self;
2412
2413
    /// Returns the intersection between the two sets of flags.
2414
    #[inline]
2415
0
    fn bitand(self, other: Self) -> Self {
2416
0
        Self {
2417
0
            bits: self.bits & other.bits,
2418
0
        }
2419
0
    }
2420
}
2421
2422
impl std::ops::BitAndAssign for PartFlags {
2423
    /// Disables all flags disabled in the set.
2424
    #[inline]
2425
0
    fn bitand_assign(&mut self, other: Self) {
2426
0
        self.bits &= other.bits;
2427
0
    }
2428
}
2429
2430
impl std::ops::Sub for PartFlags {
2431
    type Output = Self;
2432
2433
    /// Returns the set difference of the two sets of flags.
2434
    #[inline]
2435
0
    fn sub(self, other: Self) -> Self {
2436
0
        Self {
2437
0
            bits: self.bits & !other.bits,
2438
0
        }
2439
0
    }
2440
}
2441
2442
impl std::ops::SubAssign for PartFlags {
2443
    /// Disables all flags enabled in the set.
2444
    #[inline]
2445
0
    fn sub_assign(&mut self, other: Self) {
2446
0
        self.bits &= !other.bits;
2447
0
    }
2448
}
2449
2450
impl std::ops::Not for PartFlags {
2451
    type Output = Self;
2452
2453
    /// Returns the complement of this set of flags.
2454
    #[inline]
2455
0
    fn not(self) -> Self {
2456
0
        Self { bits: !self.bits } & Self::all()
2457
0
    }
2458
}
2459
2460
impl std::fmt::Debug for PartFlags {
2461
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2462
0
        let members: &[(&str, Self)] = &[("EXTENDER_FLAG", Self::EXTENDER_FLAG)];
2463
0
        let mut first = true;
2464
0
        for (name, value) in members {
2465
0
            if self.contains(*value) {
2466
0
                if !first {
2467
0
                    f.write_str(" | ")?;
2468
0
                }
2469
0
                first = false;
2470
0
                f.write_str(name)?;
2471
0
            }
2472
        }
2473
0
        if first {
2474
0
            f.write_str("(empty)")?;
2475
0
        }
2476
0
        Ok(())
2477
0
    }
2478
}
2479
2480
impl std::fmt::Binary for PartFlags {
2481
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2482
0
        std::fmt::Binary::fmt(&self.bits, f)
2483
0
    }
2484
}
2485
2486
impl std::fmt::Octal for PartFlags {
2487
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2488
0
        std::fmt::Octal::fmt(&self.bits, f)
2489
0
    }
2490
}
2491
2492
impl std::fmt::LowerHex for PartFlags {
2493
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2494
0
        std::fmt::LowerHex::fmt(&self.bits, f)
2495
0
    }
2496
}
2497
2498
impl std::fmt::UpperHex for PartFlags {
2499
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2500
0
        std::fmt::UpperHex::fmt(&self.bits, f)
2501
0
    }
2502
}
2503
2504
impl font_types::Scalar for PartFlags {
2505
    type Raw = <u16 as font_types::Scalar>::Raw;
2506
0
    fn to_raw(self) -> Self::Raw {
2507
0
        self.bits().to_raw()
2508
0
    }
2509
0
    fn from_raw(raw: Self::Raw) -> Self {
2510
0
        let t = <u16>::from_raw(raw);
2511
0
        Self::from_bits_truncate(t)
2512
0
    }
2513
}