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_layout.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 ScriptList<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.script_records_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 ReadArgs for ScriptList<'_> {
19
    type Args = ();
20
}
21
22
impl<'a> FontRead<'a> for ScriptList<'a> {
23
147k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
24
        #[allow(clippy::absurd_extreme_comparisons)]
25
147k
        if data.len() < Self::MIN_SIZE {
26
10
            return Err(ReadError::OutOfBounds);
27
147k
        }
28
147k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
29
0
            return Err(ReadError::OutOfBounds);
30
        };
31
147k
        Ok(Self { data })
32
147k
    }
33
}
34
35
/// The fields at the start of the table, which are read directly.
36
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
37
#[repr(C, packed)]
38
#[doc(hidden)]
39
pub struct ScriptListFixedHeader {
40
    pub script_count: BigEndian<u16>,
41
}
42
43
#[allow(clippy::absurd_extreme_comparisons)]
44
const _: () = assert!(std::mem::size_of::<ScriptListFixedHeader>() <= ScriptList::MIN_SIZE);
45
46
/// [Script List Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#script-list-table-and-script-record)
47
#[derive(Clone)]
48
pub struct ScriptList<'a> {
49
    data: TableDataRef<'a, ScriptListFixedHeader>,
50
}
51
52
#[allow(clippy::needless_lifetimes)]
53
impl<'a> ScriptList<'a> {
54
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
55
    basic_table_impls!(impl_the_methods);
56
57
    /// Number of ScriptRecords
58
203k
    pub fn script_count(&self) -> u16 {
59
203k
        self.data.header().script_count.get()
60
203k
    }
61
62
    /// Array of ScriptRecords, listed alphabetically by script tag
63
203k
    pub fn script_records(&self) -> &'a [ScriptRecord] {
64
203k
        let range = self.script_records_byte_range();
65
203k
        self.offset_data()
66
203k
            .read_array(range)
67
203k
            .ok()
68
203k
            .unwrap_or_default()
69
203k
    }
70
71
203k
    pub fn script_count_byte_range(&self) -> Range<usize> {
72
203k
        let start = 0usize;
73
203k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
74
203k
        start..end
75
203k
    }
76
77
203k
    pub fn script_records_byte_range(&self) -> Range<usize> {
78
203k
        let script_count = self.script_count();
79
203k
        let start = self.script_count_byte_range().end;
80
203k
        let end = start.saturating_add(
81
203k
            (transforms::to_usize(script_count)).saturating_mul(ScriptRecord::RAW_BYTE_LEN),
82
        );
83
203k
        start..end
84
203k
    }
85
}
86
87
const _: () = assert!(FontData::default_data_long_enough(ScriptList::MIN_SIZE));
88
89
impl Default for ScriptList<'_> {
90
0
    fn default() -> Self {
91
        Self {
92
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
93
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
94
        }
95
0
    }
96
}
97
98
/// [Script Record](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#script-list-table-and-script-record)
99
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
100
#[repr(C)]
101
#[repr(packed)]
102
pub struct ScriptRecord {
103
    /// 4-byte script tag identifier
104
    pub script_tag: BigEndian<Tag>,
105
    /// Offset to Script table, from beginning of ScriptList
106
    pub script_offset: BigEndian<Offset16>,
107
}
108
109
impl ScriptRecord {
110
    /// 4-byte script tag identifier
111
393k
    pub fn script_tag(&self) -> Tag {
112
393k
        self.script_tag.get()
113
393k
    }
114
115
    /// Offset to Script table, from beginning of ScriptList
116
107k
    pub fn script_offset(&self) -> Offset16 {
117
107k
        self.script_offset.get()
118
107k
    }
119
120
    /// Offset to Script table, from beginning of ScriptList
121
    ///
122
    /// The `data` argument should be retrieved from the parent table
123
    /// By calling its `offset_data` method.
124
107k
    pub fn script<'a>(&self, data: FontData<'a>) -> Result<Script<'a>, ReadError> {
125
107k
        self.script_offset().resolve(data)
126
107k
    }
127
}
128
129
impl FixedSize for ScriptRecord {
130
    const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
131
}
132
133
impl<'a> MinByteRange<'a> for Script<'a> {
134
0
    fn min_byte_range(&self) -> Range<usize> {
135
0
        0..self.lang_sys_records_byte_range().end
136
0
    }
137
0
    fn min_table_bytes(&self) -> &'a [u8] {
138
0
        let range = self.min_byte_range();
139
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
140
0
    }
141
}
142
143
impl ReadArgs for Script<'_> {
144
    type Args = ();
145
}
146
147
impl<'a> FontRead<'a> for Script<'a> {
148
106k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
149
        #[allow(clippy::absurd_extreme_comparisons)]
150
106k
        if data.len() < Self::MIN_SIZE {
151
24
            return Err(ReadError::OutOfBounds);
152
106k
        }
153
106k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
154
0
            return Err(ReadError::OutOfBounds);
155
        };
156
106k
        Ok(Self { data })
157
106k
    }
158
}
159
160
/// The fields at the start of the table, which are read directly.
161
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
162
#[repr(C, packed)]
163
#[doc(hidden)]
164
pub struct ScriptFixedHeader {
165
    pub default_lang_sys_offset: BigEndian<Nullable<Offset16>>,
166
    pub lang_sys_count: BigEndian<u16>,
167
}
168
169
#[allow(clippy::absurd_extreme_comparisons)]
170
const _: () = assert!(std::mem::size_of::<ScriptFixedHeader>() <= Script::MIN_SIZE);
171
172
/// [Script Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#script-table-and-language-system-record)
173
#[derive(Clone)]
174
pub struct Script<'a> {
175
    data: TableDataRef<'a, ScriptFixedHeader>,
176
}
177
178
#[allow(clippy::needless_lifetimes)]
179
impl<'a> Script<'a> {
180
    pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
181
    basic_table_impls!(impl_the_methods);
182
183
    /// Offset to default LangSys table, from beginning of Script table
184
    /// — may be NULL
185
71.4k
    pub fn default_lang_sys_offset(&self) -> Nullable<Offset16> {
186
71.4k
        self.data.header().default_lang_sys_offset.get()
187
71.4k
    }
188
189
    /// Attempt to resolve [`default_lang_sys_offset`][Self::default_lang_sys_offset].
190
71.4k
    pub fn default_lang_sys(&self) -> Option<Result<LangSys<'a>, ReadError>> {
191
71.4k
        let data = self.offset_data();
192
71.4k
        self.default_lang_sys_offset().resolve(data)
193
71.4k
    }
194
195
    /// Number of LangSysRecords for this script — excluding the
196
    /// default LangSys
197
35.2k
    pub fn lang_sys_count(&self) -> u16 {
198
35.2k
        self.data.header().lang_sys_count.get()
199
35.2k
    }
200
201
    /// Array of LangSysRecords, listed alphabetically by LangSys tag
202
35.2k
    pub fn lang_sys_records(&self) -> &'a [LangSysRecord] {
203
35.2k
        let range = self.lang_sys_records_byte_range();
204
35.2k
        self.offset_data()
205
35.2k
            .read_array(range)
206
35.2k
            .ok()
207
35.2k
            .unwrap_or_default()
208
35.2k
    }
209
210
35.2k
    pub fn default_lang_sys_offset_byte_range(&self) -> Range<usize> {
211
35.2k
        let start = 0usize;
212
35.2k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
213
35.2k
        start..end
214
35.2k
    }
215
216
35.2k
    pub fn lang_sys_count_byte_range(&self) -> Range<usize> {
217
35.2k
        let start = self.default_lang_sys_offset_byte_range().end;
218
35.2k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
219
35.2k
        start..end
220
35.2k
    }
221
222
35.2k
    pub fn lang_sys_records_byte_range(&self) -> Range<usize> {
223
35.2k
        let lang_sys_count = self.lang_sys_count();
224
35.2k
        let start = self.lang_sys_count_byte_range().end;
225
35.2k
        let end = start.saturating_add(
226
35.2k
            (transforms::to_usize(lang_sys_count)).saturating_mul(LangSysRecord::RAW_BYTE_LEN),
227
        );
228
35.2k
        start..end
229
35.2k
    }
230
}
231
232
const _: () = assert!(FontData::default_data_long_enough(Script::MIN_SIZE));
233
234
impl Default for Script<'_> {
235
0
    fn default() -> Self {
236
        Self {
237
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
238
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
239
        }
240
0
    }
241
}
242
243
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
244
#[repr(C)]
245
#[repr(packed)]
246
pub struct LangSysRecord {
247
    /// 4-byte LangSysTag identifier
248
    pub lang_sys_tag: BigEndian<Tag>,
249
    /// Offset to LangSys table, from beginning of Script table
250
    pub lang_sys_offset: BigEndian<Offset16>,
251
}
252
253
impl LangSysRecord {
254
    /// 4-byte LangSysTag identifier
255
14.4k
    pub fn lang_sys_tag(&self) -> Tag {
256
14.4k
        self.lang_sys_tag.get()
257
14.4k
    }
258
259
    /// Offset to LangSys table, from beginning of Script table
260
82
    pub fn lang_sys_offset(&self) -> Offset16 {
261
82
        self.lang_sys_offset.get()
262
82
    }
263
264
    /// Offset to LangSys table, from beginning of Script table
265
    ///
266
    /// The `data` argument should be retrieved from the parent table
267
    /// By calling its `offset_data` method.
268
82
    pub fn lang_sys<'a>(&self, data: FontData<'a>) -> Result<LangSys<'a>, ReadError> {
269
82
        self.lang_sys_offset().resolve(data)
270
82
    }
271
}
272
273
impl FixedSize for LangSysRecord {
274
    const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
275
}
276
277
impl<'a> MinByteRange<'a> for LangSys<'a> {
278
0
    fn min_byte_range(&self) -> Range<usize> {
279
0
        0..self.feature_indices_byte_range().end
280
0
    }
281
0
    fn min_table_bytes(&self) -> &'a [u8] {
282
0
        let range = self.min_byte_range();
283
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
284
0
    }
285
}
286
287
impl ReadArgs for LangSys<'_> {
288
    type Args = ();
289
}
290
291
impl<'a> FontRead<'a> for LangSys<'a> {
292
71.3k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
293
        #[allow(clippy::absurd_extreme_comparisons)]
294
71.3k
        if data.len() < Self::MIN_SIZE {
295
31
            return Err(ReadError::OutOfBounds);
296
71.2k
        }
297
71.2k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
298
0
            return Err(ReadError::OutOfBounds);
299
        };
300
71.2k
        Ok(Self { data })
301
71.3k
    }
302
}
303
304
/// The fields at the start of the table, which are read directly.
305
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
306
#[repr(C, packed)]
307
#[doc(hidden)]
308
pub struct LangSysFixedHeader {
309
    pub lookup_order_offset: BigEndian<u16>,
310
    pub required_feature_index: BigEndian<u16>,
311
    pub feature_index_count: BigEndian<u16>,
312
}
313
314
#[allow(clippy::absurd_extreme_comparisons)]
315
const _: () = assert!(std::mem::size_of::<LangSysFixedHeader>() <= LangSys::MIN_SIZE);
316
317
/// [Language System Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#language-system-table)
318
#[derive(Clone)]
319
pub struct LangSys<'a> {
320
    data: TableDataRef<'a, LangSysFixedHeader>,
321
}
322
323
#[allow(clippy::needless_lifetimes)]
324
impl<'a> LangSys<'a> {
325
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
326
    basic_table_impls!(impl_the_methods);
327
328
    /// Index of a feature required for this language system; if no
329
    /// required features = 0xFFFF
330
35.0k
    pub fn required_feature_index(&self) -> u16 {
331
35.0k
        self.data.header().required_feature_index.get()
332
35.0k
    }
333
334
    /// Number of feature index values for this language system —
335
    /// excludes the required feature
336
36.1k
    pub fn feature_index_count(&self) -> u16 {
337
36.1k
        self.data.header().feature_index_count.get()
338
36.1k
    }
339
340
    /// Array of indices into the FeatureList, in arbitrary order
341
36.1k
    pub fn feature_indices(&self) -> &'a [BigEndian<u16>] {
342
36.1k
        let range = self.feature_indices_byte_range();
343
36.1k
        self.offset_data()
344
36.1k
            .read_array(range)
345
36.1k
            .ok()
346
36.1k
            .unwrap_or_default()
347
36.1k
    }
348
349
36.1k
    pub fn lookup_order_offset_byte_range(&self) -> Range<usize> {
350
36.1k
        let start = 0usize;
351
36.1k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
352
36.1k
        start..end
353
36.1k
    }
354
355
36.1k
    pub fn required_feature_index_byte_range(&self) -> Range<usize> {
356
36.1k
        let start = self.lookup_order_offset_byte_range().end;
357
36.1k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
358
36.1k
        start..end
359
36.1k
    }
360
361
36.1k
    pub fn feature_index_count_byte_range(&self) -> Range<usize> {
362
36.1k
        let start = self.required_feature_index_byte_range().end;
363
36.1k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
364
36.1k
        start..end
365
36.1k
    }
366
367
36.1k
    pub fn feature_indices_byte_range(&self) -> Range<usize> {
368
36.1k
        let feature_index_count = self.feature_index_count();
369
36.1k
        let start = self.feature_index_count_byte_range().end;
370
36.1k
        let end = start.saturating_add(
371
36.1k
            (transforms::to_usize(feature_index_count)).saturating_mul(u16::RAW_BYTE_LEN),
372
        );
373
36.1k
        start..end
374
36.1k
    }
375
}
376
377
const _: () = assert!(FontData::default_data_long_enough(LangSys::MIN_SIZE));
378
379
impl Default for LangSys<'_> {
380
0
    fn default() -> Self {
381
        Self {
382
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
383
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
384
        }
385
0
    }
386
}
387
388
impl<'a> MinByteRange<'a> for FeatureList<'a> {
389
0
    fn min_byte_range(&self) -> Range<usize> {
390
0
        0..self.feature_records_byte_range().end
391
0
    }
392
0
    fn min_table_bytes(&self) -> &'a [u8] {
393
0
        let range = self.min_byte_range();
394
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
395
0
    }
396
}
397
398
impl ReadArgs for FeatureList<'_> {
399
    type Args = ();
400
}
401
402
impl<'a> FontRead<'a> for FeatureList<'a> {
403
110k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
404
        #[allow(clippy::absurd_extreme_comparisons)]
405
110k
        if data.len() < Self::MIN_SIZE {
406
26
            return Err(ReadError::OutOfBounds);
407
110k
        }
408
110k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
409
0
            return Err(ReadError::OutOfBounds);
410
        };
411
110k
        Ok(Self { data })
412
110k
    }
413
}
414
415
/// The fields at the start of the table, which are read directly.
416
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
417
#[repr(C, packed)]
418
#[doc(hidden)]
419
pub struct FeatureListFixedHeader {
420
    pub feature_count: BigEndian<u16>,
421
}
422
423
#[allow(clippy::absurd_extreme_comparisons)]
424
const _: () = assert!(std::mem::size_of::<FeatureListFixedHeader>() <= FeatureList::MIN_SIZE);
425
426
/// [Feature List Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#feature-list-table)
427
#[derive(Clone)]
428
pub struct FeatureList<'a> {
429
    data: TableDataRef<'a, FeatureListFixedHeader>,
430
}
431
432
#[allow(clippy::needless_lifetimes)]
433
impl<'a> FeatureList<'a> {
434
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
435
    basic_table_impls!(impl_the_methods);
436
437
    /// Number of FeatureRecords in this table
438
110k
    pub fn feature_count(&self) -> u16 {
439
110k
        self.data.header().feature_count.get()
440
110k
    }
441
442
    /// Array of FeatureRecords — zero-based (first feature has
443
    /// FeatureIndex = 0), listed alphabetically by feature tag
444
110k
    pub fn feature_records(&self) -> &'a [FeatureRecord] {
445
110k
        let range = self.feature_records_byte_range();
446
110k
        self.offset_data()
447
110k
            .read_array(range)
448
110k
            .ok()
449
110k
            .unwrap_or_default()
450
110k
    }
451
452
110k
    pub fn feature_count_byte_range(&self) -> Range<usize> {
453
110k
        let start = 0usize;
454
110k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
455
110k
        start..end
456
110k
    }
457
458
110k
    pub fn feature_records_byte_range(&self) -> Range<usize> {
459
110k
        let feature_count = self.feature_count();
460
110k
        let start = self.feature_count_byte_range().end;
461
110k
        let end = start.saturating_add(
462
110k
            (transforms::to_usize(feature_count)).saturating_mul(FeatureRecord::RAW_BYTE_LEN),
463
        );
464
110k
        start..end
465
110k
    }
466
}
467
468
const _: () = assert!(FontData::default_data_long_enough(FeatureList::MIN_SIZE));
469
470
impl Default for FeatureList<'_> {
471
0
    fn default() -> Self {
472
        Self {
473
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
474
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
475
        }
476
0
    }
477
}
478
479
/// Part of [FeatureList]
480
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
481
#[repr(C)]
482
#[repr(packed)]
483
pub struct FeatureRecord {
484
    /// 4-byte feature identification tag
485
    pub feature_tag: BigEndian<Tag>,
486
    /// Offset to Feature table, from beginning of FeatureList
487
    pub feature_offset: BigEndian<Offset16>,
488
}
489
490
impl FeatureRecord {
491
    /// 4-byte feature identification tag
492
821k
    pub fn feature_tag(&self) -> Tag {
493
821k
        self.feature_tag.get()
494
821k
    }
495
496
    /// Offset to Feature table, from beginning of FeatureList
497
73.0k
    pub fn feature_offset(&self) -> Offset16 {
498
73.0k
        self.feature_offset.get()
499
73.0k
    }
500
501
    /// Offset to Feature table, from beginning of FeatureList
502
    ///
503
    /// The `data` argument should be retrieved from the parent table
504
    /// By calling its `offset_data` method.
505
73.0k
    pub fn feature<'a>(&self, data: FontData<'a>) -> Result<Feature<'a>, ReadError> {
506
73.0k
        let args = self.feature_tag();
507
73.0k
        self.feature_offset().resolve_with_args(data, args)
508
73.0k
    }
509
}
510
511
impl FixedSize for FeatureRecord {
512
    const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN;
513
}
514
515
impl<'a> MinByteRange<'a> for Feature<'a> {
516
0
    fn min_byte_range(&self) -> Range<usize> {
517
0
        0..self.lookup_list_indices_byte_range().end
518
0
    }
519
0
    fn min_table_bytes(&self) -> &'a [u8] {
520
0
        let range = self.min_byte_range();
521
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
522
0
    }
523
}
524
525
impl ReadArgs for Feature<'_> {
526
    type Args = Tag;
527
}
528
529
impl<'a> FontRead<'a> for Feature<'a> {
530
72.2k
    fn read_with_args(data: FontData<'a>, args: Tag) -> Result<Self, ReadError> {
531
72.2k
        let feature_tag = args;
532
533
        #[allow(clippy::absurd_extreme_comparisons)]
534
72.2k
        if data.len() < Self::MIN_SIZE {
535
19
            return Err(ReadError::OutOfBounds);
536
72.2k
        }
537
72.2k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
538
0
            return Err(ReadError::OutOfBounds);
539
        };
540
72.2k
        Ok(Self { data, feature_tag })
541
72.2k
    }
542
}
543
544
impl<'a> Feature<'a> {
545
    /// A constructor that requires additional arguments.
546
    ///
547
    /// This type requires some external state in order to be
548
    /// parsed.
549
0
    pub fn read(data: FontData<'a>, feature_tag: Tag) -> Result<Self, ReadError> {
550
0
        let args = feature_tag;
551
0
        Self::read_with_args(data, args)
552
0
    }
553
}
554
555
/// The fields at the start of the table, which are read directly.
556
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
557
#[repr(C, packed)]
558
#[doc(hidden)]
559
pub struct FeatureFixedHeader {
560
    pub feature_params_offset: BigEndian<Nullable<Offset16>>,
561
    pub lookup_index_count: BigEndian<u16>,
562
}
563
564
#[allow(clippy::absurd_extreme_comparisons)]
565
const _: () = assert!(std::mem::size_of::<FeatureFixedHeader>() <= Feature::MIN_SIZE);
566
567
/// [Feature Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#feature-table)
568
#[derive(Clone)]
569
pub struct Feature<'a> {
570
    data: TableDataRef<'a, FeatureFixedHeader>,
571
    feature_tag: Tag,
572
}
573
574
#[allow(clippy::needless_lifetimes)]
575
impl<'a> Feature<'a> {
576
    pub const MIN_SIZE: usize = (Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
577
    basic_table_impls!(impl_the_methods);
578
579
    /// Offset from start of Feature table to FeatureParams table, if defined for the feature and present, else NULL
580
0
    pub fn feature_params_offset(&self) -> Nullable<Offset16> {
581
0
        self.data.header().feature_params_offset.get()
582
0
    }
583
584
    /// Attempt to resolve [`feature_params_offset`][Self::feature_params_offset].
585
0
    pub fn feature_params(&self) -> Option<Result<FeatureParams<'a>, ReadError>> {
586
0
        let data = self.offset_data();
587
0
        let args = self.feature_tag();
588
0
        self.feature_params_offset().resolve_with_args(data, args)
589
0
    }
590
591
    /// Number of LookupList indices for this feature
592
39.1k
    pub fn lookup_index_count(&self) -> u16 {
593
39.1k
        self.data.header().lookup_index_count.get()
594
39.1k
    }
595
596
    /// Array of indices into the LookupList — zero-based (first
597
    /// lookup is LookupListIndex = 0)
598
39.1k
    pub fn lookup_list_indices(&self) -> &'a [BigEndian<u16>] {
599
39.1k
        let range = self.lookup_list_indices_byte_range();
600
39.1k
        self.offset_data()
601
39.1k
            .read_array(range)
602
39.1k
            .ok()
603
39.1k
            .unwrap_or_default()
604
39.1k
    }
605
606
0
    pub(crate) fn feature_tag(&self) -> Tag {
607
0
        self.feature_tag
608
0
    }
609
610
39.1k
    pub fn feature_params_offset_byte_range(&self) -> Range<usize> {
611
39.1k
        let start = 0usize;
612
39.1k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
613
39.1k
        start..end
614
39.1k
    }
615
616
39.1k
    pub fn lookup_index_count_byte_range(&self) -> Range<usize> {
617
39.1k
        let start = self.feature_params_offset_byte_range().end;
618
39.1k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
619
39.1k
        start..end
620
39.1k
    }
621
622
39.1k
    pub fn lookup_list_indices_byte_range(&self) -> Range<usize> {
623
39.1k
        let lookup_index_count = self.lookup_index_count();
624
39.1k
        let start = self.lookup_index_count_byte_range().end;
625
39.1k
        let end = start.saturating_add(
626
39.1k
            (transforms::to_usize(lookup_index_count)).saturating_mul(u16::RAW_BYTE_LEN),
627
        );
628
39.1k
        start..end
629
39.1k
    }
630
}
631
632
const _: () = assert!(FontData::default_data_long_enough(Feature::MIN_SIZE));
633
634
impl Default for Feature<'_> {
635
0
    fn default() -> Self {
636
        Self {
637
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
638
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
639
0
            feature_tag: Default::default(),
640
        }
641
0
    }
642
}
643
644
impl<'a, T> MinByteRange<'a> for LookupList<'a, T> {
645
0
    fn min_byte_range(&self) -> Range<usize> {
646
0
        0..self.lookup_offsets_byte_range().end
647
0
    }
648
0
    fn min_table_bytes(&self) -> &'a [u8] {
649
0
        let range = self.min_byte_range();
650
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
651
0
    }
652
}
653
654
impl<T> ReadArgs for LookupList<'_, T> {
655
    type Args = ();
656
}
657
658
impl<'a, T> FontRead<'a> for LookupList<'a, T> {
659
355k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
660
        #[allow(clippy::absurd_extreme_comparisons)]
661
355k
        if data.len() < Self::MIN_SIZE {
662
23
            return Err(ReadError::OutOfBounds);
663
355k
        }
664
355k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
665
0
            return Err(ReadError::OutOfBounds);
666
        };
667
355k
        Ok(Self {
668
355k
            data,
669
355k
            offset_type: std::marker::PhantomData,
670
355k
        })
671
355k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gpos::PositionLookup> as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
659
111k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
660
        #[allow(clippy::absurd_extreme_comparisons)]
661
111k
        if data.len() < Self::MIN_SIZE {
662
15
            return Err(ReadError::OutOfBounds);
663
111k
        }
664
111k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
665
0
            return Err(ReadError::OutOfBounds);
666
        };
667
111k
        Ok(Self {
668
111k
            data,
669
111k
            offset_type: std::marker::PhantomData,
670
111k
        })
671
111k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gsub::SubstitutionLookup> as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
659
244k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
660
        #[allow(clippy::absurd_extreme_comparisons)]
661
244k
        if data.len() < Self::MIN_SIZE {
662
8
            return Err(ReadError::OutOfBounds);
663
244k
        }
664
244k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
665
0
            return Err(ReadError::OutOfBounds);
666
        };
667
244k
        Ok(Self {
668
244k
            data,
669
244k
            offset_type: std::marker::PhantomData,
670
244k
        })
671
244k
    }
672
}
673
674
impl<'a, T> LookupList<'a, T> {
675
    #[allow(dead_code)]
676
    /// Replace the specific generic type on this implementation with `()`
677
0
    pub(crate) fn of_unit_type(&self) -> LookupList<'a, ()> {
678
0
        LookupList {
679
0
            data: self.data,
680
0
            offset_type: std::marker::PhantomData,
681
0
        }
682
0
    }
683
}
684
685
/// The fields at the start of the table, which are read directly.
686
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
687
#[repr(C, packed)]
688
#[doc(hidden)]
689
pub struct LookupListFixedHeader {
690
    pub lookup_count: BigEndian<u16>,
691
}
692
693
#[allow(clippy::absurd_extreme_comparisons)]
694
const _: () = assert!(std::mem::size_of::<LookupListFixedHeader>() <= LookupList::<()>::MIN_SIZE);
695
696
/// [Lookup List Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#lookup-list-table)
697
#[derive(Clone)]
698
pub struct LookupList<'a, T = ()> {
699
    data: TableDataRef<'a, LookupListFixedHeader>,
700
    offset_type: std::marker::PhantomData<*const T>,
701
}
702
703
#[allow(clippy::needless_lifetimes)]
704
impl<'a, T> LookupList<'a, T> {
705
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
706
    basic_table_impls!(impl_the_methods);
707
708
    /// Number of lookups in this table
709
355k
    pub fn lookup_count(&self) -> u16 {
710
355k
        self.data.header().lookup_count.get()
711
355k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gpos::PositionLookup>>::lookup_count
Line
Count
Source
709
111k
    pub fn lookup_count(&self) -> u16 {
710
111k
        self.data.header().lookup_count.get()
711
111k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gsub::SubstitutionLookup>>::lookup_count
Line
Count
Source
709
244k
    pub fn lookup_count(&self) -> u16 {
710
244k
        self.data.header().lookup_count.get()
711
244k
    }
712
713
    /// Array of offsets to Lookup tables, from beginning of LookupList
714
    /// — zero based (first lookup is Lookup index = 0)
715
295k
    pub fn lookup_offsets(&self) -> &'a [BigEndian<Offset16>] {
716
295k
        let range = self.lookup_offsets_byte_range();
717
295k
        self.offset_data()
718
295k
            .read_array(range)
719
295k
            .ok()
720
295k
            .unwrap_or_default()
721
295k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gpos::PositionLookup>>::lookup_offsets
Line
Count
Source
715
91.7k
    pub fn lookup_offsets(&self) -> &'a [BigEndian<Offset16>] {
716
91.7k
        let range = self.lookup_offsets_byte_range();
717
91.7k
        self.offset_data()
718
91.7k
            .read_array(range)
719
91.7k
            .ok()
720
91.7k
            .unwrap_or_default()
721
91.7k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gsub::SubstitutionLookup>>::lookup_offsets
Line
Count
Source
715
203k
    pub fn lookup_offsets(&self) -> &'a [BigEndian<Offset16>] {
716
203k
        let range = self.lookup_offsets_byte_range();
717
203k
        self.offset_data()
718
203k
            .read_array(range)
719
203k
            .ok()
720
203k
            .unwrap_or_default()
721
203k
    }
722
723
    /// A dynamically resolving wrapper for [`lookup_offsets`][Self::lookup_offsets].
724
0
    pub fn lookups(&self) -> ArrayOfOffsets<'a, T, Offset16>
725
0
    where
726
0
        T: FontRead<'a, Args = ()>,
727
    {
728
0
        let data = self.offset_data();
729
0
        let offsets = self.lookup_offsets();
730
0
        ArrayOfOffsets::new(offsets, data, ())
731
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::LookupList<read_fonts::tables::gpos::PositionLookup>>::lookups
Unexecuted instantiation: <read_fonts::tables::layout::LookupList<read_fonts::tables::gsub::SubstitutionLookup>>::lookups
732
733
295k
    pub fn lookup_count_byte_range(&self) -> Range<usize> {
734
295k
        let start = 0usize;
735
295k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
736
295k
        start..end
737
295k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gpos::PositionLookup>>::lookup_count_byte_range
Line
Count
Source
733
91.7k
    pub fn lookup_count_byte_range(&self) -> Range<usize> {
734
91.7k
        let start = 0usize;
735
91.7k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
736
91.7k
        start..end
737
91.7k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gsub::SubstitutionLookup>>::lookup_count_byte_range
Line
Count
Source
733
203k
    pub fn lookup_count_byte_range(&self) -> Range<usize> {
734
203k
        let start = 0usize;
735
203k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
736
203k
        start..end
737
203k
    }
738
739
295k
    pub fn lookup_offsets_byte_range(&self) -> Range<usize> {
740
295k
        let lookup_count = self.lookup_count();
741
295k
        let start = self.lookup_count_byte_range().end;
742
295k
        let end = start.saturating_add(
743
295k
            (transforms::to_usize(lookup_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
744
        );
745
295k
        start..end
746
295k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gpos::PositionLookup>>::lookup_offsets_byte_range
Line
Count
Source
739
91.7k
    pub fn lookup_offsets_byte_range(&self) -> Range<usize> {
740
91.7k
        let lookup_count = self.lookup_count();
741
91.7k
        let start = self.lookup_count_byte_range().end;
742
91.7k
        let end = start.saturating_add(
743
91.7k
            (transforms::to_usize(lookup_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
744
        );
745
91.7k
        start..end
746
91.7k
    }
<read_fonts::tables::layout::LookupList<read_fonts::tables::gsub::SubstitutionLookup>>::lookup_offsets_byte_range
Line
Count
Source
739
203k
    pub fn lookup_offsets_byte_range(&self) -> Range<usize> {
740
203k
        let lookup_count = self.lookup_count();
741
203k
        let start = self.lookup_count_byte_range().end;
742
203k
        let end = start.saturating_add(
743
203k
            (transforms::to_usize(lookup_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
744
        );
745
203k
        start..end
746
203k
    }
747
}
748
749
const _: () = assert!(FontData::default_data_long_enough(
750
    LookupList::<()>::MIN_SIZE
751
));
752
753
impl<T> Default for LookupList<'_, T> {
754
0
    fn default() -> Self {
755
        Self {
756
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
757
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
758
0
            offset_type: std::marker::PhantomData,
759
        }
760
0
    }
761
}
762
763
impl Discriminant for Lookup<'_, ()> {
764
0
    fn read_discriminant(data: FontData<'_>) -> Result<u16, ReadError> {
765
0
        data.read_at(0)
766
0
    }
767
}
768
769
impl<'a, T> MinByteRange<'a> for Lookup<'a, T> {
770
0
    fn min_byte_range(&self) -> Range<usize> {
771
0
        0..self.subtable_offsets_byte_range().end
772
0
    }
773
0
    fn min_table_bytes(&self) -> &'a [u8] {
774
0
        let range = self.min_byte_range();
775
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
776
0
    }
777
}
778
779
impl<T> ReadArgs for Lookup<'_, T> {
780
    type Args = ();
781
}
782
783
impl<'a, T> FontRead<'a> for Lookup<'a, T> {
784
179k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
785
        #[allow(clippy::absurd_extreme_comparisons)]
786
179k
        if data.len() < Self::MIN_SIZE {
787
93
            return Err(ReadError::OutOfBounds);
788
179k
        }
789
179k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
790
0
            return Err(ReadError::OutOfBounds);
791
        };
792
179k
        Ok(Self {
793
179k
            data,
794
179k
            offset_type: std::marker::PhantomData,
795
179k
        })
796
179k
    }
<read_fonts::tables::layout::Lookup as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
784
179k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
785
        #[allow(clippy::absurd_extreme_comparisons)]
786
179k
        if data.len() < Self::MIN_SIZE {
787
93
            return Err(ReadError::OutOfBounds);
788
179k
        }
789
179k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
790
0
            return Err(ReadError::OutOfBounds);
791
        };
792
179k
        Ok(Self {
793
179k
            data,
794
179k
            offset_type: std::marker::PhantomData,
795
179k
        })
796
179k
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable> as read_fonts::read::FontRead>::read_with_args
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst> as read_fonts::read::FontRead>::read_with_args
797
}
798
799
impl<'a, T> Lookup<'a, T> {
800
    #[allow(dead_code)]
801
    /// Replace the specific generic type on this implementation with `()`
802
0
    pub(crate) fn of_unit_type(&self) -> Lookup<'a, ()> {
803
0
        Lookup {
804
0
            data: self.data,
805
0
            offset_type: std::marker::PhantomData,
806
0
        }
807
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable>>::of_unit_type
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst>>::of_unit_type
808
}
809
810
/// The fields at the start of the table, which are read directly.
811
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
812
#[repr(C, packed)]
813
#[doc(hidden)]
814
pub struct LookupFixedHeader {
815
    pub lookup_type: BigEndian<u16>,
816
    pub lookup_flag: BigEndian<LookupFlag>,
817
    pub sub_table_count: BigEndian<u16>,
818
}
819
820
#[allow(clippy::absurd_extreme_comparisons)]
821
const _: () = assert!(std::mem::size_of::<LookupFixedHeader>() <= Lookup::<()>::MIN_SIZE);
822
823
/// [Lookup Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#lookup-table)
824
#[derive(Clone)]
825
pub struct Lookup<'a, T = ()> {
826
    data: TableDataRef<'a, LookupFixedHeader>,
827
    offset_type: std::marker::PhantomData<*const T>,
828
}
829
830
#[allow(clippy::needless_lifetimes)]
831
impl<'a, T> Lookup<'a, T> {
832
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + LookupFlag::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
833
    basic_table_impls!(impl_the_methods);
834
835
    /// Different enumerations for GSUB and GPOS
836
213k
    pub fn lookup_type(&self) -> u16 {
837
213k
        self.data.header().lookup_type.get()
838
213k
    }
839
840
    /// Lookup qualifiers
841
151k
    pub fn lookup_flag(&self) -> LookupFlag {
842
151k
        self.data.header().lookup_flag.get()
843
151k
    }
844
845
    /// Number of subtables for this lookup
846
331k
    pub fn sub_table_count(&self) -> u16 {
847
331k
        self.data.header().sub_table_count.get()
848
331k
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable>>::sub_table_count
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst>>::sub_table_count
<read_fonts::tables::layout::Lookup>::sub_table_count
Line
Count
Source
846
331k
    pub fn sub_table_count(&self) -> u16 {
847
331k
        self.data.header().sub_table_count.get()
848
331k
    }
849
850
    /// Array of offsets to lookup subtables, from beginning of Lookup
851
    /// table
852
126k
    pub fn subtable_offsets(&self) -> &'a [BigEndian<Offset16>] {
853
126k
        let range = self.subtable_offsets_byte_range();
854
126k
        self.offset_data()
855
126k
            .read_array(range)
856
126k
            .ok()
857
126k
            .unwrap_or_default()
858
126k
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable>>::subtable_offsets
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst>>::subtable_offsets
<read_fonts::tables::layout::Lookup>::subtable_offsets
Line
Count
Source
852
126k
    pub fn subtable_offsets(&self) -> &'a [BigEndian<Offset16>] {
853
126k
        let range = self.subtable_offsets_byte_range();
854
126k
        self.offset_data()
855
126k
            .read_array(range)
856
126k
            .ok()
857
126k
            .unwrap_or_default()
858
126k
    }
859
860
    /// A dynamically resolving wrapper for [`subtable_offsets`][Self::subtable_offsets].
861
0
    pub fn subtables(&self) -> ArrayOfOffsets<'a, T, Offset16>
862
0
    where
863
0
        T: FontRead<'a, Args = ()>,
864
    {
865
0
        let data = self.offset_data();
866
0
        let offsets = self.subtable_offsets();
867
0
        ArrayOfOffsets::new(offsets, data, ())
868
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable>>::subtables
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst>>::subtables
869
870
    /// Index (base 0) into GDEF mark glyph sets structure. This field
871
    /// is only present if the USE_MARK_FILTERING_SET lookup flag is
872
    /// set.
873
25.6k
    pub fn mark_filtering_set(&self) -> Option<u16> {
874
25.6k
        let range = self.mark_filtering_set_byte_range();
875
25.6k
        (!range.is_empty())
876
25.6k
            .then(|| self.offset_data().read_at(range.start).ok())
877
25.6k
            .flatten()
878
25.6k
    }
879
880
151k
    pub fn lookup_type_byte_range(&self) -> Range<usize> {
881
151k
        let start = 0usize;
882
151k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
883
151k
        start..end
884
151k
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable>>::lookup_type_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst>>::lookup_type_byte_range
<read_fonts::tables::layout::Lookup>::lookup_type_byte_range
Line
Count
Source
880
151k
    pub fn lookup_type_byte_range(&self) -> Range<usize> {
881
151k
        let start = 0usize;
882
151k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
883
151k
        start..end
884
151k
    }
885
886
151k
    pub fn lookup_flag_byte_range(&self) -> Range<usize> {
887
151k
        let start = self.lookup_type_byte_range().end;
888
151k
        let end = start.saturating_add(LookupFlag::RAW_BYTE_LEN);
889
151k
        start..end
890
151k
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable>>::lookup_flag_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst>>::lookup_flag_byte_range
<read_fonts::tables::layout::Lookup>::lookup_flag_byte_range
Line
Count
Source
886
151k
    pub fn lookup_flag_byte_range(&self) -> Range<usize> {
887
151k
        let start = self.lookup_type_byte_range().end;
888
151k
        let end = start.saturating_add(LookupFlag::RAW_BYTE_LEN);
889
151k
        start..end
890
151k
    }
891
892
151k
    pub fn sub_table_count_byte_range(&self) -> Range<usize> {
893
151k
        let start = self.lookup_flag_byte_range().end;
894
151k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
895
151k
        start..end
896
151k
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable>>::sub_table_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst>>::sub_table_count_byte_range
<read_fonts::tables::layout::Lookup>::sub_table_count_byte_range
Line
Count
Source
892
151k
    pub fn sub_table_count_byte_range(&self) -> Range<usize> {
893
151k
        let start = self.lookup_flag_byte_range().end;
894
151k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
895
151k
        start..end
896
151k
    }
897
898
151k
    pub fn subtable_offsets_byte_range(&self) -> Range<usize> {
899
151k
        let sub_table_count = self.sub_table_count();
900
151k
        let start = self.sub_table_count_byte_range().end;
901
151k
        let end = start.saturating_add(
902
151k
            (transforms::to_usize(sub_table_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
903
        );
904
151k
        start..end
905
151k
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::SequenceContext>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::layout::ChainedSequenceContext>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::CursivePos>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkLigPos>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkBasePos>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::MarkMarkPos>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::ExtensionSubtable>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::PairPos>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::LigatureSubst>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::MultipleSubst>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::AlternateSubst>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ExtensionSubtable>>::subtable_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::ReverseChainSingleSubst>>::subtable_offsets_byte_range
<read_fonts::tables::layout::Lookup>::subtable_offsets_byte_range
Line
Count
Source
898
151k
    pub fn subtable_offsets_byte_range(&self) -> Range<usize> {
899
151k
        let sub_table_count = self.sub_table_count();
900
151k
        let start = self.sub_table_count_byte_range().end;
901
151k
        let end = start.saturating_add(
902
151k
            (transforms::to_usize(sub_table_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
903
        );
904
151k
        start..end
905
151k
    }
906
907
25.6k
    pub fn mark_filtering_set_byte_range(&self) -> Range<usize> {
908
25.6k
        let start = self.subtable_offsets_byte_range().end;
909
25.6k
        let end = if self
910
25.6k
            .lookup_flag()
911
25.6k
            .contains(LookupFlag::USE_MARK_FILTERING_SET)
912
        {
913
25.6k
            start.saturating_add(u16::RAW_BYTE_LEN)
914
        } else {
915
0
            start
916
        };
917
25.6k
        start..end
918
25.6k
    }
919
}
920
921
const _: () = assert!(FontData::default_data_long_enough(Lookup::<()>::MIN_SIZE));
922
923
impl<T> Default for Lookup<'_, T> {
924
0
    fn default() -> Self {
925
        Self {
926
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
927
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos> as core::default::Default>::default::{closure#0}
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst> as core::default::Default>::default::{closure#0}
928
0
            offset_type: std::marker::PhantomData,
929
        }
930
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gpos::SinglePos> as core::default::Default>::default
Unexecuted instantiation: <read_fonts::tables::layout::Lookup<read_fonts::tables::gsub::SingleSubst> as core::default::Default>::default
931
}
932
933
impl Format<u16> for CoverageFormat1<'_> {
934
    const FORMAT: u16 = 1;
935
}
936
937
impl<'a> MinByteRange<'a> for CoverageFormat1<'a> {
938
0
    fn min_byte_range(&self) -> Range<usize> {
939
0
        0..self.glyph_array_byte_range().end
940
0
    }
941
0
    fn min_table_bytes(&self) -> &'a [u8] {
942
0
        let range = self.min_byte_range();
943
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
944
0
    }
945
}
946
947
impl ReadArgs for CoverageFormat1<'_> {
948
    type Args = ();
949
}
950
951
impl<'a> FontRead<'a> for CoverageFormat1<'a> {
952
135k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
953
        #[allow(clippy::absurd_extreme_comparisons)]
954
135k
        if data.len() < Self::MIN_SIZE {
955
2.48k
            return Err(ReadError::OutOfBounds);
956
132k
        }
957
132k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
958
0
            return Err(ReadError::OutOfBounds);
959
        };
960
132k
        Ok(Self { data })
961
135k
    }
962
}
963
964
/// The fields at the start of the table, which are read directly.
965
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
966
#[repr(C, packed)]
967
#[doc(hidden)]
968
pub struct CoverageFormat1FixedHeader {
969
    pub coverage_format: BigEndian<u16>,
970
    pub glyph_count: BigEndian<u16>,
971
}
972
973
#[allow(clippy::absurd_extreme_comparisons)]
974
const _: () =
975
    assert!(std::mem::size_of::<CoverageFormat1FixedHeader>() <= CoverageFormat1::MIN_SIZE);
976
977
/// [Coverage Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-format-1)
978
#[derive(Clone)]
979
pub struct CoverageFormat1<'a> {
980
    data: TableDataRef<'a, CoverageFormat1FixedHeader>,
981
}
982
983
#[allow(clippy::needless_lifetimes)]
984
impl<'a> CoverageFormat1<'a> {
985
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
986
    basic_table_impls!(impl_the_methods);
987
988
    /// Format identifier — format = 1
989
0
    pub fn coverage_format(&self) -> u16 {
990
0
        self.data.header().coverage_format.get()
991
0
    }
992
993
    /// Number of glyphs in the glyph array
994
134k
    pub fn glyph_count(&self) -> u16 {
995
134k
        self.data.header().glyph_count.get()
996
134k
    }
997
998
    /// Array of glyph IDs — in numerical order
999
134k
    pub fn glyph_array(&self) -> &'a [BigEndian<GlyphId16>] {
1000
134k
        let range = self.glyph_array_byte_range();
1001
134k
        self.offset_data()
1002
134k
            .read_array(range)
1003
134k
            .ok()
1004
134k
            .unwrap_or_default()
1005
134k
    }
1006
1007
134k
    pub fn coverage_format_byte_range(&self) -> Range<usize> {
1008
134k
        let start = 0usize;
1009
134k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1010
134k
        start..end
1011
134k
    }
1012
1013
134k
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
1014
134k
        let start = self.coverage_format_byte_range().end;
1015
134k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1016
134k
        start..end
1017
134k
    }
1018
1019
134k
    pub fn glyph_array_byte_range(&self) -> Range<usize> {
1020
134k
        let glyph_count = self.glyph_count();
1021
134k
        let start = self.glyph_count_byte_range().end;
1022
134k
        let end = start.saturating_add(
1023
134k
            (transforms::to_usize(glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN),
1024
        );
1025
134k
        start..end
1026
134k
    }
1027
}
1028
1029
const _: () = assert!(FontData::default_data_long_enough(
1030
    CoverageFormat1::MIN_SIZE
1031
));
1032
1033
impl Default for CoverageFormat1<'_> {
1034
0
    fn default() -> Self {
1035
        Self {
1036
0
            data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1037
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1038
        }
1039
0
    }
1040
}
1041
1042
impl Format<u16> for CoverageFormat2<'_> {
1043
    const FORMAT: u16 = 2;
1044
}
1045
1046
impl<'a> MinByteRange<'a> for CoverageFormat2<'a> {
1047
0
    fn min_byte_range(&self) -> Range<usize> {
1048
0
        0..self.range_records_byte_range().end
1049
0
    }
1050
0
    fn min_table_bytes(&self) -> &'a [u8] {
1051
0
        let range = self.min_byte_range();
1052
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1053
0
    }
1054
}
1055
1056
impl ReadArgs for CoverageFormat2<'_> {
1057
    type Args = ();
1058
}
1059
1060
impl<'a> FontRead<'a> for CoverageFormat2<'a> {
1061
316k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1062
        #[allow(clippy::absurd_extreme_comparisons)]
1063
316k
        if data.len() < Self::MIN_SIZE {
1064
2.34k
            return Err(ReadError::OutOfBounds);
1065
314k
        }
1066
314k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1067
0
            return Err(ReadError::OutOfBounds);
1068
        };
1069
314k
        Ok(Self { data })
1070
316k
    }
1071
}
1072
1073
/// The fields at the start of the table, which are read directly.
1074
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1075
#[repr(C, packed)]
1076
#[doc(hidden)]
1077
pub struct CoverageFormat2FixedHeader {
1078
    pub coverage_format: BigEndian<u16>,
1079
    pub range_count: BigEndian<u16>,
1080
}
1081
1082
#[allow(clippy::absurd_extreme_comparisons)]
1083
const _: () =
1084
    assert!(std::mem::size_of::<CoverageFormat2FixedHeader>() <= CoverageFormat2::MIN_SIZE);
1085
1086
/// [Coverage Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-format-2)
1087
#[derive(Clone)]
1088
pub struct CoverageFormat2<'a> {
1089
    data: TableDataRef<'a, CoverageFormat2FixedHeader>,
1090
}
1091
1092
#[allow(clippy::needless_lifetimes)]
1093
impl<'a> CoverageFormat2<'a> {
1094
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1095
    basic_table_impls!(impl_the_methods);
1096
1097
    /// Format identifier — format = 2
1098
0
    pub fn coverage_format(&self) -> u16 {
1099
0
        self.data.header().coverage_format.get()
1100
0
    }
1101
1102
    /// Number of RangeRecords
1103
315k
    pub fn range_count(&self) -> u16 {
1104
315k
        self.data.header().range_count.get()
1105
315k
    }
1106
1107
    /// Array of glyph ranges — ordered by startGlyphID.
1108
315k
    pub fn range_records(&self) -> &'a [RangeRecord] {
1109
315k
        let range = self.range_records_byte_range();
1110
315k
        self.offset_data()
1111
315k
            .read_array(range)
1112
315k
            .ok()
1113
315k
            .unwrap_or_default()
1114
315k
    }
1115
1116
315k
    pub fn coverage_format_byte_range(&self) -> Range<usize> {
1117
315k
        let start = 0usize;
1118
315k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1119
315k
        start..end
1120
315k
    }
1121
1122
315k
    pub fn range_count_byte_range(&self) -> Range<usize> {
1123
315k
        let start = self.coverage_format_byte_range().end;
1124
315k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1125
315k
        start..end
1126
315k
    }
1127
1128
315k
    pub fn range_records_byte_range(&self) -> Range<usize> {
1129
315k
        let range_count = self.range_count();
1130
315k
        let start = self.range_count_byte_range().end;
1131
315k
        let end = start.saturating_add(
1132
315k
            (transforms::to_usize(range_count)).saturating_mul(RangeRecord::RAW_BYTE_LEN),
1133
        );
1134
315k
        start..end
1135
315k
    }
1136
}
1137
1138
/// Used in [CoverageFormat2]
1139
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1140
#[repr(C)]
1141
#[repr(packed)]
1142
pub struct RangeRecord {
1143
    /// First glyph ID in the range
1144
    pub start_glyph_id: BigEndian<GlyphId16>,
1145
    /// Last glyph ID in the range
1146
    pub end_glyph_id: BigEndian<GlyphId16>,
1147
    /// Coverage Index of first glyph ID in range
1148
    pub start_coverage_index: BigEndian<u16>,
1149
}
1150
1151
impl RangeRecord {
1152
    /// First glyph ID in the range
1153
444M
    pub fn start_glyph_id(&self) -> GlyphId16 {
1154
444M
        self.start_glyph_id.get()
1155
444M
    }
1156
1157
    /// Last glyph ID in the range
1158
379M
    pub fn end_glyph_id(&self) -> GlyphId16 {
1159
379M
        self.end_glyph_id.get()
1160
379M
    }
1161
1162
    /// Coverage Index of first glyph ID in range
1163
64.8M
    pub fn start_coverage_index(&self) -> u16 {
1164
64.8M
        self.start_coverage_index.get()
1165
64.8M
    }
1166
}
1167
1168
impl FixedSize for RangeRecord {
1169
    const RAW_BYTE_LEN: usize =
1170
        GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
1171
}
1172
1173
/// [Coverage Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-table)
1174
#[derive(Clone)]
1175
pub enum CoverageTable<'a> {
1176
    Format1(CoverageFormat1<'a>),
1177
    Format2(CoverageFormat2<'a>),
1178
    Format3(CoverageFormat3<'a>),
1179
    Format4(CoverageFormat4<'a>),
1180
}
1181
1182
impl Default for CoverageTable<'_> {
1183
0
    fn default() -> Self {
1184
0
        Self::Format1(Default::default())
1185
0
    }
1186
}
1187
1188
impl<'a> CoverageTable<'a> {
1189
    ///Return the `FontData` used to resolve offsets for this table.
1190
0
    pub fn offset_data(&self) -> FontData<'a> {
1191
0
        match self {
1192
0
            Self::Format1(item) => item.offset_data(),
1193
0
            Self::Format2(item) => item.offset_data(),
1194
0
            Self::Format3(item) => item.offset_data(),
1195
0
            Self::Format4(item) => item.offset_data(),
1196
        }
1197
0
    }
1198
1199
    /// Format identifier — format = 1
1200
0
    pub fn coverage_format(&self) -> u16 {
1201
0
        match self {
1202
0
            Self::Format1(item) => item.coverage_format(),
1203
0
            Self::Format2(item) => item.coverage_format(),
1204
0
            Self::Format3(item) => item.coverage_format(),
1205
0
            Self::Format4(item) => item.coverage_format(),
1206
        }
1207
0
    }
1208
}
1209
1210
impl ReadArgs for CoverageTable<'_> {
1211
    type Args = ();
1212
}
1213
1214
impl<'a> FontRead<'a> for CoverageTable<'a> {
1215
    #[inline]
1216
1.03M
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1217
1.03M
        let format: u16 = data.read_at(0usize)?;
1218
1.03M
        match format {
1219
135k
            CoverageFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
1220
316k
            CoverageFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
1221
34.5k
            CoverageFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
1222
36.5k
            CoverageFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
1223
511k
            other => Err(ReadError::InvalidFormat(other.into())),
1224
        }
1225
1.03M
    }
<read_fonts::tables::layout::CoverageTable as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
1216
573k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1217
573k
        let format: u16 = data.read_at(0usize)?;
1218
571k
        match format {
1219
75.4k
            CoverageFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
1220
190k
            CoverageFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
1221
11.9k
            CoverageFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
1222
5.58k
            CoverageFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
1223
287k
            other => Err(ReadError::InvalidFormat(other.into())),
1224
        }
1225
573k
    }
<read_fonts::tables::layout::CoverageTable as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
1216
465k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1217
465k
        let format: u16 = data.read_at(0usize)?;
1218
462k
        match format {
1219
59.8k
            CoverageFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
1220
125k
            CoverageFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
1221
22.6k
            CoverageFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
1222
31.0k
            CoverageFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
1223
223k
            other => Err(ReadError::InvalidFormat(other.into())),
1224
        }
1225
465k
    }
1226
}
1227
1228
impl<'a> MinByteRange<'a> for CoverageTable<'a> {
1229
0
    fn min_byte_range(&self) -> Range<usize> {
1230
0
        match self {
1231
0
            Self::Format1(item) => item.min_byte_range(),
1232
0
            Self::Format2(item) => item.min_byte_range(),
1233
0
            Self::Format3(item) => item.min_byte_range(),
1234
0
            Self::Format4(item) => item.min_byte_range(),
1235
        }
1236
0
    }
1237
0
    fn min_table_bytes(&self) -> &'a [u8] {
1238
0
        match self {
1239
0
            Self::Format1(item) => item.min_table_bytes(),
1240
0
            Self::Format2(item) => item.min_table_bytes(),
1241
0
            Self::Format3(item) => item.min_table_bytes(),
1242
0
            Self::Format4(item) => item.min_table_bytes(),
1243
        }
1244
0
    }
1245
}
1246
1247
impl Format<u16> for ClassDefFormat1<'_> {
1248
    const FORMAT: u16 = 1;
1249
}
1250
1251
impl<'a> MinByteRange<'a> for ClassDefFormat1<'a> {
1252
0
    fn min_byte_range(&self) -> Range<usize> {
1253
0
        0..self.class_value_array_byte_range().end
1254
0
    }
1255
0
    fn min_table_bytes(&self) -> &'a [u8] {
1256
0
        let range = self.min_byte_range();
1257
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1258
0
    }
1259
}
1260
1261
impl ReadArgs for ClassDefFormat1<'_> {
1262
    type Args = ();
1263
}
1264
1265
impl<'a> FontRead<'a> for ClassDefFormat1<'a> {
1266
31.8k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1267
        #[allow(clippy::absurd_extreme_comparisons)]
1268
31.8k
        if data.len() < Self::MIN_SIZE {
1269
1.90k
            return Err(ReadError::OutOfBounds);
1270
29.9k
        }
1271
29.9k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1272
0
            return Err(ReadError::OutOfBounds);
1273
        };
1274
29.9k
        Ok(Self { data })
1275
31.8k
    }
1276
}
1277
1278
/// The fields at the start of the table, which are read directly.
1279
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1280
#[repr(C, packed)]
1281
#[doc(hidden)]
1282
pub struct ClassDefFormat1FixedHeader {
1283
    pub class_format: BigEndian<u16>,
1284
    pub start_glyph_id: BigEndian<GlyphId16>,
1285
    pub glyph_count: BigEndian<u16>,
1286
}
1287
1288
#[allow(clippy::absurd_extreme_comparisons)]
1289
const _: () =
1290
    assert!(std::mem::size_of::<ClassDefFormat1FixedHeader>() <= ClassDefFormat1::MIN_SIZE);
1291
1292
/// [Class Definition Table Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table-format-1)
1293
#[derive(Clone)]
1294
pub struct ClassDefFormat1<'a> {
1295
    data: TableDataRef<'a, ClassDefFormat1FixedHeader>,
1296
}
1297
1298
#[allow(clippy::needless_lifetimes)]
1299
impl<'a> ClassDefFormat1<'a> {
1300
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1301
    basic_table_impls!(impl_the_methods);
1302
1303
    /// Format identifier — format = 1
1304
0
    pub fn class_format(&self) -> u16 {
1305
0
        self.data.header().class_format.get()
1306
0
    }
1307
1308
    /// First glyph ID of the classValueArray
1309
29.9k
    pub fn start_glyph_id(&self) -> GlyphId16 {
1310
29.9k
        self.data.header().start_glyph_id.get()
1311
29.9k
    }
1312
1313
    /// Size of the classValueArray
1314
29.9k
    pub fn glyph_count(&self) -> u16 {
1315
29.9k
        self.data.header().glyph_count.get()
1316
29.9k
    }
1317
1318
    /// Array of Class Values — one per glyph ID
1319
29.9k
    pub fn class_value_array(&self) -> &'a [BigEndian<u16>] {
1320
29.9k
        let range = self.class_value_array_byte_range();
1321
29.9k
        self.offset_data()
1322
29.9k
            .read_array(range)
1323
29.9k
            .ok()
1324
29.9k
            .unwrap_or_default()
1325
29.9k
    }
1326
1327
29.9k
    pub fn class_format_byte_range(&self) -> Range<usize> {
1328
29.9k
        let start = 0usize;
1329
29.9k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1330
29.9k
        start..end
1331
29.9k
    }
1332
1333
29.9k
    pub fn start_glyph_id_byte_range(&self) -> Range<usize> {
1334
29.9k
        let start = self.class_format_byte_range().end;
1335
29.9k
        let end = start.saturating_add(GlyphId16::RAW_BYTE_LEN);
1336
29.9k
        start..end
1337
29.9k
    }
1338
1339
29.9k
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
1340
29.9k
        let start = self.start_glyph_id_byte_range().end;
1341
29.9k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1342
29.9k
        start..end
1343
29.9k
    }
1344
1345
29.9k
    pub fn class_value_array_byte_range(&self) -> Range<usize> {
1346
29.9k
        let glyph_count = self.glyph_count();
1347
29.9k
        let start = self.glyph_count_byte_range().end;
1348
29.9k
        let end = start
1349
29.9k
            .saturating_add((transforms::to_usize(glyph_count)).saturating_mul(u16::RAW_BYTE_LEN));
1350
29.9k
        start..end
1351
29.9k
    }
1352
}
1353
1354
const _: () = assert!(FontData::default_data_long_enough(
1355
    ClassDefFormat1::MIN_SIZE
1356
));
1357
1358
impl Default for ClassDefFormat1<'_> {
1359
0
    fn default() -> Self {
1360
        Self {
1361
0
            data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1362
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1363
        }
1364
0
    }
1365
}
1366
1367
impl Format<u16> for ClassDefFormat2<'_> {
1368
    const FORMAT: u16 = 2;
1369
}
1370
1371
impl<'a> MinByteRange<'a> for ClassDefFormat2<'a> {
1372
0
    fn min_byte_range(&self) -> Range<usize> {
1373
0
        0..self.class_range_records_byte_range().end
1374
0
    }
1375
0
    fn min_table_bytes(&self) -> &'a [u8] {
1376
0
        let range = self.min_byte_range();
1377
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1378
0
    }
1379
}
1380
1381
impl ReadArgs for ClassDefFormat2<'_> {
1382
    type Args = ();
1383
}
1384
1385
impl<'a> FontRead<'a> for ClassDefFormat2<'a> {
1386
24.8k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1387
        #[allow(clippy::absurd_extreme_comparisons)]
1388
24.8k
        if data.len() < Self::MIN_SIZE {
1389
2.06k
            return Err(ReadError::OutOfBounds);
1390
22.8k
        }
1391
22.8k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1392
0
            return Err(ReadError::OutOfBounds);
1393
        };
1394
22.8k
        Ok(Self { data })
1395
24.8k
    }
1396
}
1397
1398
/// The fields at the start of the table, which are read directly.
1399
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1400
#[repr(C, packed)]
1401
#[doc(hidden)]
1402
pub struct ClassDefFormat2FixedHeader {
1403
    pub class_format: BigEndian<u16>,
1404
    pub class_range_count: BigEndian<u16>,
1405
}
1406
1407
#[allow(clippy::absurd_extreme_comparisons)]
1408
const _: () =
1409
    assert!(std::mem::size_of::<ClassDefFormat2FixedHeader>() <= ClassDefFormat2::MIN_SIZE);
1410
1411
/// [Class Definition Table Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table-format-2)
1412
#[derive(Clone)]
1413
pub struct ClassDefFormat2<'a> {
1414
    data: TableDataRef<'a, ClassDefFormat2FixedHeader>,
1415
}
1416
1417
#[allow(clippy::needless_lifetimes)]
1418
impl<'a> ClassDefFormat2<'a> {
1419
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1420
    basic_table_impls!(impl_the_methods);
1421
1422
    /// Format identifier — format = 2
1423
0
    pub fn class_format(&self) -> u16 {
1424
0
        self.data.header().class_format.get()
1425
0
    }
1426
1427
    /// Number of ClassRangeRecords
1428
22.8k
    pub fn class_range_count(&self) -> u16 {
1429
22.8k
        self.data.header().class_range_count.get()
1430
22.8k
    }
1431
1432
    /// Array of ClassRangeRecords — ordered by startGlyphID
1433
22.8k
    pub fn class_range_records(&self) -> &'a [ClassRangeRecord] {
1434
22.8k
        let range = self.class_range_records_byte_range();
1435
22.8k
        self.offset_data()
1436
22.8k
            .read_array(range)
1437
22.8k
            .ok()
1438
22.8k
            .unwrap_or_default()
1439
22.8k
    }
1440
1441
22.8k
    pub fn class_format_byte_range(&self) -> Range<usize> {
1442
22.8k
        let start = 0usize;
1443
22.8k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1444
22.8k
        start..end
1445
22.8k
    }
1446
1447
22.8k
    pub fn class_range_count_byte_range(&self) -> Range<usize> {
1448
22.8k
        let start = self.class_format_byte_range().end;
1449
22.8k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1450
22.8k
        start..end
1451
22.8k
    }
1452
1453
22.8k
    pub fn class_range_records_byte_range(&self) -> Range<usize> {
1454
22.8k
        let class_range_count = self.class_range_count();
1455
22.8k
        let start = self.class_range_count_byte_range().end;
1456
22.8k
        let end = start.saturating_add(
1457
22.8k
            (transforms::to_usize(class_range_count))
1458
22.8k
                .saturating_mul(ClassRangeRecord::RAW_BYTE_LEN),
1459
        );
1460
22.8k
        start..end
1461
22.8k
    }
1462
}
1463
1464
/// Used in [ClassDefFormat2]
1465
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1466
#[repr(C)]
1467
#[repr(packed)]
1468
pub struct ClassRangeRecord {
1469
    /// First glyph ID in the range
1470
    pub start_glyph_id: BigEndian<GlyphId16>,
1471
    /// Last glyph ID in the range
1472
    pub end_glyph_id: BigEndian<GlyphId16>,
1473
    /// Applied to all glyphs in the range
1474
    pub class: BigEndian<u16>,
1475
}
1476
1477
impl ClassRangeRecord {
1478
    /// First glyph ID in the range
1479
10.2M
    pub fn start_glyph_id(&self) -> GlyphId16 {
1480
10.2M
        self.start_glyph_id.get()
1481
10.2M
    }
1482
1483
    /// Last glyph ID in the range
1484
10.2M
    pub fn end_glyph_id(&self) -> GlyphId16 {
1485
10.2M
        self.end_glyph_id.get()
1486
10.2M
    }
1487
1488
    /// Applied to all glyphs in the range
1489
1.30M
    pub fn class(&self) -> u16 {
1490
1.30M
        self.class.get()
1491
1.30M
    }
1492
}
1493
1494
impl FixedSize for ClassRangeRecord {
1495
    const RAW_BYTE_LEN: usize =
1496
        GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
1497
}
1498
1499
/// A [Class Definition Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table)
1500
#[derive(Clone)]
1501
pub enum ClassDef<'a> {
1502
    Format1(ClassDefFormat1<'a>),
1503
    Format2(ClassDefFormat2<'a>),
1504
    Format3(ClassDefFormat3<'a>),
1505
    Format4(ClassDefFormat4<'a>),
1506
}
1507
1508
impl Default for ClassDef<'_> {
1509
0
    fn default() -> Self {
1510
0
        Self::Format1(Default::default())
1511
0
    }
1512
}
1513
1514
impl<'a> ClassDef<'a> {
1515
    ///Return the `FontData` used to resolve offsets for this table.
1516
0
    pub fn offset_data(&self) -> FontData<'a> {
1517
0
        match self {
1518
0
            Self::Format1(item) => item.offset_data(),
1519
0
            Self::Format2(item) => item.offset_data(),
1520
0
            Self::Format3(item) => item.offset_data(),
1521
0
            Self::Format4(item) => item.offset_data(),
1522
        }
1523
0
    }
1524
1525
    /// Format identifier — format = 1
1526
0
    pub fn class_format(&self) -> u16 {
1527
0
        match self {
1528
0
            Self::Format1(item) => item.class_format(),
1529
0
            Self::Format2(item) => item.class_format(),
1530
0
            Self::Format3(item) => item.class_format(),
1531
0
            Self::Format4(item) => item.class_format(),
1532
        }
1533
0
    }
1534
}
1535
1536
impl ReadArgs for ClassDef<'_> {
1537
    type Args = ();
1538
}
1539
1540
impl<'a> FontRead<'a> for ClassDef<'a> {
1541
    #[inline]
1542
349k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1543
349k
        let format: u16 = data.read_at(0usize)?;
1544
347k
        match format {
1545
31.8k
            ClassDefFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
1546
24.8k
            ClassDefFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
1547
8.35k
            ClassDefFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
1548
9.14k
            ClassDefFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
1549
273k
            other => Err(ReadError::InvalidFormat(other.into())),
1550
        }
1551
349k
    }
1552
}
1553
1554
impl<'a> MinByteRange<'a> for ClassDef<'a> {
1555
0
    fn min_byte_range(&self) -> Range<usize> {
1556
0
        match self {
1557
0
            Self::Format1(item) => item.min_byte_range(),
1558
0
            Self::Format2(item) => item.min_byte_range(),
1559
0
            Self::Format3(item) => item.min_byte_range(),
1560
0
            Self::Format4(item) => item.min_byte_range(),
1561
        }
1562
0
    }
1563
0
    fn min_table_bytes(&self) -> &'a [u8] {
1564
0
        match self {
1565
0
            Self::Format1(item) => item.min_table_bytes(),
1566
0
            Self::Format2(item) => item.min_table_bytes(),
1567
0
            Self::Format3(item) => item.min_table_bytes(),
1568
0
            Self::Format4(item) => item.min_table_bytes(),
1569
        }
1570
0
    }
1571
}
1572
1573
/// [Sequence Lookup Record](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-lookup-record)
1574
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1575
#[repr(C)]
1576
#[repr(packed)]
1577
pub struct SequenceLookupRecord {
1578
    /// Index (zero-based) into the input glyph sequence
1579
    pub sequence_index: BigEndian<u16>,
1580
    /// Index (zero-based) into the LookupList
1581
    pub lookup_list_index: BigEndian<u16>,
1582
}
1583
1584
impl SequenceLookupRecord {
1585
    /// Index (zero-based) into the input glyph sequence
1586
0
    pub fn sequence_index(&self) -> u16 {
1587
0
        self.sequence_index.get()
1588
0
    }
1589
1590
    /// Index (zero-based) into the LookupList
1591
0
    pub fn lookup_list_index(&self) -> u16 {
1592
0
        self.lookup_list_index.get()
1593
0
    }
1594
}
1595
1596
impl FixedSize for SequenceLookupRecord {
1597
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
1598
}
1599
1600
impl Format<u16> for SequenceContextFormat1<'_> {
1601
    const FORMAT: u16 = 1;
1602
}
1603
1604
impl<'a> MinByteRange<'a> for SequenceContextFormat1<'a> {
1605
0
    fn min_byte_range(&self) -> Range<usize> {
1606
0
        0..self.seq_rule_set_offsets_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 SequenceContextFormat1<'_> {
1615
    type Args = ();
1616
}
1617
1618
impl<'a> FontRead<'a> for SequenceContextFormat1<'a> {
1619
26.4k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1620
        #[allow(clippy::absurd_extreme_comparisons)]
1621
26.4k
        if data.len() < Self::MIN_SIZE {
1622
290
            return Err(ReadError::OutOfBounds);
1623
26.1k
        }
1624
26.1k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1625
0
            return Err(ReadError::OutOfBounds);
1626
        };
1627
26.1k
        Ok(Self { data })
1628
26.4k
    }
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 SequenceContextFormat1FixedHeader {
1636
    pub format: BigEndian<u16>,
1637
    pub coverage_offset: BigEndian<Offset16>,
1638
    pub seq_rule_set_count: BigEndian<u16>,
1639
}
1640
1641
#[allow(clippy::absurd_extreme_comparisons)]
1642
const _: () = assert!(
1643
    std::mem::size_of::<SequenceContextFormat1FixedHeader>() <= SequenceContextFormat1::MIN_SIZE
1644
);
1645
1646
/// [Sequence Context Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-1-simple-glyph-contexts)
1647
#[derive(Clone)]
1648
pub struct SequenceContextFormat1<'a> {
1649
    data: TableDataRef<'a, SequenceContextFormat1FixedHeader>,
1650
}
1651
1652
#[allow(clippy::needless_lifetimes)]
1653
impl<'a> SequenceContextFormat1<'a> {
1654
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1655
    basic_table_impls!(impl_the_methods);
1656
1657
    /// Format identifier: format = 1
1658
0
    pub fn format(&self) -> u16 {
1659
0
        self.data.header().format.get()
1660
0
    }
1661
1662
    /// Offset to Coverage table, from beginning of
1663
    /// SequenceContextFormat1 table
1664
26.1k
    pub fn coverage_offset(&self) -> Offset16 {
1665
26.1k
        self.data.header().coverage_offset.get()
1666
26.1k
    }
1667
1668
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
1669
26.1k
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
1670
26.1k
        let data = self.offset_data();
1671
26.1k
        self.coverage_offset().resolve(data)
1672
26.1k
    }
1673
1674
    /// Number of SequenceRuleSet tables
1675
26.1k
    pub fn seq_rule_set_count(&self) -> u16 {
1676
26.1k
        self.data.header().seq_rule_set_count.get()
1677
26.1k
    }
1678
1679
    /// Array of offsets to SequenceRuleSet tables, from beginning of
1680
    /// SequenceContextFormat1 table (offsets may be NULL)
1681
0
    pub fn seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] {
1682
0
        let range = self.seq_rule_set_offsets_byte_range();
1683
0
        self.offset_data()
1684
0
            .read_array(range)
1685
0
            .ok()
1686
0
            .unwrap_or_default()
1687
0
    }
1688
1689
    /// A dynamically resolving wrapper for [`seq_rule_set_offsets`][Self::seq_rule_set_offsets].
1690
0
    pub fn seq_rule_sets(&self) -> ArrayOfNullableOffsets<'a, SequenceRuleSet<'a>, Offset16> {
1691
0
        let data = self.offset_data();
1692
0
        let offsets = self.seq_rule_set_offsets();
1693
0
        ArrayOfNullableOffsets::new(offsets, data, ())
1694
0
    }
1695
1696
26.1k
    pub fn format_byte_range(&self) -> Range<usize> {
1697
26.1k
        let start = 0usize;
1698
26.1k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1699
26.1k
        start..end
1700
26.1k
    }
1701
1702
26.1k
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
1703
26.1k
        let start = self.format_byte_range().end;
1704
26.1k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
1705
26.1k
        start..end
1706
26.1k
    }
1707
1708
26.1k
    pub fn seq_rule_set_count_byte_range(&self) -> Range<usize> {
1709
26.1k
        let start = self.coverage_offset_byte_range().end;
1710
26.1k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1711
26.1k
        start..end
1712
26.1k
    }
1713
1714
26.1k
    pub fn seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
1715
26.1k
        let seq_rule_set_count = self.seq_rule_set_count();
1716
26.1k
        let start = self.seq_rule_set_count_byte_range().end;
1717
26.1k
        let end = start.saturating_add(
1718
26.1k
            (transforms::to_usize(seq_rule_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
1719
        );
1720
26.1k
        start..end
1721
26.1k
    }
1722
}
1723
1724
const _: () = assert!(FontData::default_data_long_enough(
1725
    SequenceContextFormat1::MIN_SIZE
1726
));
1727
1728
impl Default for SequenceContextFormat1<'_> {
1729
0
    fn default() -> Self {
1730
        Self {
1731
0
            data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
1732
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1733
        }
1734
0
    }
1735
}
1736
1737
impl<'a> MinByteRange<'a> for SequenceRuleSet<'a> {
1738
0
    fn min_byte_range(&self) -> Range<usize> {
1739
0
        0..self.seq_rule_offsets_byte_range().end
1740
0
    }
1741
0
    fn min_table_bytes(&self) -> &'a [u8] {
1742
0
        let range = self.min_byte_range();
1743
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1744
0
    }
1745
}
1746
1747
impl ReadArgs for SequenceRuleSet<'_> {
1748
    type Args = ();
1749
}
1750
1751
impl<'a> FontRead<'a> for SequenceRuleSet<'a> {
1752
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1753
        #[allow(clippy::absurd_extreme_comparisons)]
1754
0
        if data.len() < Self::MIN_SIZE {
1755
0
            return Err(ReadError::OutOfBounds);
1756
0
        }
1757
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1758
0
            return Err(ReadError::OutOfBounds);
1759
        };
1760
0
        Ok(Self { data })
1761
0
    }
1762
}
1763
1764
/// The fields at the start of the table, which are read directly.
1765
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1766
#[repr(C, packed)]
1767
#[doc(hidden)]
1768
pub struct SequenceRuleSetFixedHeader {
1769
    pub seq_rule_count: BigEndian<u16>,
1770
}
1771
1772
#[allow(clippy::absurd_extreme_comparisons)]
1773
const _: () =
1774
    assert!(std::mem::size_of::<SequenceRuleSetFixedHeader>() <= SequenceRuleSet::MIN_SIZE);
1775
1776
/// Part of [SequenceContextFormat1]
1777
#[derive(Clone)]
1778
pub struct SequenceRuleSet<'a> {
1779
    data: TableDataRef<'a, SequenceRuleSetFixedHeader>,
1780
}
1781
1782
#[allow(clippy::needless_lifetimes)]
1783
impl<'a> SequenceRuleSet<'a> {
1784
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
1785
    basic_table_impls!(impl_the_methods);
1786
1787
    /// Number of SequenceRule tables
1788
0
    pub fn seq_rule_count(&self) -> u16 {
1789
0
        self.data.header().seq_rule_count.get()
1790
0
    }
1791
1792
    /// Array of offsets to SequenceRule tables, from beginning of the
1793
    /// SequenceRuleSet table
1794
0
    pub fn seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
1795
0
        let range = self.seq_rule_offsets_byte_range();
1796
0
        self.offset_data()
1797
0
            .read_array(range)
1798
0
            .ok()
1799
0
            .unwrap_or_default()
1800
0
    }
1801
1802
    /// A dynamically resolving wrapper for [`seq_rule_offsets`][Self::seq_rule_offsets].
1803
0
    pub fn seq_rules(&self) -> ArrayOfOffsets<'a, SequenceRule<'a>, Offset16> {
1804
0
        let data = self.offset_data();
1805
0
        let offsets = self.seq_rule_offsets();
1806
0
        ArrayOfOffsets::new(offsets, data, ())
1807
0
    }
1808
1809
0
    pub fn seq_rule_count_byte_range(&self) -> Range<usize> {
1810
0
        let start = 0usize;
1811
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1812
0
        start..end
1813
0
    }
1814
1815
0
    pub fn seq_rule_offsets_byte_range(&self) -> Range<usize> {
1816
0
        let seq_rule_count = self.seq_rule_count();
1817
0
        let start = self.seq_rule_count_byte_range().end;
1818
0
        let end = start.saturating_add(
1819
0
            (transforms::to_usize(seq_rule_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
1820
        );
1821
0
        start..end
1822
0
    }
1823
}
1824
1825
const _: () = assert!(FontData::default_data_long_enough(
1826
    SequenceRuleSet::MIN_SIZE
1827
));
1828
1829
impl Default for SequenceRuleSet<'_> {
1830
0
    fn default() -> Self {
1831
        Self {
1832
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1833
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1834
        }
1835
0
    }
1836
}
1837
1838
impl<'a> MinByteRange<'a> for SequenceRule<'a> {
1839
0
    fn min_byte_range(&self) -> Range<usize> {
1840
0
        0..self.seq_lookup_records_byte_range().end
1841
0
    }
1842
0
    fn min_table_bytes(&self) -> &'a [u8] {
1843
0
        let range = self.min_byte_range();
1844
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1845
0
    }
1846
}
1847
1848
impl ReadArgs for SequenceRule<'_> {
1849
    type Args = ();
1850
}
1851
1852
impl<'a> FontRead<'a> for SequenceRule<'a> {
1853
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1854
        #[allow(clippy::absurd_extreme_comparisons)]
1855
0
        if data.len() < Self::MIN_SIZE {
1856
0
            return Err(ReadError::OutOfBounds);
1857
0
        }
1858
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1859
0
            return Err(ReadError::OutOfBounds);
1860
        };
1861
0
        Ok(Self { data })
1862
0
    }
1863
}
1864
1865
/// The fields at the start of the table, which are read directly.
1866
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1867
#[repr(C, packed)]
1868
#[doc(hidden)]
1869
pub struct SequenceRuleFixedHeader {
1870
    pub glyph_count: BigEndian<u16>,
1871
    pub seq_lookup_count: BigEndian<u16>,
1872
}
1873
1874
#[allow(clippy::absurd_extreme_comparisons)]
1875
const _: () = assert!(std::mem::size_of::<SequenceRuleFixedHeader>() <= SequenceRule::MIN_SIZE);
1876
1877
/// Part of [SequenceContextFormat1]
1878
#[derive(Clone)]
1879
pub struct SequenceRule<'a> {
1880
    data: TableDataRef<'a, SequenceRuleFixedHeader>,
1881
}
1882
1883
#[allow(clippy::needless_lifetimes)]
1884
impl<'a> SequenceRule<'a> {
1885
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1886
    basic_table_impls!(impl_the_methods);
1887
1888
    /// Number of glyphs in the input glyph sequence
1889
0
    pub fn glyph_count(&self) -> u16 {
1890
0
        self.data.header().glyph_count.get()
1891
0
    }
1892
1893
    /// Number of SequenceLookupRecords
1894
0
    pub fn seq_lookup_count(&self) -> u16 {
1895
0
        self.data.header().seq_lookup_count.get()
1896
0
    }
1897
1898
    /// Array of input glyph IDs—starting with the second glyph
1899
0
    pub fn input_sequence(&self) -> &'a [BigEndian<GlyphId16>] {
1900
0
        let range = self.input_sequence_byte_range();
1901
0
        self.offset_data()
1902
0
            .read_array(range)
1903
0
            .ok()
1904
0
            .unwrap_or_default()
1905
0
    }
1906
1907
    /// Array of Sequence lookup records
1908
0
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
1909
0
        let range = self.seq_lookup_records_byte_range();
1910
0
        self.offset_data()
1911
0
            .read_array(range)
1912
0
            .ok()
1913
0
            .unwrap_or_default()
1914
0
    }
1915
1916
0
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
1917
0
        let start = 0usize;
1918
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1919
0
        start..end
1920
0
    }
1921
1922
0
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
1923
0
        let start = self.glyph_count_byte_range().end;
1924
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1925
0
        start..end
1926
0
    }
1927
1928
0
    pub fn input_sequence_byte_range(&self) -> Range<usize> {
1929
0
        let glyph_count = self.glyph_count();
1930
0
        let start = self.seq_lookup_count_byte_range().end;
1931
0
        let end = start.saturating_add(
1932
0
            (transforms::subtract(glyph_count, 1_usize)).saturating_mul(GlyphId16::RAW_BYTE_LEN),
1933
        );
1934
0
        start..end
1935
0
    }
1936
1937
0
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
1938
0
        let seq_lookup_count = self.seq_lookup_count();
1939
0
        let start = self.input_sequence_byte_range().end;
1940
0
        let end = start.saturating_add(
1941
0
            (transforms::to_usize(seq_lookup_count))
1942
0
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
1943
        );
1944
0
        start..end
1945
0
    }
1946
}
1947
1948
const _: () = assert!(FontData::default_data_long_enough(SequenceRule::MIN_SIZE));
1949
1950
impl Default for SequenceRule<'_> {
1951
0
    fn default() -> Self {
1952
        Self {
1953
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1954
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1955
        }
1956
0
    }
1957
}
1958
1959
impl Format<u16> for SequenceContextFormat2<'_> {
1960
    const FORMAT: u16 = 2;
1961
}
1962
1963
impl<'a> MinByteRange<'a> for SequenceContextFormat2<'a> {
1964
0
    fn min_byte_range(&self) -> Range<usize> {
1965
0
        0..self.class_seq_rule_set_offsets_byte_range().end
1966
0
    }
1967
0
    fn min_table_bytes(&self) -> &'a [u8] {
1968
0
        let range = self.min_byte_range();
1969
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1970
0
    }
1971
}
1972
1973
impl ReadArgs for SequenceContextFormat2<'_> {
1974
    type Args = ();
1975
}
1976
1977
impl<'a> FontRead<'a> for SequenceContextFormat2<'a> {
1978
24.1k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1979
        #[allow(clippy::absurd_extreme_comparisons)]
1980
24.1k
        if data.len() < Self::MIN_SIZE {
1981
411
            return Err(ReadError::OutOfBounds);
1982
23.7k
        }
1983
23.7k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1984
0
            return Err(ReadError::OutOfBounds);
1985
        };
1986
23.7k
        Ok(Self { data })
1987
24.1k
    }
1988
}
1989
1990
/// The fields at the start of the table, which are read directly.
1991
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1992
#[repr(C, packed)]
1993
#[doc(hidden)]
1994
pub struct SequenceContextFormat2FixedHeader {
1995
    pub format: BigEndian<u16>,
1996
    pub coverage_offset: BigEndian<Offset16>,
1997
    pub class_def_offset: BigEndian<Offset16>,
1998
    pub class_seq_rule_set_count: BigEndian<u16>,
1999
}
2000
2001
#[allow(clippy::absurd_extreme_comparisons)]
2002
const _: () = assert!(
2003
    std::mem::size_of::<SequenceContextFormat2FixedHeader>() <= SequenceContextFormat2::MIN_SIZE
2004
);
2005
2006
/// [Sequence Context Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-2-class-based-glyph-contexts)
2007
#[derive(Clone)]
2008
pub struct SequenceContextFormat2<'a> {
2009
    data: TableDataRef<'a, SequenceContextFormat2FixedHeader>,
2010
}
2011
2012
#[allow(clippy::needless_lifetimes)]
2013
impl<'a> SequenceContextFormat2<'a> {
2014
    pub const MIN_SIZE: usize =
2015
        (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2016
    basic_table_impls!(impl_the_methods);
2017
2018
    /// Format identifier: format = 2
2019
0
    pub fn format(&self) -> u16 {
2020
0
        self.data.header().format.get()
2021
0
    }
2022
2023
    /// Offset to Coverage table, from beginning of
2024
    /// SequenceContextFormat2 table
2025
23.7k
    pub fn coverage_offset(&self) -> Offset16 {
2026
23.7k
        self.data.header().coverage_offset.get()
2027
23.7k
    }
2028
2029
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
2030
23.7k
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
2031
23.7k
        let data = self.offset_data();
2032
23.7k
        self.coverage_offset().resolve(data)
2033
23.7k
    }
2034
2035
    /// Offset to ClassDef table, from beginning of
2036
    /// SequenceContextFormat2 table
2037
23.7k
    pub fn class_def_offset(&self) -> Offset16 {
2038
23.7k
        self.data.header().class_def_offset.get()
2039
23.7k
    }
2040
2041
    /// Attempt to resolve [`class_def_offset`][Self::class_def_offset].
2042
23.7k
    pub fn class_def(&self) -> Result<ClassDef<'a>, ReadError> {
2043
23.7k
        let data = self.offset_data();
2044
23.7k
        self.class_def_offset().resolve(data)
2045
23.7k
    }
2046
2047
    /// Number of ClassSequenceRuleSet tables
2048
23.7k
    pub fn class_seq_rule_set_count(&self) -> u16 {
2049
23.7k
        self.data.header().class_seq_rule_set_count.get()
2050
23.7k
    }
2051
2052
    /// Array of offsets to ClassSequenceRuleSet tables, from beginning
2053
    /// of SequenceContextFormat2 table (may be NULL)
2054
0
    pub fn class_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] {
2055
0
        let range = self.class_seq_rule_set_offsets_byte_range();
2056
0
        self.offset_data()
2057
0
            .read_array(range)
2058
0
            .ok()
2059
0
            .unwrap_or_default()
2060
0
    }
2061
2062
    /// A dynamically resolving wrapper for [`class_seq_rule_set_offsets`][Self::class_seq_rule_set_offsets].
2063
0
    pub fn class_seq_rule_sets(
2064
0
        &self,
2065
0
    ) -> ArrayOfNullableOffsets<'a, ClassSequenceRuleSet<'a>, Offset16> {
2066
0
        let data = self.offset_data();
2067
0
        let offsets = self.class_seq_rule_set_offsets();
2068
0
        ArrayOfNullableOffsets::new(offsets, data, ())
2069
0
    }
2070
2071
23.7k
    pub fn format_byte_range(&self) -> Range<usize> {
2072
23.7k
        let start = 0usize;
2073
23.7k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2074
23.7k
        start..end
2075
23.7k
    }
2076
2077
23.7k
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
2078
23.7k
        let start = self.format_byte_range().end;
2079
23.7k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
2080
23.7k
        start..end
2081
23.7k
    }
2082
2083
23.7k
    pub fn class_def_offset_byte_range(&self) -> Range<usize> {
2084
23.7k
        let start = self.coverage_offset_byte_range().end;
2085
23.7k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
2086
23.7k
        start..end
2087
23.7k
    }
2088
2089
23.7k
    pub fn class_seq_rule_set_count_byte_range(&self) -> Range<usize> {
2090
23.7k
        let start = self.class_def_offset_byte_range().end;
2091
23.7k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2092
23.7k
        start..end
2093
23.7k
    }
2094
2095
23.7k
    pub fn class_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
2096
23.7k
        let class_seq_rule_set_count = self.class_seq_rule_set_count();
2097
23.7k
        let start = self.class_seq_rule_set_count_byte_range().end;
2098
23.7k
        let end = start.saturating_add(
2099
23.7k
            (transforms::to_usize(class_seq_rule_set_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
2100
        );
2101
23.7k
        start..end
2102
23.7k
    }
2103
}
2104
2105
impl<'a> MinByteRange<'a> for ClassSequenceRuleSet<'a> {
2106
0
    fn min_byte_range(&self) -> Range<usize> {
2107
0
        0..self.class_seq_rule_offsets_byte_range().end
2108
0
    }
2109
0
    fn min_table_bytes(&self) -> &'a [u8] {
2110
0
        let range = self.min_byte_range();
2111
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2112
0
    }
2113
}
2114
2115
impl ReadArgs for ClassSequenceRuleSet<'_> {
2116
    type Args = ();
2117
}
2118
2119
impl<'a> FontRead<'a> for ClassSequenceRuleSet<'a> {
2120
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2121
        #[allow(clippy::absurd_extreme_comparisons)]
2122
0
        if data.len() < Self::MIN_SIZE {
2123
0
            return Err(ReadError::OutOfBounds);
2124
0
        }
2125
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2126
0
            return Err(ReadError::OutOfBounds);
2127
        };
2128
0
        Ok(Self { data })
2129
0
    }
2130
}
2131
2132
/// The fields at the start of the table, which are read directly.
2133
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2134
#[repr(C, packed)]
2135
#[doc(hidden)]
2136
pub struct ClassSequenceRuleSetFixedHeader {
2137
    pub class_seq_rule_count: BigEndian<u16>,
2138
}
2139
2140
#[allow(clippy::absurd_extreme_comparisons)]
2141
const _: () = assert!(
2142
    std::mem::size_of::<ClassSequenceRuleSetFixedHeader>() <= ClassSequenceRuleSet::MIN_SIZE
2143
);
2144
2145
/// Part of [SequenceContextFormat2]
2146
#[derive(Clone)]
2147
pub struct ClassSequenceRuleSet<'a> {
2148
    data: TableDataRef<'a, ClassSequenceRuleSetFixedHeader>,
2149
}
2150
2151
#[allow(clippy::needless_lifetimes)]
2152
impl<'a> ClassSequenceRuleSet<'a> {
2153
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
2154
    basic_table_impls!(impl_the_methods);
2155
2156
    /// Number of ClassSequenceRule tables
2157
0
    pub fn class_seq_rule_count(&self) -> u16 {
2158
0
        self.data.header().class_seq_rule_count.get()
2159
0
    }
2160
2161
    /// Array of offsets to ClassSequenceRule tables, from beginning of
2162
    /// ClassSequenceRuleSet table
2163
0
    pub fn class_seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
2164
0
        let range = self.class_seq_rule_offsets_byte_range();
2165
0
        self.offset_data()
2166
0
            .read_array(range)
2167
0
            .ok()
2168
0
            .unwrap_or_default()
2169
0
    }
2170
2171
    /// A dynamically resolving wrapper for [`class_seq_rule_offsets`][Self::class_seq_rule_offsets].
2172
0
    pub fn class_seq_rules(&self) -> ArrayOfOffsets<'a, ClassSequenceRule<'a>, Offset16> {
2173
0
        let data = self.offset_data();
2174
0
        let offsets = self.class_seq_rule_offsets();
2175
0
        ArrayOfOffsets::new(offsets, data, ())
2176
0
    }
2177
2178
0
    pub fn class_seq_rule_count_byte_range(&self) -> Range<usize> {
2179
0
        let start = 0usize;
2180
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2181
0
        start..end
2182
0
    }
2183
2184
0
    pub fn class_seq_rule_offsets_byte_range(&self) -> Range<usize> {
2185
0
        let class_seq_rule_count = self.class_seq_rule_count();
2186
0
        let start = self.class_seq_rule_count_byte_range().end;
2187
0
        let end = start.saturating_add(
2188
0
            (transforms::to_usize(class_seq_rule_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
2189
        );
2190
0
        start..end
2191
0
    }
2192
}
2193
2194
const _: () = assert!(FontData::default_data_long_enough(
2195
    ClassSequenceRuleSet::MIN_SIZE
2196
));
2197
2198
impl Default for ClassSequenceRuleSet<'_> {
2199
0
    fn default() -> Self {
2200
        Self {
2201
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
2202
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2203
        }
2204
0
    }
2205
}
2206
2207
impl<'a> MinByteRange<'a> for ClassSequenceRule<'a> {
2208
0
    fn min_byte_range(&self) -> Range<usize> {
2209
0
        0..self.seq_lookup_records_byte_range().end
2210
0
    }
2211
0
    fn min_table_bytes(&self) -> &'a [u8] {
2212
0
        let range = self.min_byte_range();
2213
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2214
0
    }
2215
}
2216
2217
impl ReadArgs for ClassSequenceRule<'_> {
2218
    type Args = ();
2219
}
2220
2221
impl<'a> FontRead<'a> for ClassSequenceRule<'a> {
2222
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2223
        #[allow(clippy::absurd_extreme_comparisons)]
2224
0
        if data.len() < Self::MIN_SIZE {
2225
0
            return Err(ReadError::OutOfBounds);
2226
0
        }
2227
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2228
0
            return Err(ReadError::OutOfBounds);
2229
        };
2230
0
        Ok(Self { data })
2231
0
    }
2232
}
2233
2234
/// The fields at the start of the table, which are read directly.
2235
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2236
#[repr(C, packed)]
2237
#[doc(hidden)]
2238
pub struct ClassSequenceRuleFixedHeader {
2239
    pub glyph_count: BigEndian<u16>,
2240
    pub seq_lookup_count: BigEndian<u16>,
2241
}
2242
2243
#[allow(clippy::absurd_extreme_comparisons)]
2244
const _: () =
2245
    assert!(std::mem::size_of::<ClassSequenceRuleFixedHeader>() <= ClassSequenceRule::MIN_SIZE);
2246
2247
/// Part of [SequenceContextFormat2]
2248
#[derive(Clone)]
2249
pub struct ClassSequenceRule<'a> {
2250
    data: TableDataRef<'a, ClassSequenceRuleFixedHeader>,
2251
}
2252
2253
#[allow(clippy::needless_lifetimes)]
2254
impl<'a> ClassSequenceRule<'a> {
2255
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2256
    basic_table_impls!(impl_the_methods);
2257
2258
    /// Number of glyphs to be matched
2259
0
    pub fn glyph_count(&self) -> u16 {
2260
0
        self.data.header().glyph_count.get()
2261
0
    }
2262
2263
    /// Number of SequenceLookupRecords
2264
0
    pub fn seq_lookup_count(&self) -> u16 {
2265
0
        self.data.header().seq_lookup_count.get()
2266
0
    }
2267
2268
    /// Sequence of classes to be matched to the input glyph sequence,
2269
    /// beginning with the second glyph position
2270
0
    pub fn input_sequence(&self) -> &'a [BigEndian<u16>] {
2271
0
        let range = self.input_sequence_byte_range();
2272
0
        self.offset_data()
2273
0
            .read_array(range)
2274
0
            .ok()
2275
0
            .unwrap_or_default()
2276
0
    }
2277
2278
    /// Array of SequenceLookupRecords
2279
0
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
2280
0
        let range = self.seq_lookup_records_byte_range();
2281
0
        self.offset_data()
2282
0
            .read_array(range)
2283
0
            .ok()
2284
0
            .unwrap_or_default()
2285
0
    }
2286
2287
0
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
2288
0
        let start = 0usize;
2289
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2290
0
        start..end
2291
0
    }
2292
2293
0
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
2294
0
        let start = self.glyph_count_byte_range().end;
2295
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2296
0
        start..end
2297
0
    }
2298
2299
0
    pub fn input_sequence_byte_range(&self) -> Range<usize> {
2300
0
        let glyph_count = self.glyph_count();
2301
0
        let start = self.seq_lookup_count_byte_range().end;
2302
0
        let end = start.saturating_add(
2303
0
            (transforms::subtract(glyph_count, 1_usize)).saturating_mul(u16::RAW_BYTE_LEN),
2304
        );
2305
0
        start..end
2306
0
    }
2307
2308
0
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
2309
0
        let seq_lookup_count = self.seq_lookup_count();
2310
0
        let start = self.input_sequence_byte_range().end;
2311
0
        let end = start.saturating_add(
2312
0
            (transforms::to_usize(seq_lookup_count))
2313
0
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
2314
        );
2315
0
        start..end
2316
0
    }
2317
}
2318
2319
const _: () = assert!(FontData::default_data_long_enough(
2320
    ClassSequenceRule::MIN_SIZE
2321
));
2322
2323
impl Default for ClassSequenceRule<'_> {
2324
0
    fn default() -> Self {
2325
        Self {
2326
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
2327
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2328
        }
2329
0
    }
2330
}
2331
2332
impl Format<u16> for SequenceContextFormat3<'_> {
2333
    const FORMAT: u16 = 3;
2334
}
2335
2336
impl<'a> MinByteRange<'a> for SequenceContextFormat3<'a> {
2337
0
    fn min_byte_range(&self) -> Range<usize> {
2338
0
        0..self.seq_lookup_records_byte_range().end
2339
0
    }
2340
0
    fn min_table_bytes(&self) -> &'a [u8] {
2341
0
        let range = self.min_byte_range();
2342
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2343
0
    }
2344
}
2345
2346
impl ReadArgs for SequenceContextFormat3<'_> {
2347
    type Args = ();
2348
}
2349
2350
impl<'a> FontRead<'a> for SequenceContextFormat3<'a> {
2351
9.92k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2352
        #[allow(clippy::absurd_extreme_comparisons)]
2353
9.92k
        if data.len() < Self::MIN_SIZE {
2354
303
            return Err(ReadError::OutOfBounds);
2355
9.61k
        }
2356
9.61k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2357
0
            return Err(ReadError::OutOfBounds);
2358
        };
2359
9.61k
        Ok(Self { data })
2360
9.92k
    }
2361
}
2362
2363
/// The fields at the start of the table, which are read directly.
2364
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2365
#[repr(C, packed)]
2366
#[doc(hidden)]
2367
pub struct SequenceContextFormat3FixedHeader {
2368
    pub format: BigEndian<u16>,
2369
    pub glyph_count: BigEndian<u16>,
2370
    pub seq_lookup_count: BigEndian<u16>,
2371
}
2372
2373
#[allow(clippy::absurd_extreme_comparisons)]
2374
const _: () = assert!(
2375
    std::mem::size_of::<SequenceContextFormat3FixedHeader>() <= SequenceContextFormat3::MIN_SIZE
2376
);
2377
2378
/// [Sequence Context Format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#sequence-context-format-3-coverage-based-glyph-contexts)
2379
#[derive(Clone)]
2380
pub struct SequenceContextFormat3<'a> {
2381
    data: TableDataRef<'a, SequenceContextFormat3FixedHeader>,
2382
}
2383
2384
#[allow(clippy::needless_lifetimes)]
2385
impl<'a> SequenceContextFormat3<'a> {
2386
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2387
    basic_table_impls!(impl_the_methods);
2388
2389
    /// Format identifier: format = 3
2390
0
    pub fn format(&self) -> u16 {
2391
0
        self.data.header().format.get()
2392
0
    }
2393
2394
    /// Number of glyphs in the input sequence
2395
28.8k
    pub fn glyph_count(&self) -> u16 {
2396
28.8k
        self.data.header().glyph_count.get()
2397
28.8k
    }
2398
2399
    /// Number of SequenceLookupRecords
2400
9.61k
    pub fn seq_lookup_count(&self) -> u16 {
2401
9.61k
        self.data.header().seq_lookup_count.get()
2402
9.61k
    }
2403
2404
    /// Array of offsets to Coverage tables, from beginning of
2405
    /// SequenceContextFormat3 subtable
2406
9.61k
    pub fn coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
2407
9.61k
        let range = self.coverage_offsets_byte_range();
2408
9.61k
        self.offset_data()
2409
9.61k
            .read_array(range)
2410
9.61k
            .ok()
2411
9.61k
            .unwrap_or_default()
2412
9.61k
    }
2413
2414
    /// A dynamically resolving wrapper for [`coverage_offsets`][Self::coverage_offsets].
2415
9.61k
    pub fn coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
2416
9.61k
        let data = self.offset_data();
2417
9.61k
        let offsets = self.coverage_offsets();
2418
9.61k
        ArrayOfOffsets::new(offsets, data, ())
2419
9.61k
    }
2420
2421
    /// Array of SequenceLookupRecords
2422
9.61k
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
2423
9.61k
        let range = self.seq_lookup_records_byte_range();
2424
9.61k
        self.offset_data()
2425
9.61k
            .read_array(range)
2426
9.61k
            .ok()
2427
9.61k
            .unwrap_or_default()
2428
9.61k
    }
2429
2430
28.8k
    pub fn format_byte_range(&self) -> Range<usize> {
2431
28.8k
        let start = 0usize;
2432
28.8k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2433
28.8k
        start..end
2434
28.8k
    }
2435
2436
28.8k
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
2437
28.8k
        let start = self.format_byte_range().end;
2438
28.8k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2439
28.8k
        start..end
2440
28.8k
    }
2441
2442
28.8k
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
2443
28.8k
        let start = self.glyph_count_byte_range().end;
2444
28.8k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2445
28.8k
        start..end
2446
28.8k
    }
2447
2448
28.8k
    pub fn coverage_offsets_byte_range(&self) -> Range<usize> {
2449
28.8k
        let glyph_count = self.glyph_count();
2450
28.8k
        let start = self.seq_lookup_count_byte_range().end;
2451
28.8k
        let end = start.saturating_add(
2452
28.8k
            (transforms::to_usize(glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
2453
        );
2454
28.8k
        start..end
2455
28.8k
    }
2456
2457
9.61k
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
2458
9.61k
        let seq_lookup_count = self.seq_lookup_count();
2459
9.61k
        let start = self.coverage_offsets_byte_range().end;
2460
9.61k
        let end = start.saturating_add(
2461
9.61k
            (transforms::to_usize(seq_lookup_count))
2462
9.61k
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
2463
        );
2464
9.61k
        start..end
2465
9.61k
    }
2466
}
2467
2468
#[derive(Clone)]
2469
pub enum SequenceContext<'a> {
2470
    Format1(SequenceContextFormat1<'a>),
2471
    Format2(SequenceContextFormat2<'a>),
2472
    Format3(SequenceContextFormat3<'a>),
2473
    Format4(SequenceContextFormat4<'a>),
2474
    Format5(SequenceContextFormat5<'a>),
2475
    Format6(SequenceContextFormat6<'a>),
2476
}
2477
2478
impl Default for SequenceContext<'_> {
2479
0
    fn default() -> Self {
2480
0
        Self::Format1(Default::default())
2481
0
    }
2482
}
2483
2484
impl<'a> SequenceContext<'a> {
2485
    ///Return the `FontData` used to resolve offsets for this table.
2486
0
    pub fn offset_data(&self) -> FontData<'a> {
2487
0
        match self {
2488
0
            Self::Format1(item) => item.offset_data(),
2489
0
            Self::Format2(item) => item.offset_data(),
2490
0
            Self::Format3(item) => item.offset_data(),
2491
0
            Self::Format4(item) => item.offset_data(),
2492
0
            Self::Format5(item) => item.offset_data(),
2493
0
            Self::Format6(item) => item.offset_data(),
2494
        }
2495
0
    }
2496
2497
    /// Format identifier: format = 1
2498
0
    pub fn format(&self) -> u16 {
2499
0
        match self {
2500
0
            Self::Format1(item) => item.format(),
2501
0
            Self::Format2(item) => item.format(),
2502
0
            Self::Format3(item) => item.format(),
2503
0
            Self::Format4(item) => item.format(),
2504
0
            Self::Format5(item) => item.format(),
2505
0
            Self::Format6(item) => item.format(),
2506
        }
2507
0
    }
2508
}
2509
2510
impl ReadArgs for SequenceContext<'_> {
2511
    type Args = ();
2512
}
2513
2514
impl<'a> FontRead<'a> for SequenceContext<'a> {
2515
    #[inline]
2516
1.21M
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2517
1.21M
        let format: u16 = data.read_at(0usize)?;
2518
1.21M
        match format {
2519
26.4k
            SequenceContextFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
2520
24.1k
            SequenceContextFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
2521
9.92k
            SequenceContextFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
2522
12.3k
            SequenceContextFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
2523
337k
            SequenceContextFormat5::FORMAT => Ok(Self::Format5(FontRead::read(data)?)),
2524
8.83k
            SequenceContextFormat6::FORMAT => Ok(Self::Format6(FontRead::read(data)?)),
2525
793k
            other => Err(ReadError::InvalidFormat(other.into())),
2526
        }
2527
1.21M
    }
<read_fonts::tables::layout::SequenceContext as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
2516
1.21M
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2517
1.21M
        let format: u16 = data.read_at(0usize)?;
2518
1.21M
        match format {
2519
26.4k
            SequenceContextFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
2520
24.1k
            SequenceContextFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
2521
9.92k
            SequenceContextFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
2522
12.3k
            SequenceContextFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
2523
337k
            SequenceContextFormat5::FORMAT => Ok(Self::Format5(FontRead::read(data)?)),
2524
8.83k
            SequenceContextFormat6::FORMAT => Ok(Self::Format6(FontRead::read(data)?)),
2525
793k
            other => Err(ReadError::InvalidFormat(other.into())),
2526
        }
2527
1.21M
    }
Unexecuted instantiation: <read_fonts::tables::layout::SequenceContext as read_fonts::read::FontRead>::read_with_args
2528
}
2529
2530
impl<'a> MinByteRange<'a> for SequenceContext<'a> {
2531
0
    fn min_byte_range(&self) -> Range<usize> {
2532
0
        match self {
2533
0
            Self::Format1(item) => item.min_byte_range(),
2534
0
            Self::Format2(item) => item.min_byte_range(),
2535
0
            Self::Format3(item) => item.min_byte_range(),
2536
0
            Self::Format4(item) => item.min_byte_range(),
2537
0
            Self::Format5(item) => item.min_byte_range(),
2538
0
            Self::Format6(item) => item.min_byte_range(),
2539
        }
2540
0
    }
2541
0
    fn min_table_bytes(&self) -> &'a [u8] {
2542
0
        match self {
2543
0
            Self::Format1(item) => item.min_table_bytes(),
2544
0
            Self::Format2(item) => item.min_table_bytes(),
2545
0
            Self::Format3(item) => item.min_table_bytes(),
2546
0
            Self::Format4(item) => item.min_table_bytes(),
2547
0
            Self::Format5(item) => item.min_table_bytes(),
2548
0
            Self::Format6(item) => item.min_table_bytes(),
2549
        }
2550
0
    }
2551
}
2552
2553
impl Format<u16> for ChainedSequenceContextFormat1<'_> {
2554
    const FORMAT: u16 = 1;
2555
}
2556
2557
impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat1<'a> {
2558
0
    fn min_byte_range(&self) -> Range<usize> {
2559
0
        0..self.chained_seq_rule_set_offsets_byte_range().end
2560
0
    }
2561
0
    fn min_table_bytes(&self) -> &'a [u8] {
2562
0
        let range = self.min_byte_range();
2563
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2564
0
    }
2565
}
2566
2567
impl ReadArgs for ChainedSequenceContextFormat1<'_> {
2568
    type Args = ();
2569
}
2570
2571
impl<'a> FontRead<'a> for ChainedSequenceContextFormat1<'a> {
2572
28.5k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2573
        #[allow(clippy::absurd_extreme_comparisons)]
2574
28.5k
        if data.len() < Self::MIN_SIZE {
2575
352
            return Err(ReadError::OutOfBounds);
2576
28.2k
        }
2577
28.2k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2578
0
            return Err(ReadError::OutOfBounds);
2579
        };
2580
28.2k
        Ok(Self { data })
2581
28.5k
    }
2582
}
2583
2584
/// The fields at the start of the table, which are read directly.
2585
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2586
#[repr(C, packed)]
2587
#[doc(hidden)]
2588
pub struct ChainedSequenceContextFormat1FixedHeader {
2589
    pub format: BigEndian<u16>,
2590
    pub coverage_offset: BigEndian<Offset16>,
2591
    pub chained_seq_rule_set_count: BigEndian<u16>,
2592
}
2593
2594
#[allow(clippy::absurd_extreme_comparisons)]
2595
const _: () = assert!(
2596
    std::mem::size_of::<ChainedSequenceContextFormat1FixedHeader>()
2597
        <= ChainedSequenceContextFormat1::MIN_SIZE
2598
);
2599
2600
/// [Chained Sequence Context Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chained-sequence-context-format-1-simple-glyph-contexts)
2601
#[derive(Clone)]
2602
pub struct ChainedSequenceContextFormat1<'a> {
2603
    data: TableDataRef<'a, ChainedSequenceContextFormat1FixedHeader>,
2604
}
2605
2606
#[allow(clippy::needless_lifetimes)]
2607
impl<'a> ChainedSequenceContextFormat1<'a> {
2608
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2609
    basic_table_impls!(impl_the_methods);
2610
2611
    /// Format identifier: format = 1
2612
0
    pub fn format(&self) -> u16 {
2613
0
        self.data.header().format.get()
2614
0
    }
2615
2616
    /// Offset to Coverage table, from beginning of
2617
    /// ChainSequenceContextFormat1 table
2618
28.2k
    pub fn coverage_offset(&self) -> Offset16 {
2619
28.2k
        self.data.header().coverage_offset.get()
2620
28.2k
    }
2621
2622
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
2623
28.2k
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
2624
28.2k
        let data = self.offset_data();
2625
28.2k
        self.coverage_offset().resolve(data)
2626
28.2k
    }
2627
2628
    /// Number of ChainedSequenceRuleSet tables
2629
28.2k
    pub fn chained_seq_rule_set_count(&self) -> u16 {
2630
28.2k
        self.data.header().chained_seq_rule_set_count.get()
2631
28.2k
    }
2632
2633
    /// Array of offsets to ChainedSeqRuleSet tables, from beginning of
2634
    /// ChainedSequenceContextFormat1 table (may be NULL)
2635
0
    pub fn chained_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] {
2636
0
        let range = self.chained_seq_rule_set_offsets_byte_range();
2637
0
        self.offset_data()
2638
0
            .read_array(range)
2639
0
            .ok()
2640
0
            .unwrap_or_default()
2641
0
    }
2642
2643
    /// A dynamically resolving wrapper for [`chained_seq_rule_set_offsets`][Self::chained_seq_rule_set_offsets].
2644
0
    pub fn chained_seq_rule_sets(
2645
0
        &self,
2646
0
    ) -> ArrayOfNullableOffsets<'a, ChainedSequenceRuleSet<'a>, Offset16> {
2647
0
        let data = self.offset_data();
2648
0
        let offsets = self.chained_seq_rule_set_offsets();
2649
0
        ArrayOfNullableOffsets::new(offsets, data, ())
2650
0
    }
2651
2652
28.2k
    pub fn format_byte_range(&self) -> Range<usize> {
2653
28.2k
        let start = 0usize;
2654
28.2k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2655
28.2k
        start..end
2656
28.2k
    }
2657
2658
28.2k
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
2659
28.2k
        let start = self.format_byte_range().end;
2660
28.2k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
2661
28.2k
        start..end
2662
28.2k
    }
2663
2664
28.2k
    pub fn chained_seq_rule_set_count_byte_range(&self) -> Range<usize> {
2665
28.2k
        let start = self.coverage_offset_byte_range().end;
2666
28.2k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2667
28.2k
        start..end
2668
28.2k
    }
2669
2670
28.2k
    pub fn chained_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
2671
28.2k
        let chained_seq_rule_set_count = self.chained_seq_rule_set_count();
2672
28.2k
        let start = self.chained_seq_rule_set_count_byte_range().end;
2673
28.2k
        let end = start.saturating_add(
2674
28.2k
            (transforms::to_usize(chained_seq_rule_set_count))
2675
28.2k
                .saturating_mul(Offset16::RAW_BYTE_LEN),
2676
        );
2677
28.2k
        start..end
2678
28.2k
    }
2679
}
2680
2681
const _: () = assert!(FontData::default_data_long_enough(
2682
    ChainedSequenceContextFormat1::MIN_SIZE
2683
));
2684
2685
impl Default for ChainedSequenceContextFormat1<'_> {
2686
0
    fn default() -> Self {
2687
        Self {
2688
0
            data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
2689
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2690
        }
2691
0
    }
2692
}
2693
2694
impl<'a> MinByteRange<'a> for ChainedSequenceRuleSet<'a> {
2695
0
    fn min_byte_range(&self) -> Range<usize> {
2696
0
        0..self.chained_seq_rule_offsets_byte_range().end
2697
0
    }
2698
0
    fn min_table_bytes(&self) -> &'a [u8] {
2699
0
        let range = self.min_byte_range();
2700
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2701
0
    }
2702
}
2703
2704
impl ReadArgs for ChainedSequenceRuleSet<'_> {
2705
    type Args = ();
2706
}
2707
2708
impl<'a> FontRead<'a> for ChainedSequenceRuleSet<'a> {
2709
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2710
        #[allow(clippy::absurd_extreme_comparisons)]
2711
0
        if data.len() < Self::MIN_SIZE {
2712
0
            return Err(ReadError::OutOfBounds);
2713
0
        }
2714
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2715
0
            return Err(ReadError::OutOfBounds);
2716
        };
2717
0
        Ok(Self { data })
2718
0
    }
2719
}
2720
2721
/// The fields at the start of the table, which are read directly.
2722
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2723
#[repr(C, packed)]
2724
#[doc(hidden)]
2725
pub struct ChainedSequenceRuleSetFixedHeader {
2726
    pub chained_seq_rule_count: BigEndian<u16>,
2727
}
2728
2729
#[allow(clippy::absurd_extreme_comparisons)]
2730
const _: () = assert!(
2731
    std::mem::size_of::<ChainedSequenceRuleSetFixedHeader>() <= ChainedSequenceRuleSet::MIN_SIZE
2732
);
2733
2734
/// Part of [ChainedSequenceContextFormat1]
2735
#[derive(Clone)]
2736
pub struct ChainedSequenceRuleSet<'a> {
2737
    data: TableDataRef<'a, ChainedSequenceRuleSetFixedHeader>,
2738
}
2739
2740
#[allow(clippy::needless_lifetimes)]
2741
impl<'a> ChainedSequenceRuleSet<'a> {
2742
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
2743
    basic_table_impls!(impl_the_methods);
2744
2745
    /// Number of ChainedSequenceRule tables
2746
0
    pub fn chained_seq_rule_count(&self) -> u16 {
2747
0
        self.data.header().chained_seq_rule_count.get()
2748
0
    }
2749
2750
    /// Array of offsets to ChainedSequenceRule tables, from beginning
2751
    /// of ChainedSequenceRuleSet table
2752
0
    pub fn chained_seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
2753
0
        let range = self.chained_seq_rule_offsets_byte_range();
2754
0
        self.offset_data()
2755
0
            .read_array(range)
2756
0
            .ok()
2757
0
            .unwrap_or_default()
2758
0
    }
2759
2760
    /// A dynamically resolving wrapper for [`chained_seq_rule_offsets`][Self::chained_seq_rule_offsets].
2761
0
    pub fn chained_seq_rules(&self) -> ArrayOfOffsets<'a, ChainedSequenceRule<'a>, Offset16> {
2762
0
        let data = self.offset_data();
2763
0
        let offsets = self.chained_seq_rule_offsets();
2764
0
        ArrayOfOffsets::new(offsets, data, ())
2765
0
    }
2766
2767
0
    pub fn chained_seq_rule_count_byte_range(&self) -> Range<usize> {
2768
0
        let start = 0usize;
2769
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2770
0
        start..end
2771
0
    }
2772
2773
0
    pub fn chained_seq_rule_offsets_byte_range(&self) -> Range<usize> {
2774
0
        let chained_seq_rule_count = self.chained_seq_rule_count();
2775
0
        let start = self.chained_seq_rule_count_byte_range().end;
2776
0
        let end = start.saturating_add(
2777
0
            (transforms::to_usize(chained_seq_rule_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
2778
        );
2779
0
        start..end
2780
0
    }
2781
}
2782
2783
const _: () = assert!(FontData::default_data_long_enough(
2784
    ChainedSequenceRuleSet::MIN_SIZE
2785
));
2786
2787
impl Default for ChainedSequenceRuleSet<'_> {
2788
0
    fn default() -> Self {
2789
        Self {
2790
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
2791
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2792
        }
2793
0
    }
2794
}
2795
2796
impl<'a> MinByteRange<'a> for ChainedSequenceRule<'a> {
2797
0
    fn min_byte_range(&self) -> Range<usize> {
2798
0
        0..self.seq_lookup_records_byte_range().end
2799
0
    }
2800
0
    fn min_table_bytes(&self) -> &'a [u8] {
2801
0
        let range = self.min_byte_range();
2802
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2803
0
    }
2804
}
2805
2806
impl ReadArgs for ChainedSequenceRule<'_> {
2807
    type Args = ();
2808
}
2809
2810
impl<'a> FontRead<'a> for ChainedSequenceRule<'a> {
2811
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2812
        #[allow(clippy::absurd_extreme_comparisons)]
2813
0
        if data.len() < Self::MIN_SIZE {
2814
0
            return Err(ReadError::OutOfBounds);
2815
0
        }
2816
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2817
0
            return Err(ReadError::OutOfBounds);
2818
        };
2819
0
        Ok(Self { data })
2820
0
    }
2821
}
2822
2823
/// The fields at the start of the table, which are read directly.
2824
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2825
#[repr(C, packed)]
2826
#[doc(hidden)]
2827
pub struct ChainedSequenceRuleFixedHeader {
2828
    pub backtrack_glyph_count: BigEndian<u16>,
2829
}
2830
2831
#[allow(clippy::absurd_extreme_comparisons)]
2832
const _: () =
2833
    assert!(std::mem::size_of::<ChainedSequenceRuleFixedHeader>() <= ChainedSequenceRule::MIN_SIZE);
2834
2835
/// Part of [ChainedSequenceContextFormat1]
2836
#[derive(Clone)]
2837
pub struct ChainedSequenceRule<'a> {
2838
    data: TableDataRef<'a, ChainedSequenceRuleFixedHeader>,
2839
}
2840
2841
#[allow(clippy::needless_lifetimes)]
2842
impl<'a> ChainedSequenceRule<'a> {
2843
    pub const MIN_SIZE: usize =
2844
        (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
2845
    basic_table_impls!(impl_the_methods);
2846
2847
    /// Number of glyphs in the backtrack sequence
2848
0
    pub fn backtrack_glyph_count(&self) -> u16 {
2849
0
        self.data.header().backtrack_glyph_count.get()
2850
0
    }
2851
2852
    /// Array of backtrack glyph IDs
2853
0
    pub fn backtrack_sequence(&self) -> &'a [BigEndian<GlyphId16>] {
2854
0
        let range = self.backtrack_sequence_byte_range();
2855
0
        self.offset_data()
2856
0
            .read_array(range)
2857
0
            .ok()
2858
0
            .unwrap_or_default()
2859
0
    }
2860
2861
    /// Number of glyphs in the input sequence
2862
0
    pub fn input_glyph_count(&self) -> u16 {
2863
0
        let range = self.input_glyph_count_byte_range();
2864
0
        self.offset_data()
2865
0
            .read_at(range.start)
2866
0
            .ok()
2867
0
            .unwrap_or_default()
2868
0
    }
2869
2870
    /// Array of input glyph IDs—start with second glyph
2871
0
    pub fn input_sequence(&self) -> &'a [BigEndian<GlyphId16>] {
2872
0
        let range = self.input_sequence_byte_range();
2873
0
        self.offset_data()
2874
0
            .read_array(range)
2875
0
            .ok()
2876
0
            .unwrap_or_default()
2877
0
    }
2878
2879
    /// Number of glyphs in the lookahead sequence
2880
0
    pub fn lookahead_glyph_count(&self) -> u16 {
2881
0
        let range = self.lookahead_glyph_count_byte_range();
2882
0
        self.offset_data()
2883
0
            .read_at(range.start)
2884
0
            .ok()
2885
0
            .unwrap_or_default()
2886
0
    }
2887
2888
    /// Array of lookahead glyph IDs
2889
0
    pub fn lookahead_sequence(&self) -> &'a [BigEndian<GlyphId16>] {
2890
0
        let range = self.lookahead_sequence_byte_range();
2891
0
        self.offset_data()
2892
0
            .read_array(range)
2893
0
            .ok()
2894
0
            .unwrap_or_default()
2895
0
    }
2896
2897
    /// Number of SequenceLookupRecords
2898
0
    pub fn seq_lookup_count(&self) -> u16 {
2899
0
        let range = self.seq_lookup_count_byte_range();
2900
0
        self.offset_data()
2901
0
            .read_at(range.start)
2902
0
            .ok()
2903
0
            .unwrap_or_default()
2904
0
    }
2905
2906
    /// Array of SequenceLookupRecords
2907
0
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
2908
0
        let range = self.seq_lookup_records_byte_range();
2909
0
        self.offset_data()
2910
0
            .read_array(range)
2911
0
            .ok()
2912
0
            .unwrap_or_default()
2913
0
    }
2914
2915
0
    pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
2916
0
        let start = 0usize;
2917
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2918
0
        start..end
2919
0
    }
2920
2921
0
    pub fn backtrack_sequence_byte_range(&self) -> Range<usize> {
2922
0
        let backtrack_glyph_count = self.backtrack_glyph_count();
2923
0
        let start = self.backtrack_glyph_count_byte_range().end;
2924
0
        let end = start.saturating_add(
2925
0
            (transforms::to_usize(backtrack_glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN),
2926
        );
2927
0
        start..end
2928
0
    }
2929
2930
0
    pub fn input_glyph_count_byte_range(&self) -> Range<usize> {
2931
0
        let start = self.backtrack_sequence_byte_range().end;
2932
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2933
0
        start..end
2934
0
    }
2935
2936
0
    pub fn input_sequence_byte_range(&self) -> Range<usize> {
2937
0
        let input_glyph_count = self.input_glyph_count();
2938
0
        let start = self.input_glyph_count_byte_range().end;
2939
0
        let end = start.saturating_add(
2940
0
            (transforms::subtract(input_glyph_count, 1_usize))
2941
0
                .saturating_mul(GlyphId16::RAW_BYTE_LEN),
2942
        );
2943
0
        start..end
2944
0
    }
2945
2946
0
    pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
2947
0
        let start = self.input_sequence_byte_range().end;
2948
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2949
0
        start..end
2950
0
    }
2951
2952
0
    pub fn lookahead_sequence_byte_range(&self) -> Range<usize> {
2953
0
        let lookahead_glyph_count = self.lookahead_glyph_count();
2954
0
        let start = self.lookahead_glyph_count_byte_range().end;
2955
0
        let end = start.saturating_add(
2956
0
            (transforms::to_usize(lookahead_glyph_count)).saturating_mul(GlyphId16::RAW_BYTE_LEN),
2957
        );
2958
0
        start..end
2959
0
    }
2960
2961
0
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
2962
0
        let start = self.lookahead_sequence_byte_range().end;
2963
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
2964
0
        start..end
2965
0
    }
2966
2967
0
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
2968
0
        let seq_lookup_count = self.seq_lookup_count();
2969
0
        let start = self.seq_lookup_count_byte_range().end;
2970
0
        let end = start.saturating_add(
2971
0
            (transforms::to_usize(seq_lookup_count))
2972
0
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
2973
        );
2974
0
        start..end
2975
0
    }
2976
}
2977
2978
const _: () = assert!(FontData::default_data_long_enough(
2979
    ChainedSequenceRule::MIN_SIZE
2980
));
2981
2982
impl Default for ChainedSequenceRule<'_> {
2983
0
    fn default() -> Self {
2984
        Self {
2985
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
2986
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
2987
        }
2988
0
    }
2989
}
2990
2991
impl Format<u16> for ChainedSequenceContextFormat2<'_> {
2992
    const FORMAT: u16 = 2;
2993
}
2994
2995
impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat2<'a> {
2996
0
    fn min_byte_range(&self) -> Range<usize> {
2997
0
        0..self.chained_class_seq_rule_set_offsets_byte_range().end
2998
0
    }
2999
0
    fn min_table_bytes(&self) -> &'a [u8] {
3000
0
        let range = self.min_byte_range();
3001
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3002
0
    }
3003
}
3004
3005
impl ReadArgs for ChainedSequenceContextFormat2<'_> {
3006
    type Args = ();
3007
}
3008
3009
impl<'a> FontRead<'a> for ChainedSequenceContextFormat2<'a> {
3010
32.2k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3011
        #[allow(clippy::absurd_extreme_comparisons)]
3012
32.2k
        if data.len() < Self::MIN_SIZE {
3013
468
            return Err(ReadError::OutOfBounds);
3014
31.7k
        }
3015
31.7k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3016
0
            return Err(ReadError::OutOfBounds);
3017
        };
3018
31.7k
        Ok(Self { data })
3019
32.2k
    }
3020
}
3021
3022
/// The fields at the start of the table, which are read directly.
3023
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3024
#[repr(C, packed)]
3025
#[doc(hidden)]
3026
pub struct ChainedSequenceContextFormat2FixedHeader {
3027
    pub format: BigEndian<u16>,
3028
    pub coverage_offset: BigEndian<Offset16>,
3029
    pub backtrack_class_def_offset: BigEndian<Offset16>,
3030
    pub input_class_def_offset: BigEndian<Offset16>,
3031
    pub lookahead_class_def_offset: BigEndian<Offset16>,
3032
    pub chained_class_seq_rule_set_count: BigEndian<u16>,
3033
}
3034
3035
#[allow(clippy::absurd_extreme_comparisons)]
3036
const _: () = assert!(
3037
    std::mem::size_of::<ChainedSequenceContextFormat2FixedHeader>()
3038
        <= ChainedSequenceContextFormat2::MIN_SIZE
3039
);
3040
3041
/// [Chained Sequence Context Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chained-sequence-context-format-2-class-based-glyph-contexts)
3042
#[derive(Clone)]
3043
pub struct ChainedSequenceContextFormat2<'a> {
3044
    data: TableDataRef<'a, ChainedSequenceContextFormat2FixedHeader>,
3045
}
3046
3047
#[allow(clippy::needless_lifetimes)]
3048
impl<'a> ChainedSequenceContextFormat2<'a> {
3049
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
3050
        + Offset16::RAW_BYTE_LEN
3051
        + Offset16::RAW_BYTE_LEN
3052
        + Offset16::RAW_BYTE_LEN
3053
        + Offset16::RAW_BYTE_LEN
3054
        + u16::RAW_BYTE_LEN);
3055
    basic_table_impls!(impl_the_methods);
3056
3057
    /// Format identifier: format = 2
3058
0
    pub fn format(&self) -> u16 {
3059
0
        self.data.header().format.get()
3060
0
    }
3061
3062
    /// Offset to Coverage table, from beginning of
3063
    /// ChainedSequenceContextFormat2 table
3064
31.7k
    pub fn coverage_offset(&self) -> Offset16 {
3065
31.7k
        self.data.header().coverage_offset.get()
3066
31.7k
    }
3067
3068
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
3069
31.7k
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
3070
31.7k
        let data = self.offset_data();
3071
31.7k
        self.coverage_offset().resolve(data)
3072
31.7k
    }
3073
3074
    /// Offset to ClassDef table containing backtrack sequence context,
3075
    /// from beginning of ChainedSequenceContextFormat2 table
3076
31.7k
    pub fn backtrack_class_def_offset(&self) -> Offset16 {
3077
31.7k
        self.data.header().backtrack_class_def_offset.get()
3078
31.7k
    }
3079
3080
    /// Attempt to resolve [`backtrack_class_def_offset`][Self::backtrack_class_def_offset].
3081
31.7k
    pub fn backtrack_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
3082
31.7k
        let data = self.offset_data();
3083
31.7k
        self.backtrack_class_def_offset().resolve(data)
3084
31.7k
    }
3085
3086
    /// Offset to ClassDef table containing input sequence context,
3087
    /// from beginning of ChainedSequenceContextFormat2 table
3088
31.7k
    pub fn input_class_def_offset(&self) -> Offset16 {
3089
31.7k
        self.data.header().input_class_def_offset.get()
3090
31.7k
    }
3091
3092
    /// Attempt to resolve [`input_class_def_offset`][Self::input_class_def_offset].
3093
31.7k
    pub fn input_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
3094
31.7k
        let data = self.offset_data();
3095
31.7k
        self.input_class_def_offset().resolve(data)
3096
31.7k
    }
3097
3098
    /// Offset to ClassDef table containing lookahead sequence context,
3099
    /// from beginning of ChainedSequenceContextFormat2 table
3100
31.7k
    pub fn lookahead_class_def_offset(&self) -> Offset16 {
3101
31.7k
        self.data.header().lookahead_class_def_offset.get()
3102
31.7k
    }
3103
3104
    /// Attempt to resolve [`lookahead_class_def_offset`][Self::lookahead_class_def_offset].
3105
31.7k
    pub fn lookahead_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
3106
31.7k
        let data = self.offset_data();
3107
31.7k
        self.lookahead_class_def_offset().resolve(data)
3108
31.7k
    }
3109
3110
    /// Number of ChainedClassSequenceRuleSet tables
3111
31.7k
    pub fn chained_class_seq_rule_set_count(&self) -> u16 {
3112
31.7k
        self.data.header().chained_class_seq_rule_set_count.get()
3113
31.7k
    }
3114
3115
    /// Array of offsets to ChainedClassSequenceRuleSet tables, from
3116
    /// beginning of ChainedSequenceContextFormat2 table (may be NULL)
3117
0
    pub fn chained_class_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset16>>] {
3118
0
        let range = self.chained_class_seq_rule_set_offsets_byte_range();
3119
0
        self.offset_data()
3120
0
            .read_array(range)
3121
0
            .ok()
3122
0
            .unwrap_or_default()
3123
0
    }
3124
3125
    /// A dynamically resolving wrapper for [`chained_class_seq_rule_set_offsets`][Self::chained_class_seq_rule_set_offsets].
3126
0
    pub fn chained_class_seq_rule_sets(
3127
0
        &self,
3128
0
    ) -> ArrayOfNullableOffsets<'a, ChainedClassSequenceRuleSet<'a>, Offset16> {
3129
0
        let data = self.offset_data();
3130
0
        let offsets = self.chained_class_seq_rule_set_offsets();
3131
0
        ArrayOfNullableOffsets::new(offsets, data, ())
3132
0
    }
3133
3134
31.7k
    pub fn format_byte_range(&self) -> Range<usize> {
3135
31.7k
        let start = 0usize;
3136
31.7k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3137
31.7k
        start..end
3138
31.7k
    }
3139
3140
31.7k
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
3141
31.7k
        let start = self.format_byte_range().end;
3142
31.7k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
3143
31.7k
        start..end
3144
31.7k
    }
3145
3146
31.7k
    pub fn backtrack_class_def_offset_byte_range(&self) -> Range<usize> {
3147
31.7k
        let start = self.coverage_offset_byte_range().end;
3148
31.7k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
3149
31.7k
        start..end
3150
31.7k
    }
3151
3152
31.7k
    pub fn input_class_def_offset_byte_range(&self) -> Range<usize> {
3153
31.7k
        let start = self.backtrack_class_def_offset_byte_range().end;
3154
31.7k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
3155
31.7k
        start..end
3156
31.7k
    }
3157
3158
31.7k
    pub fn lookahead_class_def_offset_byte_range(&self) -> Range<usize> {
3159
31.7k
        let start = self.input_class_def_offset_byte_range().end;
3160
31.7k
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
3161
31.7k
        start..end
3162
31.7k
    }
3163
3164
31.7k
    pub fn chained_class_seq_rule_set_count_byte_range(&self) -> Range<usize> {
3165
31.7k
        let start = self.lookahead_class_def_offset_byte_range().end;
3166
31.7k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3167
31.7k
        start..end
3168
31.7k
    }
3169
3170
31.7k
    pub fn chained_class_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
3171
31.7k
        let chained_class_seq_rule_set_count = self.chained_class_seq_rule_set_count();
3172
31.7k
        let start = self.chained_class_seq_rule_set_count_byte_range().end;
3173
31.7k
        let end = start.saturating_add(
3174
31.7k
            (transforms::to_usize(chained_class_seq_rule_set_count))
3175
31.7k
                .saturating_mul(Offset16::RAW_BYTE_LEN),
3176
        );
3177
31.7k
        start..end
3178
31.7k
    }
3179
}
3180
3181
impl<'a> MinByteRange<'a> for ChainedClassSequenceRuleSet<'a> {
3182
0
    fn min_byte_range(&self) -> Range<usize> {
3183
0
        0..self.chained_class_seq_rule_offsets_byte_range().end
3184
0
    }
3185
0
    fn min_table_bytes(&self) -> &'a [u8] {
3186
0
        let range = self.min_byte_range();
3187
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3188
0
    }
3189
}
3190
3191
impl ReadArgs for ChainedClassSequenceRuleSet<'_> {
3192
    type Args = ();
3193
}
3194
3195
impl<'a> FontRead<'a> for ChainedClassSequenceRuleSet<'a> {
3196
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3197
        #[allow(clippy::absurd_extreme_comparisons)]
3198
0
        if data.len() < Self::MIN_SIZE {
3199
0
            return Err(ReadError::OutOfBounds);
3200
0
        }
3201
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3202
0
            return Err(ReadError::OutOfBounds);
3203
        };
3204
0
        Ok(Self { data })
3205
0
    }
3206
}
3207
3208
/// The fields at the start of the table, which are read directly.
3209
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3210
#[repr(C, packed)]
3211
#[doc(hidden)]
3212
pub struct ChainedClassSequenceRuleSetFixedHeader {
3213
    pub chained_class_seq_rule_count: BigEndian<u16>,
3214
}
3215
3216
#[allow(clippy::absurd_extreme_comparisons)]
3217
const _: () = assert!(
3218
    std::mem::size_of::<ChainedClassSequenceRuleSetFixedHeader>()
3219
        <= ChainedClassSequenceRuleSet::MIN_SIZE
3220
);
3221
3222
/// Part of [ChainedSequenceContextFormat2]
3223
#[derive(Clone)]
3224
pub struct ChainedClassSequenceRuleSet<'a> {
3225
    data: TableDataRef<'a, ChainedClassSequenceRuleSetFixedHeader>,
3226
}
3227
3228
#[allow(clippy::needless_lifetimes)]
3229
impl<'a> ChainedClassSequenceRuleSet<'a> {
3230
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
3231
    basic_table_impls!(impl_the_methods);
3232
3233
    /// Number of ChainedClassSequenceRule tables
3234
0
    pub fn chained_class_seq_rule_count(&self) -> u16 {
3235
0
        self.data.header().chained_class_seq_rule_count.get()
3236
0
    }
3237
3238
    /// Array of offsets to ChainedClassSequenceRule tables, from
3239
    /// beginning of ChainedClassSequenceRuleSet
3240
0
    pub fn chained_class_seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
3241
0
        let range = self.chained_class_seq_rule_offsets_byte_range();
3242
0
        self.offset_data()
3243
0
            .read_array(range)
3244
0
            .ok()
3245
0
            .unwrap_or_default()
3246
0
    }
3247
3248
    /// A dynamically resolving wrapper for [`chained_class_seq_rule_offsets`][Self::chained_class_seq_rule_offsets].
3249
0
    pub fn chained_class_seq_rules(
3250
0
        &self,
3251
0
    ) -> ArrayOfOffsets<'a, ChainedClassSequenceRule<'a>, Offset16> {
3252
0
        let data = self.offset_data();
3253
0
        let offsets = self.chained_class_seq_rule_offsets();
3254
0
        ArrayOfOffsets::new(offsets, data, ())
3255
0
    }
3256
3257
0
    pub fn chained_class_seq_rule_count_byte_range(&self) -> Range<usize> {
3258
0
        let start = 0usize;
3259
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3260
0
        start..end
3261
0
    }
3262
3263
0
    pub fn chained_class_seq_rule_offsets_byte_range(&self) -> Range<usize> {
3264
0
        let chained_class_seq_rule_count = self.chained_class_seq_rule_count();
3265
0
        let start = self.chained_class_seq_rule_count_byte_range().end;
3266
0
        let end = start.saturating_add(
3267
0
            (transforms::to_usize(chained_class_seq_rule_count))
3268
0
                .saturating_mul(Offset16::RAW_BYTE_LEN),
3269
        );
3270
0
        start..end
3271
0
    }
3272
}
3273
3274
const _: () = assert!(FontData::default_data_long_enough(
3275
    ChainedClassSequenceRuleSet::MIN_SIZE
3276
));
3277
3278
impl Default for ChainedClassSequenceRuleSet<'_> {
3279
0
    fn default() -> Self {
3280
        Self {
3281
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
3282
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3283
        }
3284
0
    }
3285
}
3286
3287
impl<'a> MinByteRange<'a> for ChainedClassSequenceRule<'a> {
3288
0
    fn min_byte_range(&self) -> Range<usize> {
3289
0
        0..self.seq_lookup_records_byte_range().end
3290
0
    }
3291
0
    fn min_table_bytes(&self) -> &'a [u8] {
3292
0
        let range = self.min_byte_range();
3293
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3294
0
    }
3295
}
3296
3297
impl ReadArgs for ChainedClassSequenceRule<'_> {
3298
    type Args = ();
3299
}
3300
3301
impl<'a> FontRead<'a> for ChainedClassSequenceRule<'a> {
3302
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3303
        #[allow(clippy::absurd_extreme_comparisons)]
3304
0
        if data.len() < Self::MIN_SIZE {
3305
0
            return Err(ReadError::OutOfBounds);
3306
0
        }
3307
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3308
0
            return Err(ReadError::OutOfBounds);
3309
        };
3310
0
        Ok(Self { data })
3311
0
    }
3312
}
3313
3314
/// The fields at the start of the table, which are read directly.
3315
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3316
#[repr(C, packed)]
3317
#[doc(hidden)]
3318
pub struct ChainedClassSequenceRuleFixedHeader {
3319
    pub backtrack_glyph_count: BigEndian<u16>,
3320
}
3321
3322
#[allow(clippy::absurd_extreme_comparisons)]
3323
const _: () = assert!(
3324
    std::mem::size_of::<ChainedClassSequenceRuleFixedHeader>()
3325
        <= ChainedClassSequenceRule::MIN_SIZE
3326
);
3327
3328
/// Part of [ChainedSequenceContextFormat2]
3329
#[derive(Clone)]
3330
pub struct ChainedClassSequenceRule<'a> {
3331
    data: TableDataRef<'a, ChainedClassSequenceRuleFixedHeader>,
3332
}
3333
3334
#[allow(clippy::needless_lifetimes)]
3335
impl<'a> ChainedClassSequenceRule<'a> {
3336
    pub const MIN_SIZE: usize =
3337
        (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
3338
    basic_table_impls!(impl_the_methods);
3339
3340
    /// Number of glyphs in the backtrack sequence
3341
0
    pub fn backtrack_glyph_count(&self) -> u16 {
3342
0
        self.data.header().backtrack_glyph_count.get()
3343
0
    }
3344
3345
    /// Array of backtrack-sequence classes
3346
0
    pub fn backtrack_sequence(&self) -> &'a [BigEndian<u16>] {
3347
0
        let range = self.backtrack_sequence_byte_range();
3348
0
        self.offset_data()
3349
0
            .read_array(range)
3350
0
            .ok()
3351
0
            .unwrap_or_default()
3352
0
    }
3353
3354
    /// Total number of glyphs in the input sequence
3355
0
    pub fn input_glyph_count(&self) -> u16 {
3356
0
        let range = self.input_glyph_count_byte_range();
3357
0
        self.offset_data()
3358
0
            .read_at(range.start)
3359
0
            .ok()
3360
0
            .unwrap_or_default()
3361
0
    }
3362
3363
    /// Array of input sequence classes, beginning with the second
3364
    /// glyph position
3365
0
    pub fn input_sequence(&self) -> &'a [BigEndian<u16>] {
3366
0
        let range = self.input_sequence_byte_range();
3367
0
        self.offset_data()
3368
0
            .read_array(range)
3369
0
            .ok()
3370
0
            .unwrap_or_default()
3371
0
    }
3372
3373
    /// Number of glyphs in the lookahead sequence
3374
0
    pub fn lookahead_glyph_count(&self) -> u16 {
3375
0
        let range = self.lookahead_glyph_count_byte_range();
3376
0
        self.offset_data()
3377
0
            .read_at(range.start)
3378
0
            .ok()
3379
0
            .unwrap_or_default()
3380
0
    }
3381
3382
    /// Array of lookahead-sequence classes
3383
0
    pub fn lookahead_sequence(&self) -> &'a [BigEndian<u16>] {
3384
0
        let range = self.lookahead_sequence_byte_range();
3385
0
        self.offset_data()
3386
0
            .read_array(range)
3387
0
            .ok()
3388
0
            .unwrap_or_default()
3389
0
    }
3390
3391
    /// Number of SequenceLookupRecords
3392
0
    pub fn seq_lookup_count(&self) -> u16 {
3393
0
        let range = self.seq_lookup_count_byte_range();
3394
0
        self.offset_data()
3395
0
            .read_at(range.start)
3396
0
            .ok()
3397
0
            .unwrap_or_default()
3398
0
    }
3399
3400
    /// Array of SequenceLookupRecords
3401
0
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
3402
0
        let range = self.seq_lookup_records_byte_range();
3403
0
        self.offset_data()
3404
0
            .read_array(range)
3405
0
            .ok()
3406
0
            .unwrap_or_default()
3407
0
    }
3408
3409
0
    pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
3410
0
        let start = 0usize;
3411
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3412
0
        start..end
3413
0
    }
3414
3415
0
    pub fn backtrack_sequence_byte_range(&self) -> Range<usize> {
3416
0
        let backtrack_glyph_count = self.backtrack_glyph_count();
3417
0
        let start = self.backtrack_glyph_count_byte_range().end;
3418
0
        let end = start.saturating_add(
3419
0
            (transforms::to_usize(backtrack_glyph_count)).saturating_mul(u16::RAW_BYTE_LEN),
3420
        );
3421
0
        start..end
3422
0
    }
3423
3424
0
    pub fn input_glyph_count_byte_range(&self) -> Range<usize> {
3425
0
        let start = self.backtrack_sequence_byte_range().end;
3426
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3427
0
        start..end
3428
0
    }
3429
3430
0
    pub fn input_sequence_byte_range(&self) -> Range<usize> {
3431
0
        let input_glyph_count = self.input_glyph_count();
3432
0
        let start = self.input_glyph_count_byte_range().end;
3433
0
        let end = start.saturating_add(
3434
0
            (transforms::subtract(input_glyph_count, 1_usize)).saturating_mul(u16::RAW_BYTE_LEN),
3435
        );
3436
0
        start..end
3437
0
    }
3438
3439
0
    pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
3440
0
        let start = self.input_sequence_byte_range().end;
3441
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3442
0
        start..end
3443
0
    }
3444
3445
0
    pub fn lookahead_sequence_byte_range(&self) -> Range<usize> {
3446
0
        let lookahead_glyph_count = self.lookahead_glyph_count();
3447
0
        let start = self.lookahead_glyph_count_byte_range().end;
3448
0
        let end = start.saturating_add(
3449
0
            (transforms::to_usize(lookahead_glyph_count)).saturating_mul(u16::RAW_BYTE_LEN),
3450
        );
3451
0
        start..end
3452
0
    }
3453
3454
0
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
3455
0
        let start = self.lookahead_sequence_byte_range().end;
3456
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3457
0
        start..end
3458
0
    }
3459
3460
0
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
3461
0
        let seq_lookup_count = self.seq_lookup_count();
3462
0
        let start = self.seq_lookup_count_byte_range().end;
3463
0
        let end = start.saturating_add(
3464
0
            (transforms::to_usize(seq_lookup_count))
3465
0
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
3466
        );
3467
0
        start..end
3468
0
    }
3469
}
3470
3471
const _: () = assert!(FontData::default_data_long_enough(
3472
    ChainedClassSequenceRule::MIN_SIZE
3473
));
3474
3475
impl Default for ChainedClassSequenceRule<'_> {
3476
0
    fn default() -> Self {
3477
        Self {
3478
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
3479
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3480
        }
3481
0
    }
3482
}
3483
3484
impl Format<u16> for ChainedSequenceContextFormat3<'_> {
3485
    const FORMAT: u16 = 3;
3486
}
3487
3488
impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat3<'a> {
3489
0
    fn min_byte_range(&self) -> Range<usize> {
3490
0
        0..self.seq_lookup_records_byte_range().end
3491
0
    }
3492
0
    fn min_table_bytes(&self) -> &'a [u8] {
3493
0
        let range = self.min_byte_range();
3494
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3495
0
    }
3496
}
3497
3498
impl ReadArgs for ChainedSequenceContextFormat3<'_> {
3499
    type Args = ();
3500
}
3501
3502
impl<'a> FontRead<'a> for ChainedSequenceContextFormat3<'a> {
3503
18.6k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3504
        #[allow(clippy::absurd_extreme_comparisons)]
3505
18.6k
        if data.len() < Self::MIN_SIZE {
3506
408
            return Err(ReadError::OutOfBounds);
3507
18.2k
        }
3508
18.2k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3509
0
            return Err(ReadError::OutOfBounds);
3510
        };
3511
18.2k
        Ok(Self { data })
3512
18.6k
    }
3513
}
3514
3515
/// The fields at the start of the table, which are read directly.
3516
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3517
#[repr(C, packed)]
3518
#[doc(hidden)]
3519
pub struct ChainedSequenceContextFormat3FixedHeader {
3520
    pub format: BigEndian<u16>,
3521
    pub backtrack_glyph_count: BigEndian<u16>,
3522
}
3523
3524
#[allow(clippy::absurd_extreme_comparisons)]
3525
const _: () = assert!(
3526
    std::mem::size_of::<ChainedSequenceContextFormat3FixedHeader>()
3527
        <= ChainedSequenceContextFormat3::MIN_SIZE
3528
);
3529
3530
/// [Chained Sequence Context Format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chained-sequence-context-format-3-coverage-based-glyph-contexts)
3531
#[derive(Clone)]
3532
pub struct ChainedSequenceContextFormat3<'a> {
3533
    data: TableDataRef<'a, ChainedSequenceContextFormat3FixedHeader>,
3534
}
3535
3536
#[allow(clippy::needless_lifetimes)]
3537
impl<'a> ChainedSequenceContextFormat3<'a> {
3538
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
3539
        + u16::RAW_BYTE_LEN
3540
        + u16::RAW_BYTE_LEN
3541
        + u16::RAW_BYTE_LEN
3542
        + u16::RAW_BYTE_LEN);
3543
    basic_table_impls!(impl_the_methods);
3544
3545
    /// Format identifier: format = 3
3546
0
    pub fn format(&self) -> u16 {
3547
0
        self.data.header().format.get()
3548
0
    }
3549
3550
    /// Number of glyphs in the backtrack sequence
3551
449k
    pub fn backtrack_glyph_count(&self) -> u16 {
3552
449k
        self.data.header().backtrack_glyph_count.get()
3553
449k
    }
3554
3555
    /// Array of offsets to coverage tables for the backtrack sequence
3556
0
    pub fn backtrack_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
3557
0
        let range = self.backtrack_coverage_offsets_byte_range();
3558
0
        self.offset_data()
3559
0
            .read_array(range)
3560
0
            .ok()
3561
0
            .unwrap_or_default()
3562
0
    }
3563
3564
    /// A dynamically resolving wrapper for [`backtrack_coverage_offsets`][Self::backtrack_coverage_offsets].
3565
0
    pub fn backtrack_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
3566
0
        let data = self.offset_data();
3567
0
        let offsets = self.backtrack_coverage_offsets();
3568
0
        ArrayOfOffsets::new(offsets, data, ())
3569
0
    }
3570
3571
    /// Number of glyphs in the input sequence
3572
215k
    pub fn input_glyph_count(&self) -> u16 {
3573
215k
        let range = self.input_glyph_count_byte_range();
3574
215k
        self.offset_data()
3575
215k
            .read_at(range.start)
3576
215k
            .ok()
3577
215k
            .unwrap_or_default()
3578
215k
    }
3579
3580
    /// Array of offsets to coverage tables for the input sequence
3581
18.2k
    pub fn input_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
3582
18.2k
        let range = self.input_coverage_offsets_byte_range();
3583
18.2k
        self.offset_data()
3584
18.2k
            .read_array(range)
3585
18.2k
            .ok()
3586
18.2k
            .unwrap_or_default()
3587
18.2k
    }
3588
3589
    /// A dynamically resolving wrapper for [`input_coverage_offsets`][Self::input_coverage_offsets].
3590
18.2k
    pub fn input_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
3591
18.2k
        let data = self.offset_data();
3592
18.2k
        let offsets = self.input_coverage_offsets();
3593
18.2k
        ArrayOfOffsets::new(offsets, data, ())
3594
18.2k
    }
3595
3596
    /// Number of glyphs in the lookahead sequence
3597
89.5k
    pub fn lookahead_glyph_count(&self) -> u16 {
3598
89.5k
        let range = self.lookahead_glyph_count_byte_range();
3599
89.5k
        self.offset_data()
3600
89.5k
            .read_at(range.start)
3601
89.5k
            .ok()
3602
89.5k
            .unwrap_or_default()
3603
89.5k
    }
3604
3605
    /// Array of offsets to coverage tables for the lookahead sequence
3606
0
    pub fn lookahead_coverage_offsets(&self) -> &'a [BigEndian<Offset16>] {
3607
0
        let range = self.lookahead_coverage_offsets_byte_range();
3608
0
        self.offset_data()
3609
0
            .read_array(range)
3610
0
            .ok()
3611
0
            .unwrap_or_default()
3612
0
    }
3613
3614
    /// A dynamically resolving wrapper for [`lookahead_coverage_offsets`][Self::lookahead_coverage_offsets].
3615
0
    pub fn lookahead_coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset16> {
3616
0
        let data = self.offset_data();
3617
0
        let offsets = self.lookahead_coverage_offsets();
3618
0
        ArrayOfOffsets::new(offsets, data, ())
3619
0
    }
3620
3621
    /// Number of SequenceLookupRecords
3622
35.8k
    pub fn seq_lookup_count(&self) -> u16 {
3623
35.8k
        let range = self.seq_lookup_count_byte_range();
3624
35.8k
        self.offset_data()
3625
35.8k
            .read_at(range.start)
3626
35.8k
            .ok()
3627
35.8k
            .unwrap_or_default()
3628
35.8k
    }
3629
3630
    /// Array of SequenceLookupRecords
3631
35.8k
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
3632
35.8k
        let range = self.seq_lookup_records_byte_range();
3633
35.8k
        self.offset_data()
3634
35.8k
            .read_array(range)
3635
35.8k
            .ok()
3636
35.8k
            .unwrap_or_default()
3637
35.8k
    }
3638
3639
449k
    pub fn format_byte_range(&self) -> Range<usize> {
3640
449k
        let start = 0usize;
3641
449k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3642
449k
        start..end
3643
449k
    }
3644
3645
449k
    pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
3646
449k
        let start = self.format_byte_range().end;
3647
449k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3648
449k
        start..end
3649
449k
    }
3650
3651
449k
    pub fn backtrack_coverage_offsets_byte_range(&self) -> Range<usize> {
3652
449k
        let backtrack_glyph_count = self.backtrack_glyph_count();
3653
449k
        let start = self.backtrack_glyph_count_byte_range().end;
3654
449k
        let end = start.saturating_add(
3655
449k
            (transforms::to_usize(backtrack_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
3656
        );
3657
449k
        start..end
3658
449k
    }
3659
3660
430k
    pub fn input_glyph_count_byte_range(&self) -> Range<usize> {
3661
430k
        let start = self.backtrack_coverage_offsets_byte_range().end;
3662
430k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3663
430k
        start..end
3664
430k
    }
3665
3666
215k
    pub fn input_coverage_offsets_byte_range(&self) -> Range<usize> {
3667
215k
        let input_glyph_count = self.input_glyph_count();
3668
215k
        let start = self.input_glyph_count_byte_range().end;
3669
215k
        let end = start.saturating_add(
3670
215k
            (transforms::to_usize(input_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
3671
        );
3672
215k
        start..end
3673
215k
    }
3674
3675
179k
    pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
3676
179k
        let start = self.input_coverage_offsets_byte_range().end;
3677
179k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3678
179k
        start..end
3679
179k
    }
3680
3681
89.5k
    pub fn lookahead_coverage_offsets_byte_range(&self) -> Range<usize> {
3682
89.5k
        let lookahead_glyph_count = self.lookahead_glyph_count();
3683
89.5k
        let start = self.lookahead_glyph_count_byte_range().end;
3684
89.5k
        let end = start.saturating_add(
3685
89.5k
            (transforms::to_usize(lookahead_glyph_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
3686
        );
3687
89.5k
        start..end
3688
89.5k
    }
3689
3690
71.6k
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
3691
71.6k
        let start = self.lookahead_coverage_offsets_byte_range().end;
3692
71.6k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3693
71.6k
        start..end
3694
71.6k
    }
3695
3696
35.8k
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
3697
35.8k
        let seq_lookup_count = self.seq_lookup_count();
3698
35.8k
        let start = self.seq_lookup_count_byte_range().end;
3699
35.8k
        let end = start.saturating_add(
3700
35.8k
            (transforms::to_usize(seq_lookup_count))
3701
35.8k
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
3702
        );
3703
35.8k
        start..end
3704
35.8k
    }
3705
}
3706
3707
#[derive(Clone)]
3708
pub enum ChainedSequenceContext<'a> {
3709
    Format1(ChainedSequenceContextFormat1<'a>),
3710
    Format2(ChainedSequenceContextFormat2<'a>),
3711
    Format3(ChainedSequenceContextFormat3<'a>),
3712
    Format4(ChainedSequenceContextFormat4<'a>),
3713
    Format5(ChainedSequenceContextFormat5<'a>),
3714
}
3715
3716
impl Default for ChainedSequenceContext<'_> {
3717
0
    fn default() -> Self {
3718
0
        Self::Format1(Default::default())
3719
0
    }
3720
}
3721
3722
impl<'a> ChainedSequenceContext<'a> {
3723
    ///Return the `FontData` used to resolve offsets for this table.
3724
0
    pub fn offset_data(&self) -> FontData<'a> {
3725
0
        match self {
3726
0
            Self::Format1(item) => item.offset_data(),
3727
0
            Self::Format2(item) => item.offset_data(),
3728
0
            Self::Format3(item) => item.offset_data(),
3729
0
            Self::Format4(item) => item.offset_data(),
3730
0
            Self::Format5(item) => item.offset_data(),
3731
        }
3732
0
    }
3733
3734
    /// Format identifier: format = 1
3735
0
    pub fn format(&self) -> u16 {
3736
0
        match self {
3737
0
            Self::Format1(item) => item.format(),
3738
0
            Self::Format2(item) => item.format(),
3739
0
            Self::Format3(item) => item.format(),
3740
0
            Self::Format4(item) => item.format(),
3741
0
            Self::Format5(item) => item.format(),
3742
        }
3743
0
    }
3744
}
3745
3746
impl ReadArgs for ChainedSequenceContext<'_> {
3747
    type Args = ();
3748
}
3749
3750
impl<'a> FontRead<'a> for ChainedSequenceContext<'a> {
3751
    #[inline]
3752
683k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3753
683k
        let format: u16 = data.read_at(0usize)?;
3754
683k
        match format {
3755
28.5k
            ChainedSequenceContextFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
3756
32.2k
            ChainedSequenceContextFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
3757
18.6k
            ChainedSequenceContextFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
3758
9.75k
            ChainedSequenceContextFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
3759
8.83k
            ChainedSequenceContextFormat5::FORMAT => Ok(Self::Format5(FontRead::read(data)?)),
3760
585k
            other => Err(ReadError::InvalidFormat(other.into())),
3761
        }
3762
683k
    }
<read_fonts::tables::layout::ChainedSequenceContext as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
3752
683k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3753
683k
        let format: u16 = data.read_at(0usize)?;
3754
683k
        match format {
3755
28.5k
            ChainedSequenceContextFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
3756
32.2k
            ChainedSequenceContextFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
3757
18.6k
            ChainedSequenceContextFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
3758
9.75k
            ChainedSequenceContextFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
3759
8.83k
            ChainedSequenceContextFormat5::FORMAT => Ok(Self::Format5(FontRead::read(data)?)),
3760
585k
            other => Err(ReadError::InvalidFormat(other.into())),
3761
        }
3762
683k
    }
Unexecuted instantiation: <read_fonts::tables::layout::ChainedSequenceContext as read_fonts::read::FontRead>::read_with_args
3763
}
3764
3765
impl<'a> MinByteRange<'a> for ChainedSequenceContext<'a> {
3766
0
    fn min_byte_range(&self) -> Range<usize> {
3767
0
        match self {
3768
0
            Self::Format1(item) => item.min_byte_range(),
3769
0
            Self::Format2(item) => item.min_byte_range(),
3770
0
            Self::Format3(item) => item.min_byte_range(),
3771
0
            Self::Format4(item) => item.min_byte_range(),
3772
0
            Self::Format5(item) => item.min_byte_range(),
3773
        }
3774
0
    }
3775
0
    fn min_table_bytes(&self) -> &'a [u8] {
3776
0
        match self {
3777
0
            Self::Format1(item) => item.min_table_bytes(),
3778
0
            Self::Format2(item) => item.min_table_bytes(),
3779
0
            Self::Format3(item) => item.min_table_bytes(),
3780
0
            Self::Format4(item) => item.min_table_bytes(),
3781
0
            Self::Format5(item) => item.min_table_bytes(),
3782
        }
3783
0
    }
3784
}
3785
3786
/// [Device](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#device-and-variationindex-tables)
3787
/// delta formats
3788
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
3789
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3790
#[repr(u16)]
3791
#[allow(clippy::manual_non_exhaustive)]
3792
pub enum DeltaFormat {
3793
    /// Signed 2-bit value, 8 values per uint16
3794
    #[default]
3795
    Local2BitDeltas = 0x0001,
3796
    /// Signed 4-bit value, 4 values per uint16
3797
    Local4BitDeltas = 0x0002,
3798
    /// Signed 8-bit value, 2 values per uint16
3799
    Local8BitDeltas = 0x0003,
3800
    /// VariationIndex table, contains a delta-set index pair.
3801
    VariationIndex = 0x8000,
3802
    #[doc(hidden)]
3803
    /// If font data is malformed we will map unknown values to this variant
3804
    Unknown,
3805
}
3806
3807
impl DeltaFormat {
3808
    /// Create from a raw scalar.
3809
    ///
3810
    /// This will never fail; unknown values will be mapped to the `Unknown` variant
3811
0
    pub fn new(raw: u16) -> Self {
3812
0
        match raw {
3813
0
            0x0001 => Self::Local2BitDeltas,
3814
0
            0x0002 => Self::Local4BitDeltas,
3815
0
            0x0003 => Self::Local8BitDeltas,
3816
0
            0x8000 => Self::VariationIndex,
3817
0
            _ => Self::Unknown,
3818
        }
3819
0
    }
3820
}
3821
3822
impl font_types::Scalar for DeltaFormat {
3823
    type Raw = <u16 as font_types::Scalar>::Raw;
3824
0
    fn to_raw(self) -> Self::Raw {
3825
0
        (self as u16).to_raw()
3826
0
    }
3827
0
    fn from_raw(raw: Self::Raw) -> Self {
3828
0
        let t = <u16>::from_raw(raw);
3829
0
        Self::new(t)
3830
0
    }
3831
}
3832
3833
impl<'a> MinByteRange<'a> for Device<'a> {
3834
0
    fn min_byte_range(&self) -> Range<usize> {
3835
0
        0..self.delta_value_byte_range().end
3836
0
    }
3837
0
    fn min_table_bytes(&self) -> &'a [u8] {
3838
0
        let range = self.min_byte_range();
3839
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3840
0
    }
3841
}
3842
3843
impl ReadArgs for Device<'_> {
3844
    type Args = ();
3845
}
3846
3847
impl<'a> FontRead<'a> for Device<'a> {
3848
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3849
        #[allow(clippy::absurd_extreme_comparisons)]
3850
0
        if data.len() < Self::MIN_SIZE {
3851
0
            return Err(ReadError::OutOfBounds);
3852
0
        }
3853
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3854
0
            return Err(ReadError::OutOfBounds);
3855
        };
3856
0
        Ok(Self { data })
3857
0
    }
3858
}
3859
3860
/// The fields at the start of the table, which are read directly.
3861
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3862
#[repr(C, packed)]
3863
#[doc(hidden)]
3864
pub struct DeviceFixedHeader {
3865
    pub start_size: BigEndian<u16>,
3866
    pub end_size: BigEndian<u16>,
3867
    pub delta_format: BigEndian<DeltaFormat>,
3868
}
3869
3870
#[allow(clippy::absurd_extreme_comparisons)]
3871
const _: () = assert!(std::mem::size_of::<DeviceFixedHeader>() <= Device::MIN_SIZE);
3872
3873
/// [Device Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#device-and-variationindex-tables)
3874
#[derive(Clone)]
3875
pub struct Device<'a> {
3876
    data: TableDataRef<'a, DeviceFixedHeader>,
3877
}
3878
3879
#[allow(clippy::needless_lifetimes)]
3880
impl<'a> Device<'a> {
3881
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + DeltaFormat::RAW_BYTE_LEN);
3882
    basic_table_impls!(impl_the_methods);
3883
3884
    /// Smallest size to correct, in ppem
3885
0
    pub fn start_size(&self) -> u16 {
3886
0
        self.data.header().start_size.get()
3887
0
    }
3888
3889
    /// Largest size to correct, in ppem
3890
0
    pub fn end_size(&self) -> u16 {
3891
0
        self.data.header().end_size.get()
3892
0
    }
3893
3894
    /// Format of deltaValue array data: 0x0001, 0x0002, or 0x0003
3895
0
    pub fn delta_format(&self) -> DeltaFormat {
3896
0
        self.data.header().delta_format.get()
3897
0
    }
3898
3899
    /// Array of compressed data
3900
0
    pub fn delta_value(&self) -> &'a [BigEndian<u16>] {
3901
0
        let range = self.delta_value_byte_range();
3902
0
        self.offset_data()
3903
0
            .read_array(range)
3904
0
            .ok()
3905
0
            .unwrap_or_default()
3906
0
    }
3907
3908
0
    pub fn start_size_byte_range(&self) -> Range<usize> {
3909
0
        let start = 0usize;
3910
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3911
0
        start..end
3912
0
    }
3913
3914
0
    pub fn end_size_byte_range(&self) -> Range<usize> {
3915
0
        let start = self.start_size_byte_range().end;
3916
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
3917
0
        start..end
3918
0
    }
3919
3920
0
    pub fn delta_format_byte_range(&self) -> Range<usize> {
3921
0
        let start = self.end_size_byte_range().end;
3922
0
        let end = start.saturating_add(DeltaFormat::RAW_BYTE_LEN);
3923
0
        start..end
3924
0
    }
3925
3926
0
    pub fn delta_value_byte_range(&self) -> Range<usize> {
3927
0
        let delta_format = self.delta_format();
3928
0
        let start_size = self.start_size();
3929
0
        let end_size = self.end_size();
3930
0
        let start = self.delta_format_byte_range().end;
3931
0
        let end = start.saturating_add(
3932
0
            (DeltaFormat::value_count(delta_format, start_size, end_size))
3933
0
                .saturating_mul(u16::RAW_BYTE_LEN),
3934
        );
3935
0
        start..end
3936
0
    }
3937
}
3938
3939
const _: () = assert!(FontData::default_data_long_enough(Device::MIN_SIZE));
3940
3941
impl Default for Device<'_> {
3942
0
    fn default() -> Self {
3943
        Self {
3944
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
3945
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3946
        }
3947
0
    }
3948
}
3949
3950
impl<'a> MinByteRange<'a> for VariationIndex<'a> {
3951
0
    fn min_byte_range(&self) -> Range<usize> {
3952
0
        0..self.delta_format_byte_range().end
3953
0
    }
3954
0
    fn min_table_bytes(&self) -> &'a [u8] {
3955
0
        let range = self.min_byte_range();
3956
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3957
0
    }
3958
}
3959
3960
impl ReadArgs for VariationIndex<'_> {
3961
    type Args = ();
3962
}
3963
3964
impl<'a> FontRead<'a> for VariationIndex<'a> {
3965
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3966
        #[allow(clippy::absurd_extreme_comparisons)]
3967
0
        if data.len() < Self::MIN_SIZE {
3968
0
            return Err(ReadError::OutOfBounds);
3969
0
        }
3970
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3971
0
            return Err(ReadError::OutOfBounds);
3972
        };
3973
0
        Ok(Self { data })
3974
0
    }
3975
}
3976
3977
/// The fields at the start of the table, which are read directly.
3978
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3979
#[repr(C, packed)]
3980
#[doc(hidden)]
3981
pub struct VariationIndexFixedHeader {
3982
    pub delta_set_outer_index: BigEndian<u16>,
3983
    pub delta_set_inner_index: BigEndian<u16>,
3984
    pub delta_format: BigEndian<DeltaFormat>,
3985
}
3986
3987
#[allow(clippy::absurd_extreme_comparisons)]
3988
const _: () = assert!(std::mem::size_of::<VariationIndexFixedHeader>() <= VariationIndex::MIN_SIZE);
3989
3990
/// Variation index table
3991
#[derive(Clone)]
3992
pub struct VariationIndex<'a> {
3993
    data: TableDataRef<'a, VariationIndexFixedHeader>,
3994
}
3995
3996
#[allow(clippy::needless_lifetimes)]
3997
impl<'a> VariationIndex<'a> {
3998
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + DeltaFormat::RAW_BYTE_LEN);
3999
    basic_table_impls!(impl_the_methods);
4000
4001
    /// A delta-set outer index — used to select an item variation
4002
    /// data subtable within the item variation store.
4003
0
    pub fn delta_set_outer_index(&self) -> u16 {
4004
0
        self.data.header().delta_set_outer_index.get()
4005
0
    }
4006
4007
    /// A delta-set inner index — used to select a delta-set row
4008
    /// within an item variation data subtable.
4009
0
    pub fn delta_set_inner_index(&self) -> u16 {
4010
0
        self.data.header().delta_set_inner_index.get()
4011
0
    }
4012
4013
    /// Format, = 0x8000
4014
0
    pub fn delta_format(&self) -> DeltaFormat {
4015
0
        self.data.header().delta_format.get()
4016
0
    }
4017
4018
0
    pub fn delta_set_outer_index_byte_range(&self) -> Range<usize> {
4019
0
        let start = 0usize;
4020
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
4021
0
        start..end
4022
0
    }
4023
4024
0
    pub fn delta_set_inner_index_byte_range(&self) -> Range<usize> {
4025
0
        let start = self.delta_set_outer_index_byte_range().end;
4026
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
4027
0
        start..end
4028
0
    }
4029
4030
0
    pub fn delta_format_byte_range(&self) -> Range<usize> {
4031
0
        let start = self.delta_set_inner_index_byte_range().end;
4032
0
        let end = start.saturating_add(DeltaFormat::RAW_BYTE_LEN);
4033
0
        start..end
4034
0
    }
4035
}
4036
4037
const _: () = assert!(FontData::default_data_long_enough(VariationIndex::MIN_SIZE));
4038
4039
impl Default for VariationIndex<'_> {
4040
0
    fn default() -> Self {
4041
        Self {
4042
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
4043
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4044
        }
4045
0
    }
4046
}
4047
4048
/// Either a [Device] table (in a non-variable font) or a [VariationIndex] table (in a variable font)
4049
#[derive(Clone)]
4050
pub enum DeviceOrVariationIndex<'a> {
4051
    Device(Device<'a>),
4052
    VariationIndex(VariationIndex<'a>),
4053
}
4054
4055
impl Default for DeviceOrVariationIndex<'_> {
4056
0
    fn default() -> Self {
4057
0
        Self::Device(Default::default())
4058
0
    }
4059
}
4060
4061
impl<'a> DeviceOrVariationIndex<'a> {
4062
    ///Return the `FontData` used to resolve offsets for this table.
4063
0
    pub fn offset_data(&self) -> FontData<'a> {
4064
0
        match self {
4065
0
            Self::Device(item) => item.offset_data(),
4066
0
            Self::VariationIndex(item) => item.offset_data(),
4067
        }
4068
0
    }
4069
}
4070
4071
impl ReadArgs for DeviceOrVariationIndex<'_> {
4072
    type Args = ();
4073
}
4074
4075
impl<'a> FontRead<'a> for DeviceOrVariationIndex<'a> {
4076
    #[inline]
4077
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4078
0
        let format: DeltaFormat = data.read_at(4usize)?;
4079
4080
        #[allow(clippy::redundant_guards)]
4081
0
        match format {
4082
0
            format if format != DeltaFormat::VariationIndex => {
4083
0
                Ok(Self::Device(FontRead::read(data)?))
4084
            }
4085
0
            format if format == DeltaFormat::VariationIndex => {
4086
0
                Ok(Self::VariationIndex(FontRead::read(data)?))
4087
            }
4088
0
            other => Err(ReadError::InvalidFormat(other.into())),
4089
        }
4090
0
    }
4091
}
4092
4093
impl<'a> MinByteRange<'a> for DeviceOrVariationIndex<'a> {
4094
0
    fn min_byte_range(&self) -> Range<usize> {
4095
0
        match self {
4096
0
            Self::Device(item) => item.min_byte_range(),
4097
0
            Self::VariationIndex(item) => item.min_byte_range(),
4098
        }
4099
0
    }
4100
0
    fn min_table_bytes(&self) -> &'a [u8] {
4101
0
        match self {
4102
0
            Self::Device(item) => item.min_table_bytes(),
4103
0
            Self::VariationIndex(item) => item.min_table_bytes(),
4104
        }
4105
0
    }
4106
}
4107
4108
impl<'a> MinByteRange<'a> for FeatureVariations<'a> {
4109
0
    fn min_byte_range(&self) -> Range<usize> {
4110
0
        0..self.feature_variation_records_byte_range().end
4111
0
    }
4112
0
    fn min_table_bytes(&self) -> &'a [u8] {
4113
0
        let range = self.min_byte_range();
4114
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4115
0
    }
4116
}
4117
4118
impl ReadArgs for FeatureVariations<'_> {
4119
    type Args = ();
4120
}
4121
4122
impl<'a> FontRead<'a> for FeatureVariations<'a> {
4123
495
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4124
        #[allow(clippy::absurd_extreme_comparisons)]
4125
495
        if data.len() < Self::MIN_SIZE {
4126
0
            return Err(ReadError::OutOfBounds);
4127
495
        }
4128
495
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4129
0
            return Err(ReadError::OutOfBounds);
4130
        };
4131
495
        Ok(Self { data })
4132
495
    }
4133
}
4134
4135
/// The fields at the start of the table, which are read directly.
4136
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4137
#[repr(C, packed)]
4138
#[doc(hidden)]
4139
pub struct FeatureVariationsFixedHeader {
4140
    pub version: BigEndian<MajorMinor>,
4141
    pub feature_variation_record_count: BigEndian<u32>,
4142
}
4143
4144
#[allow(clippy::absurd_extreme_comparisons)]
4145
const _: () =
4146
    assert!(std::mem::size_of::<FeatureVariationsFixedHeader>() <= FeatureVariations::MIN_SIZE);
4147
4148
/// [FeatureVariations Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#featurevariations-table)
4149
/// Version 1.1 is defined in ISO/IEC 14496-22:2026, 6.2.11.
4150
#[derive(Clone)]
4151
pub struct FeatureVariations<'a> {
4152
    data: TableDataRef<'a, FeatureVariationsFixedHeader>,
4153
}
4154
4155
#[allow(clippy::needless_lifetimes)]
4156
impl<'a> FeatureVariations<'a> {
4157
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
4158
    basic_table_impls!(impl_the_methods);
4159
4160
1.64k
    pub fn version(&self) -> MajorMinor {
4161
1.64k
        self.data.header().version.get()
4162
1.64k
    }
4163
4164
    /// Number of feature variation records.
4165
1.59k
    pub fn feature_variation_record_count(&self) -> u32 {
4166
1.59k
        self.data.header().feature_variation_record_count.get()
4167
1.59k
    }
4168
4169
    /// Array of feature variation records.
4170
381
    pub fn feature_variation_records(&self) -> &'a [FeatureVariationRecord] {
4171
381
        let range = self.feature_variation_records_byte_range();
4172
381
        self.offset_data()
4173
381
            .read_array(range)
4174
381
            .ok()
4175
381
            .unwrap_or_default()
4176
381
    }
4177
4178
    /// Number of lookup variation records.
4179
407
    pub fn lookup_variation_record_count(&self) -> Option<u32> {
4180
407
        let range = self.lookup_variation_record_count_byte_range();
4181
407
        (!range.is_empty())
4182
407
            .then(|| self.offset_data().read_at(range.start).ok())
4183
407
            .flatten()
4184
407
    }
4185
4186
1.14k
    pub fn version_byte_range(&self) -> Range<usize> {
4187
1.14k
        let start = 0usize;
4188
1.14k
        let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
4189
1.14k
        start..end
4190
1.14k
    }
4191
4192
1.14k
    pub fn feature_variation_record_count_byte_range(&self) -> Range<usize> {
4193
1.14k
        let start = self.version_byte_range().end;
4194
1.14k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4195
1.14k
        start..end
4196
1.14k
    }
4197
4198
1.14k
    pub fn feature_variation_records_byte_range(&self) -> Range<usize> {
4199
1.14k
        let feature_variation_record_count = self.feature_variation_record_count();
4200
1.14k
        let start = self.feature_variation_record_count_byte_range().end;
4201
1.14k
        let end = start.saturating_add(
4202
1.14k
            (transforms::to_usize(feature_variation_record_count))
4203
1.14k
                .saturating_mul(FeatureVariationRecord::RAW_BYTE_LEN),
4204
        );
4205
1.14k
        start..end
4206
1.14k
    }
4207
4208
762
    pub fn lookup_variation_record_count_byte_range(&self) -> Range<usize> {
4209
762
        let start = self.feature_variation_records_byte_range().end;
4210
762
        let end = if self.version().compatible((1u16, 1u16)) {
4211
762
            start.saturating_add(u32::RAW_BYTE_LEN)
4212
        } else {
4213
0
            start
4214
        };
4215
762
        start..end
4216
762
    }
4217
4218
0
    pub fn lookup_variation_records_byte_range(&self) -> Range<usize> {
4219
0
        let lookup_variation_record_count =
4220
0
            self.lookup_variation_record_count().unwrap_or_default();
4221
0
        let start = self.lookup_variation_record_count_byte_range().end;
4222
0
        let end = if self.version().compatible((1u16, 1u16)) {
4223
0
            start.saturating_add(
4224
0
                (transforms::to_usize(lookup_variation_record_count))
4225
0
                    .saturating_mul(LookupVariationRecord::RAW_BYTE_LEN),
4226
            )
4227
        } else {
4228
0
            start
4229
        };
4230
0
        start..end
4231
0
    }
4232
}
4233
4234
const _: () = assert!(FontData::default_data_long_enough(
4235
    FeatureVariations::MIN_SIZE
4236
));
4237
4238
impl Default for FeatureVariations<'_> {
4239
0
    fn default() -> Self {
4240
        Self {
4241
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
4242
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4243
        }
4244
0
    }
4245
}
4246
4247
/// Part of [FeatureVariations]
4248
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
4249
#[repr(C)]
4250
#[repr(packed)]
4251
pub struct FeatureVariationRecord {
4252
    /// Offset to a condition set table, from beginning of
4253
    /// FeatureVariations table.
4254
    pub condition_set_offset: BigEndian<Nullable<Offset32>>,
4255
    /// Offset to a feature table substitution table, from beginning of
4256
    /// the FeatureVariations table.
4257
    pub feature_table_substitution_offset: BigEndian<Nullable<Offset32>>,
4258
}
4259
4260
impl FeatureVariationRecord {
4261
    /// Offset to a condition set table, from beginning of
4262
    /// FeatureVariations table.
4263
10.5k
    pub fn condition_set_offset(&self) -> Nullable<Offset32> {
4264
10.5k
        self.condition_set_offset.get()
4265
10.5k
    }
4266
4267
    /// Offset to a condition set table, from beginning of
4268
    /// FeatureVariations table.
4269
    ///
4270
    /// The `data` argument should be retrieved from the parent table
4271
    /// By calling its `offset_data` method.
4272
5.23k
    pub fn condition_set<'a>(
4273
5.23k
        &self,
4274
5.23k
        data: FontData<'a>,
4275
5.23k
    ) -> Option<Result<ConditionSet<'a>, ReadError>> {
4276
5.23k
        self.condition_set_offset().resolve(data)
4277
5.23k
    }
4278
4279
    /// Offset to a feature table substitution table, from beginning of
4280
    /// the FeatureVariations table.
4281
0
    pub fn feature_table_substitution_offset(&self) -> Nullable<Offset32> {
4282
0
        self.feature_table_substitution_offset.get()
4283
0
    }
4284
4285
    /// Offset to a feature table substitution table, from beginning of
4286
    /// the FeatureVariations table.
4287
    ///
4288
    /// The `data` argument should be retrieved from the parent table
4289
    /// By calling its `offset_data` method.
4290
0
    pub fn feature_table_substitution<'a>(
4291
0
        &self,
4292
0
        data: FontData<'a>,
4293
0
    ) -> Option<Result<FeatureTableSubstitution<'a>, ReadError>> {
4294
0
        self.feature_table_substitution_offset().resolve(data)
4295
0
    }
4296
}
4297
4298
impl FixedSize for FeatureVariationRecord {
4299
    const RAW_BYTE_LEN: usize = Offset32::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
4300
}
4301
4302
/// Lookup variations for one feature (ISO/IEC 14496-22:2026, 6.2.11).
4303
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
4304
#[repr(C)]
4305
#[repr(packed)]
4306
pub struct LookupVariationRecord {
4307
    pub feature_index: BigEndian<u16>,
4308
    /// Offset from the beginning of FeatureVariations.
4309
    pub feature_lookups_offset: BigEndian<Offset32>,
4310
}
4311
4312
impl LookupVariationRecord {
4313
354
    pub fn feature_index(&self) -> u16 {
4314
354
        self.feature_index.get()
4315
354
    }
4316
4317
    /// Offset from the beginning of FeatureVariations.
4318
0
    pub fn feature_lookups_offset(&self) -> Offset32 {
4319
0
        self.feature_lookups_offset.get()
4320
0
    }
4321
4322
    /// Offset from the beginning of FeatureVariations.
4323
    ///
4324
    /// The `data` argument should be retrieved from the parent table
4325
    /// By calling its `offset_data` method.
4326
0
    pub fn feature_lookups<'a>(&self, data: FontData<'a>) -> Result<FeatureLookups<'a>, ReadError> {
4327
0
        self.feature_lookups_offset().resolve(data)
4328
0
    }
4329
}
4330
4331
impl FixedSize for LookupVariationRecord {
4332
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
4333
}
4334
4335
impl<'a> MinByteRange<'a> for FeatureLookups<'a> {
4336
0
    fn min_byte_range(&self) -> Range<usize> {
4337
0
        0..self.lookup_condition_records_byte_range().end
4338
0
    }
4339
0
    fn min_table_bytes(&self) -> &'a [u8] {
4340
0
        let range = self.min_byte_range();
4341
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4342
0
    }
4343
}
4344
4345
impl ReadArgs for FeatureLookups<'_> {
4346
    type Args = ();
4347
}
4348
4349
impl<'a> FontRead<'a> for FeatureLookups<'a> {
4350
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4351
        #[allow(clippy::absurd_extreme_comparisons)]
4352
0
        if data.len() < Self::MIN_SIZE {
4353
0
            return Err(ReadError::OutOfBounds);
4354
0
        }
4355
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4356
0
            return Err(ReadError::OutOfBounds);
4357
        };
4358
0
        Ok(Self { data })
4359
0
    }
4360
}
4361
4362
/// The fields at the start of the table, which are read directly.
4363
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4364
#[repr(C, packed)]
4365
#[doc(hidden)]
4366
pub struct FeatureLookupsFixedHeader {
4367
    pub version: BigEndian<MajorMinor>,
4368
    pub flags: BigEndian<FeatureLookupsFlags>,
4369
    pub lookup_condition_count: BigEndian<u32>,
4370
}
4371
4372
#[allow(clippy::absurd_extreme_comparisons)]
4373
const _: () = assert!(std::mem::size_of::<FeatureLookupsFixedHeader>() <= FeatureLookups::MIN_SIZE);
4374
4375
/// Conditional lookup sets for one feature (ISO/IEC 14496-22:2026, 6.2.11).
4376
#[derive(Clone)]
4377
pub struct FeatureLookups<'a> {
4378
    data: TableDataRef<'a, FeatureLookupsFixedHeader>,
4379
}
4380
4381
#[allow(clippy::needless_lifetimes)]
4382
impl<'a> FeatureLookups<'a> {
4383
    pub const MIN_SIZE: usize =
4384
        (MajorMinor::RAW_BYTE_LEN + FeatureLookupsFlags::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
4385
    basic_table_impls!(impl_the_methods);
4386
4387
0
    pub fn version(&self) -> MajorMinor {
4388
0
        self.data.header().version.get()
4389
0
    }
4390
4391
0
    pub fn flags(&self) -> FeatureLookupsFlags {
4392
0
        self.data.header().flags.get()
4393
0
    }
4394
4395
0
    pub fn lookup_condition_count(&self) -> u32 {
4396
0
        self.data.header().lookup_condition_count.get()
4397
0
    }
4398
4399
0
    pub fn lookup_condition_records(&self) -> &'a [LookupConditionRecord] {
4400
0
        let range = self.lookup_condition_records_byte_range();
4401
0
        self.offset_data()
4402
0
            .read_array(range)
4403
0
            .ok()
4404
0
            .unwrap_or_default()
4405
0
    }
4406
4407
0
    pub fn version_byte_range(&self) -> Range<usize> {
4408
0
        let start = 0usize;
4409
0
        let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
4410
0
        start..end
4411
0
    }
4412
4413
0
    pub fn flags_byte_range(&self) -> Range<usize> {
4414
0
        let start = self.version_byte_range().end;
4415
0
        let end = start.saturating_add(FeatureLookupsFlags::RAW_BYTE_LEN);
4416
0
        start..end
4417
0
    }
4418
4419
0
    pub fn lookup_condition_count_byte_range(&self) -> Range<usize> {
4420
0
        let start = self.flags_byte_range().end;
4421
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4422
0
        start..end
4423
0
    }
4424
4425
0
    pub fn lookup_condition_records_byte_range(&self) -> Range<usize> {
4426
0
        let lookup_condition_count = self.lookup_condition_count();
4427
0
        let start = self.lookup_condition_count_byte_range().end;
4428
0
        let end = start.saturating_add(
4429
0
            (transforms::to_usize(lookup_condition_count))
4430
0
                .saturating_mul(LookupConditionRecord::RAW_BYTE_LEN),
4431
        );
4432
0
        start..end
4433
0
    }
4434
}
4435
4436
const _: () = assert!(FontData::default_data_long_enough(FeatureLookups::MIN_SIZE));
4437
4438
impl Default for FeatureLookups<'_> {
4439
0
    fn default() -> Self {
4440
        Self {
4441
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
4442
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4443
        }
4444
0
    }
4445
}
4446
4447
/// Qualifiers for [FeatureLookups].
4448
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
4449
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4450
#[repr(transparent)]
4451
pub struct FeatureLookupsFlags {
4452
    bits: u16,
4453
}
4454
4455
impl FeatureLookupsFlags {
4456
    /// Include the current feature's lookups as well as conditional lookups.
4457
    pub const ADD_DEFAULT_LOOKUPS: Self = Self { bits: 0x0001 };
4458
}
4459
4460
impl FeatureLookupsFlags {
4461
    ///  Returns an empty set of flags.
4462
    #[inline]
4463
0
    pub const fn empty() -> Self {
4464
0
        Self { bits: 0 }
4465
0
    }
4466
4467
    /// Returns the set containing all flags.
4468
    #[inline]
4469
0
    pub const fn all() -> Self {
4470
0
        Self {
4471
0
            bits: Self::ADD_DEFAULT_LOOKUPS.bits,
4472
0
        }
4473
0
    }
4474
4475
    /// Returns the raw value of the flags currently stored.
4476
    #[inline]
4477
0
    pub const fn bits(&self) -> u16 {
4478
0
        self.bits
4479
0
    }
4480
4481
    /// Convert from underlying bit representation, unless that
4482
    /// representation contains bits that do not correspond to a flag.
4483
    #[inline]
4484
0
    pub const fn from_bits(bits: u16) -> Option<Self> {
4485
0
        if (bits & !Self::all().bits()) == 0 {
4486
0
            Some(Self { bits })
4487
        } else {
4488
0
            None
4489
        }
4490
0
    }
4491
4492
    /// Convert from underlying bit representation, dropping any bits
4493
    /// that do not correspond to flags.
4494
    #[inline]
4495
0
    pub const fn from_bits_truncate(bits: u16) -> Self {
4496
0
        Self {
4497
0
            bits: bits & Self::all().bits,
4498
0
        }
4499
0
    }
4500
4501
    /// Returns `true` if no flags are currently stored.
4502
    #[inline]
4503
0
    pub const fn is_empty(&self) -> bool {
4504
0
        self.bits() == Self::empty().bits()
4505
0
    }
4506
4507
    /// Returns `true` if there are flags common to both `self` and `other`.
4508
    #[inline]
4509
0
    pub const fn intersects(&self, other: Self) -> bool {
4510
0
        !(Self {
4511
0
            bits: self.bits & other.bits,
4512
0
        })
4513
0
        .is_empty()
4514
0
    }
4515
4516
    /// Returns `true` if all of the flags in `other` are contained within `self`.
4517
    #[inline]
4518
0
    pub const fn contains(&self, other: Self) -> bool {
4519
0
        (self.bits & other.bits) == other.bits
4520
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::FeatureLookupsFlags>::contains
Unexecuted instantiation: <read_fonts::tables::layout::FeatureLookupsFlags>::contains
4521
4522
    /// Inserts the specified flags in-place.
4523
    #[inline]
4524
0
    pub fn insert(&mut self, other: Self) {
4525
0
        self.bits |= other.bits;
4526
0
    }
4527
4528
    /// Removes the specified flags in-place.
4529
    #[inline]
4530
0
    pub fn remove(&mut self, other: Self) {
4531
0
        self.bits &= !other.bits;
4532
0
    }
4533
4534
    /// Toggles the specified flags in-place.
4535
    #[inline]
4536
0
    pub fn toggle(&mut self, other: Self) {
4537
0
        self.bits ^= other.bits;
4538
0
    }
4539
4540
    /// Returns the intersection between the flags in `self` and
4541
    /// `other`.
4542
    ///
4543
    /// Specifically, the returned set contains only the flags which are
4544
    /// present in *both* `self` *and* `other`.
4545
    ///
4546
    /// This is equivalent to using the `&` operator (e.g.
4547
    /// [`ops::BitAnd`]), as in `flags & other`.
4548
    ///
4549
    /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
4550
    #[inline]
4551
    #[must_use]
4552
0
    pub const fn intersection(self, other: Self) -> Self {
4553
0
        Self {
4554
0
            bits: self.bits & other.bits,
4555
0
        }
4556
0
    }
4557
4558
    /// Returns the union of between the flags in `self` and `other`.
4559
    ///
4560
    /// Specifically, the returned set contains all flags which are
4561
    /// present in *either* `self` *or* `other`, including any which are
4562
    /// present in both.
4563
    ///
4564
    /// This is equivalent to using the `|` operator (e.g.
4565
    /// [`ops::BitOr`]), as in `flags | other`.
4566
    ///
4567
    /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
4568
    #[inline]
4569
    #[must_use]
4570
0
    pub const fn union(self, other: Self) -> Self {
4571
0
        Self {
4572
0
            bits: self.bits | other.bits,
4573
0
        }
4574
0
    }
4575
4576
    /// Returns the difference between the flags in `self` and `other`.
4577
    ///
4578
    /// Specifically, the returned set contains all flags present in
4579
    /// `self`, except for the ones present in `other`.
4580
    ///
4581
    /// It is also conceptually equivalent to the "bit-clear" operation:
4582
    /// `flags & !other` (and this syntax is also supported).
4583
    ///
4584
    /// This is equivalent to using the `-` operator (e.g.
4585
    /// [`ops::Sub`]), as in `flags - other`.
4586
    ///
4587
    /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
4588
    #[inline]
4589
    #[must_use]
4590
0
    pub const fn difference(self, other: Self) -> Self {
4591
0
        Self {
4592
0
            bits: self.bits & !other.bits,
4593
0
        }
4594
0
    }
4595
}
4596
4597
impl std::ops::BitOr for FeatureLookupsFlags {
4598
    type Output = Self;
4599
4600
    /// Returns the union of the two sets of flags.
4601
    #[inline]
4602
0
    fn bitor(self, other: FeatureLookupsFlags) -> Self {
4603
0
        Self {
4604
0
            bits: self.bits | other.bits,
4605
0
        }
4606
0
    }
4607
}
4608
4609
impl std::ops::BitOrAssign for FeatureLookupsFlags {
4610
    /// Adds the set of flags.
4611
    #[inline]
4612
0
    fn bitor_assign(&mut self, other: Self) {
4613
0
        self.bits |= other.bits;
4614
0
    }
4615
}
4616
4617
impl std::ops::BitXor for FeatureLookupsFlags {
4618
    type Output = Self;
4619
4620
    /// Returns the left flags, but with all the right flags toggled.
4621
    #[inline]
4622
0
    fn bitxor(self, other: Self) -> Self {
4623
0
        Self {
4624
0
            bits: self.bits ^ other.bits,
4625
0
        }
4626
0
    }
4627
}
4628
4629
impl std::ops::BitXorAssign for FeatureLookupsFlags {
4630
    /// Toggles the set of flags.
4631
    #[inline]
4632
0
    fn bitxor_assign(&mut self, other: Self) {
4633
0
        self.bits ^= other.bits;
4634
0
    }
4635
}
4636
4637
impl std::ops::BitAnd for FeatureLookupsFlags {
4638
    type Output = Self;
4639
4640
    /// Returns the intersection between the two sets of flags.
4641
    #[inline]
4642
0
    fn bitand(self, other: Self) -> Self {
4643
0
        Self {
4644
0
            bits: self.bits & other.bits,
4645
0
        }
4646
0
    }
4647
}
4648
4649
impl std::ops::BitAndAssign for FeatureLookupsFlags {
4650
    /// Disables all flags disabled in the set.
4651
    #[inline]
4652
0
    fn bitand_assign(&mut self, other: Self) {
4653
0
        self.bits &= other.bits;
4654
0
    }
4655
}
4656
4657
impl std::ops::Sub for FeatureLookupsFlags {
4658
    type Output = Self;
4659
4660
    /// Returns the set difference of the two sets of flags.
4661
    #[inline]
4662
0
    fn sub(self, other: Self) -> Self {
4663
0
        Self {
4664
0
            bits: self.bits & !other.bits,
4665
0
        }
4666
0
    }
4667
}
4668
4669
impl std::ops::SubAssign for FeatureLookupsFlags {
4670
    /// Disables all flags enabled in the set.
4671
    #[inline]
4672
0
    fn sub_assign(&mut self, other: Self) {
4673
0
        self.bits &= !other.bits;
4674
0
    }
4675
}
4676
4677
impl std::ops::Not for FeatureLookupsFlags {
4678
    type Output = Self;
4679
4680
    /// Returns the complement of this set of flags.
4681
    #[inline]
4682
0
    fn not(self) -> Self {
4683
0
        Self { bits: !self.bits } & Self::all()
4684
0
    }
4685
}
4686
4687
impl std::fmt::Debug for FeatureLookupsFlags {
4688
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4689
0
        let members: &[(&str, Self)] = &[("ADD_DEFAULT_LOOKUPS", Self::ADD_DEFAULT_LOOKUPS)];
4690
0
        let mut first = true;
4691
0
        for (name, value) in members {
4692
0
            if self.contains(*value) {
4693
0
                if !first {
4694
0
                    f.write_str(" | ")?;
4695
0
                }
4696
0
                first = false;
4697
0
                f.write_str(name)?;
4698
0
            }
4699
        }
4700
0
        if first {
4701
0
            f.write_str("(empty)")?;
4702
0
        }
4703
0
        Ok(())
4704
0
    }
4705
}
4706
4707
impl std::fmt::Binary for FeatureLookupsFlags {
4708
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4709
0
        std::fmt::Binary::fmt(&self.bits, f)
4710
0
    }
4711
}
4712
4713
impl std::fmt::Octal for FeatureLookupsFlags {
4714
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4715
0
        std::fmt::Octal::fmt(&self.bits, f)
4716
0
    }
4717
}
4718
4719
impl std::fmt::LowerHex for FeatureLookupsFlags {
4720
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4721
0
        std::fmt::LowerHex::fmt(&self.bits, f)
4722
0
    }
4723
}
4724
4725
impl std::fmt::UpperHex for FeatureLookupsFlags {
4726
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4727
0
        std::fmt::UpperHex::fmt(&self.bits, f)
4728
0
    }
4729
}
4730
4731
impl font_types::Scalar for FeatureLookupsFlags {
4732
    type Raw = <u16 as font_types::Scalar>::Raw;
4733
0
    fn to_raw(self) -> Self::Raw {
4734
0
        self.bits().to_raw()
4735
0
    }
4736
0
    fn from_raw(raw: Self::Raw) -> Self {
4737
0
        let t = <u16>::from_raw(raw);
4738
0
        Self::from_bits_truncate(t)
4739
0
    }
4740
}
4741
4742
/// Lookups to include when a condition is true.
4743
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
4744
#[repr(C)]
4745
#[repr(packed)]
4746
pub struct LookupConditionRecord {
4747
    /// Offset from the beginning of FeatureLookups; null means true.
4748
    pub condition_offset: BigEndian<Nullable<Offset32>>,
4749
    /// Offset from the beginning of FeatureLookups.
4750
    pub lookup_index_list_offset: BigEndian<Offset32>,
4751
}
4752
4753
impl LookupConditionRecord {
4754
    /// Offset from the beginning of FeatureLookups; null means true.
4755
0
    pub fn condition_offset(&self) -> Nullable<Offset32> {
4756
0
        self.condition_offset.get()
4757
0
    }
4758
4759
    /// Offset from the beginning of FeatureLookups; null means true.
4760
    ///
4761
    /// The `data` argument should be retrieved from the parent table
4762
    /// By calling its `offset_data` method.
4763
0
    pub fn condition<'a>(&self, data: FontData<'a>) -> Option<Result<Condition<'a>, ReadError>> {
4764
0
        self.condition_offset().resolve(data)
4765
0
    }
4766
4767
    /// Offset from the beginning of FeatureLookups.
4768
0
    pub fn lookup_index_list_offset(&self) -> Offset32 {
4769
0
        self.lookup_index_list_offset.get()
4770
0
    }
4771
4772
    /// Offset from the beginning of FeatureLookups.
4773
    ///
4774
    /// The `data` argument should be retrieved from the parent table
4775
    /// By calling its `offset_data` method.
4776
0
    pub fn lookup_index_list<'a>(
4777
0
        &self,
4778
0
        data: FontData<'a>,
4779
0
    ) -> Result<LookupIndexList<'a>, ReadError> {
4780
0
        self.lookup_index_list_offset().resolve(data)
4781
0
    }
4782
}
4783
4784
impl FixedSize for LookupConditionRecord {
4785
    const RAW_BYTE_LEN: usize = Offset32::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
4786
}
4787
4788
impl<'a> MinByteRange<'a> for LookupIndexList<'a> {
4789
0
    fn min_byte_range(&self) -> Range<usize> {
4790
0
        0..self.lookup_indices_byte_range().end
4791
0
    }
4792
0
    fn min_table_bytes(&self) -> &'a [u8] {
4793
0
        let range = self.min_byte_range();
4794
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4795
0
    }
4796
}
4797
4798
impl ReadArgs for LookupIndexList<'_> {
4799
    type Args = ();
4800
}
4801
4802
impl<'a> FontRead<'a> for LookupIndexList<'a> {
4803
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4804
        #[allow(clippy::absurd_extreme_comparisons)]
4805
0
        if data.len() < Self::MIN_SIZE {
4806
0
            return Err(ReadError::OutOfBounds);
4807
0
        }
4808
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4809
0
            return Err(ReadError::OutOfBounds);
4810
        };
4811
0
        Ok(Self { data })
4812
0
    }
4813
}
4814
4815
/// The fields at the start of the table, which are read directly.
4816
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4817
#[repr(C, packed)]
4818
#[doc(hidden)]
4819
pub struct LookupIndexListFixedHeader {
4820
    pub lookup_index_count: BigEndian<u16>,
4821
}
4822
4823
#[allow(clippy::absurd_extreme_comparisons)]
4824
const _: () =
4825
    assert!(std::mem::size_of::<LookupIndexListFixedHeader>() <= LookupIndexList::MIN_SIZE);
4826
4827
/// Indices into the GSUB or GPOS LookupList.
4828
#[derive(Clone)]
4829
pub struct LookupIndexList<'a> {
4830
    data: TableDataRef<'a, LookupIndexListFixedHeader>,
4831
}
4832
4833
#[allow(clippy::needless_lifetimes)]
4834
impl<'a> LookupIndexList<'a> {
4835
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
4836
    basic_table_impls!(impl_the_methods);
4837
4838
0
    pub fn lookup_index_count(&self) -> u16 {
4839
0
        self.data.header().lookup_index_count.get()
4840
0
    }
4841
4842
0
    pub fn lookup_indices(&self) -> &'a [BigEndian<u16>] {
4843
0
        let range = self.lookup_indices_byte_range();
4844
0
        self.offset_data()
4845
0
            .read_array(range)
4846
0
            .ok()
4847
0
            .unwrap_or_default()
4848
0
    }
4849
4850
0
    pub fn lookup_index_count_byte_range(&self) -> Range<usize> {
4851
0
        let start = 0usize;
4852
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
4853
0
        start..end
4854
0
    }
4855
4856
0
    pub fn lookup_indices_byte_range(&self) -> Range<usize> {
4857
0
        let lookup_index_count = self.lookup_index_count();
4858
0
        let start = self.lookup_index_count_byte_range().end;
4859
0
        let end = start.saturating_add(
4860
0
            (transforms::to_usize(lookup_index_count)).saturating_mul(u16::RAW_BYTE_LEN),
4861
        );
4862
0
        start..end
4863
0
    }
4864
}
4865
4866
const _: () = assert!(FontData::default_data_long_enough(
4867
    LookupIndexList::MIN_SIZE
4868
));
4869
4870
impl Default for LookupIndexList<'_> {
4871
0
    fn default() -> Self {
4872
        Self {
4873
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
4874
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4875
        }
4876
0
    }
4877
}
4878
4879
impl<'a> MinByteRange<'a> for ConditionSet<'a> {
4880
0
    fn min_byte_range(&self) -> Range<usize> {
4881
0
        0..self.condition_offsets_byte_range().end
4882
0
    }
4883
0
    fn min_table_bytes(&self) -> &'a [u8] {
4884
0
        let range = self.min_byte_range();
4885
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4886
0
    }
4887
}
4888
4889
impl ReadArgs for ConditionSet<'_> {
4890
    type Args = ();
4891
}
4892
4893
impl<'a> FontRead<'a> for ConditionSet<'a> {
4894
1.02k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4895
        #[allow(clippy::absurd_extreme_comparisons)]
4896
1.02k
        if data.len() < Self::MIN_SIZE {
4897
32
            return Err(ReadError::OutOfBounds);
4898
994
        }
4899
994
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4900
0
            return Err(ReadError::OutOfBounds);
4901
        };
4902
994
        Ok(Self { data })
4903
1.02k
    }
4904
}
4905
4906
/// The fields at the start of the table, which are read directly.
4907
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4908
#[repr(C, packed)]
4909
#[doc(hidden)]
4910
pub struct ConditionSetFixedHeader {
4911
    pub condition_count: BigEndian<u16>,
4912
}
4913
4914
#[allow(clippy::absurd_extreme_comparisons)]
4915
const _: () = assert!(std::mem::size_of::<ConditionSetFixedHeader>() <= ConditionSet::MIN_SIZE);
4916
4917
/// [ConditionSet Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#conditionset-table)
4918
#[derive(Clone)]
4919
pub struct ConditionSet<'a> {
4920
    data: TableDataRef<'a, ConditionSetFixedHeader>,
4921
}
4922
4923
#[allow(clippy::needless_lifetimes)]
4924
impl<'a> ConditionSet<'a> {
4925
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
4926
    basic_table_impls!(impl_the_methods);
4927
4928
    /// Number of conditions for this condition set.
4929
1.98k
    pub fn condition_count(&self) -> u16 {
4930
1.98k
        self.data.header().condition_count.get()
4931
1.98k
    }
4932
4933
    /// Array of offsets to condition tables, from beginning of the
4934
    /// ConditionSet table.
4935
994
    pub fn condition_offsets(&self) -> &'a [BigEndian<Offset32>] {
4936
994
        let range = self.condition_offsets_byte_range();
4937
994
        self.offset_data()
4938
994
            .read_array(range)
4939
994
            .ok()
4940
994
            .unwrap_or_default()
4941
994
    }
4942
4943
    /// A dynamically resolving wrapper for [`condition_offsets`][Self::condition_offsets].
4944
0
    pub fn conditions(&self) -> ArrayOfOffsets<'a, Condition<'a>, Offset32> {
4945
0
        let data = self.offset_data();
4946
0
        let offsets = self.condition_offsets();
4947
0
        ArrayOfOffsets::new(offsets, data, ())
4948
0
    }
4949
4950
994
    pub fn condition_count_byte_range(&self) -> Range<usize> {
4951
994
        let start = 0usize;
4952
994
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
4953
994
        start..end
4954
994
    }
4955
4956
994
    pub fn condition_offsets_byte_range(&self) -> Range<usize> {
4957
994
        let condition_count = self.condition_count();
4958
994
        let start = self.condition_count_byte_range().end;
4959
994
        let end = start.saturating_add(
4960
994
            (transforms::to_usize(condition_count)).saturating_mul(Offset32::RAW_BYTE_LEN),
4961
        );
4962
994
        start..end
4963
994
    }
4964
}
4965
4966
const _: () = assert!(FontData::default_data_long_enough(ConditionSet::MIN_SIZE));
4967
4968
impl Default for ConditionSet<'_> {
4969
0
    fn default() -> Self {
4970
        Self {
4971
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
4972
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
4973
        }
4974
0
    }
4975
}
4976
4977
/// [Condition Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#condition-table)
4978
///
4979
/// Formats 2..5 are defined in ISO/IEC 14496-22:2026, 6.2.10.
4980
#[derive(Clone)]
4981
pub enum Condition<'a> {
4982
    Format1AxisRange(ConditionFormat1<'a>),
4983
    Format2VariableValue(ConditionFormat2<'a>),
4984
    Format3And(ConditionFormat3<'a>),
4985
    Format4Or(ConditionFormat4<'a>),
4986
    Format5Negate(ConditionFormat5<'a>),
4987
}
4988
4989
impl Default for Condition<'_> {
4990
0
    fn default() -> Self {
4991
0
        Self::Format1AxisRange(Default::default())
4992
0
    }
4993
}
4994
4995
impl<'a> Condition<'a> {
4996
    ///Return the `FontData` used to resolve offsets for this table.
4997
0
    pub fn offset_data(&self) -> FontData<'a> {
4998
0
        match self {
4999
0
            Self::Format1AxisRange(item) => item.offset_data(),
5000
0
            Self::Format2VariableValue(item) => item.offset_data(),
5001
0
            Self::Format3And(item) => item.offset_data(),
5002
0
            Self::Format4Or(item) => item.offset_data(),
5003
0
            Self::Format5Negate(item) => item.offset_data(),
5004
        }
5005
0
    }
5006
5007
    /// Format, = 1
5008
0
    pub fn format(&self) -> u16 {
5009
0
        match self {
5010
0
            Self::Format1AxisRange(item) => item.format(),
5011
0
            Self::Format2VariableValue(item) => item.format(),
5012
0
            Self::Format3And(item) => item.format(),
5013
0
            Self::Format4Or(item) => item.format(),
5014
0
            Self::Format5Negate(item) => item.format(),
5015
        }
5016
0
    }
5017
}
5018
5019
impl ReadArgs for Condition<'_> {
5020
    type Args = ();
5021
}
5022
5023
impl<'a> FontRead<'a> for Condition<'a> {
5024
    #[inline]
5025
3.00k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5026
3.00k
        let format: u16 = data.read_at(0usize)?;
5027
2.99k
        match format {
5028
371
            ConditionFormat1::FORMAT => Ok(Self::Format1AxisRange(FontRead::read(data)?)),
5029
175
            ConditionFormat2::FORMAT => Ok(Self::Format2VariableValue(FontRead::read(data)?)),
5030
468
            ConditionFormat3::FORMAT => Ok(Self::Format3And(FontRead::read(data)?)),
5031
528
            ConditionFormat4::FORMAT => Ok(Self::Format4Or(FontRead::read(data)?)),
5032
72
            ConditionFormat5::FORMAT => Ok(Self::Format5Negate(FontRead::read(data)?)),
5033
1.37k
            other => Err(ReadError::InvalidFormat(other.into())),
5034
        }
5035
3.00k
    }
5036
}
5037
5038
impl<'a> MinByteRange<'a> for Condition<'a> {
5039
0
    fn min_byte_range(&self) -> Range<usize> {
5040
0
        match self {
5041
0
            Self::Format1AxisRange(item) => item.min_byte_range(),
5042
0
            Self::Format2VariableValue(item) => item.min_byte_range(),
5043
0
            Self::Format3And(item) => item.min_byte_range(),
5044
0
            Self::Format4Or(item) => item.min_byte_range(),
5045
0
            Self::Format5Negate(item) => item.min_byte_range(),
5046
        }
5047
0
    }
5048
0
    fn min_table_bytes(&self) -> &'a [u8] {
5049
0
        match self {
5050
0
            Self::Format1AxisRange(item) => item.min_table_bytes(),
5051
0
            Self::Format2VariableValue(item) => item.min_table_bytes(),
5052
0
            Self::Format3And(item) => item.min_table_bytes(),
5053
0
            Self::Format4Or(item) => item.min_table_bytes(),
5054
0
            Self::Format5Negate(item) => item.min_table_bytes(),
5055
        }
5056
0
    }
5057
}
5058
5059
impl Format<u16> for ConditionFormat1<'_> {
5060
    const FORMAT: u16 = 1;
5061
}
5062
5063
impl<'a> MinByteRange<'a> for ConditionFormat1<'a> {
5064
0
    fn min_byte_range(&self) -> Range<usize> {
5065
0
        0..self.filter_range_max_value_byte_range().end
5066
0
    }
5067
0
    fn min_table_bytes(&self) -> &'a [u8] {
5068
0
        let range = self.min_byte_range();
5069
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5070
0
    }
5071
}
5072
5073
impl ReadArgs for ConditionFormat1<'_> {
5074
    type Args = ();
5075
}
5076
5077
impl<'a> FontRead<'a> for ConditionFormat1<'a> {
5078
371
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5079
        #[allow(clippy::absurd_extreme_comparisons)]
5080
371
        if data.len() < Self::MIN_SIZE {
5081
18
            return Err(ReadError::OutOfBounds);
5082
353
        }
5083
353
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5084
0
            return Err(ReadError::OutOfBounds);
5085
        };
5086
353
        Ok(Self { data })
5087
371
    }
5088
}
5089
5090
/// The fields at the start of the table, which are read directly.
5091
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5092
#[repr(C, packed)]
5093
#[doc(hidden)]
5094
pub struct ConditionFormat1FixedHeader {
5095
    pub format: BigEndian<u16>,
5096
    pub axis_index: BigEndian<u16>,
5097
    pub filter_range_min_value: BigEndian<F2Dot14>,
5098
    pub filter_range_max_value: BigEndian<F2Dot14>,
5099
}
5100
5101
#[allow(clippy::absurd_extreme_comparisons)]
5102
const _: () =
5103
    assert!(std::mem::size_of::<ConditionFormat1FixedHeader>() <= ConditionFormat1::MIN_SIZE);
5104
5105
/// [Condition Table Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#condition-table-format-1-font-variation-axis-range): Font Variation Axis Range
5106
#[derive(Clone)]
5107
pub struct ConditionFormat1<'a> {
5108
    data: TableDataRef<'a, ConditionFormat1FixedHeader>,
5109
}
5110
5111
#[allow(clippy::needless_lifetimes)]
5112
impl<'a> ConditionFormat1<'a> {
5113
    pub const MIN_SIZE: usize =
5114
        (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN);
5115
    basic_table_impls!(impl_the_methods);
5116
5117
    /// Format, = 1
5118
0
    pub fn format(&self) -> u16 {
5119
0
        self.data.header().format.get()
5120
0
    }
5121
5122
    /// Index (zero-based) for the variation axis within the 'fvar'
5123
    /// table.
5124
353
    pub fn axis_index(&self) -> u16 {
5125
353
        self.data.header().axis_index.get()
5126
353
    }
5127
5128
    /// Minimum value of the font variation instances that satisfy this
5129
    /// condition.
5130
353
    pub fn filter_range_min_value(&self) -> F2Dot14 {
5131
353
        self.data.header().filter_range_min_value.get()
5132
353
    }
5133
5134
    /// Maximum value of the font variation instances that satisfy this
5135
    /// condition.
5136
38
    pub fn filter_range_max_value(&self) -> F2Dot14 {
5137
38
        self.data.header().filter_range_max_value.get()
5138
38
    }
5139
5140
0
    pub fn format_byte_range(&self) -> Range<usize> {
5141
0
        let start = 0usize;
5142
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5143
0
        start..end
5144
0
    }
5145
5146
0
    pub fn axis_index_byte_range(&self) -> Range<usize> {
5147
0
        let start = self.format_byte_range().end;
5148
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5149
0
        start..end
5150
0
    }
5151
5152
0
    pub fn filter_range_min_value_byte_range(&self) -> Range<usize> {
5153
0
        let start = self.axis_index_byte_range().end;
5154
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5155
0
        start..end
5156
0
    }
5157
5158
0
    pub fn filter_range_max_value_byte_range(&self) -> Range<usize> {
5159
0
        let start = self.filter_range_min_value_byte_range().end;
5160
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5161
0
        start..end
5162
0
    }
5163
}
5164
5165
const _: () = assert!(FontData::default_data_long_enough(
5166
    ConditionFormat1::MIN_SIZE
5167
));
5168
5169
impl Default for ConditionFormat1<'_> {
5170
0
    fn default() -> Self {
5171
        Self {
5172
0
            data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
5173
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
5174
        }
5175
0
    }
5176
}
5177
5178
impl Format<u16> for ConditionFormat2<'_> {
5179
    const FORMAT: u16 = 2;
5180
}
5181
5182
impl<'a> MinByteRange<'a> for ConditionFormat2<'a> {
5183
0
    fn min_byte_range(&self) -> Range<usize> {
5184
0
        0..self.var_index_byte_range().end
5185
0
    }
5186
0
    fn min_table_bytes(&self) -> &'a [u8] {
5187
0
        let range = self.min_byte_range();
5188
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5189
0
    }
5190
}
5191
5192
impl ReadArgs for ConditionFormat2<'_> {
5193
    type Args = ();
5194
}
5195
5196
impl<'a> FontRead<'a> for ConditionFormat2<'a> {
5197
175
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5198
        #[allow(clippy::absurd_extreme_comparisons)]
5199
175
        if data.len() < Self::MIN_SIZE {
5200
19
            return Err(ReadError::OutOfBounds);
5201
156
        }
5202
156
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5203
0
            return Err(ReadError::OutOfBounds);
5204
        };
5205
156
        Ok(Self { data })
5206
175
    }
5207
}
5208
5209
/// The fields at the start of the table, which are read directly.
5210
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5211
#[repr(C, packed)]
5212
#[doc(hidden)]
5213
pub struct ConditionFormat2FixedHeader {
5214
    pub format: BigEndian<u16>,
5215
    pub default_value: BigEndian<i16>,
5216
    pub var_index: BigEndian<u32>,
5217
}
5218
5219
#[allow(clippy::absurd_extreme_comparisons)]
5220
const _: () =
5221
    assert!(std::mem::size_of::<ConditionFormat2FixedHeader>() <= ConditionFormat2::MIN_SIZE);
5222
5223
/// [Condition Table Format 2](https://github.com/fonttools/fonttools/blob/5e6b12d12fa08abafbeb7570f47707fbedf69a45/Lib/fontTools/ttLib/tables/otData.py#L3237-L3255): Variation index
5224
#[derive(Clone)]
5225
pub struct ConditionFormat2<'a> {
5226
    data: TableDataRef<'a, ConditionFormat2FixedHeader>,
5227
}
5228
5229
#[allow(clippy::needless_lifetimes)]
5230
impl<'a> ConditionFormat2<'a> {
5231
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
5232
    basic_table_impls!(impl_the_methods);
5233
5234
    /// Format, = 2
5235
0
    pub fn format(&self) -> u16 {
5236
0
        self.data.header().format.get()
5237
0
    }
5238
5239
    /// Value at default instance.
5240
156
    pub fn default_value(&self) -> i16 {
5241
156
        self.data.header().default_value.get()
5242
156
    }
5243
5244
    /// Variation index to vary the value based on current designspace location.
5245
156
    pub fn var_index(&self) -> u32 {
5246
156
        self.data.header().var_index.get()
5247
156
    }
5248
5249
0
    pub fn format_byte_range(&self) -> Range<usize> {
5250
0
        let start = 0usize;
5251
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5252
0
        start..end
5253
0
    }
5254
5255
0
    pub fn default_value_byte_range(&self) -> Range<usize> {
5256
0
        let start = self.format_byte_range().end;
5257
0
        let end = start.saturating_add(i16::RAW_BYTE_LEN);
5258
0
        start..end
5259
0
    }
5260
5261
0
    pub fn var_index_byte_range(&self) -> Range<usize> {
5262
0
        let start = self.default_value_byte_range().end;
5263
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5264
0
        start..end
5265
0
    }
5266
}
5267
5268
impl Format<u16> for ConditionFormat3<'_> {
5269
    const FORMAT: u16 = 3;
5270
}
5271
5272
impl<'a> MinByteRange<'a> for ConditionFormat3<'a> {
5273
0
    fn min_byte_range(&self) -> Range<usize> {
5274
0
        0..self.condition_offsets_byte_range().end
5275
0
    }
5276
0
    fn min_table_bytes(&self) -> &'a [u8] {
5277
0
        let range = self.min_byte_range();
5278
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5279
0
    }
5280
}
5281
5282
impl ReadArgs for ConditionFormat3<'_> {
5283
    type Args = ();
5284
}
5285
5286
impl<'a> FontRead<'a> for ConditionFormat3<'a> {
5287
468
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5288
        #[allow(clippy::absurd_extreme_comparisons)]
5289
468
        if data.len() < Self::MIN_SIZE {
5290
18
            return Err(ReadError::OutOfBounds);
5291
450
        }
5292
450
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5293
0
            return Err(ReadError::OutOfBounds);
5294
        };
5295
450
        Ok(Self { data })
5296
468
    }
5297
}
5298
5299
/// The fields at the start of the table, which are read directly.
5300
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5301
#[repr(C, packed)]
5302
#[doc(hidden)]
5303
pub struct ConditionFormat3FixedHeader {
5304
    pub format: BigEndian<u16>,
5305
    pub condition_count: u8,
5306
}
5307
5308
#[allow(clippy::absurd_extreme_comparisons)]
5309
const _: () =
5310
    assert!(std::mem::size_of::<ConditionFormat3FixedHeader>() <= ConditionFormat3::MIN_SIZE);
5311
5312
/// [Condition Table Format 3](https://github.com/fonttools/fonttools/blob/5e6b12d12fa08abafbeb7570f47707fbedf69a45/Lib/fontTools/ttLib/tables/otData.py#L3257-L3275): AND
5313
#[derive(Clone)]
5314
pub struct ConditionFormat3<'a> {
5315
    data: TableDataRef<'a, ConditionFormat3FixedHeader>,
5316
}
5317
5318
#[allow(clippy::needless_lifetimes)]
5319
impl<'a> ConditionFormat3<'a> {
5320
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u8::RAW_BYTE_LEN);
5321
    basic_table_impls!(impl_the_methods);
5322
5323
    /// Format, = 3
5324
0
    pub fn format(&self) -> u16 {
5325
0
        self.data.header().format.get()
5326
0
    }
5327
5328
    /// Number of conditions.
5329
900
    pub fn condition_count(&self) -> u8 {
5330
900
        self.data.header().condition_count
5331
900
    }
5332
5333
    /// Array of condition tables for this conjunction (AND) expression.
5334
450
    pub fn condition_offsets(&self) -> &'a [BigEndian<Offset24>] {
5335
450
        let range = self.condition_offsets_byte_range();
5336
450
        self.offset_data()
5337
450
            .read_array(range)
5338
450
            .ok()
5339
450
            .unwrap_or_default()
5340
450
    }
5341
5342
    /// A dynamically resolving wrapper for [`condition_offsets`][Self::condition_offsets].
5343
0
    pub fn conditions(&self) -> ArrayOfOffsets<'a, Condition<'a>, Offset24> {
5344
0
        let data = self.offset_data();
5345
0
        let offsets = self.condition_offsets();
5346
0
        ArrayOfOffsets::new(offsets, data, ())
5347
0
    }
5348
5349
450
    pub fn format_byte_range(&self) -> Range<usize> {
5350
450
        let start = 0usize;
5351
450
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5352
450
        start..end
5353
450
    }
5354
5355
450
    pub fn condition_count_byte_range(&self) -> Range<usize> {
5356
450
        let start = self.format_byte_range().end;
5357
450
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5358
450
        start..end
5359
450
    }
5360
5361
450
    pub fn condition_offsets_byte_range(&self) -> Range<usize> {
5362
450
        let condition_count = self.condition_count();
5363
450
        let start = self.condition_count_byte_range().end;
5364
450
        let end = start.saturating_add(
5365
450
            (transforms::to_usize(condition_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
5366
        );
5367
450
        start..end
5368
450
    }
5369
}
5370
5371
impl Format<u16> for ConditionFormat4<'_> {
5372
    const FORMAT: u16 = 4;
5373
}
5374
5375
impl<'a> MinByteRange<'a> for ConditionFormat4<'a> {
5376
0
    fn min_byte_range(&self) -> Range<usize> {
5377
0
        0..self.condition_offsets_byte_range().end
5378
0
    }
5379
0
    fn min_table_bytes(&self) -> &'a [u8] {
5380
0
        let range = self.min_byte_range();
5381
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5382
0
    }
5383
}
5384
5385
impl ReadArgs for ConditionFormat4<'_> {
5386
    type Args = ();
5387
}
5388
5389
impl<'a> FontRead<'a> for ConditionFormat4<'a> {
5390
528
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5391
        #[allow(clippy::absurd_extreme_comparisons)]
5392
528
        if data.len() < Self::MIN_SIZE {
5393
18
            return Err(ReadError::OutOfBounds);
5394
510
        }
5395
510
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5396
0
            return Err(ReadError::OutOfBounds);
5397
        };
5398
510
        Ok(Self { data })
5399
528
    }
5400
}
5401
5402
/// The fields at the start of the table, which are read directly.
5403
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5404
#[repr(C, packed)]
5405
#[doc(hidden)]
5406
pub struct ConditionFormat4FixedHeader {
5407
    pub format: BigEndian<u16>,
5408
    pub condition_count: u8,
5409
}
5410
5411
#[allow(clippy::absurd_extreme_comparisons)]
5412
const _: () =
5413
    assert!(std::mem::size_of::<ConditionFormat4FixedHeader>() <= ConditionFormat4::MIN_SIZE);
5414
5415
/// [Condition Table Format 4](https://github.com/fonttools/fonttools/blob/5e6b12d12fa08abafbeb7570f47707fbedf69a45/Lib/fontTools/ttLib/tables/otData.py#L3276-L3295): OR
5416
#[derive(Clone)]
5417
pub struct ConditionFormat4<'a> {
5418
    data: TableDataRef<'a, ConditionFormat4FixedHeader>,
5419
}
5420
5421
#[allow(clippy::needless_lifetimes)]
5422
impl<'a> ConditionFormat4<'a> {
5423
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u8::RAW_BYTE_LEN);
5424
    basic_table_impls!(impl_the_methods);
5425
5426
    /// Format, = 4
5427
0
    pub fn format(&self) -> u16 {
5428
0
        self.data.header().format.get()
5429
0
    }
5430
5431
    /// Number of conditions.
5432
1.02k
    pub fn condition_count(&self) -> u8 {
5433
1.02k
        self.data.header().condition_count
5434
1.02k
    }
5435
5436
    /// Array of condition tables for this disjunction (OR) expression.
5437
510
    pub fn condition_offsets(&self) -> &'a [BigEndian<Offset24>] {
5438
510
        let range = self.condition_offsets_byte_range();
5439
510
        self.offset_data()
5440
510
            .read_array(range)
5441
510
            .ok()
5442
510
            .unwrap_or_default()
5443
510
    }
5444
5445
    /// A dynamically resolving wrapper for [`condition_offsets`][Self::condition_offsets].
5446
0
    pub fn conditions(&self) -> ArrayOfOffsets<'a, Condition<'a>, Offset24> {
5447
0
        let data = self.offset_data();
5448
0
        let offsets = self.condition_offsets();
5449
0
        ArrayOfOffsets::new(offsets, data, ())
5450
0
    }
5451
5452
510
    pub fn format_byte_range(&self) -> Range<usize> {
5453
510
        let start = 0usize;
5454
510
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5455
510
        start..end
5456
510
    }
5457
5458
510
    pub fn condition_count_byte_range(&self) -> Range<usize> {
5459
510
        let start = self.format_byte_range().end;
5460
510
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5461
510
        start..end
5462
510
    }
5463
5464
510
    pub fn condition_offsets_byte_range(&self) -> Range<usize> {
5465
510
        let condition_count = self.condition_count();
5466
510
        let start = self.condition_count_byte_range().end;
5467
510
        let end = start.saturating_add(
5468
510
            (transforms::to_usize(condition_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
5469
        );
5470
510
        start..end
5471
510
    }
5472
}
5473
5474
impl Format<u16> for ConditionFormat5<'_> {
5475
    const FORMAT: u16 = 5;
5476
}
5477
5478
impl<'a> MinByteRange<'a> for ConditionFormat5<'a> {
5479
0
    fn min_byte_range(&self) -> Range<usize> {
5480
0
        0..self.condition_offset_byte_range().end
5481
0
    }
5482
0
    fn min_table_bytes(&self) -> &'a [u8] {
5483
0
        let range = self.min_byte_range();
5484
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5485
0
    }
5486
}
5487
5488
impl ReadArgs for ConditionFormat5<'_> {
5489
    type Args = ();
5490
}
5491
5492
impl<'a> FontRead<'a> for ConditionFormat5<'a> {
5493
72
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5494
        #[allow(clippy::absurd_extreme_comparisons)]
5495
72
        if data.len() < Self::MIN_SIZE {
5496
18
            return Err(ReadError::OutOfBounds);
5497
54
        }
5498
54
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5499
0
            return Err(ReadError::OutOfBounds);
5500
        };
5501
54
        Ok(Self { data })
5502
72
    }
5503
}
5504
5505
/// The fields at the start of the table, which are read directly.
5506
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5507
#[repr(C, packed)]
5508
#[doc(hidden)]
5509
pub struct ConditionFormat5FixedHeader {
5510
    pub format: BigEndian<u16>,
5511
    pub condition_offset: BigEndian<Offset24>,
5512
}
5513
5514
#[allow(clippy::absurd_extreme_comparisons)]
5515
const _: () =
5516
    assert!(std::mem::size_of::<ConditionFormat5FixedHeader>() <= ConditionFormat5::MIN_SIZE);
5517
5518
/// [Condition Table Format 5](https://github.com/fonttools/fonttools/blob/5e6b12d12fa08abafbeb7570f47707fbedf69a45/Lib/fontTools/ttLib/tables/otData.py#L3296-L3308): NOT
5519
#[derive(Clone)]
5520
pub struct ConditionFormat5<'a> {
5521
    data: TableDataRef<'a, ConditionFormat5FixedHeader>,
5522
}
5523
5524
#[allow(clippy::needless_lifetimes)]
5525
impl<'a> ConditionFormat5<'a> {
5526
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN);
5527
    basic_table_impls!(impl_the_methods);
5528
5529
    /// Format, = 5
5530
0
    pub fn format(&self) -> u16 {
5531
0
        self.data.header().format.get()
5532
0
    }
5533
5534
    /// Condition to negate.
5535
54
    pub fn condition_offset(&self) -> Offset24 {
5536
54
        self.data.header().condition_offset.get()
5537
54
    }
5538
5539
    /// Attempt to resolve [`condition_offset`][Self::condition_offset].
5540
0
    pub fn condition(&self) -> Result<Condition<'a>, ReadError> {
5541
0
        let data = self.offset_data();
5542
0
        self.condition_offset().resolve(data)
5543
0
    }
5544
5545
0
    pub fn format_byte_range(&self) -> Range<usize> {
5546
0
        let start = 0usize;
5547
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5548
0
        start..end
5549
0
    }
5550
5551
0
    pub fn condition_offset_byte_range(&self) -> Range<usize> {
5552
0
        let start = self.format_byte_range().end;
5553
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5554
0
        start..end
5555
0
    }
5556
}
5557
5558
impl<'a> MinByteRange<'a> for FeatureTableSubstitution<'a> {
5559
0
    fn min_byte_range(&self) -> Range<usize> {
5560
0
        0..self.substitutions_byte_range().end
5561
0
    }
5562
0
    fn min_table_bytes(&self) -> &'a [u8] {
5563
0
        let range = self.min_byte_range();
5564
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5565
0
    }
5566
}
5567
5568
impl ReadArgs for FeatureTableSubstitution<'_> {
5569
    type Args = ();
5570
}
5571
5572
impl<'a> FontRead<'a> for FeatureTableSubstitution<'a> {
5573
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5574
        #[allow(clippy::absurd_extreme_comparisons)]
5575
0
        if data.len() < Self::MIN_SIZE {
5576
0
            return Err(ReadError::OutOfBounds);
5577
0
        }
5578
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5579
0
            return Err(ReadError::OutOfBounds);
5580
        };
5581
0
        Ok(Self { data })
5582
0
    }
5583
}
5584
5585
/// The fields at the start of the table, which are read directly.
5586
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5587
#[repr(C, packed)]
5588
#[doc(hidden)]
5589
pub struct FeatureTableSubstitutionFixedHeader {
5590
    pub version: BigEndian<MajorMinor>,
5591
    pub substitution_count: BigEndian<u16>,
5592
}
5593
5594
#[allow(clippy::absurd_extreme_comparisons)]
5595
const _: () = assert!(
5596
    std::mem::size_of::<FeatureTableSubstitutionFixedHeader>()
5597
        <= FeatureTableSubstitution::MIN_SIZE
5598
);
5599
5600
/// [FeatureTableSubstitution Table](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#featuretablesubstitution-table)
5601
#[derive(Clone)]
5602
pub struct FeatureTableSubstitution<'a> {
5603
    data: TableDataRef<'a, FeatureTableSubstitutionFixedHeader>,
5604
}
5605
5606
#[allow(clippy::needless_lifetimes)]
5607
impl<'a> FeatureTableSubstitution<'a> {
5608
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
5609
    basic_table_impls!(impl_the_methods);
5610
5611
    /// Major & minor version of the table: (1, 0)
5612
0
    pub fn version(&self) -> MajorMinor {
5613
0
        self.data.header().version.get()
5614
0
    }
5615
5616
    /// Number of feature table substitution records.
5617
0
    pub fn substitution_count(&self) -> u16 {
5618
0
        self.data.header().substitution_count.get()
5619
0
    }
5620
5621
    /// Array of feature table substitution records.
5622
0
    pub fn substitutions(&self) -> &'a [FeatureTableSubstitutionRecord] {
5623
0
        let range = self.substitutions_byte_range();
5624
0
        self.offset_data()
5625
0
            .read_array(range)
5626
0
            .ok()
5627
0
            .unwrap_or_default()
5628
0
    }
5629
5630
0
    pub fn version_byte_range(&self) -> Range<usize> {
5631
0
        let start = 0usize;
5632
0
        let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
5633
0
        start..end
5634
0
    }
5635
5636
0
    pub fn substitution_count_byte_range(&self) -> Range<usize> {
5637
0
        let start = self.version_byte_range().end;
5638
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5639
0
        start..end
5640
0
    }
5641
5642
0
    pub fn substitutions_byte_range(&self) -> Range<usize> {
5643
0
        let substitution_count = self.substitution_count();
5644
0
        let start = self.substitution_count_byte_range().end;
5645
0
        let end = start.saturating_add(
5646
0
            (transforms::to_usize(substitution_count))
5647
0
                .saturating_mul(FeatureTableSubstitutionRecord::RAW_BYTE_LEN),
5648
        );
5649
0
        start..end
5650
0
    }
5651
}
5652
5653
const _: () = assert!(FontData::default_data_long_enough(
5654
    FeatureTableSubstitution::MIN_SIZE
5655
));
5656
5657
impl Default for FeatureTableSubstitution<'_> {
5658
0
    fn default() -> Self {
5659
        Self {
5660
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
5661
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
5662
        }
5663
0
    }
5664
}
5665
5666
/// Used in [FeatureTableSubstitution]
5667
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
5668
#[repr(C)]
5669
#[repr(packed)]
5670
pub struct FeatureTableSubstitutionRecord {
5671
    /// The feature table index to match.
5672
    pub feature_index: BigEndian<u16>,
5673
    /// Offset to an alternate feature table, from start of the
5674
    /// FeatureTableSubstitution table.
5675
    pub alternate_feature_offset: BigEndian<Offset32>,
5676
}
5677
5678
impl FeatureTableSubstitutionRecord {
5679
    /// The feature table index to match.
5680
0
    pub fn feature_index(&self) -> u16 {
5681
0
        self.feature_index.get()
5682
0
    }
5683
5684
    /// Offset to an alternate feature table, from start of the
5685
    /// FeatureTableSubstitution table.
5686
0
    pub fn alternate_feature_offset(&self) -> Offset32 {
5687
0
        self.alternate_feature_offset.get()
5688
0
    }
5689
}
5690
5691
impl FixedSize for FeatureTableSubstitutionRecord {
5692
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
5693
}
5694
5695
impl<'a> MinByteRange<'a> for SizeParams<'a> {
5696
0
    fn min_byte_range(&self) -> Range<usize> {
5697
0
        0..self.range_end_byte_range().end
5698
0
    }
5699
0
    fn min_table_bytes(&self) -> &'a [u8] {
5700
0
        let range = self.min_byte_range();
5701
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5702
0
    }
5703
}
5704
5705
impl ReadArgs for SizeParams<'_> {
5706
    type Args = ();
5707
}
5708
5709
impl<'a> FontRead<'a> for SizeParams<'a> {
5710
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5711
        #[allow(clippy::absurd_extreme_comparisons)]
5712
0
        if data.len() < Self::MIN_SIZE {
5713
0
            return Err(ReadError::OutOfBounds);
5714
0
        }
5715
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5716
0
            return Err(ReadError::OutOfBounds);
5717
        };
5718
0
        Ok(Self { data })
5719
0
    }
5720
}
5721
5722
/// The fields at the start of the table, which are read directly.
5723
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5724
#[repr(C, packed)]
5725
#[doc(hidden)]
5726
pub struct SizeParamsFixedHeader {
5727
    pub design_size: BigEndian<u16>,
5728
    pub identifier: BigEndian<u16>,
5729
    pub name_entry: BigEndian<u16>,
5730
    pub range_start: BigEndian<u16>,
5731
    pub range_end: BigEndian<u16>,
5732
}
5733
5734
#[allow(clippy::absurd_extreme_comparisons)]
5735
const _: () = assert!(std::mem::size_of::<SizeParamsFixedHeader>() <= SizeParams::MIN_SIZE);
5736
5737
#[derive(Clone)]
5738
pub struct SizeParams<'a> {
5739
    data: TableDataRef<'a, SizeParamsFixedHeader>,
5740
}
5741
5742
#[allow(clippy::needless_lifetimes)]
5743
impl<'a> SizeParams<'a> {
5744
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
5745
        + u16::RAW_BYTE_LEN
5746
        + u16::RAW_BYTE_LEN
5747
        + u16::RAW_BYTE_LEN
5748
        + u16::RAW_BYTE_LEN);
5749
    basic_table_impls!(impl_the_methods);
5750
5751
    /// The first value represents the design size in 720/inch units (decipoints).
5752
    ///
5753
    /// The design size entry must be non-zero. When there is a design size but
5754
    /// no recommended size range, the rest of the array will consist of zeros.
5755
0
    pub fn design_size(&self) -> u16 {
5756
0
        self.data.header().design_size.get()
5757
0
    }
5758
5759
    /// The second value has no independent meaning, but serves as an identifier that associates fonts in a subfamily.
5760
    ///
5761
    /// All fonts which share a Typographic or Font Family name and which differ
5762
    /// only by size range shall have the same subfamily value, and no fonts
5763
    /// which differ in weight or style shall have the same subfamily value.
5764
    /// If this value is zero, the remaining fields in the array will be ignored.
5765
0
    pub fn identifier(&self) -> u16 {
5766
0
        self.data.header().identifier.get()
5767
0
    }
5768
5769
    /// The third value enables applications to use a single name for the subfamily identified by the second value.
5770
    ///
5771
    /// If the preceding value is non-zero, this value must be set in the range
5772
    /// 256 – 32767 (inclusive). It records the value of a field in the 'name'
5773
    /// table, which must contain English-language strings encoded in Windows
5774
    /// Unicode and Macintosh Roman, and may contain additional strings localized
5775
    /// to other scripts and languages. Each of these strings is the name
5776
    /// an application should use, in combination with the family name, to
5777
    /// represent the subfamily in a menu. Applications will choose the
5778
    /// appropriate version based on their selection criteria.
5779
0
    pub fn name_entry(&self) -> u16 {
5780
0
        self.data.header().name_entry.get()
5781
0
    }
5782
5783
    /// The fourth and fifth values represent the small end of the recommended
5784
    /// usage range (exclusive) and the large end of the recommended usage range
5785
    /// (inclusive), stored in 720/inch units (decipoints).
5786
    ///
5787
    /// Ranges must not overlap, and should generally be contiguous.
5788
0
    pub fn range_start(&self) -> u16 {
5789
0
        self.data.header().range_start.get()
5790
0
    }
5791
5792
0
    pub fn range_end(&self) -> u16 {
5793
0
        self.data.header().range_end.get()
5794
0
    }
5795
5796
0
    pub fn design_size_byte_range(&self) -> Range<usize> {
5797
0
        let start = 0usize;
5798
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5799
0
        start..end
5800
0
    }
5801
5802
0
    pub fn identifier_byte_range(&self) -> Range<usize> {
5803
0
        let start = self.design_size_byte_range().end;
5804
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5805
0
        start..end
5806
0
    }
5807
5808
0
    pub fn name_entry_byte_range(&self) -> Range<usize> {
5809
0
        let start = self.identifier_byte_range().end;
5810
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5811
0
        start..end
5812
0
    }
5813
5814
0
    pub fn range_start_byte_range(&self) -> Range<usize> {
5815
0
        let start = self.name_entry_byte_range().end;
5816
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5817
0
        start..end
5818
0
    }
5819
5820
0
    pub fn range_end_byte_range(&self) -> Range<usize> {
5821
0
        let start = self.range_start_byte_range().end;
5822
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5823
0
        start..end
5824
0
    }
5825
}
5826
5827
const _: () = assert!(FontData::default_data_long_enough(SizeParams::MIN_SIZE));
5828
5829
impl Default for SizeParams<'_> {
5830
0
    fn default() -> Self {
5831
        Self {
5832
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
5833
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
5834
        }
5835
0
    }
5836
}
5837
5838
impl<'a> MinByteRange<'a> for StylisticSetParams<'a> {
5839
0
    fn min_byte_range(&self) -> Range<usize> {
5840
0
        0..self.ui_name_id_byte_range().end
5841
0
    }
5842
0
    fn min_table_bytes(&self) -> &'a [u8] {
5843
0
        let range = self.min_byte_range();
5844
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5845
0
    }
5846
}
5847
5848
impl ReadArgs for StylisticSetParams<'_> {
5849
    type Args = ();
5850
}
5851
5852
impl<'a> FontRead<'a> for StylisticSetParams<'a> {
5853
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5854
        #[allow(clippy::absurd_extreme_comparisons)]
5855
0
        if data.len() < Self::MIN_SIZE {
5856
0
            return Err(ReadError::OutOfBounds);
5857
0
        }
5858
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5859
0
            return Err(ReadError::OutOfBounds);
5860
        };
5861
0
        Ok(Self { data })
5862
0
    }
5863
}
5864
5865
/// The fields at the start of the table, which are read directly.
5866
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5867
#[repr(C, packed)]
5868
#[doc(hidden)]
5869
pub struct StylisticSetParamsFixedHeader {
5870
    pub version: BigEndian<u16>,
5871
    pub ui_name_id: BigEndian<NameId>,
5872
}
5873
5874
#[allow(clippy::absurd_extreme_comparisons)]
5875
const _: () =
5876
    assert!(std::mem::size_of::<StylisticSetParamsFixedHeader>() <= StylisticSetParams::MIN_SIZE);
5877
5878
#[derive(Clone)]
5879
pub struct StylisticSetParams<'a> {
5880
    data: TableDataRef<'a, StylisticSetParamsFixedHeader>,
5881
}
5882
5883
#[allow(clippy::needless_lifetimes)]
5884
impl<'a> StylisticSetParams<'a> {
5885
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + NameId::RAW_BYTE_LEN);
5886
    basic_table_impls!(impl_the_methods);
5887
5888
0
    pub fn version(&self) -> u16 {
5889
0
        self.data.header().version.get()
5890
0
    }
5891
5892
    /// The 'name' table name ID that specifies a string (or strings, for
5893
    /// multiple languages) for a user-interface label for this feature.
5894
    ///
5895
    /// The value of uiLabelNameId is expected to be in the font-specific name
5896
    /// ID range (256-32767), though that is not a requirement in this Feature
5897
    /// Parameters specification. The user-interface label for the feature can
5898
    /// be provided in multiple languages. An English string should be included
5899
    /// as a fallback. The string should be kept to a minimal length to fit
5900
    /// comfortably with different application interfaces.
5901
0
    pub fn ui_name_id(&self) -> NameId {
5902
0
        self.data.header().ui_name_id.get()
5903
0
    }
5904
5905
0
    pub fn version_byte_range(&self) -> Range<usize> {
5906
0
        let start = 0usize;
5907
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
5908
0
        start..end
5909
0
    }
5910
5911
0
    pub fn ui_name_id_byte_range(&self) -> Range<usize> {
5912
0
        let start = self.version_byte_range().end;
5913
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
5914
0
        start..end
5915
0
    }
5916
}
5917
5918
const _: () = assert!(FontData::default_data_long_enough(
5919
    StylisticSetParams::MIN_SIZE
5920
));
5921
5922
impl Default for StylisticSetParams<'_> {
5923
0
    fn default() -> Self {
5924
        Self {
5925
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
5926
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
5927
        }
5928
0
    }
5929
}
5930
5931
impl Format<u16> for CharacterVariantParams<'_> {
5932
    const FORMAT: u16 = 0;
5933
}
5934
5935
impl<'a> MinByteRange<'a> for CharacterVariantParams<'a> {
5936
0
    fn min_byte_range(&self) -> Range<usize> {
5937
0
        0..self.character_byte_range().end
5938
0
    }
5939
0
    fn min_table_bytes(&self) -> &'a [u8] {
5940
0
        let range = self.min_byte_range();
5941
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5942
0
    }
5943
}
5944
5945
impl ReadArgs for CharacterVariantParams<'_> {
5946
    type Args = ();
5947
}
5948
5949
impl<'a> FontRead<'a> for CharacterVariantParams<'a> {
5950
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5951
        #[allow(clippy::absurd_extreme_comparisons)]
5952
0
        if data.len() < Self::MIN_SIZE {
5953
0
            return Err(ReadError::OutOfBounds);
5954
0
        }
5955
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5956
0
            return Err(ReadError::OutOfBounds);
5957
        };
5958
0
        Ok(Self { data })
5959
0
    }
5960
}
5961
5962
/// The fields at the start of the table, which are read directly.
5963
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5964
#[repr(C, packed)]
5965
#[doc(hidden)]
5966
pub struct CharacterVariantParamsFixedHeader {
5967
    pub format: BigEndian<u16>,
5968
    pub feat_ui_label_name_id: BigEndian<NameId>,
5969
    pub feat_ui_tooltip_text_name_id: BigEndian<NameId>,
5970
    pub sample_text_name_id: BigEndian<NameId>,
5971
    pub num_named_parameters: BigEndian<u16>,
5972
    pub first_param_ui_label_name_id: BigEndian<NameId>,
5973
    pub char_count: BigEndian<u16>,
5974
}
5975
5976
#[allow(clippy::absurd_extreme_comparisons)]
5977
const _: () = assert!(
5978
    std::mem::size_of::<CharacterVariantParamsFixedHeader>() <= CharacterVariantParams::MIN_SIZE
5979
);
5980
5981
/// featureParams for ['cv01'-'cv99'](https://docs.microsoft.com/en-us/typography/opentype/spec/features_ae#cv01-cv99)
5982
#[derive(Clone)]
5983
pub struct CharacterVariantParams<'a> {
5984
    data: TableDataRef<'a, CharacterVariantParamsFixedHeader>,
5985
}
5986
5987
#[allow(clippy::needless_lifetimes)]
5988
impl<'a> CharacterVariantParams<'a> {
5989
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
5990
        + NameId::RAW_BYTE_LEN
5991
        + NameId::RAW_BYTE_LEN
5992
        + NameId::RAW_BYTE_LEN
5993
        + u16::RAW_BYTE_LEN
5994
        + NameId::RAW_BYTE_LEN
5995
        + u16::RAW_BYTE_LEN);
5996
    basic_table_impls!(impl_the_methods);
5997
5998
    /// Format number is set to 0.
5999
0
    pub fn format(&self) -> u16 {
6000
0
        self.data.header().format.get()
6001
0
    }
6002
6003
    /// The 'name' table name ID that specifies a string (or strings,
6004
    /// for multiple languages) for a user-interface label for this
6005
    /// feature. (May be NULL.)
6006
0
    pub fn feat_ui_label_name_id(&self) -> NameId {
6007
0
        self.data.header().feat_ui_label_name_id.get()
6008
0
    }
6009
6010
    /// The 'name' table name ID that specifies a string (or strings,
6011
    /// for multiple languages) that an application can use for tooltip
6012
    /// text for this feature. (May be NULL.)
6013
0
    pub fn feat_ui_tooltip_text_name_id(&self) -> NameId {
6014
0
        self.data.header().feat_ui_tooltip_text_name_id.get()
6015
0
    }
6016
6017
    /// The 'name' table name ID that specifies sample text that
6018
    /// illustrates the effect of this feature. (May be NULL.)
6019
0
    pub fn sample_text_name_id(&self) -> NameId {
6020
0
        self.data.header().sample_text_name_id.get()
6021
0
    }
6022
6023
    /// Number of named parameters. (May be zero.)
6024
0
    pub fn num_named_parameters(&self) -> u16 {
6025
0
        self.data.header().num_named_parameters.get()
6026
0
    }
6027
6028
    /// The first 'name' table name ID used to specify strings for
6029
    /// user-interface labels for the feature parameters. (Must be zero
6030
    /// if numParameters is zero.)
6031
0
    pub fn first_param_ui_label_name_id(&self) -> NameId {
6032
0
        self.data.header().first_param_ui_label_name_id.get()
6033
0
    }
6034
6035
    /// The count of characters for which this feature provides glyph
6036
    /// variants. (May be zero.)
6037
0
    pub fn char_count(&self) -> u16 {
6038
0
        self.data.header().char_count.get()
6039
0
    }
6040
6041
    /// The Unicode Scalar Value of the characters for which this
6042
    /// feature provides glyph variants.
6043
0
    pub fn character(&self) -> &'a [BigEndian<Uint24>] {
6044
0
        let range = self.character_byte_range();
6045
0
        self.offset_data()
6046
0
            .read_array(range)
6047
0
            .ok()
6048
0
            .unwrap_or_default()
6049
0
    }
6050
6051
0
    pub fn format_byte_range(&self) -> Range<usize> {
6052
0
        let start = 0usize;
6053
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6054
0
        start..end
6055
0
    }
6056
6057
0
    pub fn feat_ui_label_name_id_byte_range(&self) -> Range<usize> {
6058
0
        let start = self.format_byte_range().end;
6059
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
6060
0
        start..end
6061
0
    }
6062
6063
0
    pub fn feat_ui_tooltip_text_name_id_byte_range(&self) -> Range<usize> {
6064
0
        let start = self.feat_ui_label_name_id_byte_range().end;
6065
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
6066
0
        start..end
6067
0
    }
6068
6069
0
    pub fn sample_text_name_id_byte_range(&self) -> Range<usize> {
6070
0
        let start = self.feat_ui_tooltip_text_name_id_byte_range().end;
6071
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
6072
0
        start..end
6073
0
    }
6074
6075
0
    pub fn num_named_parameters_byte_range(&self) -> Range<usize> {
6076
0
        let start = self.sample_text_name_id_byte_range().end;
6077
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6078
0
        start..end
6079
0
    }
6080
6081
0
    pub fn first_param_ui_label_name_id_byte_range(&self) -> Range<usize> {
6082
0
        let start = self.num_named_parameters_byte_range().end;
6083
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
6084
0
        start..end
6085
0
    }
6086
6087
0
    pub fn char_count_byte_range(&self) -> Range<usize> {
6088
0
        let start = self.first_param_ui_label_name_id_byte_range().end;
6089
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6090
0
        start..end
6091
0
    }
6092
6093
0
    pub fn character_byte_range(&self) -> Range<usize> {
6094
0
        let char_count = self.char_count();
6095
0
        let start = self.char_count_byte_range().end;
6096
0
        let end = start.saturating_add(
6097
0
            (transforms::to_usize(char_count)).saturating_mul(Uint24::RAW_BYTE_LEN),
6098
        );
6099
0
        start..end
6100
0
    }
6101
}
6102
6103
const _: () = assert!(FontData::default_data_long_enough(
6104
    CharacterVariantParams::MIN_SIZE
6105
));
6106
6107
impl Default for CharacterVariantParams<'_> {
6108
0
    fn default() -> Self {
6109
        Self {
6110
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
6111
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
6112
        }
6113
0
    }
6114
}
6115
6116
impl Format<u16> for CoverageFormat3<'_> {
6117
    const FORMAT: u16 = 3;
6118
}
6119
6120
impl<'a> MinByteRange<'a> for CoverageFormat3<'a> {
6121
0
    fn min_byte_range(&self) -> Range<usize> {
6122
0
        0..self.glyph_array_byte_range().end
6123
0
    }
6124
0
    fn min_table_bytes(&self) -> &'a [u8] {
6125
0
        let range = self.min_byte_range();
6126
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
6127
0
    }
6128
}
6129
6130
impl ReadArgs for CoverageFormat3<'_> {
6131
    type Args = ();
6132
}
6133
6134
impl<'a> FontRead<'a> for CoverageFormat3<'a> {
6135
34.5k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6136
        #[allow(clippy::absurd_extreme_comparisons)]
6137
34.5k
        if data.len() < Self::MIN_SIZE {
6138
1.85k
            return Err(ReadError::OutOfBounds);
6139
32.6k
        }
6140
32.6k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6141
0
            return Err(ReadError::OutOfBounds);
6142
        };
6143
32.6k
        Ok(Self { data })
6144
34.5k
    }
6145
}
6146
6147
/// The fields at the start of the table, which are read directly.
6148
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6149
#[repr(C, packed)]
6150
#[doc(hidden)]
6151
pub struct CoverageFormat3FixedHeader {
6152
    pub coverage_format: BigEndian<u16>,
6153
    pub glyph_count: BigEndian<Uint24>,
6154
}
6155
6156
#[allow(clippy::absurd_extreme_comparisons)]
6157
const _: () =
6158
    assert!(std::mem::size_of::<CoverageFormat3FixedHeader>() <= CoverageFormat3::MIN_SIZE);
6159
6160
/// CoverageFormat3 (ISO/IEC 14496-22:2026).
6161
#[derive(Clone)]
6162
pub struct CoverageFormat3<'a> {
6163
    data: TableDataRef<'a, CoverageFormat3FixedHeader>,
6164
}
6165
6166
#[allow(clippy::needless_lifetimes)]
6167
impl<'a> CoverageFormat3<'a> {
6168
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6169
    basic_table_impls!(impl_the_methods);
6170
6171
    /// Format identifier — format = 3
6172
0
    pub fn coverage_format(&self) -> u16 {
6173
0
        self.data.header().coverage_format.get()
6174
0
    }
6175
6176
    /// Number of glyphs in the glyph array
6177
34.1k
    pub fn glyph_count(&self) -> Uint24 {
6178
34.1k
        self.data.header().glyph_count.get()
6179
34.1k
    }
6180
6181
    /// Array of glyph IDs — in numerical order
6182
34.1k
    pub fn glyph_array(&self) -> &'a [BigEndian<GlyphId24>] {
6183
34.1k
        let range = self.glyph_array_byte_range();
6184
34.1k
        self.offset_data()
6185
34.1k
            .read_array(range)
6186
34.1k
            .ok()
6187
34.1k
            .unwrap_or_default()
6188
34.1k
    }
6189
6190
34.1k
    pub fn coverage_format_byte_range(&self) -> Range<usize> {
6191
34.1k
        let start = 0usize;
6192
34.1k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6193
34.1k
        start..end
6194
34.1k
    }
6195
6196
34.1k
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
6197
34.1k
        let start = self.coverage_format_byte_range().end;
6198
34.1k
        let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6199
34.1k
        start..end
6200
34.1k
    }
6201
6202
34.1k
    pub fn glyph_array_byte_range(&self) -> Range<usize> {
6203
34.1k
        let glyph_count = self.glyph_count();
6204
34.1k
        let start = self.glyph_count_byte_range().end;
6205
34.1k
        let end = start.saturating_add(
6206
34.1k
            (transforms::to_usize(glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN),
6207
        );
6208
34.1k
        start..end
6209
34.1k
    }
6210
}
6211
6212
impl Format<u16> for CoverageFormat4<'_> {
6213
    const FORMAT: u16 = 4;
6214
}
6215
6216
impl<'a> MinByteRange<'a> for CoverageFormat4<'a> {
6217
0
    fn min_byte_range(&self) -> Range<usize> {
6218
0
        0..self.range_records_byte_range().end
6219
0
    }
6220
0
    fn min_table_bytes(&self) -> &'a [u8] {
6221
0
        let range = self.min_byte_range();
6222
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
6223
0
    }
6224
}
6225
6226
impl ReadArgs for CoverageFormat4<'_> {
6227
    type Args = ();
6228
}
6229
6230
impl<'a> FontRead<'a> for CoverageFormat4<'a> {
6231
36.5k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6232
        #[allow(clippy::absurd_extreme_comparisons)]
6233
36.5k
        if data.len() < Self::MIN_SIZE {
6234
2.04k
            return Err(ReadError::OutOfBounds);
6235
34.5k
        }
6236
34.5k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6237
0
            return Err(ReadError::OutOfBounds);
6238
        };
6239
34.5k
        Ok(Self { data })
6240
36.5k
    }
6241
}
6242
6243
/// The fields at the start of the table, which are read directly.
6244
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6245
#[repr(C, packed)]
6246
#[doc(hidden)]
6247
pub struct CoverageFormat4FixedHeader {
6248
    pub coverage_format: BigEndian<u16>,
6249
    pub range_count: BigEndian<Uint24>,
6250
}
6251
6252
#[allow(clippy::absurd_extreme_comparisons)]
6253
const _: () =
6254
    assert!(std::mem::size_of::<CoverageFormat4FixedHeader>() <= CoverageFormat4::MIN_SIZE);
6255
6256
/// CoverageFormat4 (ISO/IEC 14496-22:2026).
6257
#[derive(Clone)]
6258
pub struct CoverageFormat4<'a> {
6259
    data: TableDataRef<'a, CoverageFormat4FixedHeader>,
6260
}
6261
6262
#[allow(clippy::needless_lifetimes)]
6263
impl<'a> CoverageFormat4<'a> {
6264
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6265
    basic_table_impls!(impl_the_methods);
6266
6267
    /// Format identifier — format = 4
6268
0
    pub fn coverage_format(&self) -> u16 {
6269
0
        self.data.header().coverage_format.get()
6270
0
    }
6271
6272
    /// Number of RangeRecords
6273
35.8k
    pub fn range_count(&self) -> Uint24 {
6274
35.8k
        self.data.header().range_count.get()
6275
35.8k
    }
6276
6277
    /// Array of glyph ranges — ordered by startGlyphID.
6278
35.8k
    pub fn range_records(&self) -> &'a [RangeRecord2] {
6279
35.8k
        let range = self.range_records_byte_range();
6280
35.8k
        self.offset_data()
6281
35.8k
            .read_array(range)
6282
35.8k
            .ok()
6283
35.8k
            .unwrap_or_default()
6284
35.8k
    }
6285
6286
35.8k
    pub fn coverage_format_byte_range(&self) -> Range<usize> {
6287
35.8k
        let start = 0usize;
6288
35.8k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6289
35.8k
        start..end
6290
35.8k
    }
6291
6292
35.8k
    pub fn range_count_byte_range(&self) -> Range<usize> {
6293
35.8k
        let start = self.coverage_format_byte_range().end;
6294
35.8k
        let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6295
35.8k
        start..end
6296
35.8k
    }
6297
6298
35.8k
    pub fn range_records_byte_range(&self) -> Range<usize> {
6299
35.8k
        let range_count = self.range_count();
6300
35.8k
        let start = self.range_count_byte_range().end;
6301
35.8k
        let end = start.saturating_add(
6302
35.8k
            (transforms::to_usize(range_count)).saturating_mul(RangeRecord2::RAW_BYTE_LEN),
6303
        );
6304
35.8k
        start..end
6305
35.8k
    }
6306
}
6307
6308
/// RangeRecord2 (ISO/IEC 14496-22:2026).
6309
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
6310
#[repr(C)]
6311
#[repr(packed)]
6312
pub struct RangeRecord2 {
6313
    /// First glyph ID in the range
6314
    pub start_glyph_id: BigEndian<GlyphId24>,
6315
    /// Last glyph ID in the range
6316
    pub end_glyph_id: BigEndian<GlyphId24>,
6317
    /// Coverage Index of first glyph ID in range
6318
    pub start_coverage_index: BigEndian<Uint24>,
6319
}
6320
6321
impl RangeRecord2 {
6322
    /// First glyph ID in the range
6323
20.5M
    pub fn start_glyph_id(&self) -> GlyphId24 {
6324
20.5M
        self.start_glyph_id.get()
6325
20.5M
    }
6326
6327
    /// Last glyph ID in the range
6328
17.7M
    pub fn end_glyph_id(&self) -> GlyphId24 {
6329
17.7M
        self.end_glyph_id.get()
6330
17.7M
    }
6331
6332
    /// Coverage Index of first glyph ID in range
6333
2.73M
    pub fn start_coverage_index(&self) -> Uint24 {
6334
2.73M
        self.start_coverage_index.get()
6335
2.73M
    }
6336
}
6337
6338
impl FixedSize for RangeRecord2 {
6339
    const RAW_BYTE_LEN: usize =
6340
        GlyphId24::RAW_BYTE_LEN + GlyphId24::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN;
6341
}
6342
6343
impl Format<u16> for ClassDefFormat3<'_> {
6344
    const FORMAT: u16 = 3;
6345
}
6346
6347
impl<'a> MinByteRange<'a> for ClassDefFormat3<'a> {
6348
0
    fn min_byte_range(&self) -> Range<usize> {
6349
0
        0..self.class_value_array_byte_range().end
6350
0
    }
6351
0
    fn min_table_bytes(&self) -> &'a [u8] {
6352
0
        let range = self.min_byte_range();
6353
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
6354
0
    }
6355
}
6356
6357
impl ReadArgs for ClassDefFormat3<'_> {
6358
    type Args = ();
6359
}
6360
6361
impl<'a> FontRead<'a> for ClassDefFormat3<'a> {
6362
8.35k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6363
        #[allow(clippy::absurd_extreme_comparisons)]
6364
8.35k
        if data.len() < Self::MIN_SIZE {
6365
1.57k
            return Err(ReadError::OutOfBounds);
6366
6.77k
        }
6367
6.77k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6368
0
            return Err(ReadError::OutOfBounds);
6369
        };
6370
6.77k
        Ok(Self { data })
6371
8.35k
    }
6372
}
6373
6374
/// The fields at the start of the table, which are read directly.
6375
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6376
#[repr(C, packed)]
6377
#[doc(hidden)]
6378
pub struct ClassDefFormat3FixedHeader {
6379
    pub class_format: BigEndian<u16>,
6380
    pub start_glyph_id: BigEndian<GlyphId24>,
6381
    pub glyph_count: BigEndian<Uint24>,
6382
}
6383
6384
#[allow(clippy::absurd_extreme_comparisons)]
6385
const _: () =
6386
    assert!(std::mem::size_of::<ClassDefFormat3FixedHeader>() <= ClassDefFormat3::MIN_SIZE);
6387
6388
/// ClassDefFormat3 (ISO/IEC 14496-22:2026).
6389
#[derive(Clone)]
6390
pub struct ClassDefFormat3<'a> {
6391
    data: TableDataRef<'a, ClassDefFormat3FixedHeader>,
6392
}
6393
6394
#[allow(clippy::needless_lifetimes)]
6395
impl<'a> ClassDefFormat3<'a> {
6396
    pub const MIN_SIZE: usize =
6397
        (u16::RAW_BYTE_LEN + GlyphId24::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6398
    basic_table_impls!(impl_the_methods);
6399
6400
    /// Format identifier — format = 3
6401
0
    pub fn class_format(&self) -> u16 {
6402
0
        self.data.header().class_format.get()
6403
0
    }
6404
6405
    /// First glyph ID of the classValueArray
6406
6.77k
    pub fn start_glyph_id(&self) -> GlyphId24 {
6407
6.77k
        self.data.header().start_glyph_id.get()
6408
6.77k
    }
6409
6410
    /// Size of the classValueArray
6411
6.77k
    pub fn glyph_count(&self) -> Uint24 {
6412
6.77k
        self.data.header().glyph_count.get()
6413
6.77k
    }
6414
6415
    /// Array of Class Values — one per glyph ID
6416
6.77k
    pub fn class_value_array(&self) -> &'a [BigEndian<Uint24>] {
6417
6.77k
        let range = self.class_value_array_byte_range();
6418
6.77k
        self.offset_data()
6419
6.77k
            .read_array(range)
6420
6.77k
            .ok()
6421
6.77k
            .unwrap_or_default()
6422
6.77k
    }
6423
6424
6.77k
    pub fn class_format_byte_range(&self) -> Range<usize> {
6425
6.77k
        let start = 0usize;
6426
6.77k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6427
6.77k
        start..end
6428
6.77k
    }
6429
6430
6.77k
    pub fn start_glyph_id_byte_range(&self) -> Range<usize> {
6431
6.77k
        let start = self.class_format_byte_range().end;
6432
6.77k
        let end = start.saturating_add(GlyphId24::RAW_BYTE_LEN);
6433
6.77k
        start..end
6434
6.77k
    }
6435
6436
6.77k
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
6437
6.77k
        let start = self.start_glyph_id_byte_range().end;
6438
6.77k
        let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6439
6.77k
        start..end
6440
6.77k
    }
6441
6442
6.77k
    pub fn class_value_array_byte_range(&self) -> Range<usize> {
6443
6.77k
        let glyph_count = self.glyph_count();
6444
6.77k
        let start = self.glyph_count_byte_range().end;
6445
6.77k
        let end = start.saturating_add(
6446
6.77k
            (transforms::to_usize(glyph_count)).saturating_mul(Uint24::RAW_BYTE_LEN),
6447
        );
6448
6.77k
        start..end
6449
6.77k
    }
6450
}
6451
6452
impl Format<u16> for ClassDefFormat4<'_> {
6453
    const FORMAT: u16 = 4;
6454
}
6455
6456
impl<'a> MinByteRange<'a> for ClassDefFormat4<'a> {
6457
0
    fn min_byte_range(&self) -> Range<usize> {
6458
0
        0..self.class_range_records_byte_range().end
6459
0
    }
6460
0
    fn min_table_bytes(&self) -> &'a [u8] {
6461
0
        let range = self.min_byte_range();
6462
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
6463
0
    }
6464
}
6465
6466
impl ReadArgs for ClassDefFormat4<'_> {
6467
    type Args = ();
6468
}
6469
6470
impl<'a> FontRead<'a> for ClassDefFormat4<'a> {
6471
9.14k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6472
        #[allow(clippy::absurd_extreme_comparisons)]
6473
9.14k
        if data.len() < Self::MIN_SIZE {
6474
1.63k
            return Err(ReadError::OutOfBounds);
6475
7.50k
        }
6476
7.50k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6477
0
            return Err(ReadError::OutOfBounds);
6478
        };
6479
7.50k
        Ok(Self { data })
6480
9.14k
    }
6481
}
6482
6483
/// The fields at the start of the table, which are read directly.
6484
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6485
#[repr(C, packed)]
6486
#[doc(hidden)]
6487
pub struct ClassDefFormat4FixedHeader {
6488
    pub class_format: BigEndian<u16>,
6489
    pub class_range_count: BigEndian<Uint24>,
6490
}
6491
6492
#[allow(clippy::absurd_extreme_comparisons)]
6493
const _: () =
6494
    assert!(std::mem::size_of::<ClassDefFormat4FixedHeader>() <= ClassDefFormat4::MIN_SIZE);
6495
6496
/// ClassDefFormat4 (ISO/IEC 14496-22:2026).
6497
#[derive(Clone)]
6498
pub struct ClassDefFormat4<'a> {
6499
    data: TableDataRef<'a, ClassDefFormat4FixedHeader>,
6500
}
6501
6502
#[allow(clippy::needless_lifetimes)]
6503
impl<'a> ClassDefFormat4<'a> {
6504
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6505
    basic_table_impls!(impl_the_methods);
6506
6507
    /// Format identifier — format = 4
6508
0
    pub fn class_format(&self) -> u16 {
6509
0
        self.data.header().class_format.get()
6510
0
    }
6511
6512
    /// Number of ClassRangeRecords
6513
7.50k
    pub fn class_range_count(&self) -> Uint24 {
6514
7.50k
        self.data.header().class_range_count.get()
6515
7.50k
    }
6516
6517
    /// Array of ClassRangeRecords — ordered by startGlyphID
6518
7.50k
    pub fn class_range_records(&self) -> &'a [ClassRangeRecord2] {
6519
7.50k
        let range = self.class_range_records_byte_range();
6520
7.50k
        self.offset_data()
6521
7.50k
            .read_array(range)
6522
7.50k
            .ok()
6523
7.50k
            .unwrap_or_default()
6524
7.50k
    }
6525
6526
7.50k
    pub fn class_format_byte_range(&self) -> Range<usize> {
6527
7.50k
        let start = 0usize;
6528
7.50k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6529
7.50k
        start..end
6530
7.50k
    }
6531
6532
7.50k
    pub fn class_range_count_byte_range(&self) -> Range<usize> {
6533
7.50k
        let start = self.class_format_byte_range().end;
6534
7.50k
        let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6535
7.50k
        start..end
6536
7.50k
    }
6537
6538
7.50k
    pub fn class_range_records_byte_range(&self) -> Range<usize> {
6539
7.50k
        let class_range_count = self.class_range_count();
6540
7.50k
        let start = self.class_range_count_byte_range().end;
6541
7.50k
        let end = start.saturating_add(
6542
7.50k
            (transforms::to_usize(class_range_count))
6543
7.50k
                .saturating_mul(ClassRangeRecord2::RAW_BYTE_LEN),
6544
        );
6545
7.50k
        start..end
6546
7.50k
    }
6547
}
6548
6549
/// ClassRangeRecord2 (ISO/IEC 14496-22:2026).
6550
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
6551
#[repr(C)]
6552
#[repr(packed)]
6553
pub struct ClassRangeRecord2 {
6554
    /// First glyph ID in the range
6555
    pub start_glyph_id: BigEndian<GlyphId24>,
6556
    /// Last glyph ID in the range
6557
    pub end_glyph_id: BigEndian<GlyphId24>,
6558
    /// Applied to all glyphs in the range
6559
    pub class: BigEndian<u16>,
6560
}
6561
6562
impl ClassRangeRecord2 {
6563
    /// First glyph ID in the range
6564
596k
    pub fn start_glyph_id(&self) -> GlyphId24 {
6565
596k
        self.start_glyph_id.get()
6566
596k
    }
6567
6568
    /// Last glyph ID in the range
6569
596k
    pub fn end_glyph_id(&self) -> GlyphId24 {
6570
596k
        self.end_glyph_id.get()
6571
596k
    }
6572
6573
    /// Applied to all glyphs in the range
6574
53.5k
    pub fn class(&self) -> u16 {
6575
53.5k
        self.class.get()
6576
53.5k
    }
6577
}
6578
6579
impl FixedSize for ClassRangeRecord2 {
6580
    const RAW_BYTE_LEN: usize =
6581
        GlyphId24::RAW_BYTE_LEN + GlyphId24::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
6582
}
6583
6584
impl Format<u16> for SequenceContextFormat4<'_> {
6585
    const FORMAT: u16 = 4;
6586
}
6587
6588
impl<'a> MinByteRange<'a> for SequenceContextFormat4<'a> {
6589
0
    fn min_byte_range(&self) -> Range<usize> {
6590
0
        0..self.seq_rule_set_offsets_byte_range().end
6591
0
    }
6592
0
    fn min_table_bytes(&self) -> &'a [u8] {
6593
0
        let range = self.min_byte_range();
6594
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
6595
0
    }
6596
}
6597
6598
impl ReadArgs for SequenceContextFormat4<'_> {
6599
    type Args = ();
6600
}
6601
6602
impl<'a> FontRead<'a> for SequenceContextFormat4<'a> {
6603
12.3k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6604
        #[allow(clippy::absurd_extreme_comparisons)]
6605
12.3k
        if data.len() < Self::MIN_SIZE {
6606
261
            return Err(ReadError::OutOfBounds);
6607
12.0k
        }
6608
12.0k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6609
0
            return Err(ReadError::OutOfBounds);
6610
        };
6611
12.0k
        Ok(Self { data })
6612
12.3k
    }
6613
}
6614
6615
/// The fields at the start of the table, which are read directly.
6616
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6617
#[repr(C, packed)]
6618
#[doc(hidden)]
6619
pub struct SequenceContextFormat4FixedHeader {
6620
    pub format: BigEndian<u16>,
6621
    pub coverage_offset: BigEndian<Offset32>,
6622
    pub seq_rule_set_count: BigEndian<Uint24>,
6623
}
6624
6625
#[allow(clippy::absurd_extreme_comparisons)]
6626
const _: () = assert!(
6627
    std::mem::size_of::<SequenceContextFormat4FixedHeader>() <= SequenceContextFormat4::MIN_SIZE
6628
);
6629
6630
/// SequenceContextFormat4 (ISO/IEC 14496-22:2026).
6631
#[derive(Clone)]
6632
pub struct SequenceContextFormat4<'a> {
6633
    data: TableDataRef<'a, SequenceContextFormat4FixedHeader>,
6634
}
6635
6636
#[allow(clippy::needless_lifetimes)]
6637
impl<'a> SequenceContextFormat4<'a> {
6638
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
6639
    basic_table_impls!(impl_the_methods);
6640
6641
    /// Format identifier: format = 4
6642
0
    pub fn format(&self) -> u16 {
6643
0
        self.data.header().format.get()
6644
0
    }
6645
6646
    /// Offset to Coverage table, from beginning of
6647
    /// SequenceContextFormat4 table
6648
12.0k
    pub fn coverage_offset(&self) -> Offset32 {
6649
12.0k
        self.data.header().coverage_offset.get()
6650
12.0k
    }
6651
6652
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
6653
12.0k
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
6654
12.0k
        let data = self.offset_data();
6655
12.0k
        self.coverage_offset().resolve(data)
6656
12.0k
    }
6657
6658
    /// Number of SequenceRuleSet tables
6659
12.0k
    pub fn seq_rule_set_count(&self) -> Uint24 {
6660
12.0k
        self.data.header().seq_rule_set_count.get()
6661
12.0k
    }
6662
6663
    /// Array of offsets to SequenceRuleSet tables, from beginning of
6664
    /// SequenceContextFormat4 table (offsets may be NULL)
6665
0
    pub fn seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] {
6666
0
        let range = self.seq_rule_set_offsets_byte_range();
6667
0
        self.offset_data()
6668
0
            .read_array(range)
6669
0
            .ok()
6670
0
            .unwrap_or_default()
6671
0
    }
6672
6673
    /// A dynamically resolving wrapper for [`seq_rule_set_offsets`][Self::seq_rule_set_offsets].
6674
0
    pub fn seq_rule_sets(&self) -> ArrayOfNullableOffsets<'a, SequenceRuleSet2<'a>, Offset24> {
6675
0
        let data = self.offset_data();
6676
0
        let offsets = self.seq_rule_set_offsets();
6677
0
        ArrayOfNullableOffsets::new(offsets, data, ())
6678
0
    }
6679
6680
12.0k
    pub fn format_byte_range(&self) -> Range<usize> {
6681
12.0k
        let start = 0usize;
6682
12.0k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6683
12.0k
        start..end
6684
12.0k
    }
6685
6686
12.0k
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
6687
12.0k
        let start = self.format_byte_range().end;
6688
12.0k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
6689
12.0k
        start..end
6690
12.0k
    }
6691
6692
12.0k
    pub fn seq_rule_set_count_byte_range(&self) -> Range<usize> {
6693
12.0k
        let start = self.coverage_offset_byte_range().end;
6694
12.0k
        let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
6695
12.0k
        start..end
6696
12.0k
    }
6697
6698
12.0k
    pub fn seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
6699
12.0k
        let seq_rule_set_count = self.seq_rule_set_count();
6700
12.0k
        let start = self.seq_rule_set_count_byte_range().end;
6701
12.0k
        let end = start.saturating_add(
6702
12.0k
            (transforms::to_usize(seq_rule_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
6703
        );
6704
12.0k
        start..end
6705
12.0k
    }
6706
}
6707
6708
impl<'a> MinByteRange<'a> for SequenceRuleSet2<'a> {
6709
0
    fn min_byte_range(&self) -> Range<usize> {
6710
0
        0..self.seq_rule_offsets_byte_range().end
6711
0
    }
6712
0
    fn min_table_bytes(&self) -> &'a [u8] {
6713
0
        let range = self.min_byte_range();
6714
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
6715
0
    }
6716
}
6717
6718
impl ReadArgs for SequenceRuleSet2<'_> {
6719
    type Args = ();
6720
}
6721
6722
impl<'a> FontRead<'a> for SequenceRuleSet2<'a> {
6723
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6724
        #[allow(clippy::absurd_extreme_comparisons)]
6725
0
        if data.len() < Self::MIN_SIZE {
6726
0
            return Err(ReadError::OutOfBounds);
6727
0
        }
6728
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6729
0
            return Err(ReadError::OutOfBounds);
6730
        };
6731
0
        Ok(Self { data })
6732
0
    }
6733
}
6734
6735
/// The fields at the start of the table, which are read directly.
6736
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6737
#[repr(C, packed)]
6738
#[doc(hidden)]
6739
pub struct SequenceRuleSet2FixedHeader {
6740
    pub seq_rule_count: BigEndian<u16>,
6741
}
6742
6743
#[allow(clippy::absurd_extreme_comparisons)]
6744
const _: () =
6745
    assert!(std::mem::size_of::<SequenceRuleSet2FixedHeader>() <= SequenceRuleSet2::MIN_SIZE);
6746
6747
/// SequenceRuleSet2 (ISO/IEC 14496-22:2026).
6748
#[derive(Clone)]
6749
pub struct SequenceRuleSet2<'a> {
6750
    data: TableDataRef<'a, SequenceRuleSet2FixedHeader>,
6751
}
6752
6753
#[allow(clippy::needless_lifetimes)]
6754
impl<'a> SequenceRuleSet2<'a> {
6755
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
6756
    basic_table_impls!(impl_the_methods);
6757
6758
    /// Number of SequenceRule tables
6759
0
    pub fn seq_rule_count(&self) -> u16 {
6760
0
        self.data.header().seq_rule_count.get()
6761
0
    }
6762
6763
    /// Array of offsets to SequenceRule tables, from beginning of the
6764
    /// SequenceRuleSet2 table
6765
0
    pub fn seq_rule_offsets(&self) -> &'a [BigEndian<Offset16>] {
6766
0
        let range = self.seq_rule_offsets_byte_range();
6767
0
        self.offset_data()
6768
0
            .read_array(range)
6769
0
            .ok()
6770
0
            .unwrap_or_default()
6771
0
    }
6772
6773
    /// A dynamically resolving wrapper for [`seq_rule_offsets`][Self::seq_rule_offsets].
6774
0
    pub fn seq_rules(&self) -> ArrayOfOffsets<'a, SequenceRule2<'a>, Offset16> {
6775
0
        let data = self.offset_data();
6776
0
        let offsets = self.seq_rule_offsets();
6777
0
        ArrayOfOffsets::new(offsets, data, ())
6778
0
    }
6779
6780
0
    pub fn seq_rule_count_byte_range(&self) -> Range<usize> {
6781
0
        let start = 0usize;
6782
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6783
0
        start..end
6784
0
    }
6785
6786
0
    pub fn seq_rule_offsets_byte_range(&self) -> Range<usize> {
6787
0
        let seq_rule_count = self.seq_rule_count();
6788
0
        let start = self.seq_rule_count_byte_range().end;
6789
0
        let end = start.saturating_add(
6790
0
            (transforms::to_usize(seq_rule_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
6791
        );
6792
0
        start..end
6793
0
    }
6794
}
6795
6796
const _: () = assert!(FontData::default_data_long_enough(
6797
    SequenceRuleSet2::MIN_SIZE
6798
));
6799
6800
impl Default for SequenceRuleSet2<'_> {
6801
0
    fn default() -> Self {
6802
        Self {
6803
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
6804
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
6805
        }
6806
0
    }
6807
}
6808
6809
impl<'a> MinByteRange<'a> for SequenceRule2<'a> {
6810
0
    fn min_byte_range(&self) -> Range<usize> {
6811
0
        0..self.seq_lookup_records_byte_range().end
6812
0
    }
6813
0
    fn min_table_bytes(&self) -> &'a [u8] {
6814
0
        let range = self.min_byte_range();
6815
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
6816
0
    }
6817
}
6818
6819
impl ReadArgs for SequenceRule2<'_> {
6820
    type Args = ();
6821
}
6822
6823
impl<'a> FontRead<'a> for SequenceRule2<'a> {
6824
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6825
        #[allow(clippy::absurd_extreme_comparisons)]
6826
0
        if data.len() < Self::MIN_SIZE {
6827
0
            return Err(ReadError::OutOfBounds);
6828
0
        }
6829
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6830
0
            return Err(ReadError::OutOfBounds);
6831
        };
6832
0
        Ok(Self { data })
6833
0
    }
6834
}
6835
6836
/// The fields at the start of the table, which are read directly.
6837
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6838
#[repr(C, packed)]
6839
#[doc(hidden)]
6840
pub struct SequenceRule2FixedHeader {
6841
    pub glyph_count: BigEndian<u16>,
6842
    pub seq_lookup_count: BigEndian<u16>,
6843
}
6844
6845
#[allow(clippy::absurd_extreme_comparisons)]
6846
const _: () = assert!(std::mem::size_of::<SequenceRule2FixedHeader>() <= SequenceRule2::MIN_SIZE);
6847
6848
/// SequenceRule2 (ISO/IEC 14496-22:2026).
6849
#[derive(Clone)]
6850
pub struct SequenceRule2<'a> {
6851
    data: TableDataRef<'a, SequenceRule2FixedHeader>,
6852
}
6853
6854
#[allow(clippy::needless_lifetimes)]
6855
impl<'a> SequenceRule2<'a> {
6856
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
6857
    basic_table_impls!(impl_the_methods);
6858
6859
    /// Number of glyphs in the input glyph sequence
6860
0
    pub fn glyph_count(&self) -> u16 {
6861
0
        self.data.header().glyph_count.get()
6862
0
    }
6863
6864
    /// Number of SequenceLookupRecords
6865
0
    pub fn seq_lookup_count(&self) -> u16 {
6866
0
        self.data.header().seq_lookup_count.get()
6867
0
    }
6868
6869
    /// Array of input glyph IDs—starting with the second glyph
6870
0
    pub fn input_sequence(&self) -> &'a [BigEndian<GlyphId24>] {
6871
0
        let range = self.input_sequence_byte_range();
6872
0
        self.offset_data()
6873
0
            .read_array(range)
6874
0
            .ok()
6875
0
            .unwrap_or_default()
6876
0
    }
6877
6878
    /// Array of Sequence lookup records
6879
0
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
6880
0
        let range = self.seq_lookup_records_byte_range();
6881
0
        self.offset_data()
6882
0
            .read_array(range)
6883
0
            .ok()
6884
0
            .unwrap_or_default()
6885
0
    }
6886
6887
0
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
6888
0
        let start = 0usize;
6889
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6890
0
        start..end
6891
0
    }
6892
6893
0
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
6894
0
        let start = self.glyph_count_byte_range().end;
6895
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
6896
0
        start..end
6897
0
    }
6898
6899
0
    pub fn input_sequence_byte_range(&self) -> Range<usize> {
6900
0
        let glyph_count = self.glyph_count();
6901
0
        let start = self.seq_lookup_count_byte_range().end;
6902
0
        let end = start.saturating_add(
6903
0
            (transforms::subtract(glyph_count, 1_usize)).saturating_mul(GlyphId24::RAW_BYTE_LEN),
6904
        );
6905
0
        start..end
6906
0
    }
6907
6908
0
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
6909
0
        let seq_lookup_count = self.seq_lookup_count();
6910
0
        let start = self.input_sequence_byte_range().end;
6911
0
        let end = start.saturating_add(
6912
0
            (transforms::to_usize(seq_lookup_count))
6913
0
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
6914
        );
6915
0
        start..end
6916
0
    }
6917
}
6918
6919
const _: () = assert!(FontData::default_data_long_enough(SequenceRule2::MIN_SIZE));
6920
6921
impl Default for SequenceRule2<'_> {
6922
0
    fn default() -> Self {
6923
        Self {
6924
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
6925
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
6926
        }
6927
0
    }
6928
}
6929
6930
impl Format<u16> for SequenceContextFormat5<'_> {
6931
    const FORMAT: u16 = 5;
6932
}
6933
6934
impl<'a> MinByteRange<'a> for SequenceContextFormat5<'a> {
6935
0
    fn min_byte_range(&self) -> Range<usize> {
6936
0
        0..self.class_seq_rule_set_offsets_byte_range().end
6937
0
    }
6938
0
    fn min_table_bytes(&self) -> &'a [u8] {
6939
0
        let range = self.min_byte_range();
6940
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
6941
0
    }
6942
}
6943
6944
impl ReadArgs for SequenceContextFormat5<'_> {
6945
    type Args = ();
6946
}
6947
6948
impl<'a> FontRead<'a> for SequenceContextFormat5<'a> {
6949
337k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6950
        #[allow(clippy::absurd_extreme_comparisons)]
6951
337k
        if data.len() < Self::MIN_SIZE {
6952
263
            return Err(ReadError::OutOfBounds);
6953
337k
        }
6954
337k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6955
0
            return Err(ReadError::OutOfBounds);
6956
        };
6957
337k
        Ok(Self { data })
6958
337k
    }
6959
}
6960
6961
/// The fields at the start of the table, which are read directly.
6962
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6963
#[repr(C, packed)]
6964
#[doc(hidden)]
6965
pub struct SequenceContextFormat5FixedHeader {
6966
    pub format: BigEndian<u16>,
6967
    pub coverage_offset: BigEndian<Offset32>,
6968
    pub class_def_offset: BigEndian<Offset32>,
6969
    pub class_seq_rule_set_count: BigEndian<Uint24>,
6970
}
6971
6972
#[allow(clippy::absurd_extreme_comparisons)]
6973
const _: () = assert!(
6974
    std::mem::size_of::<SequenceContextFormat5FixedHeader>() <= SequenceContextFormat5::MIN_SIZE
6975
);
6976
6977
/// SequenceContextFormat5 (ISO/IEC 14496-22:2026).
6978
#[derive(Clone)]
6979
pub struct SequenceContextFormat5<'a> {
6980
    data: TableDataRef<'a, SequenceContextFormat5FixedHeader>,
6981
}
6982
6983
#[allow(clippy::needless_lifetimes)]
6984
impl<'a> SequenceContextFormat5<'a> {
6985
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
6986
        + Offset32::RAW_BYTE_LEN
6987
        + Offset32::RAW_BYTE_LEN
6988
        + Uint24::RAW_BYTE_LEN);
6989
    basic_table_impls!(impl_the_methods);
6990
6991
    /// Format identifier: format = 5
6992
0
    pub fn format(&self) -> u16 {
6993
0
        self.data.header().format.get()
6994
0
    }
6995
6996
    /// Offset to Coverage table, from beginning of
6997
    /// SequenceContextFormat5 table
6998
337k
    pub fn coverage_offset(&self) -> Offset32 {
6999
337k
        self.data.header().coverage_offset.get()
7000
337k
    }
7001
7002
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
7003
337k
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
7004
337k
        let data = self.offset_data();
7005
337k
        self.coverage_offset().resolve(data)
7006
337k
    }
7007
7008
    /// Offset to ClassDef table, from beginning of
7009
    /// SequenceContextFormat5 table
7010
337k
    pub fn class_def_offset(&self) -> Offset32 {
7011
337k
        self.data.header().class_def_offset.get()
7012
337k
    }
7013
7014
    /// Attempt to resolve [`class_def_offset`][Self::class_def_offset].
7015
337k
    pub fn class_def(&self) -> Result<ClassDef<'a>, ReadError> {
7016
337k
        let data = self.offset_data();
7017
337k
        self.class_def_offset().resolve(data)
7018
337k
    }
7019
7020
    /// Number of ClassSequenceRuleSet tables
7021
337k
    pub fn class_seq_rule_set_count(&self) -> Uint24 {
7022
337k
        self.data.header().class_seq_rule_set_count.get()
7023
337k
    }
7024
7025
    /// Array of offsets to ClassSequenceRuleSet tables, from beginning
7026
    /// of SequenceContextFormat5 table (may be NULL)
7027
0
    pub fn class_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] {
7028
0
        let range = self.class_seq_rule_set_offsets_byte_range();
7029
0
        self.offset_data()
7030
0
            .read_array(range)
7031
0
            .ok()
7032
0
            .unwrap_or_default()
7033
0
    }
7034
7035
    /// A dynamically resolving wrapper for [`class_seq_rule_set_offsets`][Self::class_seq_rule_set_offsets].
7036
0
    pub fn class_seq_rule_sets(
7037
0
        &self,
7038
0
    ) -> ArrayOfNullableOffsets<'a, ClassSequenceRuleSet2<'a>, Offset24> {
7039
0
        let data = self.offset_data();
7040
0
        let offsets = self.class_seq_rule_set_offsets();
7041
0
        ArrayOfNullableOffsets::new(offsets, data, ())
7042
0
    }
7043
7044
337k
    pub fn format_byte_range(&self) -> Range<usize> {
7045
337k
        let start = 0usize;
7046
337k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7047
337k
        start..end
7048
337k
    }
7049
7050
337k
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
7051
337k
        let start = self.format_byte_range().end;
7052
337k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7053
337k
        start..end
7054
337k
    }
7055
7056
337k
    pub fn class_def_offset_byte_range(&self) -> Range<usize> {
7057
337k
        let start = self.coverage_offset_byte_range().end;
7058
337k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7059
337k
        start..end
7060
337k
    }
7061
7062
337k
    pub fn class_seq_rule_set_count_byte_range(&self) -> Range<usize> {
7063
337k
        let start = self.class_def_offset_byte_range().end;
7064
337k
        let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
7065
337k
        start..end
7066
337k
    }
7067
7068
337k
    pub fn class_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
7069
337k
        let class_seq_rule_set_count = self.class_seq_rule_set_count();
7070
337k
        let start = self.class_seq_rule_set_count_byte_range().end;
7071
337k
        let end = start.saturating_add(
7072
337k
            (transforms::to_usize(class_seq_rule_set_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
7073
        );
7074
337k
        start..end
7075
337k
    }
7076
}
7077
7078
impl<'a> MinByteRange<'a> for ClassSequenceRuleSet2<'a> {
7079
0
    fn min_byte_range(&self) -> Range<usize> {
7080
0
        0..self.class_seq_rule_offsets_byte_range().end
7081
0
    }
7082
0
    fn min_table_bytes(&self) -> &'a [u8] {
7083
0
        let range = self.min_byte_range();
7084
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
7085
0
    }
7086
}
7087
7088
impl ReadArgs for ClassSequenceRuleSet2<'_> {
7089
    type Args = ();
7090
}
7091
7092
impl<'a> FontRead<'a> for ClassSequenceRuleSet2<'a> {
7093
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7094
        #[allow(clippy::absurd_extreme_comparisons)]
7095
0
        if data.len() < Self::MIN_SIZE {
7096
0
            return Err(ReadError::OutOfBounds);
7097
0
        }
7098
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
7099
0
            return Err(ReadError::OutOfBounds);
7100
        };
7101
0
        Ok(Self { data })
7102
0
    }
7103
}
7104
7105
/// The fields at the start of the table, which are read directly.
7106
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7107
#[repr(C, packed)]
7108
#[doc(hidden)]
7109
pub struct ClassSequenceRuleSet2FixedHeader {
7110
    pub class_seq_rule_count: BigEndian<u16>,
7111
}
7112
7113
#[allow(clippy::absurd_extreme_comparisons)]
7114
const _: () = assert!(
7115
    std::mem::size_of::<ClassSequenceRuleSet2FixedHeader>() <= ClassSequenceRuleSet2::MIN_SIZE
7116
);
7117
7118
/// ClassSequenceRuleSet2 (ISO/IEC 14496-22:2026).
7119
#[derive(Clone)]
7120
pub struct ClassSequenceRuleSet2<'a> {
7121
    data: TableDataRef<'a, ClassSequenceRuleSet2FixedHeader>,
7122
}
7123
7124
#[allow(clippy::needless_lifetimes)]
7125
impl<'a> ClassSequenceRuleSet2<'a> {
7126
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
7127
    basic_table_impls!(impl_the_methods);
7128
7129
    /// Number of ClassSequenceRule tables
7130
0
    pub fn class_seq_rule_count(&self) -> u16 {
7131
0
        self.data.header().class_seq_rule_count.get()
7132
0
    }
7133
7134
    /// Array of offsets to ClassSequenceRule tables, from beginning of
7135
    /// ClassSequenceRuleSet2 table
7136
0
    pub fn class_seq_rule_offsets(&self) -> &'a [BigEndian<Offset24>] {
7137
0
        let range = self.class_seq_rule_offsets_byte_range();
7138
0
        self.offset_data()
7139
0
            .read_array(range)
7140
0
            .ok()
7141
0
            .unwrap_or_default()
7142
0
    }
7143
7144
    /// A dynamically resolving wrapper for [`class_seq_rule_offsets`][Self::class_seq_rule_offsets].
7145
0
    pub fn class_seq_rules(&self) -> ArrayOfOffsets<'a, ClassSequenceRule<'a>, Offset24> {
7146
0
        let data = self.offset_data();
7147
0
        let offsets = self.class_seq_rule_offsets();
7148
0
        ArrayOfOffsets::new(offsets, data, ())
7149
0
    }
7150
7151
0
    pub fn class_seq_rule_count_byte_range(&self) -> Range<usize> {
7152
0
        let start = 0usize;
7153
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7154
0
        start..end
7155
0
    }
7156
7157
0
    pub fn class_seq_rule_offsets_byte_range(&self) -> Range<usize> {
7158
0
        let class_seq_rule_count = self.class_seq_rule_count();
7159
0
        let start = self.class_seq_rule_count_byte_range().end;
7160
0
        let end = start.saturating_add(
7161
0
            (transforms::to_usize(class_seq_rule_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
7162
        );
7163
0
        start..end
7164
0
    }
7165
}
7166
7167
const _: () = assert!(FontData::default_data_long_enough(
7168
    ClassSequenceRuleSet2::MIN_SIZE
7169
));
7170
7171
impl Default for ClassSequenceRuleSet2<'_> {
7172
0
    fn default() -> Self {
7173
        Self {
7174
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
7175
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
7176
        }
7177
0
    }
7178
}
7179
7180
impl Format<u16> for SequenceContextFormat6<'_> {
7181
    const FORMAT: u16 = 6;
7182
}
7183
7184
impl<'a> MinByteRange<'a> for SequenceContextFormat6<'a> {
7185
0
    fn min_byte_range(&self) -> Range<usize> {
7186
0
        0..self.seq_lookup_records_byte_range().end
7187
0
    }
7188
0
    fn min_table_bytes(&self) -> &'a [u8] {
7189
0
        let range = self.min_byte_range();
7190
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
7191
0
    }
7192
}
7193
7194
impl ReadArgs for SequenceContextFormat6<'_> {
7195
    type Args = ();
7196
}
7197
7198
impl<'a> FontRead<'a> for SequenceContextFormat6<'a> {
7199
8.83k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7200
        #[allow(clippy::absurd_extreme_comparisons)]
7201
8.83k
        if data.len() < Self::MIN_SIZE {
7202
342
            return Err(ReadError::OutOfBounds);
7203
8.49k
        }
7204
8.49k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
7205
0
            return Err(ReadError::OutOfBounds);
7206
        };
7207
8.49k
        Ok(Self { data })
7208
8.83k
    }
7209
}
7210
7211
/// The fields at the start of the table, which are read directly.
7212
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7213
#[repr(C, packed)]
7214
#[doc(hidden)]
7215
pub struct SequenceContextFormat6FixedHeader {
7216
    pub format: BigEndian<u16>,
7217
    pub glyph_count: BigEndian<u16>,
7218
    pub seq_lookup_count: BigEndian<u16>,
7219
}
7220
7221
#[allow(clippy::absurd_extreme_comparisons)]
7222
const _: () = assert!(
7223
    std::mem::size_of::<SequenceContextFormat6FixedHeader>() <= SequenceContextFormat6::MIN_SIZE
7224
);
7225
7226
/// SequenceContextFormat6 (ISO/IEC 14496-22:2026).
7227
#[derive(Clone)]
7228
pub struct SequenceContextFormat6<'a> {
7229
    data: TableDataRef<'a, SequenceContextFormat6FixedHeader>,
7230
}
7231
7232
#[allow(clippy::needless_lifetimes)]
7233
impl<'a> SequenceContextFormat6<'a> {
7234
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
7235
    basic_table_impls!(impl_the_methods);
7236
7237
    /// Format identifier: format = 6
7238
0
    pub fn format(&self) -> u16 {
7239
0
        self.data.header().format.get()
7240
0
    }
7241
7242
    /// Number of glyphs in the input sequence
7243
25.4k
    pub fn glyph_count(&self) -> u16 {
7244
25.4k
        self.data.header().glyph_count.get()
7245
25.4k
    }
7246
7247
    /// Number of SequenceLookupRecords
7248
8.49k
    pub fn seq_lookup_count(&self) -> u16 {
7249
8.49k
        self.data.header().seq_lookup_count.get()
7250
8.49k
    }
7251
7252
    /// Array of offsets to Coverage tables, from beginning of
7253
    /// SequenceContextFormat6 subtable
7254
8.49k
    pub fn coverage_offsets(&self) -> &'a [BigEndian<Offset24>] {
7255
8.49k
        let range = self.coverage_offsets_byte_range();
7256
8.49k
        self.offset_data()
7257
8.49k
            .read_array(range)
7258
8.49k
            .ok()
7259
8.49k
            .unwrap_or_default()
7260
8.49k
    }
7261
7262
    /// A dynamically resolving wrapper for [`coverage_offsets`][Self::coverage_offsets].
7263
8.49k
    pub fn coverages(&self) -> ArrayOfOffsets<'a, CoverageTable<'a>, Offset24> {
7264
8.49k
        let data = self.offset_data();
7265
8.49k
        let offsets = self.coverage_offsets();
7266
8.49k
        ArrayOfOffsets::new(offsets, data, ())
7267
8.49k
    }
7268
7269
    /// Array of SequenceLookupRecords
7270
8.49k
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
7271
8.49k
        let range = self.seq_lookup_records_byte_range();
7272
8.49k
        self.offset_data()
7273
8.49k
            .read_array(range)
7274
8.49k
            .ok()
7275
8.49k
            .unwrap_or_default()
7276
8.49k
    }
7277
7278
25.4k
    pub fn format_byte_range(&self) -> Range<usize> {
7279
25.4k
        let start = 0usize;
7280
25.4k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7281
25.4k
        start..end
7282
25.4k
    }
7283
7284
25.4k
    pub fn glyph_count_byte_range(&self) -> Range<usize> {
7285
25.4k
        let start = self.format_byte_range().end;
7286
25.4k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7287
25.4k
        start..end
7288
25.4k
    }
7289
7290
25.4k
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
7291
25.4k
        let start = self.glyph_count_byte_range().end;
7292
25.4k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7293
25.4k
        start..end
7294
25.4k
    }
7295
7296
25.4k
    pub fn coverage_offsets_byte_range(&self) -> Range<usize> {
7297
25.4k
        let glyph_count = self.glyph_count();
7298
25.4k
        let start = self.seq_lookup_count_byte_range().end;
7299
25.4k
        let end = start.saturating_add(
7300
25.4k
            (transforms::to_usize(glyph_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
7301
        );
7302
25.4k
        start..end
7303
25.4k
    }
7304
7305
8.49k
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
7306
8.49k
        let seq_lookup_count = self.seq_lookup_count();
7307
8.49k
        let start = self.coverage_offsets_byte_range().end;
7308
8.49k
        let end = start.saturating_add(
7309
8.49k
            (transforms::to_usize(seq_lookup_count))
7310
8.49k
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
7311
        );
7312
8.49k
        start..end
7313
8.49k
    }
7314
}
7315
7316
impl Format<u16> for ChainedSequenceContextFormat4<'_> {
7317
    const FORMAT: u16 = 4;
7318
}
7319
7320
impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat4<'a> {
7321
0
    fn min_byte_range(&self) -> Range<usize> {
7322
0
        0..self.chained_seq_rule_set_offsets_byte_range().end
7323
0
    }
7324
0
    fn min_table_bytes(&self) -> &'a [u8] {
7325
0
        let range = self.min_byte_range();
7326
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
7327
0
    }
7328
}
7329
7330
impl ReadArgs for ChainedSequenceContextFormat4<'_> {
7331
    type Args = ();
7332
}
7333
7334
impl<'a> FontRead<'a> for ChainedSequenceContextFormat4<'a> {
7335
9.75k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7336
        #[allow(clippy::absurd_extreme_comparisons)]
7337
9.75k
        if data.len() < Self::MIN_SIZE {
7338
232
            return Err(ReadError::OutOfBounds);
7339
9.52k
        }
7340
9.52k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
7341
0
            return Err(ReadError::OutOfBounds);
7342
        };
7343
9.52k
        Ok(Self { data })
7344
9.75k
    }
7345
}
7346
7347
/// The fields at the start of the table, which are read directly.
7348
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7349
#[repr(C, packed)]
7350
#[doc(hidden)]
7351
pub struct ChainedSequenceContextFormat4FixedHeader {
7352
    pub format: BigEndian<u16>,
7353
    pub coverage_offset: BigEndian<Offset32>,
7354
    pub chained_seq_rule_set_count: BigEndian<Uint24>,
7355
}
7356
7357
#[allow(clippy::absurd_extreme_comparisons)]
7358
const _: () = assert!(
7359
    std::mem::size_of::<ChainedSequenceContextFormat4FixedHeader>()
7360
        <= ChainedSequenceContextFormat4::MIN_SIZE
7361
);
7362
7363
/// ChainedSequenceContextFormat4 (ISO/IEC 14496-22:2026).
7364
#[derive(Clone)]
7365
pub struct ChainedSequenceContextFormat4<'a> {
7366
    data: TableDataRef<'a, ChainedSequenceContextFormat4FixedHeader>,
7367
}
7368
7369
#[allow(clippy::needless_lifetimes)]
7370
impl<'a> ChainedSequenceContextFormat4<'a> {
7371
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN + Uint24::RAW_BYTE_LEN);
7372
    basic_table_impls!(impl_the_methods);
7373
7374
    /// Format identifier: format = 4
7375
0
    pub fn format(&self) -> u16 {
7376
0
        self.data.header().format.get()
7377
0
    }
7378
7379
    /// Offset to Coverage table, from beginning of
7380
    /// ChainedSequenceContextFormat4 table
7381
9.52k
    pub fn coverage_offset(&self) -> Offset32 {
7382
9.52k
        self.data.header().coverage_offset.get()
7383
9.52k
    }
7384
7385
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
7386
9.52k
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
7387
9.52k
        let data = self.offset_data();
7388
9.52k
        self.coverage_offset().resolve(data)
7389
9.52k
    }
7390
7391
    /// Number of ChainedSequenceRuleSet tables
7392
9.52k
    pub fn chained_seq_rule_set_count(&self) -> Uint24 {
7393
9.52k
        self.data.header().chained_seq_rule_set_count.get()
7394
9.52k
    }
7395
7396
    /// Array of offsets to ChainedSeqRuleSet tables, from beginning of
7397
    /// ChainedSequenceContextFormat4 table (may be NULL)
7398
0
    pub fn chained_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] {
7399
0
        let range = self.chained_seq_rule_set_offsets_byte_range();
7400
0
        self.offset_data()
7401
0
            .read_array(range)
7402
0
            .ok()
7403
0
            .unwrap_or_default()
7404
0
    }
7405
7406
    /// A dynamically resolving wrapper for [`chained_seq_rule_set_offsets`][Self::chained_seq_rule_set_offsets].
7407
0
    pub fn chained_seq_rule_sets(
7408
0
        &self,
7409
0
    ) -> ArrayOfNullableOffsets<'a, ChainedSequenceRuleSet2<'a>, Offset24> {
7410
0
        let data = self.offset_data();
7411
0
        let offsets = self.chained_seq_rule_set_offsets();
7412
0
        ArrayOfNullableOffsets::new(offsets, data, ())
7413
0
    }
7414
7415
9.52k
    pub fn format_byte_range(&self) -> Range<usize> {
7416
9.52k
        let start = 0usize;
7417
9.52k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7418
9.52k
        start..end
7419
9.52k
    }
7420
7421
9.52k
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
7422
9.52k
        let start = self.format_byte_range().end;
7423
9.52k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7424
9.52k
        start..end
7425
9.52k
    }
7426
7427
9.52k
    pub fn chained_seq_rule_set_count_byte_range(&self) -> Range<usize> {
7428
9.52k
        let start = self.coverage_offset_byte_range().end;
7429
9.52k
        let end = start.saturating_add(Uint24::RAW_BYTE_LEN);
7430
9.52k
        start..end
7431
9.52k
    }
7432
7433
9.52k
    pub fn chained_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
7434
9.52k
        let chained_seq_rule_set_count = self.chained_seq_rule_set_count();
7435
9.52k
        let start = self.chained_seq_rule_set_count_byte_range().end;
7436
9.52k
        let end = start.saturating_add(
7437
9.52k
            (transforms::to_usize(chained_seq_rule_set_count))
7438
9.52k
                .saturating_mul(Offset24::RAW_BYTE_LEN),
7439
        );
7440
9.52k
        start..end
7441
9.52k
    }
7442
}
7443
7444
impl<'a> MinByteRange<'a> for ChainedSequenceRuleSet2<'a> {
7445
0
    fn min_byte_range(&self) -> Range<usize> {
7446
0
        0..self.chained_seq_rule_offsets_byte_range().end
7447
0
    }
7448
0
    fn min_table_bytes(&self) -> &'a [u8] {
7449
0
        let range = self.min_byte_range();
7450
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
7451
0
    }
7452
}
7453
7454
impl ReadArgs for ChainedSequenceRuleSet2<'_> {
7455
    type Args = ();
7456
}
7457
7458
impl<'a> FontRead<'a> for ChainedSequenceRuleSet2<'a> {
7459
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7460
        #[allow(clippy::absurd_extreme_comparisons)]
7461
0
        if data.len() < Self::MIN_SIZE {
7462
0
            return Err(ReadError::OutOfBounds);
7463
0
        }
7464
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
7465
0
            return Err(ReadError::OutOfBounds);
7466
        };
7467
0
        Ok(Self { data })
7468
0
    }
7469
}
7470
7471
/// The fields at the start of the table, which are read directly.
7472
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7473
#[repr(C, packed)]
7474
#[doc(hidden)]
7475
pub struct ChainedSequenceRuleSet2FixedHeader {
7476
    pub chained_seq_rule_count: BigEndian<u16>,
7477
}
7478
7479
#[allow(clippy::absurd_extreme_comparisons)]
7480
const _: () = assert!(
7481
    std::mem::size_of::<ChainedSequenceRuleSet2FixedHeader>() <= ChainedSequenceRuleSet2::MIN_SIZE
7482
);
7483
7484
/// ChainedSequenceRuleSet2 (ISO/IEC 14496-22:2026).
7485
#[derive(Clone)]
7486
pub struct ChainedSequenceRuleSet2<'a> {
7487
    data: TableDataRef<'a, ChainedSequenceRuleSet2FixedHeader>,
7488
}
7489
7490
#[allow(clippy::needless_lifetimes)]
7491
impl<'a> ChainedSequenceRuleSet2<'a> {
7492
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
7493
    basic_table_impls!(impl_the_methods);
7494
7495
    /// Number of ChainedSequenceRule tables
7496
0
    pub fn chained_seq_rule_count(&self) -> u16 {
7497
0
        self.data.header().chained_seq_rule_count.get()
7498
0
    }
7499
7500
    /// Array of offsets to ChainedSequenceRule tables, from beginning
7501
    /// of ChainedSequenceRuleSet2 table
7502
0
    pub fn chained_seq_rule_offsets(&self) -> &'a [BigEndian<Offset24>] {
7503
0
        let range = self.chained_seq_rule_offsets_byte_range();
7504
0
        self.offset_data()
7505
0
            .read_array(range)
7506
0
            .ok()
7507
0
            .unwrap_or_default()
7508
0
    }
7509
7510
    /// A dynamically resolving wrapper for [`chained_seq_rule_offsets`][Self::chained_seq_rule_offsets].
7511
0
    pub fn chained_seq_rules(&self) -> ArrayOfOffsets<'a, ChainedSequenceRule2<'a>, Offset24> {
7512
0
        let data = self.offset_data();
7513
0
        let offsets = self.chained_seq_rule_offsets();
7514
0
        ArrayOfOffsets::new(offsets, data, ())
7515
0
    }
7516
7517
0
    pub fn chained_seq_rule_count_byte_range(&self) -> Range<usize> {
7518
0
        let start = 0usize;
7519
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7520
0
        start..end
7521
0
    }
7522
7523
0
    pub fn chained_seq_rule_offsets_byte_range(&self) -> Range<usize> {
7524
0
        let chained_seq_rule_count = self.chained_seq_rule_count();
7525
0
        let start = self.chained_seq_rule_count_byte_range().end;
7526
0
        let end = start.saturating_add(
7527
0
            (transforms::to_usize(chained_seq_rule_count)).saturating_mul(Offset24::RAW_BYTE_LEN),
7528
        );
7529
0
        start..end
7530
0
    }
7531
}
7532
7533
const _: () = assert!(FontData::default_data_long_enough(
7534
    ChainedSequenceRuleSet2::MIN_SIZE
7535
));
7536
7537
impl Default for ChainedSequenceRuleSet2<'_> {
7538
0
    fn default() -> Self {
7539
        Self {
7540
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
7541
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
7542
        }
7543
0
    }
7544
}
7545
7546
impl<'a> MinByteRange<'a> for ChainedSequenceRule2<'a> {
7547
0
    fn min_byte_range(&self) -> Range<usize> {
7548
0
        0..self.seq_lookup_records_byte_range().end
7549
0
    }
7550
0
    fn min_table_bytes(&self) -> &'a [u8] {
7551
0
        let range = self.min_byte_range();
7552
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
7553
0
    }
7554
}
7555
7556
impl ReadArgs for ChainedSequenceRule2<'_> {
7557
    type Args = ();
7558
}
7559
7560
impl<'a> FontRead<'a> for ChainedSequenceRule2<'a> {
7561
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7562
        #[allow(clippy::absurd_extreme_comparisons)]
7563
0
        if data.len() < Self::MIN_SIZE {
7564
0
            return Err(ReadError::OutOfBounds);
7565
0
        }
7566
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
7567
0
            return Err(ReadError::OutOfBounds);
7568
        };
7569
0
        Ok(Self { data })
7570
0
    }
7571
}
7572
7573
/// The fields at the start of the table, which are read directly.
7574
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7575
#[repr(C, packed)]
7576
#[doc(hidden)]
7577
pub struct ChainedSequenceRule2FixedHeader {
7578
    pub backtrack_glyph_count: BigEndian<u16>,
7579
}
7580
7581
#[allow(clippy::absurd_extreme_comparisons)]
7582
const _: () = assert!(
7583
    std::mem::size_of::<ChainedSequenceRule2FixedHeader>() <= ChainedSequenceRule2::MIN_SIZE
7584
);
7585
7586
/// ChainedSequenceRule2 (ISO/IEC 14496-22:2026).
7587
#[derive(Clone)]
7588
pub struct ChainedSequenceRule2<'a> {
7589
    data: TableDataRef<'a, ChainedSequenceRule2FixedHeader>,
7590
}
7591
7592
#[allow(clippy::needless_lifetimes)]
7593
impl<'a> ChainedSequenceRule2<'a> {
7594
    pub const MIN_SIZE: usize =
7595
        (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
7596
    basic_table_impls!(impl_the_methods);
7597
7598
    /// Number of glyphs in the backtrack sequence
7599
0
    pub fn backtrack_glyph_count(&self) -> u16 {
7600
0
        self.data.header().backtrack_glyph_count.get()
7601
0
    }
7602
7603
    /// Array of backtrack glyph IDs
7604
0
    pub fn backtrack_sequence(&self) -> &'a [BigEndian<GlyphId24>] {
7605
0
        let range = self.backtrack_sequence_byte_range();
7606
0
        self.offset_data()
7607
0
            .read_array(range)
7608
0
            .ok()
7609
0
            .unwrap_or_default()
7610
0
    }
7611
7612
    /// Number of glyphs in the input sequence
7613
0
    pub fn input_glyph_count(&self) -> u16 {
7614
0
        let range = self.input_glyph_count_byte_range();
7615
0
        self.offset_data()
7616
0
            .read_at(range.start)
7617
0
            .ok()
7618
0
            .unwrap_or_default()
7619
0
    }
7620
7621
    /// Array of input glyph IDs—start with second glyph
7622
0
    pub fn input_sequence(&self) -> &'a [BigEndian<GlyphId24>] {
7623
0
        let range = self.input_sequence_byte_range();
7624
0
        self.offset_data()
7625
0
            .read_array(range)
7626
0
            .ok()
7627
0
            .unwrap_or_default()
7628
0
    }
7629
7630
    /// Number of glyphs in the lookahead sequence
7631
0
    pub fn lookahead_glyph_count(&self) -> u16 {
7632
0
        let range = self.lookahead_glyph_count_byte_range();
7633
0
        self.offset_data()
7634
0
            .read_at(range.start)
7635
0
            .ok()
7636
0
            .unwrap_or_default()
7637
0
    }
7638
7639
    /// Array of lookahead glyph IDs
7640
0
    pub fn lookahead_sequence(&self) -> &'a [BigEndian<GlyphId24>] {
7641
0
        let range = self.lookahead_sequence_byte_range();
7642
0
        self.offset_data()
7643
0
            .read_array(range)
7644
0
            .ok()
7645
0
            .unwrap_or_default()
7646
0
    }
7647
7648
    /// Number of SequenceLookupRecords
7649
0
    pub fn seq_lookup_count(&self) -> u16 {
7650
0
        let range = self.seq_lookup_count_byte_range();
7651
0
        self.offset_data()
7652
0
            .read_at(range.start)
7653
0
            .ok()
7654
0
            .unwrap_or_default()
7655
0
    }
7656
7657
    /// Array of SequenceLookupRecords
7658
0
    pub fn seq_lookup_records(&self) -> &'a [SequenceLookupRecord] {
7659
0
        let range = self.seq_lookup_records_byte_range();
7660
0
        self.offset_data()
7661
0
            .read_array(range)
7662
0
            .ok()
7663
0
            .unwrap_or_default()
7664
0
    }
7665
7666
0
    pub fn backtrack_glyph_count_byte_range(&self) -> Range<usize> {
7667
0
        let start = 0usize;
7668
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7669
0
        start..end
7670
0
    }
7671
7672
0
    pub fn backtrack_sequence_byte_range(&self) -> Range<usize> {
7673
0
        let backtrack_glyph_count = self.backtrack_glyph_count();
7674
0
        let start = self.backtrack_glyph_count_byte_range().end;
7675
0
        let end = start.saturating_add(
7676
0
            (transforms::to_usize(backtrack_glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN),
7677
        );
7678
0
        start..end
7679
0
    }
7680
7681
0
    pub fn input_glyph_count_byte_range(&self) -> Range<usize> {
7682
0
        let start = self.backtrack_sequence_byte_range().end;
7683
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7684
0
        start..end
7685
0
    }
7686
7687
0
    pub fn input_sequence_byte_range(&self) -> Range<usize> {
7688
0
        let input_glyph_count = self.input_glyph_count();
7689
0
        let start = self.input_glyph_count_byte_range().end;
7690
0
        let end = start.saturating_add(
7691
0
            (transforms::subtract(input_glyph_count, 1_usize))
7692
0
                .saturating_mul(GlyphId24::RAW_BYTE_LEN),
7693
        );
7694
0
        start..end
7695
0
    }
7696
7697
0
    pub fn lookahead_glyph_count_byte_range(&self) -> Range<usize> {
7698
0
        let start = self.input_sequence_byte_range().end;
7699
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7700
0
        start..end
7701
0
    }
7702
7703
0
    pub fn lookahead_sequence_byte_range(&self) -> Range<usize> {
7704
0
        let lookahead_glyph_count = self.lookahead_glyph_count();
7705
0
        let start = self.lookahead_glyph_count_byte_range().end;
7706
0
        let end = start.saturating_add(
7707
0
            (transforms::to_usize(lookahead_glyph_count)).saturating_mul(GlyphId24::RAW_BYTE_LEN),
7708
        );
7709
0
        start..end
7710
0
    }
7711
7712
0
    pub fn seq_lookup_count_byte_range(&self) -> Range<usize> {
7713
0
        let start = self.lookahead_sequence_byte_range().end;
7714
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7715
0
        start..end
7716
0
    }
7717
7718
0
    pub fn seq_lookup_records_byte_range(&self) -> Range<usize> {
7719
0
        let seq_lookup_count = self.seq_lookup_count();
7720
0
        let start = self.seq_lookup_count_byte_range().end;
7721
0
        let end = start.saturating_add(
7722
0
            (transforms::to_usize(seq_lookup_count))
7723
0
                .saturating_mul(SequenceLookupRecord::RAW_BYTE_LEN),
7724
        );
7725
0
        start..end
7726
0
    }
7727
}
7728
7729
const _: () = assert!(FontData::default_data_long_enough(
7730
    ChainedSequenceRule2::MIN_SIZE
7731
));
7732
7733
impl Default for ChainedSequenceRule2<'_> {
7734
0
    fn default() -> Self {
7735
        Self {
7736
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
7737
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
7738
        }
7739
0
    }
7740
}
7741
7742
impl Format<u16> for ChainedSequenceContextFormat5<'_> {
7743
    const FORMAT: u16 = 5;
7744
}
7745
7746
impl<'a> MinByteRange<'a> for ChainedSequenceContextFormat5<'a> {
7747
0
    fn min_byte_range(&self) -> Range<usize> {
7748
0
        0..self.chained_class_seq_rule_set_offsets_byte_range().end
7749
0
    }
7750
0
    fn min_table_bytes(&self) -> &'a [u8] {
7751
0
        let range = self.min_byte_range();
7752
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
7753
0
    }
7754
}
7755
7756
impl ReadArgs for ChainedSequenceContextFormat5<'_> {
7757
    type Args = ();
7758
}
7759
7760
impl<'a> FontRead<'a> for ChainedSequenceContextFormat5<'a> {
7761
8.83k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7762
        #[allow(clippy::absurd_extreme_comparisons)]
7763
8.83k
        if data.len() < Self::MIN_SIZE {
7764
318
            return Err(ReadError::OutOfBounds);
7765
8.51k
        }
7766
8.51k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
7767
0
            return Err(ReadError::OutOfBounds);
7768
        };
7769
8.51k
        Ok(Self { data })
7770
8.83k
    }
7771
}
7772
7773
/// The fields at the start of the table, which are read directly.
7774
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7775
#[repr(C, packed)]
7776
#[doc(hidden)]
7777
pub struct ChainedSequenceContextFormat5FixedHeader {
7778
    pub format: BigEndian<u16>,
7779
    pub coverage_offset: BigEndian<Offset32>,
7780
    pub backtrack_class_def_offset: BigEndian<Offset32>,
7781
    pub input_class_def_offset: BigEndian<Offset32>,
7782
    pub lookahead_class_def_offset: BigEndian<Offset32>,
7783
    pub chained_class_seq_rule_set_count: BigEndian<u16>,
7784
}
7785
7786
#[allow(clippy::absurd_extreme_comparisons)]
7787
const _: () = assert!(
7788
    std::mem::size_of::<ChainedSequenceContextFormat5FixedHeader>()
7789
        <= ChainedSequenceContextFormat5::MIN_SIZE
7790
);
7791
7792
/// ChainedSequenceContextFormat5 (ISO/IEC 14496-22:2026).
7793
#[derive(Clone)]
7794
pub struct ChainedSequenceContextFormat5<'a> {
7795
    data: TableDataRef<'a, ChainedSequenceContextFormat5FixedHeader>,
7796
}
7797
7798
#[allow(clippy::needless_lifetimes)]
7799
impl<'a> ChainedSequenceContextFormat5<'a> {
7800
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
7801
        + Offset32::RAW_BYTE_LEN
7802
        + Offset32::RAW_BYTE_LEN
7803
        + Offset32::RAW_BYTE_LEN
7804
        + Offset32::RAW_BYTE_LEN
7805
        + u16::RAW_BYTE_LEN);
7806
    basic_table_impls!(impl_the_methods);
7807
7808
    /// Format identifier: format = 5
7809
0
    pub fn format(&self) -> u16 {
7810
0
        self.data.header().format.get()
7811
0
    }
7812
7813
    /// Offset to Coverage table, from beginning of
7814
    /// ChainedSequenceContextFormat5 table
7815
8.51k
    pub fn coverage_offset(&self) -> Offset32 {
7816
8.51k
        self.data.header().coverage_offset.get()
7817
8.51k
    }
7818
7819
    /// Attempt to resolve [`coverage_offset`][Self::coverage_offset].
7820
8.51k
    pub fn coverage(&self) -> Result<CoverageTable<'a>, ReadError> {
7821
8.51k
        let data = self.offset_data();
7822
8.51k
        self.coverage_offset().resolve(data)
7823
8.51k
    }
7824
7825
    /// Offset to ClassDef table containing backtrack sequence context,
7826
    /// from beginning of ChainedSequenceContextFormat5 table
7827
8.51k
    pub fn backtrack_class_def_offset(&self) -> Offset32 {
7828
8.51k
        self.data.header().backtrack_class_def_offset.get()
7829
8.51k
    }
7830
7831
    /// Attempt to resolve [`backtrack_class_def_offset`][Self::backtrack_class_def_offset].
7832
8.51k
    pub fn backtrack_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
7833
8.51k
        let data = self.offset_data();
7834
8.51k
        self.backtrack_class_def_offset().resolve(data)
7835
8.51k
    }
7836
7837
    /// Offset to ClassDef table containing input sequence context,
7838
    /// from beginning of ChainedSequenceContextFormat5 table
7839
8.51k
    pub fn input_class_def_offset(&self) -> Offset32 {
7840
8.51k
        self.data.header().input_class_def_offset.get()
7841
8.51k
    }
7842
7843
    /// Attempt to resolve [`input_class_def_offset`][Self::input_class_def_offset].
7844
8.51k
    pub fn input_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
7845
8.51k
        let data = self.offset_data();
7846
8.51k
        self.input_class_def_offset().resolve(data)
7847
8.51k
    }
7848
7849
    /// Offset to ClassDef table containing lookahead sequence context,
7850
    /// from beginning of ChainedSequenceContextFormat5 table
7851
8.51k
    pub fn lookahead_class_def_offset(&self) -> Offset32 {
7852
8.51k
        self.data.header().lookahead_class_def_offset.get()
7853
8.51k
    }
7854
7855
    /// Attempt to resolve [`lookahead_class_def_offset`][Self::lookahead_class_def_offset].
7856
8.51k
    pub fn lookahead_class_def(&self) -> Result<ClassDef<'a>, ReadError> {
7857
8.51k
        let data = self.offset_data();
7858
8.51k
        self.lookahead_class_def_offset().resolve(data)
7859
8.51k
    }
7860
7861
    /// Number of ChainedClassSequenceRuleSet tables
7862
8.51k
    pub fn chained_class_seq_rule_set_count(&self) -> u16 {
7863
8.51k
        self.data.header().chained_class_seq_rule_set_count.get()
7864
8.51k
    }
7865
7866
    /// Array of offsets to ChainedClassSequenceRuleSet tables, from
7867
    /// beginning of ChainedSequenceContextFormat5 table (may be NULL)
7868
0
    pub fn chained_class_seq_rule_set_offsets(&self) -> &'a [BigEndian<Nullable<Offset24>>] {
7869
0
        let range = self.chained_class_seq_rule_set_offsets_byte_range();
7870
0
        self.offset_data()
7871
0
            .read_array(range)
7872
0
            .ok()
7873
0
            .unwrap_or_default()
7874
0
    }
7875
7876
    /// A dynamically resolving wrapper for [`chained_class_seq_rule_set_offsets`][Self::chained_class_seq_rule_set_offsets].
7877
0
    pub fn chained_class_seq_rule_sets(
7878
0
        &self,
7879
0
    ) -> ArrayOfNullableOffsets<'a, ChainedClassSequenceRuleSet2<'a>, Offset24> {
7880
0
        let data = self.offset_data();
7881
0
        let offsets = self.chained_class_seq_rule_set_offsets();
7882
0
        ArrayOfNullableOffsets::new(offsets, data, ())
7883
0
    }
7884
7885
8.51k
    pub fn format_byte_range(&self) -> Range<usize> {
7886
8.51k
        let start = 0usize;
7887
8.51k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7888
8.51k
        start..end
7889
8.51k
    }
7890
7891
8.51k
    pub fn coverage_offset_byte_range(&self) -> Range<usize> {
7892
8.51k
        let start = self.format_byte_range().end;
7893
8.51k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7894
8.51k
        start..end
7895
8.51k
    }
7896
7897
8.51k
    pub fn backtrack_class_def_offset_byte_range(&self) -> Range<usize> {
7898
8.51k
        let start = self.coverage_offset_byte_range().end;
7899
8.51k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7900
8.51k
        start..end
7901
8.51k
    }
7902
7903
8.51k
    pub fn input_class_def_offset_byte_range(&self) -> Range<usize> {
7904
8.51k
        let start = self.backtrack_class_def_offset_byte_range().end;
7905
8.51k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7906
8.51k
        start..end
7907
8.51k
    }
7908
7909
8.51k
    pub fn lookahead_class_def_offset_byte_range(&self) -> Range<usize> {
7910
8.51k
        let start = self.input_class_def_offset_byte_range().end;
7911
8.51k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
7912
8.51k
        start..end
7913
8.51k
    }
7914
7915
8.51k
    pub fn chained_class_seq_rule_set_count_byte_range(&self) -> Range<usize> {
7916
8.51k
        let start = self.lookahead_class_def_offset_byte_range().end;
7917
8.51k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
7918
8.51k
        start..end
7919
8.51k
    }
7920
7921
8.51k
    pub fn chained_class_seq_rule_set_offsets_byte_range(&self) -> Range<usize> {
7922
8.51k
        let chained_class_seq_rule_set_count = self.chained_class_seq_rule_set_count();
7923
8.51k
        let start = self.chained_class_seq_rule_set_count_byte_range().end;
7924
8.51k
        let end = start.saturating_add(
7925
8.51k
            (transforms::to_usize(chained_class_seq_rule_set_count))
7926
8.51k
                .saturating_mul(Offset24::RAW_BYTE_LEN),
7927
        );
7928
8.51k
        start..end
7929
8.51k
    }
7930
}
7931
7932
impl<'a> MinByteRange<'a> for ChainedClassSequenceRuleSet2<'a> {
7933
0
    fn min_byte_range(&self) -> Range<usize> {
7934
0
        0..self.chained_class_seq_rule_offsets_byte_range().end
7935
0
    }
7936
0
    fn min_table_bytes(&self) -> &'a [u8] {
7937
0
        let range = self.min_byte_range();
7938
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
7939
0
    }
7940
}
7941
7942
impl ReadArgs for ChainedClassSequenceRuleSet2<'_> {
7943
    type Args = ();
7944
}
7945
7946
impl<'a> FontRead<'a> for ChainedClassSequenceRuleSet2<'a> {
7947
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
7948
        #[allow(clippy::absurd_extreme_comparisons)]
7949
0
        if data.len() < Self::MIN_SIZE {
7950
0
            return Err(ReadError::OutOfBounds);
7951
0
        }
7952
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
7953
0
            return Err(ReadError::OutOfBounds);
7954
        };
7955
0
        Ok(Self { data })
7956
0
    }
7957
}
7958
7959
/// The fields at the start of the table, which are read directly.
7960
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
7961
#[repr(C, packed)]
7962
#[doc(hidden)]
7963
pub struct ChainedClassSequenceRuleSet2FixedHeader {
7964
    pub chained_class_seq_rule_count: BigEndian<u16>,
7965
}
7966
7967
#[allow(clippy::absurd_extreme_comparisons)]
7968
const _: () = assert!(
7969
    std::mem::size_of::<ChainedClassSequenceRuleSet2FixedHeader>()
7970
        <= ChainedClassSequenceRuleSet2::MIN_SIZE
7971
);
7972
7973
/// ChainedClassSequenceRuleSet2 (ISO/IEC 14496-22:2026).
7974
#[derive(Clone)]
7975
pub struct ChainedClassSequenceRuleSet2<'a> {
7976
    data: TableDataRef<'a, ChainedClassSequenceRuleSet2FixedHeader>,
7977
}
7978
7979
#[allow(clippy::needless_lifetimes)]
7980
impl<'a> ChainedClassSequenceRuleSet2<'a> {
7981
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
7982
    basic_table_impls!(impl_the_methods);
7983
7984
    /// Number of ChainedClassSequenceRule tables
7985
0
    pub fn chained_class_seq_rule_count(&self) -> u16 {
7986
0
        self.data.header().chained_class_seq_rule_count.get()
7987
0
    }
7988
7989
    /// Array of offsets to ChainedClassSequenceRule tables, from
7990
    /// beginning of ChainedClassSequenceRuleSet2
7991
0
    pub fn chained_class_seq_rule_offsets(&self) -> &'a [BigEndian<Offset24>] {
7992
0
        let range = self.chained_class_seq_rule_offsets_byte_range();
7993
0
        self.offset_data()
7994
0
            .read_array(range)
7995
0
            .ok()
7996
0
            .unwrap_or_default()
7997
0
    }
7998
7999
    /// A dynamically resolving wrapper for [`chained_class_seq_rule_offsets`][Self::chained_class_seq_rule_offsets].
8000
0
    pub fn chained_class_seq_rules(
8001
0
        &self,
8002
0
    ) -> ArrayOfOffsets<'a, ChainedClassSequenceRule<'a>, Offset24> {
8003
0
        let data = self.offset_data();
8004
0
        let offsets = self.chained_class_seq_rule_offsets();
8005
0
        ArrayOfOffsets::new(offsets, data, ())
8006
0
    }
8007
8008
0
    pub fn chained_class_seq_rule_count_byte_range(&self) -> Range<usize> {
8009
0
        let start = 0usize;
8010
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
8011
0
        start..end
8012
0
    }
8013
8014
0
    pub fn chained_class_seq_rule_offsets_byte_range(&self) -> Range<usize> {
8015
0
        let chained_class_seq_rule_count = self.chained_class_seq_rule_count();
8016
0
        let start = self.chained_class_seq_rule_count_byte_range().end;
8017
0
        let end = start.saturating_add(
8018
0
            (transforms::to_usize(chained_class_seq_rule_count))
8019
0
                .saturating_mul(Offset24::RAW_BYTE_LEN),
8020
        );
8021
0
        start..end
8022
0
    }
8023
}
8024
8025
const _: () = assert!(FontData::default_data_long_enough(
8026
    ChainedClassSequenceRuleSet2::MIN_SIZE
8027
));
8028
8029
impl Default for ChainedClassSequenceRuleSet2<'_> {
8030
0
    fn default() -> Self {
8031
        Self {
8032
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
8033
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
8034
        }
8035
0
    }
8036
}
8037
8038
impl<'a, T> MinByteRange<'a> for LookupList2<'a, T> {
8039
0
    fn min_byte_range(&self) -> Range<usize> {
8040
0
        0..self.lookup_offsets_byte_range().end
8041
0
    }
8042
0
    fn min_table_bytes(&self) -> &'a [u8] {
8043
0
        let range = self.min_byte_range();
8044
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
8045
0
    }
8046
}
8047
8048
impl<T> ReadArgs for LookupList2<'_, T> {
8049
    type Args = ();
8050
}
8051
8052
impl<'a, T> FontRead<'a> for LookupList2<'a, T> {
8053
31
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
8054
        #[allow(clippy::absurd_extreme_comparisons)]
8055
31
        if data.len() < Self::MIN_SIZE {
8056
11
            return Err(ReadError::OutOfBounds);
8057
20
        }
8058
20
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
8059
0
            return Err(ReadError::OutOfBounds);
8060
        };
8061
20
        Ok(Self {
8062
20
            data,
8063
20
            offset_type: std::marker::PhantomData,
8064
20
        })
8065
31
    }
<read_fonts::tables::layout::LookupList2<read_fonts::tables::gpos::PositionLookup> as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
8053
12
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
8054
        #[allow(clippy::absurd_extreme_comparisons)]
8055
12
        if data.len() < Self::MIN_SIZE {
8056
3
            return Err(ReadError::OutOfBounds);
8057
9
        }
8058
9
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
8059
0
            return Err(ReadError::OutOfBounds);
8060
        };
8061
9
        Ok(Self {
8062
9
            data,
8063
9
            offset_type: std::marker::PhantomData,
8064
9
        })
8065
12
    }
<read_fonts::tables::layout::LookupList2<read_fonts::tables::gsub::SubstitutionLookup> as read_fonts::read::FontRead>::read_with_args
Line
Count
Source
8053
19
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
8054
        #[allow(clippy::absurd_extreme_comparisons)]
8055
19
        if data.len() < Self::MIN_SIZE {
8056
8
            return Err(ReadError::OutOfBounds);
8057
11
        }
8058
11
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
8059
0
            return Err(ReadError::OutOfBounds);
8060
        };
8061
11
        Ok(Self {
8062
11
            data,
8063
11
            offset_type: std::marker::PhantomData,
8064
11
        })
8065
19
    }
8066
}
8067
8068
impl<'a, T> LookupList2<'a, T> {
8069
    #[allow(dead_code)]
8070
    /// Replace the specific generic type on this implementation with `()`
8071
0
    pub(crate) fn of_unit_type(&self) -> LookupList2<'a, ()> {
8072
0
        LookupList2 {
8073
0
            data: self.data,
8074
0
            offset_type: std::marker::PhantomData,
8075
0
        }
8076
0
    }
8077
}
8078
8079
/// The fields at the start of the table, which are read directly.
8080
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
8081
#[repr(C, packed)]
8082
#[doc(hidden)]
8083
pub struct LookupList2FixedHeader {
8084
    pub lookup_count: BigEndian<u16>,
8085
}
8086
8087
#[allow(clippy::absurd_extreme_comparisons)]
8088
const _: () = assert!(std::mem::size_of::<LookupList2FixedHeader>() <= LookupList2::<()>::MIN_SIZE);
8089
8090
/// LookupList2 (ISO/IEC 14496-22:2026).
8091
#[derive(Clone)]
8092
pub struct LookupList2<'a, T = ()> {
8093
    data: TableDataRef<'a, LookupList2FixedHeader>,
8094
    offset_type: std::marker::PhantomData<*const T>,
8095
}
8096
8097
#[allow(clippy::needless_lifetimes)]
8098
impl<'a, T> LookupList2<'a, T> {
8099
    pub const MIN_SIZE: usize = u16::RAW_BYTE_LEN;
8100
    basic_table_impls!(impl_the_methods);
8101
8102
    /// Number of lookups in this table
8103
20
    pub fn lookup_count(&self) -> u16 {
8104
20
        self.data.header().lookup_count.get()
8105
20
    }
<read_fonts::tables::layout::LookupList2<read_fonts::tables::gpos::PositionLookup>>::lookup_count
Line
Count
Source
8103
9
    pub fn lookup_count(&self) -> u16 {
8104
9
        self.data.header().lookup_count.get()
8105
9
    }
<read_fonts::tables::layout::LookupList2<read_fonts::tables::gsub::SubstitutionLookup>>::lookup_count
Line
Count
Source
8103
11
    pub fn lookup_count(&self) -> u16 {
8104
11
        self.data.header().lookup_count.get()
8105
11
    }
8106
8107
    /// Array of offsets to Lookup tables, from beginning of LookupList2
8108
    /// — zero based (first lookup is Lookup index = 0)
8109
0
    pub fn lookup_offsets(&self) -> &'a [BigEndian<Offset32>] {
8110
0
        let range = self.lookup_offsets_byte_range();
8111
0
        self.offset_data()
8112
0
            .read_array(range)
8113
0
            .ok()
8114
0
            .unwrap_or_default()
8115
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::LookupList2<read_fonts::tables::gpos::PositionLookup>>::lookup_offsets
Unexecuted instantiation: <read_fonts::tables::layout::LookupList2<read_fonts::tables::gsub::SubstitutionLookup>>::lookup_offsets
8116
8117
    /// A dynamically resolving wrapper for [`lookup_offsets`][Self::lookup_offsets].
8118
0
    pub fn lookups(&self) -> ArrayOfOffsets<'a, T, Offset32>
8119
0
    where
8120
0
        T: FontRead<'a, Args = ()>,
8121
    {
8122
0
        let data = self.offset_data();
8123
0
        let offsets = self.lookup_offsets();
8124
0
        ArrayOfOffsets::new(offsets, data, ())
8125
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::LookupList2<read_fonts::tables::gpos::PositionLookup>>::lookups
Unexecuted instantiation: <read_fonts::tables::layout::LookupList2<read_fonts::tables::gsub::SubstitutionLookup>>::lookups
8126
8127
0
    pub fn lookup_count_byte_range(&self) -> Range<usize> {
8128
0
        let start = 0usize;
8129
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
8130
0
        start..end
8131
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::LookupList2<read_fonts::tables::gpos::PositionLookup>>::lookup_count_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::LookupList2<read_fonts::tables::gsub::SubstitutionLookup>>::lookup_count_byte_range
8132
8133
0
    pub fn lookup_offsets_byte_range(&self) -> Range<usize> {
8134
0
        let lookup_count = self.lookup_count();
8135
0
        let start = self.lookup_count_byte_range().end;
8136
0
        let end = start.saturating_add(
8137
0
            (transforms::to_usize(lookup_count)).saturating_mul(Offset32::RAW_BYTE_LEN),
8138
        );
8139
0
        start..end
8140
0
    }
Unexecuted instantiation: <read_fonts::tables::layout::LookupList2<read_fonts::tables::gpos::PositionLookup>>::lookup_offsets_byte_range
Unexecuted instantiation: <read_fonts::tables::layout::LookupList2<read_fonts::tables::gsub::SubstitutionLookup>>::lookup_offsets_byte_range
8141
}
8142
8143
const _: () = assert!(FontData::default_data_long_enough(
8144
    LookupList2::<()>::MIN_SIZE
8145
));
8146
8147
impl<T> Default for LookupList2<'_, T> {
8148
0
    fn default() -> Self {
8149
        Self {
8150
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
8151
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
8152
0
            offset_type: std::marker::PhantomData,
8153
        }
8154
0
    }
8155
}