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_colr.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 Colr<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.num_layer_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 TopLevelTable for Colr<'_> {
19
    /// `COLR`
20
    const TAG: Tag = Tag::new(b"COLR");
21
}
22
23
impl ReadArgs for Colr<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Colr<'a> {
28
3.78k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
3.78k
        if data.len() < Self::MIN_SIZE {
31
1
            return Err(ReadError::OutOfBounds);
32
3.78k
        }
33
3.78k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
3.78k
        Ok(Self { data })
37
3.78k
    }
38
}
39
40
/// The fields at the start of the table, which are read directly.
41
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42
#[repr(C, packed)]
43
#[doc(hidden)]
44
pub struct ColrFixedHeader {
45
    pub version: BigEndian<u16>,
46
    pub num_base_glyph_records: BigEndian<u16>,
47
    pub base_glyph_records_offset: BigEndian<Nullable<Offset32>>,
48
    pub layer_records_offset: BigEndian<Nullable<Offset32>>,
49
    pub num_layer_records: BigEndian<u16>,
50
}
51
52
#[allow(clippy::absurd_extreme_comparisons)]
53
const _: () = assert!(std::mem::size_of::<ColrFixedHeader>() <= Colr::MIN_SIZE);
54
55
/// [COLR (Color)](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#colr-header) table
56
#[derive(Clone)]
57
pub struct Colr<'a> {
58
    data: TableDataRef<'a, ColrFixedHeader>,
59
}
60
61
#[allow(clippy::needless_lifetimes)]
62
impl<'a> Colr<'a> {
63
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
64
        + u16::RAW_BYTE_LEN
65
        + Offset32::RAW_BYTE_LEN
66
        + Offset32::RAW_BYTE_LEN
67
        + u16::RAW_BYTE_LEN);
68
    basic_table_impls!(impl_the_methods);
69
70
    /// Table version number - set to 0 or 1.
71
861k
    pub fn version(&self) -> u16 {
72
861k
        self.data.header().version.get()
73
861k
    }
74
75
    /// Number of BaseGlyph records; may be 0 in a version 1 table.
76
150k
    pub fn num_base_glyph_records(&self) -> u16 {
77
150k
        self.data.header().num_base_glyph_records.get()
78
150k
    }
79
80
    /// Offset to baseGlyphRecords array (may be NULL).
81
150k
    pub fn base_glyph_records_offset(&self) -> Nullable<Offset32> {
82
150k
        self.data.header().base_glyph_records_offset.get()
83
150k
    }
84
85
    /// Attempt to resolve [`base_glyph_records_offset`][Self::base_glyph_records_offset].
86
150k
    pub fn base_glyph_records(&self) -> Option<Result<&'a [BaseGlyph], ReadError>> {
87
150k
        let data = self.offset_data();
88
150k
        let args = self.num_base_glyph_records();
89
150k
        self.base_glyph_records_offset()
90
150k
            .resolve_with_args(data, args)
91
150k
    }
92
93
    /// Offset to layerRecords array (may be NULL).
94
21.4k
    pub fn layer_records_offset(&self) -> Nullable<Offset32> {
95
21.4k
        self.data.header().layer_records_offset.get()
96
21.4k
    }
97
98
    /// Attempt to resolve [`layer_records_offset`][Self::layer_records_offset].
99
21.4k
    pub fn layer_records(&self) -> Option<Result<&'a [Layer], ReadError>> {
100
21.4k
        let data = self.offset_data();
101
21.4k
        let args = self.num_layer_records();
102
21.4k
        self.layer_records_offset().resolve_with_args(data, args)
103
21.4k
    }
104
105
    /// Number of Layer records; may be 0 in a version 1 table.
106
21.4k
    pub fn num_layer_records(&self) -> u16 {
107
21.4k
        self.data.header().num_layer_records.get()
108
21.4k
    }
109
110
    /// Offset to BaseGlyphList table.
111
230k
    pub fn base_glyph_list_offset(&self) -> Option<Nullable<Offset32>> {
112
230k
        let range = self.base_glyph_list_offset_byte_range();
113
230k
        (!range.is_empty())
114
230k
            .then(|| self.offset_data().read_at(range.start).ok())
115
230k
            .flatten()
116
230k
    }
117
118
    /// Attempt to resolve [`base_glyph_list_offset`][Self::base_glyph_list_offset].
119
230k
    pub fn base_glyph_list(&self) -> Option<Result<BaseGlyphList<'a>, ReadError>> {
120
230k
        let data = self.offset_data();
121
230k
        self.base_glyph_list_offset().map(|x| x.resolve(data))?
122
230k
    }
123
124
    /// Offset to LayerList table (may be NULL).
125
3.01k
    pub fn layer_list_offset(&self) -> Option<Nullable<Offset32>> {
126
3.01k
        let range = self.layer_list_offset_byte_range();
127
3.01k
        (!range.is_empty())
128
3.01k
            .then(|| self.offset_data().read_at(range.start).ok())
129
3.01k
            .flatten()
130
3.01k
    }
131
132
    /// Attempt to resolve [`layer_list_offset`][Self::layer_list_offset].
133
3.01k
    pub fn layer_list(&self) -> Option<Result<LayerList<'a>, ReadError>> {
134
3.01k
        let data = self.offset_data();
135
3.01k
        self.layer_list_offset().map(|x| x.resolve(data))?
136
3.01k
    }
137
138
    /// Offset to ClipList table (may be NULL).
139
196k
    pub fn clip_list_offset(&self) -> Option<Nullable<Offset32>> {
140
196k
        let range = self.clip_list_offset_byte_range();
141
196k
        (!range.is_empty())
142
196k
            .then(|| self.offset_data().read_at(range.start).ok())
143
196k
            .flatten()
144
196k
    }
145
146
    /// Attempt to resolve [`clip_list_offset`][Self::clip_list_offset].
147
196k
    pub fn clip_list(&self) -> Option<Result<ClipList<'a>, ReadError>> {
148
196k
        let data = self.offset_data();
149
196k
        self.clip_list_offset().map(|x| x.resolve(data))?
150
196k
    }
151
152
    /// Offset to DeltaSetIndexMap table (may be NULL).
153
3.78k
    pub fn var_index_map_offset(&self) -> Option<Nullable<Offset32>> {
154
3.78k
        let range = self.var_index_map_offset_byte_range();
155
3.78k
        (!range.is_empty())
156
3.78k
            .then(|| self.offset_data().read_at(range.start).ok())
157
3.78k
            .flatten()
158
3.78k
    }
159
160
    /// Attempt to resolve [`var_index_map_offset`][Self::var_index_map_offset].
161
3.78k
    pub fn var_index_map(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
162
3.78k
        let data = self.offset_data();
163
3.78k
        self.var_index_map_offset().map(|x| x.resolve(data))?
164
3.78k
    }
165
166
    /// Offset to ItemVariationStore (may be NULL).
167
3.78k
    pub fn item_variation_store_offset(&self) -> Option<Nullable<Offset32>> {
168
3.78k
        let range = self.item_variation_store_offset_byte_range();
169
3.78k
        (!range.is_empty())
170
3.78k
            .then(|| self.offset_data().read_at(range.start).ok())
171
3.78k
            .flatten()
172
3.78k
    }
173
174
    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
175
3.78k
    pub fn item_variation_store(&self) -> Option<Result<ItemVariationStore<'a>, ReadError>> {
176
3.78k
        let data = self.offset_data();
177
3.78k
        self.item_variation_store_offset()
178
3.78k
            .map(|x| x.resolve(data))?
179
3.78k
    }
180
181
437k
    pub fn version_byte_range(&self) -> Range<usize> {
182
437k
        let start = 0usize;
183
437k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
184
437k
        start..end
185
437k
    }
186
187
437k
    pub fn num_base_glyph_records_byte_range(&self) -> Range<usize> {
188
437k
        let start = self.version_byte_range().end;
189
437k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
190
437k
        start..end
191
437k
    }
192
193
437k
    pub fn base_glyph_records_offset_byte_range(&self) -> Range<usize> {
194
437k
        let start = self.num_base_glyph_records_byte_range().end;
195
437k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
196
437k
        start..end
197
437k
    }
198
199
437k
    pub fn layer_records_offset_byte_range(&self) -> Range<usize> {
200
437k
        let start = self.base_glyph_records_offset_byte_range().end;
201
437k
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
202
437k
        start..end
203
437k
    }
204
205
437k
    pub fn num_layer_records_byte_range(&self) -> Range<usize> {
206
437k
        let start = self.layer_records_offset_byte_range().end;
207
437k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
208
437k
        start..end
209
437k
    }
210
211
437k
    pub fn base_glyph_list_offset_byte_range(&self) -> Range<usize> {
212
437k
        let start = self.num_layer_records_byte_range().end;
213
437k
        let end = if self.version().compatible(1u16) {
214
386k
            start.saturating_add(Offset32::RAW_BYTE_LEN)
215
        } else {
216
51.2k
            start
217
        };
218
437k
        start..end
219
437k
    }
220
221
207k
    pub fn layer_list_offset_byte_range(&self) -> Range<usize> {
222
207k
        let start = self.base_glyph_list_offset_byte_range().end;
223
207k
        let end = if self.version().compatible(1u16) {
224
192k
            start.saturating_add(Offset32::RAW_BYTE_LEN)
225
        } else {
226
15.2k
            start
227
        };
228
207k
        start..end
229
207k
    }
230
231
204k
    pub fn clip_list_offset_byte_range(&self) -> Range<usize> {
232
204k
        let start = self.layer_list_offset_byte_range().end;
233
204k
        let end = if self.version().compatible(1u16) {
234
189k
            start.saturating_add(Offset32::RAW_BYTE_LEN)
235
        } else {
236
15.2k
            start
237
        };
238
204k
        start..end
239
204k
    }
240
241
7.57k
    pub fn var_index_map_offset_byte_range(&self) -> Range<usize> {
242
7.57k
        let start = self.clip_list_offset_byte_range().end;
243
7.57k
        let end = if self.version().compatible(1u16) {
244
7.02k
            start.saturating_add(Offset32::RAW_BYTE_LEN)
245
        } else {
246
546
            start
247
        };
248
7.57k
        start..end
249
7.57k
    }
250
251
3.78k
    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
252
3.78k
        let start = self.var_index_map_offset_byte_range().end;
253
3.78k
        let end = if self.version().compatible(1u16) {
254
3.51k
            start.saturating_add(Offset32::RAW_BYTE_LEN)
255
        } else {
256
273
            start
257
        };
258
3.78k
        start..end
259
3.78k
    }
260
}
261
262
const _: () = assert!(FontData::default_data_long_enough(Colr::MIN_SIZE));
263
264
impl Default for Colr<'_> {
265
0
    fn default() -> Self {
266
        Self {
267
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
268
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
269
        }
270
0
    }
271
}
272
273
/// [BaseGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyph-and-layer-records) record
274
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
275
#[repr(C)]
276
#[repr(packed)]
277
pub struct BaseGlyph {
278
    /// Glyph ID of the base glyph.
279
    pub glyph_id: BigEndian<GlyphId16>,
280
    /// Index (base 0) into the layerRecords array.
281
    pub first_layer_index: BigEndian<u16>,
282
    /// Number of color layers associated with this glyph.
283
    pub num_layers: BigEndian<u16>,
284
}
285
286
impl BaseGlyph {
287
    /// Glyph ID of the base glyph.
288
194k
    pub fn glyph_id(&self) -> GlyphId16 {
289
194k
        self.glyph_id.get()
290
194k
    }
291
292
    /// Index (base 0) into the layerRecords array.
293
42.0k
    pub fn first_layer_index(&self) -> u16 {
294
42.0k
        self.first_layer_index.get()
295
42.0k
    }
296
297
    /// Number of color layers associated with this glyph.
298
42.0k
    pub fn num_layers(&self) -> u16 {
299
42.0k
        self.num_layers.get()
300
42.0k
    }
301
}
302
303
impl FixedSize for BaseGlyph {
304
    const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
305
}
306
307
/// [Layer](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyph-and-layer-records) record
308
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
309
#[repr(C)]
310
#[repr(packed)]
311
pub struct Layer {
312
    /// Glyph ID of the glyph used for a given layer.
313
    pub glyph_id: BigEndian<GlyphId16>,
314
    /// Index (base 0) for a palette entry in the CPAL table.
315
    pub palette_index: BigEndian<u16>,
316
}
317
318
impl Layer {
319
    /// Glyph ID of the glyph used for a given layer.
320
19.3k
    pub fn glyph_id(&self) -> GlyphId16 {
321
19.3k
        self.glyph_id.get()
322
19.3k
    }
323
324
    /// Index (base 0) for a palette entry in the CPAL table.
325
19.3k
    pub fn palette_index(&self) -> u16 {
326
19.3k
        self.palette_index.get()
327
19.3k
    }
328
}
329
330
impl FixedSize for Layer {
331
    const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
332
}
333
334
impl<'a> MinByteRange<'a> for BaseGlyphList<'a> {
335
0
    fn min_byte_range(&self) -> Range<usize> {
336
0
        0..self.base_glyph_paint_records_byte_range().end
337
0
    }
338
0
    fn min_table_bytes(&self) -> &'a [u8] {
339
0
        let range = self.min_byte_range();
340
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
341
0
    }
342
}
343
344
impl ReadArgs for BaseGlyphList<'_> {
345
    type Args = ();
346
}
347
348
impl<'a> FontRead<'a> for BaseGlyphList<'a> {
349
106k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
350
        #[allow(clippy::absurd_extreme_comparisons)]
351
106k
        if data.len() < Self::MIN_SIZE {
352
5
            return Err(ReadError::OutOfBounds);
353
106k
        }
354
106k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
355
0
            return Err(ReadError::OutOfBounds);
356
        };
357
106k
        Ok(Self { data })
358
106k
    }
359
}
360
361
/// The fields at the start of the table, which are read directly.
362
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
363
#[repr(C, packed)]
364
#[doc(hidden)]
365
pub struct BaseGlyphListFixedHeader {
366
    pub num_base_glyph_paint_records: BigEndian<u32>,
367
}
368
369
#[allow(clippy::absurd_extreme_comparisons)]
370
const _: () = assert!(std::mem::size_of::<BaseGlyphListFixedHeader>() <= BaseGlyphList::MIN_SIZE);
371
372
/// [BaseGlyphList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table
373
#[derive(Clone)]
374
pub struct BaseGlyphList<'a> {
375
    data: TableDataRef<'a, BaseGlyphListFixedHeader>,
376
}
377
378
#[allow(clippy::needless_lifetimes)]
379
impl<'a> BaseGlyphList<'a> {
380
    pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
381
    basic_table_impls!(impl_the_methods);
382
383
106k
    pub fn num_base_glyph_paint_records(&self) -> u32 {
384
106k
        self.data.header().num_base_glyph_paint_records.get()
385
106k
    }
386
387
106k
    pub fn base_glyph_paint_records(&self) -> &'a [BaseGlyphPaint] {
388
106k
        let range = self.base_glyph_paint_records_byte_range();
389
106k
        self.offset_data()
390
106k
            .read_array(range)
391
106k
            .ok()
392
106k
            .unwrap_or_default()
393
106k
    }
394
395
106k
    pub fn num_base_glyph_paint_records_byte_range(&self) -> Range<usize> {
396
106k
        let start = 0usize;
397
106k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
398
106k
        start..end
399
106k
    }
400
401
106k
    pub fn base_glyph_paint_records_byte_range(&self) -> Range<usize> {
402
106k
        let num_base_glyph_paint_records = self.num_base_glyph_paint_records();
403
106k
        let start = self.num_base_glyph_paint_records_byte_range().end;
404
106k
        let end = start.saturating_add(
405
106k
            (transforms::to_usize(num_base_glyph_paint_records))
406
106k
                .saturating_mul(BaseGlyphPaint::RAW_BYTE_LEN),
407
        );
408
106k
        start..end
409
106k
    }
410
}
411
412
const _: () = assert!(FontData::default_data_long_enough(BaseGlyphList::MIN_SIZE));
413
414
impl Default for BaseGlyphList<'_> {
415
0
    fn default() -> Self {
416
        Self {
417
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
418
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
419
        }
420
0
    }
421
}
422
423
/// [BaseGlyphPaint](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record
424
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
425
#[repr(C)]
426
#[repr(packed)]
427
pub struct BaseGlyphPaint {
428
    /// Glyph ID of the base glyph.
429
    pub glyph_id: BigEndian<GlyphId16>,
430
    /// Offset to a Paint table, from the beginning of the [`BaseGlyphList`] table.
431
    pub paint_offset: BigEndian<Offset32>,
432
}
433
434
impl BaseGlyphPaint {
435
    /// Glyph ID of the base glyph.
436
422k
    pub fn glyph_id(&self) -> GlyphId16 {
437
422k
        self.glyph_id.get()
438
422k
    }
439
440
    /// Offset to a Paint table, from the beginning of the [`BaseGlyphList`] table.
441
202k
    pub fn paint_offset(&self) -> Offset32 {
442
202k
        self.paint_offset.get()
443
202k
    }
444
445
    /// Offset to a Paint table, from the beginning of the [`BaseGlyphList`] table.
446
    ///
447
    /// The `data` argument should be retrieved from the parent table
448
    /// By calling its `offset_data` method.
449
101k
    pub fn paint<'a>(&self, data: FontData<'a>) -> Result<Paint<'a>, ReadError> {
450
101k
        self.paint_offset().resolve(data)
451
101k
    }
452
}
453
454
impl FixedSize for BaseGlyphPaint {
455
    const RAW_BYTE_LEN: usize = GlyphId16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
456
}
457
458
impl<'a> MinByteRange<'a> for LayerList<'a> {
459
0
    fn min_byte_range(&self) -> Range<usize> {
460
0
        0..self.paint_offsets_byte_range().end
461
0
    }
462
0
    fn min_table_bytes(&self) -> &'a [u8] {
463
0
        let range = self.min_byte_range();
464
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
465
0
    }
466
}
467
468
impl ReadArgs for LayerList<'_> {
469
    type Args = ();
470
}
471
472
impl<'a> FontRead<'a> for LayerList<'a> {
473
240
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
474
        #[allow(clippy::absurd_extreme_comparisons)]
475
240
        if data.len() < Self::MIN_SIZE {
476
0
            return Err(ReadError::OutOfBounds);
477
240
        }
478
240
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
479
0
            return Err(ReadError::OutOfBounds);
480
        };
481
240
        Ok(Self { data })
482
240
    }
483
}
484
485
/// The fields at the start of the table, which are read directly.
486
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
487
#[repr(C, packed)]
488
#[doc(hidden)]
489
pub struct LayerListFixedHeader {
490
    pub num_layers: BigEndian<u32>,
491
}
492
493
#[allow(clippy::absurd_extreme_comparisons)]
494
const _: () = assert!(std::mem::size_of::<LayerListFixedHeader>() <= LayerList::MIN_SIZE);
495
496
/// [LayerList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table
497
#[derive(Clone)]
498
pub struct LayerList<'a> {
499
    data: TableDataRef<'a, LayerListFixedHeader>,
500
}
501
502
#[allow(clippy::needless_lifetimes)]
503
impl<'a> LayerList<'a> {
504
    pub const MIN_SIZE: usize = u32::RAW_BYTE_LEN;
505
    basic_table_impls!(impl_the_methods);
506
507
240
    pub fn num_layers(&self) -> u32 {
508
240
        self.data.header().num_layers.get()
509
240
    }
510
511
    /// Offsets to Paint tables.
512
240
    pub fn paint_offsets(&self) -> &'a [BigEndian<Offset32>] {
513
240
        let range = self.paint_offsets_byte_range();
514
240
        self.offset_data()
515
240
            .read_array(range)
516
240
            .ok()
517
240
            .unwrap_or_default()
518
240
    }
519
520
    /// A dynamically resolving wrapper for [`paint_offsets`][Self::paint_offsets].
521
0
    pub fn paints(&self) -> ArrayOfOffsets<'a, Paint<'a>, Offset32> {
522
0
        let data = self.offset_data();
523
0
        let offsets = self.paint_offsets();
524
0
        ArrayOfOffsets::new(offsets, data, ())
525
0
    }
526
527
240
    pub fn num_layers_byte_range(&self) -> Range<usize> {
528
240
        let start = 0usize;
529
240
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
530
240
        start..end
531
240
    }
532
533
240
    pub fn paint_offsets_byte_range(&self) -> Range<usize> {
534
240
        let num_layers = self.num_layers();
535
240
        let start = self.num_layers_byte_range().end;
536
240
        let end = start.saturating_add(
537
240
            (transforms::to_usize(num_layers)).saturating_mul(Offset32::RAW_BYTE_LEN),
538
        );
539
240
        start..end
540
240
    }
541
}
542
543
const _: () = assert!(FontData::default_data_long_enough(LayerList::MIN_SIZE));
544
545
impl Default for LayerList<'_> {
546
0
    fn default() -> Self {
547
        Self {
548
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
549
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
550
        }
551
0
    }
552
}
553
554
impl<'a> MinByteRange<'a> for ClipList<'a> {
555
0
    fn min_byte_range(&self) -> Range<usize> {
556
0
        0..self.clips_byte_range().end
557
0
    }
558
0
    fn min_table_bytes(&self) -> &'a [u8] {
559
0
        let range = self.min_byte_range();
560
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
561
0
    }
562
}
563
564
impl ReadArgs for ClipList<'_> {
565
    type Args = ();
566
}
567
568
impl<'a> FontRead<'a> for ClipList<'a> {
569
62.5k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
570
        #[allow(clippy::absurd_extreme_comparisons)]
571
62.5k
        if data.len() < Self::MIN_SIZE {
572
18
            return Err(ReadError::OutOfBounds);
573
62.5k
        }
574
62.5k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
575
0
            return Err(ReadError::OutOfBounds);
576
        };
577
62.5k
        Ok(Self { data })
578
62.5k
    }
579
}
580
581
/// The fields at the start of the table, which are read directly.
582
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
583
#[repr(C, packed)]
584
#[doc(hidden)]
585
pub struct ClipListFixedHeader {
586
    pub format: u8,
587
    pub num_clips: BigEndian<u32>,
588
}
589
590
#[allow(clippy::absurd_extreme_comparisons)]
591
const _: () = assert!(std::mem::size_of::<ClipListFixedHeader>() <= ClipList::MIN_SIZE);
592
593
/// [ClipList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table
594
#[derive(Clone)]
595
pub struct ClipList<'a> {
596
    data: TableDataRef<'a, ClipListFixedHeader>,
597
}
598
599
#[allow(clippy::needless_lifetimes)]
600
impl<'a> ClipList<'a> {
601
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
602
    basic_table_impls!(impl_the_methods);
603
604
    /// Set to 1.
605
0
    pub fn format(&self) -> u8 {
606
0
        self.data.header().format
607
0
    }
608
609
    /// Number of Clip records.
610
62.5k
    pub fn num_clips(&self) -> u32 {
611
62.5k
        self.data.header().num_clips.get()
612
62.5k
    }
613
614
    /// Clip records. Sorted by startGlyphID.
615
62.5k
    pub fn clips(&self) -> &'a [Clip] {
616
62.5k
        let range = self.clips_byte_range();
617
62.5k
        self.offset_data()
618
62.5k
            .read_array(range)
619
62.5k
            .ok()
620
62.5k
            .unwrap_or_default()
621
62.5k
    }
622
623
62.5k
    pub fn format_byte_range(&self) -> Range<usize> {
624
62.5k
        let start = 0usize;
625
62.5k
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
626
62.5k
        start..end
627
62.5k
    }
628
629
62.5k
    pub fn num_clips_byte_range(&self) -> Range<usize> {
630
62.5k
        let start = self.format_byte_range().end;
631
62.5k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
632
62.5k
        start..end
633
62.5k
    }
634
635
62.5k
    pub fn clips_byte_range(&self) -> Range<usize> {
636
62.5k
        let num_clips = self.num_clips();
637
62.5k
        let start = self.num_clips_byte_range().end;
638
62.5k
        let end = start
639
62.5k
            .saturating_add((transforms::to_usize(num_clips)).saturating_mul(Clip::RAW_BYTE_LEN));
640
62.5k
        start..end
641
62.5k
    }
642
}
643
644
const _: () = assert!(FontData::default_data_long_enough(ClipList::MIN_SIZE));
645
646
impl Default for ClipList<'_> {
647
0
    fn default() -> Self {
648
        Self {
649
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
650
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
651
        }
652
0
    }
653
}
654
655
/// [Clip](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record
656
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
657
#[repr(C)]
658
#[repr(packed)]
659
pub struct Clip {
660
    /// First glyph ID in the range.
661
    pub start_glyph_id: BigEndian<GlyphId16>,
662
    /// Last glyph ID in the range.
663
    pub end_glyph_id: BigEndian<GlyphId16>,
664
    /// Offset to a ClipBox table, from the beginning of the [`ClipList`] table.
665
    pub clip_box_offset: BigEndian<Offset24>,
666
}
667
668
impl Clip {
669
    /// First glyph ID in the range.
670
51.6k
    pub fn start_glyph_id(&self) -> GlyphId16 {
671
51.6k
        self.start_glyph_id.get()
672
51.6k
    }
673
674
    /// Last glyph ID in the range.
675
23.1k
    pub fn end_glyph_id(&self) -> GlyphId16 {
676
23.1k
        self.end_glyph_id.get()
677
23.1k
    }
678
679
    /// Offset to a ClipBox table, from the beginning of the [`ClipList`] table.
680
10.5k
    pub fn clip_box_offset(&self) -> Offset24 {
681
10.5k
        self.clip_box_offset.get()
682
10.5k
    }
683
684
    /// Offset to a ClipBox table, from the beginning of the [`ClipList`] table.
685
    ///
686
    /// The `data` argument should be retrieved from the parent table
687
    /// By calling its `offset_data` method.
688
10.5k
    pub fn clip_box<'a>(&self, data: FontData<'a>) -> Result<ClipBox<'a>, ReadError> {
689
10.5k
        self.clip_box_offset().resolve(data)
690
10.5k
    }
691
}
692
693
impl FixedSize for Clip {
694
    const RAW_BYTE_LEN: usize =
695
        GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN;
696
}
697
698
/// [ClipBox](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table
699
#[derive(Clone)]
700
pub enum ClipBox<'a> {
701
    Format1(ClipBoxFormat1<'a>),
702
    Format2(ClipBoxFormat2<'a>),
703
}
704
705
impl Default for ClipBox<'_> {
706
0
    fn default() -> Self {
707
0
        Self::Format1(Default::default())
708
0
    }
709
}
710
711
impl<'a> ClipBox<'a> {
712
    ///Return the `FontData` used to resolve offsets for this table.
713
0
    pub fn offset_data(&self) -> FontData<'a> {
714
0
        match self {
715
0
            Self::Format1(item) => item.offset_data(),
716
0
            Self::Format2(item) => item.offset_data(),
717
        }
718
0
    }
719
720
    /// Set to 1.
721
0
    pub fn format(&self) -> u8 {
722
0
        match self {
723
0
            Self::Format1(item) => item.format(),
724
0
            Self::Format2(item) => item.format(),
725
        }
726
0
    }
727
728
    /// Minimum x of clip box.
729
0
    pub fn x_min(&self) -> FWord {
730
0
        match self {
731
0
            Self::Format1(item) => item.x_min(),
732
0
            Self::Format2(item) => item.x_min(),
733
        }
734
0
    }
735
736
    /// Minimum y of clip box.
737
0
    pub fn y_min(&self) -> FWord {
738
0
        match self {
739
0
            Self::Format1(item) => item.y_min(),
740
0
            Self::Format2(item) => item.y_min(),
741
        }
742
0
    }
743
744
    /// Maximum x of clip box.
745
0
    pub fn x_max(&self) -> FWord {
746
0
        match self {
747
0
            Self::Format1(item) => item.x_max(),
748
0
            Self::Format2(item) => item.x_max(),
749
        }
750
0
    }
751
752
    /// Maximum y of clip box.
753
0
    pub fn y_max(&self) -> FWord {
754
0
        match self {
755
0
            Self::Format1(item) => item.y_max(),
756
0
            Self::Format2(item) => item.y_max(),
757
        }
758
0
    }
759
}
760
761
impl ReadArgs for ClipBox<'_> {
762
    type Args = ();
763
}
764
765
impl<'a> FontRead<'a> for ClipBox<'a> {
766
    #[inline]
767
6.02k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
768
6.02k
        let format: u8 = data.read_at(0usize)?;
769
5.99k
        match format {
770
843
            ClipBoxFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
771
726
            ClipBoxFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
772
4.42k
            other => Err(ReadError::InvalidFormat(other.into())),
773
        }
774
6.02k
    }
775
}
776
777
impl<'a> MinByteRange<'a> for ClipBox<'a> {
778
0
    fn min_byte_range(&self) -> Range<usize> {
779
0
        match self {
780
0
            Self::Format1(item) => item.min_byte_range(),
781
0
            Self::Format2(item) => item.min_byte_range(),
782
        }
783
0
    }
784
0
    fn min_table_bytes(&self) -> &'a [u8] {
785
0
        match self {
786
0
            Self::Format1(item) => item.min_table_bytes(),
787
0
            Self::Format2(item) => item.min_table_bytes(),
788
        }
789
0
    }
790
}
791
792
impl Format<u8> for ClipBoxFormat1<'_> {
793
    const FORMAT: u8 = 1;
794
}
795
796
impl<'a> MinByteRange<'a> for ClipBoxFormat1<'a> {
797
0
    fn min_byte_range(&self) -> Range<usize> {
798
0
        0..self.y_max_byte_range().end
799
0
    }
800
0
    fn min_table_bytes(&self) -> &'a [u8] {
801
0
        let range = self.min_byte_range();
802
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
803
0
    }
804
}
805
806
impl ReadArgs for ClipBoxFormat1<'_> {
807
    type Args = ();
808
}
809
810
impl<'a> FontRead<'a> for ClipBoxFormat1<'a> {
811
843
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
812
        #[allow(clippy::absurd_extreme_comparisons)]
813
843
        if data.len() < Self::MIN_SIZE {
814
34
            return Err(ReadError::OutOfBounds);
815
809
        }
816
809
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
817
0
            return Err(ReadError::OutOfBounds);
818
        };
819
809
        Ok(Self { data })
820
843
    }
821
}
822
823
/// The fields at the start of the table, which are read directly.
824
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
825
#[repr(C, packed)]
826
#[doc(hidden)]
827
pub struct ClipBoxFormat1FixedHeader {
828
    pub format: u8,
829
    pub x_min: BigEndian<FWord>,
830
    pub y_min: BigEndian<FWord>,
831
    pub x_max: BigEndian<FWord>,
832
    pub y_max: BigEndian<FWord>,
833
}
834
835
#[allow(clippy::absurd_extreme_comparisons)]
836
const _: () = assert!(std::mem::size_of::<ClipBoxFormat1FixedHeader>() <= ClipBoxFormat1::MIN_SIZE);
837
838
/// [ClipBoxFormat1](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record
839
#[derive(Clone)]
840
pub struct ClipBoxFormat1<'a> {
841
    data: TableDataRef<'a, ClipBoxFormat1FixedHeader>,
842
}
843
844
#[allow(clippy::needless_lifetimes)]
845
impl<'a> ClipBoxFormat1<'a> {
846
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
847
        + FWord::RAW_BYTE_LEN
848
        + FWord::RAW_BYTE_LEN
849
        + FWord::RAW_BYTE_LEN
850
        + FWord::RAW_BYTE_LEN);
851
    basic_table_impls!(impl_the_methods);
852
853
    /// Set to 1.
854
0
    pub fn format(&self) -> u8 {
855
0
        self.data.header().format
856
0
    }
857
858
    /// Minimum x of clip box.
859
809
    pub fn x_min(&self) -> FWord {
860
809
        self.data.header().x_min.get()
861
809
    }
862
863
    /// Minimum y of clip box.
864
809
    pub fn y_min(&self) -> FWord {
865
809
        self.data.header().y_min.get()
866
809
    }
867
868
    /// Maximum x of clip box.
869
809
    pub fn x_max(&self) -> FWord {
870
809
        self.data.header().x_max.get()
871
809
    }
872
873
    /// Maximum y of clip box.
874
809
    pub fn y_max(&self) -> FWord {
875
809
        self.data.header().y_max.get()
876
809
    }
877
878
0
    pub fn format_byte_range(&self) -> Range<usize> {
879
0
        let start = 0usize;
880
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
881
0
        start..end
882
0
    }
883
884
0
    pub fn x_min_byte_range(&self) -> Range<usize> {
885
0
        let start = self.format_byte_range().end;
886
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
887
0
        start..end
888
0
    }
889
890
0
    pub fn y_min_byte_range(&self) -> Range<usize> {
891
0
        let start = self.x_min_byte_range().end;
892
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
893
0
        start..end
894
0
    }
895
896
0
    pub fn x_max_byte_range(&self) -> Range<usize> {
897
0
        let start = self.y_min_byte_range().end;
898
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
899
0
        start..end
900
0
    }
901
902
0
    pub fn y_max_byte_range(&self) -> Range<usize> {
903
0
        let start = self.x_max_byte_range().end;
904
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
905
0
        start..end
906
0
    }
907
}
908
909
const _: () = assert!(FontData::default_data_long_enough(ClipBoxFormat1::MIN_SIZE));
910
911
impl Default for ClipBoxFormat1<'_> {
912
0
    fn default() -> Self {
913
        Self {
914
0
            data: TableDataRef::new(FontData::default_format_1_u8_table_data().as_bytes())
915
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
916
        }
917
0
    }
918
}
919
920
impl Format<u8> for ClipBoxFormat2<'_> {
921
    const FORMAT: u8 = 2;
922
}
923
924
impl<'a> MinByteRange<'a> for ClipBoxFormat2<'a> {
925
0
    fn min_byte_range(&self) -> Range<usize> {
926
0
        0..self.var_index_base_byte_range().end
927
0
    }
928
0
    fn min_table_bytes(&self) -> &'a [u8] {
929
0
        let range = self.min_byte_range();
930
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
931
0
    }
932
}
933
934
impl ReadArgs for ClipBoxFormat2<'_> {
935
    type Args = ();
936
}
937
938
impl<'a> FontRead<'a> for ClipBoxFormat2<'a> {
939
726
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
940
        #[allow(clippy::absurd_extreme_comparisons)]
941
726
        if data.len() < Self::MIN_SIZE {
942
38
            return Err(ReadError::OutOfBounds);
943
688
        }
944
688
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
945
0
            return Err(ReadError::OutOfBounds);
946
        };
947
688
        Ok(Self { data })
948
726
    }
949
}
950
951
/// The fields at the start of the table, which are read directly.
952
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
953
#[repr(C, packed)]
954
#[doc(hidden)]
955
pub struct ClipBoxFormat2FixedHeader {
956
    pub format: u8,
957
    pub x_min: BigEndian<FWord>,
958
    pub y_min: BigEndian<FWord>,
959
    pub x_max: BigEndian<FWord>,
960
    pub y_max: BigEndian<FWord>,
961
    pub var_index_base: BigEndian<u32>,
962
}
963
964
#[allow(clippy::absurd_extreme_comparisons)]
965
const _: () = assert!(std::mem::size_of::<ClipBoxFormat2FixedHeader>() <= ClipBoxFormat2::MIN_SIZE);
966
967
/// [ClipBoxFormat2](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record
968
#[derive(Clone)]
969
pub struct ClipBoxFormat2<'a> {
970
    data: TableDataRef<'a, ClipBoxFormat2FixedHeader>,
971
}
972
973
#[allow(clippy::needless_lifetimes)]
974
impl<'a> ClipBoxFormat2<'a> {
975
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
976
        + FWord::RAW_BYTE_LEN
977
        + FWord::RAW_BYTE_LEN
978
        + FWord::RAW_BYTE_LEN
979
        + FWord::RAW_BYTE_LEN
980
        + u32::RAW_BYTE_LEN);
981
    basic_table_impls!(impl_the_methods);
982
983
    /// Set to 2.
984
0
    pub fn format(&self) -> u8 {
985
0
        self.data.header().format
986
0
    }
987
988
    /// Minimum x of clip box. For variation, use varIndexBase + 0.
989
688
    pub fn x_min(&self) -> FWord {
990
688
        self.data.header().x_min.get()
991
688
    }
992
993
    /// Minimum y of clip box. For variation, use varIndexBase + 1.
994
688
    pub fn y_min(&self) -> FWord {
995
688
        self.data.header().y_min.get()
996
688
    }
997
998
    /// Maximum x of clip box. For variation, use varIndexBase + 2.
999
688
    pub fn x_max(&self) -> FWord {
1000
688
        self.data.header().x_max.get()
1001
688
    }
1002
1003
    /// Maximum y of clip box. For variation, use varIndexBase + 3.
1004
688
    pub fn y_max(&self) -> FWord {
1005
688
        self.data.header().y_max.get()
1006
688
    }
1007
1008
    /// Base index into DeltaSetIndexMap.
1009
688
    pub fn var_index_base(&self) -> u32 {
1010
688
        self.data.header().var_index_base.get()
1011
688
    }
1012
1013
0
    pub fn format_byte_range(&self) -> Range<usize> {
1014
0
        let start = 0usize;
1015
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1016
0
        start..end
1017
0
    }
1018
1019
0
    pub fn x_min_byte_range(&self) -> Range<usize> {
1020
0
        let start = self.format_byte_range().end;
1021
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
1022
0
        start..end
1023
0
    }
1024
1025
0
    pub fn y_min_byte_range(&self) -> Range<usize> {
1026
0
        let start = self.x_min_byte_range().end;
1027
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
1028
0
        start..end
1029
0
    }
1030
1031
0
    pub fn x_max_byte_range(&self) -> Range<usize> {
1032
0
        let start = self.y_min_byte_range().end;
1033
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
1034
0
        start..end
1035
0
    }
1036
1037
0
    pub fn y_max_byte_range(&self) -> Range<usize> {
1038
0
        let start = self.x_max_byte_range().end;
1039
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
1040
0
        start..end
1041
0
    }
1042
1043
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
1044
0
        let start = self.y_max_byte_range().end;
1045
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
1046
0
        start..end
1047
0
    }
1048
}
1049
1050
/// [ColorIndex](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record
1051
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1052
#[repr(C)]
1053
#[repr(packed)]
1054
pub struct ColorIndex {
1055
    /// Index for a CPAL palette entry.
1056
    pub palette_index: BigEndian<u16>,
1057
    /// Alpha value.
1058
    pub alpha: BigEndian<F2Dot14>,
1059
}
1060
1061
impl ColorIndex {
1062
    /// Index for a CPAL palette entry.
1063
0
    pub fn palette_index(&self) -> u16 {
1064
0
        self.palette_index.get()
1065
0
    }
1066
1067
    /// Alpha value.
1068
0
    pub fn alpha(&self) -> F2Dot14 {
1069
0
        self.alpha.get()
1070
0
    }
1071
}
1072
1073
impl FixedSize for ColorIndex {
1074
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN;
1075
}
1076
1077
/// [VarColorIndex](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record
1078
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1079
#[repr(C)]
1080
#[repr(packed)]
1081
pub struct VarColorIndex {
1082
    /// Index for a CPAL palette entry.
1083
    pub palette_index: BigEndian<u16>,
1084
    /// Alpha value. For variation, use varIndexBase + 0.
1085
    pub alpha: BigEndian<F2Dot14>,
1086
    /// Base index into DeltaSetIndexMap.
1087
    pub var_index_base: BigEndian<u32>,
1088
}
1089
1090
impl VarColorIndex {
1091
    /// Index for a CPAL palette entry.
1092
0
    pub fn palette_index(&self) -> u16 {
1093
0
        self.palette_index.get()
1094
0
    }
1095
1096
    /// Alpha value. For variation, use varIndexBase + 0.
1097
0
    pub fn alpha(&self) -> F2Dot14 {
1098
0
        self.alpha.get()
1099
0
    }
1100
1101
    /// Base index into DeltaSetIndexMap.
1102
0
    pub fn var_index_base(&self) -> u32 {
1103
0
        self.var_index_base.get()
1104
0
    }
1105
}
1106
1107
impl FixedSize for VarColorIndex {
1108
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
1109
}
1110
1111
/// [ColorStop](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record
1112
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1113
#[repr(C)]
1114
#[repr(packed)]
1115
pub struct ColorStop {
1116
    /// Position on a color line.
1117
    pub stop_offset: BigEndian<F2Dot14>,
1118
    /// Index for a CPAL palette entry.
1119
    pub palette_index: BigEndian<u16>,
1120
    /// Alpha value.
1121
    pub alpha: BigEndian<F2Dot14>,
1122
}
1123
1124
impl ColorStop {
1125
    /// Position on a color line.
1126
1.53M
    pub fn stop_offset(&self) -> F2Dot14 {
1127
1.53M
        self.stop_offset.get()
1128
1.53M
    }
1129
1130
    /// Index for a CPAL palette entry.
1131
1.53M
    pub fn palette_index(&self) -> u16 {
1132
1.53M
        self.palette_index.get()
1133
1.53M
    }
1134
1135
    /// Alpha value.
1136
1.53M
    pub fn alpha(&self) -> F2Dot14 {
1137
1.53M
        self.alpha.get()
1138
1.53M
    }
1139
}
1140
1141
impl FixedSize for ColorStop {
1142
    const RAW_BYTE_LEN: usize = F2Dot14::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN;
1143
}
1144
1145
/// [VarColorStop](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record
1146
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
1147
#[repr(C)]
1148
#[repr(packed)]
1149
pub struct VarColorStop {
1150
    /// Position on a color line. For variation, use varIndexBase + 0.
1151
    pub stop_offset: BigEndian<F2Dot14>,
1152
    /// Index for a CPAL palette entry.
1153
    pub palette_index: BigEndian<u16>,
1154
    /// Alpha value. For variation, use varIndexBase + 1.
1155
    pub alpha: BigEndian<F2Dot14>,
1156
    /// Base index into DeltaSetIndexMap.
1157
    pub var_index_base: BigEndian<u32>,
1158
}
1159
1160
impl VarColorStop {
1161
    /// Position on a color line. For variation, use varIndexBase + 0.
1162
57.1k
    pub fn stop_offset(&self) -> F2Dot14 {
1163
57.1k
        self.stop_offset.get()
1164
57.1k
    }
1165
1166
    /// Index for a CPAL palette entry.
1167
57.1k
    pub fn palette_index(&self) -> u16 {
1168
57.1k
        self.palette_index.get()
1169
57.1k
    }
1170
1171
    /// Alpha value. For variation, use varIndexBase + 1.
1172
57.1k
    pub fn alpha(&self) -> F2Dot14 {
1173
57.1k
        self.alpha.get()
1174
57.1k
    }
1175
1176
    /// Base index into DeltaSetIndexMap.
1177
57.1k
    pub fn var_index_base(&self) -> u32 {
1178
57.1k
        self.var_index_base.get()
1179
57.1k
    }
1180
}
1181
1182
impl FixedSize for VarColorStop {
1183
    const RAW_BYTE_LEN: usize =
1184
        F2Dot14::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + u32::RAW_BYTE_LEN;
1185
}
1186
1187
impl<'a> MinByteRange<'a> for ColorLine<'a> {
1188
0
    fn min_byte_range(&self) -> Range<usize> {
1189
0
        0..self.color_stops_byte_range().end
1190
0
    }
1191
0
    fn min_table_bytes(&self) -> &'a [u8] {
1192
0
        let range = self.min_byte_range();
1193
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1194
0
    }
1195
}
1196
1197
impl ReadArgs for ColorLine<'_> {
1198
    type Args = ();
1199
}
1200
1201
impl<'a> FontRead<'a> for ColorLine<'a> {
1202
22.6k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1203
        #[allow(clippy::absurd_extreme_comparisons)]
1204
22.6k
        if data.len() < Self::MIN_SIZE {
1205
813
            return Err(ReadError::OutOfBounds);
1206
21.8k
        }
1207
21.8k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1208
0
            return Err(ReadError::OutOfBounds);
1209
        };
1210
21.8k
        Ok(Self { data })
1211
22.6k
    }
1212
}
1213
1214
/// The fields at the start of the table, which are read directly.
1215
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1216
#[repr(C, packed)]
1217
#[doc(hidden)]
1218
pub struct ColorLineFixedHeader {
1219
    pub extend: BigEndian<Extend>,
1220
    pub num_stops: BigEndian<u16>,
1221
}
1222
1223
#[allow(clippy::absurd_extreme_comparisons)]
1224
const _: () = assert!(std::mem::size_of::<ColorLineFixedHeader>() <= ColorLine::MIN_SIZE);
1225
1226
/// [ColorLine](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) table
1227
#[derive(Clone)]
1228
pub struct ColorLine<'a> {
1229
    data: TableDataRef<'a, ColorLineFixedHeader>,
1230
}
1231
1232
#[allow(clippy::needless_lifetimes)]
1233
impl<'a> ColorLine<'a> {
1234
    pub const MIN_SIZE: usize = (Extend::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1235
    basic_table_impls!(impl_the_methods);
1236
1237
    /// An Extend enum value.
1238
21.8k
    pub fn extend(&self) -> Extend {
1239
21.8k
        self.data.header().extend.get()
1240
21.8k
    }
1241
1242
    /// Number of ColorStop records.
1243
21.8k
    pub fn num_stops(&self) -> u16 {
1244
21.8k
        self.data.header().num_stops.get()
1245
21.8k
    }
1246
1247
21.8k
    pub fn color_stops(&self) -> &'a [ColorStop] {
1248
21.8k
        let range = self.color_stops_byte_range();
1249
21.8k
        self.offset_data()
1250
21.8k
            .read_array(range)
1251
21.8k
            .ok()
1252
21.8k
            .unwrap_or_default()
1253
21.8k
    }
1254
1255
21.8k
    pub fn extend_byte_range(&self) -> Range<usize> {
1256
21.8k
        let start = 0usize;
1257
21.8k
        let end = start.saturating_add(Extend::RAW_BYTE_LEN);
1258
21.8k
        start..end
1259
21.8k
    }
1260
1261
21.8k
    pub fn num_stops_byte_range(&self) -> Range<usize> {
1262
21.8k
        let start = self.extend_byte_range().end;
1263
21.8k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1264
21.8k
        start..end
1265
21.8k
    }
1266
1267
21.8k
    pub fn color_stops_byte_range(&self) -> Range<usize> {
1268
21.8k
        let num_stops = self.num_stops();
1269
21.8k
        let start = self.num_stops_byte_range().end;
1270
21.8k
        let end = start.saturating_add(
1271
21.8k
            (transforms::to_usize(num_stops)).saturating_mul(ColorStop::RAW_BYTE_LEN),
1272
        );
1273
21.8k
        start..end
1274
21.8k
    }
1275
}
1276
1277
const _: () = assert!(FontData::default_data_long_enough(ColorLine::MIN_SIZE));
1278
1279
impl Default for ColorLine<'_> {
1280
0
    fn default() -> Self {
1281
        Self {
1282
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1283
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1284
        }
1285
0
    }
1286
}
1287
1288
impl<'a> MinByteRange<'a> for VarColorLine<'a> {
1289
0
    fn min_byte_range(&self) -> Range<usize> {
1290
0
        0..self.color_stops_byte_range().end
1291
0
    }
1292
0
    fn min_table_bytes(&self) -> &'a [u8] {
1293
0
        let range = self.min_byte_range();
1294
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1295
0
    }
1296
}
1297
1298
impl ReadArgs for VarColorLine<'_> {
1299
    type Args = ();
1300
}
1301
1302
impl<'a> FontRead<'a> for VarColorLine<'a> {
1303
8.12k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1304
        #[allow(clippy::absurd_extreme_comparisons)]
1305
8.12k
        if data.len() < Self::MIN_SIZE {
1306
1.40k
            return Err(ReadError::OutOfBounds);
1307
6.72k
        }
1308
6.72k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1309
0
            return Err(ReadError::OutOfBounds);
1310
        };
1311
6.72k
        Ok(Self { data })
1312
8.12k
    }
1313
}
1314
1315
/// The fields at the start of the table, which are read directly.
1316
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1317
#[repr(C, packed)]
1318
#[doc(hidden)]
1319
pub struct VarColorLineFixedHeader {
1320
    pub extend: BigEndian<Extend>,
1321
    pub num_stops: BigEndian<u16>,
1322
}
1323
1324
#[allow(clippy::absurd_extreme_comparisons)]
1325
const _: () = assert!(std::mem::size_of::<VarColorLineFixedHeader>() <= VarColorLine::MIN_SIZE);
1326
1327
/// [VarColorLine](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) table
1328
#[derive(Clone)]
1329
pub struct VarColorLine<'a> {
1330
    data: TableDataRef<'a, VarColorLineFixedHeader>,
1331
}
1332
1333
#[allow(clippy::needless_lifetimes)]
1334
impl<'a> VarColorLine<'a> {
1335
    pub const MIN_SIZE: usize = (Extend::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
1336
    basic_table_impls!(impl_the_methods);
1337
1338
    /// An Extend enum value.
1339
6.72k
    pub fn extend(&self) -> Extend {
1340
6.72k
        self.data.header().extend.get()
1341
6.72k
    }
1342
1343
    /// Number of ColorStop records.
1344
6.72k
    pub fn num_stops(&self) -> u16 {
1345
6.72k
        self.data.header().num_stops.get()
1346
6.72k
    }
1347
1348
    /// Allows for variations.
1349
6.72k
    pub fn color_stops(&self) -> &'a [VarColorStop] {
1350
6.72k
        let range = self.color_stops_byte_range();
1351
6.72k
        self.offset_data()
1352
6.72k
            .read_array(range)
1353
6.72k
            .ok()
1354
6.72k
            .unwrap_or_default()
1355
6.72k
    }
1356
1357
6.72k
    pub fn extend_byte_range(&self) -> Range<usize> {
1358
6.72k
        let start = 0usize;
1359
6.72k
        let end = start.saturating_add(Extend::RAW_BYTE_LEN);
1360
6.72k
        start..end
1361
6.72k
    }
1362
1363
6.72k
    pub fn num_stops_byte_range(&self) -> Range<usize> {
1364
6.72k
        let start = self.extend_byte_range().end;
1365
6.72k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1366
6.72k
        start..end
1367
6.72k
    }
1368
1369
6.72k
    pub fn color_stops_byte_range(&self) -> Range<usize> {
1370
6.72k
        let num_stops = self.num_stops();
1371
6.72k
        let start = self.num_stops_byte_range().end;
1372
6.72k
        let end = start.saturating_add(
1373
6.72k
            (transforms::to_usize(num_stops)).saturating_mul(VarColorStop::RAW_BYTE_LEN),
1374
        );
1375
6.72k
        start..end
1376
6.72k
    }
1377
}
1378
1379
const _: () = assert!(FontData::default_data_long_enough(VarColorLine::MIN_SIZE));
1380
1381
impl Default for VarColorLine<'_> {
1382
0
    fn default() -> Self {
1383
        Self {
1384
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1385
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1386
        }
1387
0
    }
1388
}
1389
1390
/// How a gradient's color line extends beyond its minimum and maximum stop offsets.
1391
///
1392
/// The interval is determined by the color stops, and is not necessarily [0, 1].
1393
/// Extension applies in both directions along the color line.
1394
///
1395
/// See the [OpenType specification](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline).
1396
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
1397
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1398
#[repr(u8)]
1399
#[allow(clippy::manual_non_exhaustive)]
1400
pub enum Extend {
1401
    /// Use the nearest endpoint's color outside the interval.
1402
    #[default]
1403
    Pad = 0,
1404
    /// Repeat the color line at intervals equal to the distance between its endpoints.
1405
    Repeat = 1,
1406
    /// Repeat the color line, reversing its direction in each successive interval.
1407
    Reflect = 2,
1408
    #[doc(hidden)]
1409
    /// If font data is malformed we will map unknown values to this variant
1410
    Unknown,
1411
}
1412
1413
impl Extend {
1414
    /// Create from a raw scalar.
1415
    ///
1416
    /// This will never fail; unknown values will be mapped to the `Unknown` variant
1417
28.5k
    pub fn new(raw: u8) -> Self {
1418
28.5k
        match raw {
1419
17.5k
            0 => Self::Pad,
1420
1.07k
            1 => Self::Repeat,
1421
1.09k
            2 => Self::Reflect,
1422
8.77k
            _ => Self::Unknown,
1423
        }
1424
28.5k
    }
1425
}
1426
1427
impl font_types::Scalar for Extend {
1428
    type Raw = <u8 as font_types::Scalar>::Raw;
1429
0
    fn to_raw(self) -> Self::Raw {
1430
0
        (self as u8).to_raw()
1431
0
    }
1432
28.5k
    fn from_raw(raw: Self::Raw) -> Self {
1433
28.5k
        let t = <u8>::from_raw(raw);
1434
28.5k
        Self::new(t)
1435
28.5k
    }
1436
}
1437
1438
/// [Paint](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#paint-tables) tables
1439
#[derive(Clone)]
1440
pub enum Paint<'a> {
1441
    ColrLayers(PaintColrLayers<'a>),
1442
    Solid(PaintSolid<'a>),
1443
    VarSolid(PaintVarSolid<'a>),
1444
    LinearGradient(PaintLinearGradient<'a>),
1445
    VarLinearGradient(PaintVarLinearGradient<'a>),
1446
    RadialGradient(PaintRadialGradient<'a>),
1447
    VarRadialGradient(PaintVarRadialGradient<'a>),
1448
    SweepGradient(PaintSweepGradient<'a>),
1449
    VarSweepGradient(PaintVarSweepGradient<'a>),
1450
    Glyph(PaintGlyph<'a>),
1451
    ColrGlyph(PaintColrGlyph<'a>),
1452
    Transform(PaintTransform<'a>),
1453
    VarTransform(PaintVarTransform<'a>),
1454
    Translate(PaintTranslate<'a>),
1455
    VarTranslate(PaintVarTranslate<'a>),
1456
    Scale(PaintScale<'a>),
1457
    VarScale(PaintVarScale<'a>),
1458
    ScaleAroundCenter(PaintScaleAroundCenter<'a>),
1459
    VarScaleAroundCenter(PaintVarScaleAroundCenter<'a>),
1460
    ScaleUniform(PaintScaleUniform<'a>),
1461
    VarScaleUniform(PaintVarScaleUniform<'a>),
1462
    ScaleUniformAroundCenter(PaintScaleUniformAroundCenter<'a>),
1463
    VarScaleUniformAroundCenter(PaintVarScaleUniformAroundCenter<'a>),
1464
    Rotate(PaintRotate<'a>),
1465
    VarRotate(PaintVarRotate<'a>),
1466
    RotateAroundCenter(PaintRotateAroundCenter<'a>),
1467
    VarRotateAroundCenter(PaintVarRotateAroundCenter<'a>),
1468
    Skew(PaintSkew<'a>),
1469
    VarSkew(PaintVarSkew<'a>),
1470
    SkewAroundCenter(PaintSkewAroundCenter<'a>),
1471
    VarSkewAroundCenter(PaintVarSkewAroundCenter<'a>),
1472
    Composite(PaintComposite<'a>),
1473
    Glyph2(PaintGlyph2<'a>),
1474
}
1475
1476
impl Default for Paint<'_> {
1477
0
    fn default() -> Self {
1478
0
        Self::ColrLayers(Default::default())
1479
0
    }
1480
}
1481
1482
impl<'a> Paint<'a> {
1483
    ///Return the `FontData` used to resolve offsets for this table.
1484
0
    pub fn offset_data(&self) -> FontData<'a> {
1485
0
        match self {
1486
0
            Self::ColrLayers(item) => item.offset_data(),
1487
0
            Self::Solid(item) => item.offset_data(),
1488
0
            Self::VarSolid(item) => item.offset_data(),
1489
0
            Self::LinearGradient(item) => item.offset_data(),
1490
0
            Self::VarLinearGradient(item) => item.offset_data(),
1491
0
            Self::RadialGradient(item) => item.offset_data(),
1492
0
            Self::VarRadialGradient(item) => item.offset_data(),
1493
0
            Self::SweepGradient(item) => item.offset_data(),
1494
0
            Self::VarSweepGradient(item) => item.offset_data(),
1495
0
            Self::Glyph(item) => item.offset_data(),
1496
0
            Self::ColrGlyph(item) => item.offset_data(),
1497
0
            Self::Transform(item) => item.offset_data(),
1498
0
            Self::VarTransform(item) => item.offset_data(),
1499
0
            Self::Translate(item) => item.offset_data(),
1500
0
            Self::VarTranslate(item) => item.offset_data(),
1501
0
            Self::Scale(item) => item.offset_data(),
1502
0
            Self::VarScale(item) => item.offset_data(),
1503
0
            Self::ScaleAroundCenter(item) => item.offset_data(),
1504
0
            Self::VarScaleAroundCenter(item) => item.offset_data(),
1505
0
            Self::ScaleUniform(item) => item.offset_data(),
1506
0
            Self::VarScaleUniform(item) => item.offset_data(),
1507
0
            Self::ScaleUniformAroundCenter(item) => item.offset_data(),
1508
0
            Self::VarScaleUniformAroundCenter(item) => item.offset_data(),
1509
0
            Self::Rotate(item) => item.offset_data(),
1510
0
            Self::VarRotate(item) => item.offset_data(),
1511
0
            Self::RotateAroundCenter(item) => item.offset_data(),
1512
0
            Self::VarRotateAroundCenter(item) => item.offset_data(),
1513
0
            Self::Skew(item) => item.offset_data(),
1514
0
            Self::VarSkew(item) => item.offset_data(),
1515
0
            Self::SkewAroundCenter(item) => item.offset_data(),
1516
0
            Self::VarSkewAroundCenter(item) => item.offset_data(),
1517
0
            Self::Composite(item) => item.offset_data(),
1518
0
            Self::Glyph2(item) => item.offset_data(),
1519
        }
1520
0
    }
1521
1522
    /// Set to 1.
1523
0
    pub fn format(&self) -> u8 {
1524
0
        match self {
1525
0
            Self::ColrLayers(item) => item.format(),
1526
0
            Self::Solid(item) => item.format(),
1527
0
            Self::VarSolid(item) => item.format(),
1528
0
            Self::LinearGradient(item) => item.format(),
1529
0
            Self::VarLinearGradient(item) => item.format(),
1530
0
            Self::RadialGradient(item) => item.format(),
1531
0
            Self::VarRadialGradient(item) => item.format(),
1532
0
            Self::SweepGradient(item) => item.format(),
1533
0
            Self::VarSweepGradient(item) => item.format(),
1534
0
            Self::Glyph(item) => item.format(),
1535
0
            Self::ColrGlyph(item) => item.format(),
1536
0
            Self::Transform(item) => item.format(),
1537
0
            Self::VarTransform(item) => item.format(),
1538
0
            Self::Translate(item) => item.format(),
1539
0
            Self::VarTranslate(item) => item.format(),
1540
0
            Self::Scale(item) => item.format(),
1541
0
            Self::VarScale(item) => item.format(),
1542
0
            Self::ScaleAroundCenter(item) => item.format(),
1543
0
            Self::VarScaleAroundCenter(item) => item.format(),
1544
0
            Self::ScaleUniform(item) => item.format(),
1545
0
            Self::VarScaleUniform(item) => item.format(),
1546
0
            Self::ScaleUniformAroundCenter(item) => item.format(),
1547
0
            Self::VarScaleUniformAroundCenter(item) => item.format(),
1548
0
            Self::Rotate(item) => item.format(),
1549
0
            Self::VarRotate(item) => item.format(),
1550
0
            Self::RotateAroundCenter(item) => item.format(),
1551
0
            Self::VarRotateAroundCenter(item) => item.format(),
1552
0
            Self::Skew(item) => item.format(),
1553
0
            Self::VarSkew(item) => item.format(),
1554
0
            Self::SkewAroundCenter(item) => item.format(),
1555
0
            Self::VarSkewAroundCenter(item) => item.format(),
1556
0
            Self::Composite(item) => item.format(),
1557
0
            Self::Glyph2(item) => item.format(),
1558
        }
1559
0
    }
1560
}
1561
1562
impl ReadArgs for Paint<'_> {
1563
    type Args = ();
1564
}
1565
1566
impl<'a> FontRead<'a> for Paint<'a> {
1567
    #[inline]
1568
189k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1569
189k
        let format: u8 = data.read_at(0usize)?;
1570
188k
        match format {
1571
23.2k
            PaintColrLayers::FORMAT => Ok(Self::ColrLayers(FontRead::read(data)?)),
1572
2.60k
            PaintSolid::FORMAT => Ok(Self::Solid(FontRead::read(data)?)),
1573
6.14k
            PaintVarSolid::FORMAT => Ok(Self::VarSolid(FontRead::read(data)?)),
1574
7.01k
            PaintLinearGradient::FORMAT => Ok(Self::LinearGradient(FontRead::read(data)?)),
1575
5.51k
            PaintVarLinearGradient::FORMAT => Ok(Self::VarLinearGradient(FontRead::read(data)?)),
1576
6.41k
            PaintRadialGradient::FORMAT => Ok(Self::RadialGradient(FontRead::read(data)?)),
1577
3.66k
            PaintVarRadialGradient::FORMAT => Ok(Self::VarRadialGradient(FontRead::read(data)?)),
1578
16.7k
            PaintSweepGradient::FORMAT => Ok(Self::SweepGradient(FontRead::read(data)?)),
1579
4.51k
            PaintVarSweepGradient::FORMAT => Ok(Self::VarSweepGradient(FontRead::read(data)?)),
1580
8.53k
            PaintGlyph::FORMAT => Ok(Self::Glyph(FontRead::read(data)?)),
1581
2.40k
            PaintColrGlyph::FORMAT => Ok(Self::ColrGlyph(FontRead::read(data)?)),
1582
4.16k
            PaintTransform::FORMAT => Ok(Self::Transform(FontRead::read(data)?)),
1583
3.19k
            PaintVarTransform::FORMAT => Ok(Self::VarTransform(FontRead::read(data)?)),
1584
2.51k
            PaintTranslate::FORMAT => Ok(Self::Translate(FontRead::read(data)?)),
1585
2.81k
            PaintVarTranslate::FORMAT => Ok(Self::VarTranslate(FontRead::read(data)?)),
1586
3.08k
            PaintScale::FORMAT => Ok(Self::Scale(FontRead::read(data)?)),
1587
1.92k
            PaintVarScale::FORMAT => Ok(Self::VarScale(FontRead::read(data)?)),
1588
2.07k
            PaintScaleAroundCenter::FORMAT => Ok(Self::ScaleAroundCenter(FontRead::read(data)?)),
1589
3.32k
            PaintVarScaleAroundCenter::FORMAT => {
1590
3.32k
                Ok(Self::VarScaleAroundCenter(FontRead::read(data)?))
1591
            }
1592
2.59k
            PaintScaleUniform::FORMAT => Ok(Self::ScaleUniform(FontRead::read(data)?)),
1593
3.07k
            PaintVarScaleUniform::FORMAT => Ok(Self::VarScaleUniform(FontRead::read(data)?)),
1594
2.22k
            PaintScaleUniformAroundCenter::FORMAT => {
1595
2.22k
                Ok(Self::ScaleUniformAroundCenter(FontRead::read(data)?))
1596
            }
1597
2.41k
            PaintVarScaleUniformAroundCenter::FORMAT => {
1598
2.41k
                Ok(Self::VarScaleUniformAroundCenter(FontRead::read(data)?))
1599
            }
1600
3.36k
            PaintRotate::FORMAT => Ok(Self::Rotate(FontRead::read(data)?)),
1601
2.26k
            PaintVarRotate::FORMAT => Ok(Self::VarRotate(FontRead::read(data)?)),
1602
2.70k
            PaintRotateAroundCenter::FORMAT => Ok(Self::RotateAroundCenter(FontRead::read(data)?)),
1603
2.82k
            PaintVarRotateAroundCenter::FORMAT => {
1604
2.82k
                Ok(Self::VarRotateAroundCenter(FontRead::read(data)?))
1605
            }
1606
3.06k
            PaintSkew::FORMAT => Ok(Self::Skew(FontRead::read(data)?)),
1607
2.56k
            PaintVarSkew::FORMAT => Ok(Self::VarSkew(FontRead::read(data)?)),
1608
2.06k
            PaintSkewAroundCenter::FORMAT => Ok(Self::SkewAroundCenter(FontRead::read(data)?)),
1609
2.95k
            PaintVarSkewAroundCenter::FORMAT => {
1610
2.95k
                Ok(Self::VarSkewAroundCenter(FontRead::read(data)?))
1611
            }
1612
37.1k
            PaintComposite::FORMAT => Ok(Self::Composite(FontRead::read(data)?)),
1613
5.83k
            PaintGlyph2::FORMAT => Ok(Self::Glyph2(FontRead::read(data)?)),
1614
3.59k
            other => Err(ReadError::InvalidFormat(other.into())),
1615
        }
1616
189k
    }
1617
}
1618
1619
impl<'a> MinByteRange<'a> for Paint<'a> {
1620
0
    fn min_byte_range(&self) -> Range<usize> {
1621
0
        match self {
1622
0
            Self::ColrLayers(item) => item.min_byte_range(),
1623
0
            Self::Solid(item) => item.min_byte_range(),
1624
0
            Self::VarSolid(item) => item.min_byte_range(),
1625
0
            Self::LinearGradient(item) => item.min_byte_range(),
1626
0
            Self::VarLinearGradient(item) => item.min_byte_range(),
1627
0
            Self::RadialGradient(item) => item.min_byte_range(),
1628
0
            Self::VarRadialGradient(item) => item.min_byte_range(),
1629
0
            Self::SweepGradient(item) => item.min_byte_range(),
1630
0
            Self::VarSweepGradient(item) => item.min_byte_range(),
1631
0
            Self::Glyph(item) => item.min_byte_range(),
1632
0
            Self::ColrGlyph(item) => item.min_byte_range(),
1633
0
            Self::Transform(item) => item.min_byte_range(),
1634
0
            Self::VarTransform(item) => item.min_byte_range(),
1635
0
            Self::Translate(item) => item.min_byte_range(),
1636
0
            Self::VarTranslate(item) => item.min_byte_range(),
1637
0
            Self::Scale(item) => item.min_byte_range(),
1638
0
            Self::VarScale(item) => item.min_byte_range(),
1639
0
            Self::ScaleAroundCenter(item) => item.min_byte_range(),
1640
0
            Self::VarScaleAroundCenter(item) => item.min_byte_range(),
1641
0
            Self::ScaleUniform(item) => item.min_byte_range(),
1642
0
            Self::VarScaleUniform(item) => item.min_byte_range(),
1643
0
            Self::ScaleUniformAroundCenter(item) => item.min_byte_range(),
1644
0
            Self::VarScaleUniformAroundCenter(item) => item.min_byte_range(),
1645
0
            Self::Rotate(item) => item.min_byte_range(),
1646
0
            Self::VarRotate(item) => item.min_byte_range(),
1647
0
            Self::RotateAroundCenter(item) => item.min_byte_range(),
1648
0
            Self::VarRotateAroundCenter(item) => item.min_byte_range(),
1649
0
            Self::Skew(item) => item.min_byte_range(),
1650
0
            Self::VarSkew(item) => item.min_byte_range(),
1651
0
            Self::SkewAroundCenter(item) => item.min_byte_range(),
1652
0
            Self::VarSkewAroundCenter(item) => item.min_byte_range(),
1653
0
            Self::Composite(item) => item.min_byte_range(),
1654
0
            Self::Glyph2(item) => item.min_byte_range(),
1655
        }
1656
0
    }
1657
0
    fn min_table_bytes(&self) -> &'a [u8] {
1658
0
        match self {
1659
0
            Self::ColrLayers(item) => item.min_table_bytes(),
1660
0
            Self::Solid(item) => item.min_table_bytes(),
1661
0
            Self::VarSolid(item) => item.min_table_bytes(),
1662
0
            Self::LinearGradient(item) => item.min_table_bytes(),
1663
0
            Self::VarLinearGradient(item) => item.min_table_bytes(),
1664
0
            Self::RadialGradient(item) => item.min_table_bytes(),
1665
0
            Self::VarRadialGradient(item) => item.min_table_bytes(),
1666
0
            Self::SweepGradient(item) => item.min_table_bytes(),
1667
0
            Self::VarSweepGradient(item) => item.min_table_bytes(),
1668
0
            Self::Glyph(item) => item.min_table_bytes(),
1669
0
            Self::ColrGlyph(item) => item.min_table_bytes(),
1670
0
            Self::Transform(item) => item.min_table_bytes(),
1671
0
            Self::VarTransform(item) => item.min_table_bytes(),
1672
0
            Self::Translate(item) => item.min_table_bytes(),
1673
0
            Self::VarTranslate(item) => item.min_table_bytes(),
1674
0
            Self::Scale(item) => item.min_table_bytes(),
1675
0
            Self::VarScale(item) => item.min_table_bytes(),
1676
0
            Self::ScaleAroundCenter(item) => item.min_table_bytes(),
1677
0
            Self::VarScaleAroundCenter(item) => item.min_table_bytes(),
1678
0
            Self::ScaleUniform(item) => item.min_table_bytes(),
1679
0
            Self::VarScaleUniform(item) => item.min_table_bytes(),
1680
0
            Self::ScaleUniformAroundCenter(item) => item.min_table_bytes(),
1681
0
            Self::VarScaleUniformAroundCenter(item) => item.min_table_bytes(),
1682
0
            Self::Rotate(item) => item.min_table_bytes(),
1683
0
            Self::VarRotate(item) => item.min_table_bytes(),
1684
0
            Self::RotateAroundCenter(item) => item.min_table_bytes(),
1685
0
            Self::VarRotateAroundCenter(item) => item.min_table_bytes(),
1686
0
            Self::Skew(item) => item.min_table_bytes(),
1687
0
            Self::VarSkew(item) => item.min_table_bytes(),
1688
0
            Self::SkewAroundCenter(item) => item.min_table_bytes(),
1689
0
            Self::VarSkewAroundCenter(item) => item.min_table_bytes(),
1690
0
            Self::Composite(item) => item.min_table_bytes(),
1691
0
            Self::Glyph2(item) => item.min_table_bytes(),
1692
        }
1693
0
    }
1694
}
1695
1696
impl Format<u8> for PaintColrLayers<'_> {
1697
    const FORMAT: u8 = 1;
1698
}
1699
1700
impl<'a> MinByteRange<'a> for PaintColrLayers<'a> {
1701
0
    fn min_byte_range(&self) -> Range<usize> {
1702
0
        0..self.first_layer_index_byte_range().end
1703
0
    }
1704
0
    fn min_table_bytes(&self) -> &'a [u8] {
1705
0
        let range = self.min_byte_range();
1706
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1707
0
    }
1708
}
1709
1710
impl ReadArgs for PaintColrLayers<'_> {
1711
    type Args = ();
1712
}
1713
1714
impl<'a> FontRead<'a> for PaintColrLayers<'a> {
1715
23.2k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1716
        #[allow(clippy::absurd_extreme_comparisons)]
1717
23.2k
        if data.len() < Self::MIN_SIZE {
1718
458
            return Err(ReadError::OutOfBounds);
1719
22.7k
        }
1720
22.7k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1721
0
            return Err(ReadError::OutOfBounds);
1722
        };
1723
22.7k
        Ok(Self { data })
1724
23.2k
    }
1725
}
1726
1727
/// The fields at the start of the table, which are read directly.
1728
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1729
#[repr(C, packed)]
1730
#[doc(hidden)]
1731
pub struct PaintColrLayersFixedHeader {
1732
    pub format: u8,
1733
    pub num_layers: u8,
1734
    pub first_layer_index: BigEndian<u32>,
1735
}
1736
1737
#[allow(clippy::absurd_extreme_comparisons)]
1738
const _: () =
1739
    assert!(std::mem::size_of::<PaintColrLayersFixedHeader>() <= PaintColrLayers::MIN_SIZE);
1740
1741
/// [PaintColrLayers](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-1-paintcolrlayers) table
1742
#[derive(Clone)]
1743
pub struct PaintColrLayers<'a> {
1744
    data: TableDataRef<'a, PaintColrLayersFixedHeader>,
1745
}
1746
1747
#[allow(clippy::needless_lifetimes)]
1748
impl<'a> PaintColrLayers<'a> {
1749
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN + u8::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
1750
    basic_table_impls!(impl_the_methods);
1751
1752
    /// Set to 1.
1753
0
    pub fn format(&self) -> u8 {
1754
0
        self.data.header().format
1755
0
    }
1756
1757
    /// Number of offsets to paint tables to read from LayerList.
1758
22.7k
    pub fn num_layers(&self) -> u8 {
1759
22.7k
        self.data.header().num_layers
1760
22.7k
    }
1761
1762
    /// Index (base 0) into the LayerList.
1763
22.7k
    pub fn first_layer_index(&self) -> u32 {
1764
22.7k
        self.data.header().first_layer_index.get()
1765
22.7k
    }
1766
1767
0
    pub fn format_byte_range(&self) -> Range<usize> {
1768
0
        let start = 0usize;
1769
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1770
0
        start..end
1771
0
    }
1772
1773
0
    pub fn num_layers_byte_range(&self) -> Range<usize> {
1774
0
        let start = self.format_byte_range().end;
1775
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1776
0
        start..end
1777
0
    }
1778
1779
0
    pub fn first_layer_index_byte_range(&self) -> Range<usize> {
1780
0
        let start = self.num_layers_byte_range().end;
1781
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
1782
0
        start..end
1783
0
    }
1784
}
1785
1786
const _: () = assert!(FontData::default_data_long_enough(
1787
    PaintColrLayers::MIN_SIZE
1788
));
1789
1790
impl Default for PaintColrLayers<'_> {
1791
0
    fn default() -> Self {
1792
        Self {
1793
0
            data: TableDataRef::new(FontData::default_format_1_u8_table_data().as_bytes())
1794
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1795
        }
1796
0
    }
1797
}
1798
1799
impl Format<u8> for PaintSolid<'_> {
1800
    const FORMAT: u8 = 2;
1801
}
1802
1803
impl<'a> MinByteRange<'a> for PaintSolid<'a> {
1804
0
    fn min_byte_range(&self) -> Range<usize> {
1805
0
        0..self.alpha_byte_range().end
1806
0
    }
1807
0
    fn min_table_bytes(&self) -> &'a [u8] {
1808
0
        let range = self.min_byte_range();
1809
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1810
0
    }
1811
}
1812
1813
impl ReadArgs for PaintSolid<'_> {
1814
    type Args = ();
1815
}
1816
1817
impl<'a> FontRead<'a> for PaintSolid<'a> {
1818
2.60k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1819
        #[allow(clippy::absurd_extreme_comparisons)]
1820
2.60k
        if data.len() < Self::MIN_SIZE {
1821
712
            return Err(ReadError::OutOfBounds);
1822
1.88k
        }
1823
1.88k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1824
0
            return Err(ReadError::OutOfBounds);
1825
        };
1826
1.88k
        Ok(Self { data })
1827
2.60k
    }
1828
}
1829
1830
/// The fields at the start of the table, which are read directly.
1831
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1832
#[repr(C, packed)]
1833
#[doc(hidden)]
1834
pub struct PaintSolidFixedHeader {
1835
    pub format: u8,
1836
    pub palette_index: BigEndian<u16>,
1837
    pub alpha: BigEndian<F2Dot14>,
1838
}
1839
1840
#[allow(clippy::absurd_extreme_comparisons)]
1841
const _: () = assert!(std::mem::size_of::<PaintSolidFixedHeader>() <= PaintSolid::MIN_SIZE);
1842
1843
/// [PaintSolid](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-2-and-3-paintsolid-paintvarsolid) table
1844
#[derive(Clone)]
1845
pub struct PaintSolid<'a> {
1846
    data: TableDataRef<'a, PaintSolidFixedHeader>,
1847
}
1848
1849
#[allow(clippy::needless_lifetimes)]
1850
impl<'a> PaintSolid<'a> {
1851
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN);
1852
    basic_table_impls!(impl_the_methods);
1853
1854
    /// Set to 2.
1855
0
    pub fn format(&self) -> u8 {
1856
0
        self.data.header().format
1857
0
    }
1858
1859
    /// Index for a CPAL palette entry.
1860
1.88k
    pub fn palette_index(&self) -> u16 {
1861
1.88k
        self.data.header().palette_index.get()
1862
1.88k
    }
1863
1864
    /// Alpha value.
1865
1.88k
    pub fn alpha(&self) -> F2Dot14 {
1866
1.88k
        self.data.header().alpha.get()
1867
1.88k
    }
1868
1869
0
    pub fn format_byte_range(&self) -> Range<usize> {
1870
0
        let start = 0usize;
1871
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1872
0
        start..end
1873
0
    }
1874
1875
0
    pub fn palette_index_byte_range(&self) -> Range<usize> {
1876
0
        let start = self.format_byte_range().end;
1877
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1878
0
        start..end
1879
0
    }
1880
1881
0
    pub fn alpha_byte_range(&self) -> Range<usize> {
1882
0
        let start = self.palette_index_byte_range().end;
1883
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
1884
0
        start..end
1885
0
    }
1886
}
1887
1888
impl Format<u8> for PaintVarSolid<'_> {
1889
    const FORMAT: u8 = 3;
1890
}
1891
1892
impl<'a> MinByteRange<'a> for PaintVarSolid<'a> {
1893
0
    fn min_byte_range(&self) -> Range<usize> {
1894
0
        0..self.var_index_base_byte_range().end
1895
0
    }
1896
0
    fn min_table_bytes(&self) -> &'a [u8] {
1897
0
        let range = self.min_byte_range();
1898
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1899
0
    }
1900
}
1901
1902
impl ReadArgs for PaintVarSolid<'_> {
1903
    type Args = ();
1904
}
1905
1906
impl<'a> FontRead<'a> for PaintVarSolid<'a> {
1907
6.14k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1908
        #[allow(clippy::absurd_extreme_comparisons)]
1909
6.14k
        if data.len() < Self::MIN_SIZE {
1910
713
            return Err(ReadError::OutOfBounds);
1911
5.42k
        }
1912
5.42k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1913
0
            return Err(ReadError::OutOfBounds);
1914
        };
1915
5.42k
        Ok(Self { data })
1916
6.14k
    }
1917
}
1918
1919
/// The fields at the start of the table, which are read directly.
1920
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
1921
#[repr(C, packed)]
1922
#[doc(hidden)]
1923
pub struct PaintVarSolidFixedHeader {
1924
    pub format: u8,
1925
    pub palette_index: BigEndian<u16>,
1926
    pub alpha: BigEndian<F2Dot14>,
1927
    pub var_index_base: BigEndian<u32>,
1928
}
1929
1930
#[allow(clippy::absurd_extreme_comparisons)]
1931
const _: () = assert!(std::mem::size_of::<PaintVarSolidFixedHeader>() <= PaintVarSolid::MIN_SIZE);
1932
1933
/// [PaintVarSolid](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-2-and-3-paintsolid-paintvarsolid) table
1934
#[derive(Clone)]
1935
pub struct PaintVarSolid<'a> {
1936
    data: TableDataRef<'a, PaintVarSolidFixedHeader>,
1937
}
1938
1939
#[allow(clippy::needless_lifetimes)]
1940
impl<'a> PaintVarSolid<'a> {
1941
    pub const MIN_SIZE: usize =
1942
        (u8::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
1943
    basic_table_impls!(impl_the_methods);
1944
1945
    /// Set to 3.
1946
0
    pub fn format(&self) -> u8 {
1947
0
        self.data.header().format
1948
0
    }
1949
1950
    /// Index for a CPAL palette entry.
1951
2.57k
    pub fn palette_index(&self) -> u16 {
1952
2.57k
        self.data.header().palette_index.get()
1953
2.57k
    }
1954
1955
    /// Alpha value. For variation, use varIndexBase + 0.
1956
2.57k
    pub fn alpha(&self) -> F2Dot14 {
1957
2.57k
        self.data.header().alpha.get()
1958
2.57k
    }
1959
1960
    /// Base index into DeltaSetIndexMap.
1961
2.57k
    pub fn var_index_base(&self) -> u32 {
1962
2.57k
        self.data.header().var_index_base.get()
1963
2.57k
    }
1964
1965
0
    pub fn format_byte_range(&self) -> Range<usize> {
1966
0
        let start = 0usize;
1967
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1968
0
        start..end
1969
0
    }
1970
1971
0
    pub fn palette_index_byte_range(&self) -> Range<usize> {
1972
0
        let start = self.format_byte_range().end;
1973
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1974
0
        start..end
1975
0
    }
1976
1977
0
    pub fn alpha_byte_range(&self) -> Range<usize> {
1978
0
        let start = self.palette_index_byte_range().end;
1979
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
1980
0
        start..end
1981
0
    }
1982
1983
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
1984
0
        let start = self.alpha_byte_range().end;
1985
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
1986
0
        start..end
1987
0
    }
1988
}
1989
1990
impl Format<u8> for PaintLinearGradient<'_> {
1991
    const FORMAT: u8 = 4;
1992
}
1993
1994
impl<'a> MinByteRange<'a> for PaintLinearGradient<'a> {
1995
0
    fn min_byte_range(&self) -> Range<usize> {
1996
0
        0..self.y2_byte_range().end
1997
0
    }
1998
0
    fn min_table_bytes(&self) -> &'a [u8] {
1999
0
        let range = self.min_byte_range();
2000
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2001
0
    }
2002
}
2003
2004
impl ReadArgs for PaintLinearGradient<'_> {
2005
    type Args = ();
2006
}
2007
2008
impl<'a> FontRead<'a> for PaintLinearGradient<'a> {
2009
7.01k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2010
        #[allow(clippy::absurd_extreme_comparisons)]
2011
7.01k
        if data.len() < Self::MIN_SIZE {
2012
711
            return Err(ReadError::OutOfBounds);
2013
6.30k
        }
2014
6.30k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2015
0
            return Err(ReadError::OutOfBounds);
2016
        };
2017
6.30k
        Ok(Self { data })
2018
7.01k
    }
2019
}
2020
2021
/// The fields at the start of the table, which are read directly.
2022
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2023
#[repr(C, packed)]
2024
#[doc(hidden)]
2025
pub struct PaintLinearGradientFixedHeader {
2026
    pub format: u8,
2027
    pub color_line_offset: BigEndian<Offset24>,
2028
    pub x0: BigEndian<FWord>,
2029
    pub y0: BigEndian<FWord>,
2030
    pub x1: BigEndian<FWord>,
2031
    pub y1: BigEndian<FWord>,
2032
    pub x2: BigEndian<FWord>,
2033
    pub y2: BigEndian<FWord>,
2034
}
2035
2036
#[allow(clippy::absurd_extreme_comparisons)]
2037
const _: () =
2038
    assert!(std::mem::size_of::<PaintLinearGradientFixedHeader>() <= PaintLinearGradient::MIN_SIZE);
2039
2040
/// [PaintLinearGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-4-and-5-paintlineargradient-paintvarlineargradient) table
2041
#[derive(Clone)]
2042
pub struct PaintLinearGradient<'a> {
2043
    data: TableDataRef<'a, PaintLinearGradientFixedHeader>,
2044
}
2045
2046
#[allow(clippy::needless_lifetimes)]
2047
impl<'a> PaintLinearGradient<'a> {
2048
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
2049
        + Offset24::RAW_BYTE_LEN
2050
        + FWord::RAW_BYTE_LEN
2051
        + FWord::RAW_BYTE_LEN
2052
        + FWord::RAW_BYTE_LEN
2053
        + FWord::RAW_BYTE_LEN
2054
        + FWord::RAW_BYTE_LEN
2055
        + FWord::RAW_BYTE_LEN);
2056
    basic_table_impls!(impl_the_methods);
2057
2058
    /// Set to 4.
2059
0
    pub fn format(&self) -> u8 {
2060
0
        self.data.header().format
2061
0
    }
2062
2063
    /// Offset to ColorLine table.
2064
6.30k
    pub fn color_line_offset(&self) -> Offset24 {
2065
6.30k
        self.data.header().color_line_offset.get()
2066
6.30k
    }
2067
2068
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2069
6.30k
    pub fn color_line(&self) -> Result<ColorLine<'a>, ReadError> {
2070
6.30k
        let data = self.offset_data();
2071
6.30k
        self.color_line_offset().resolve(data)
2072
6.30k
    }
2073
2074
    /// Start point (p₀) x coordinate.
2075
3.65k
    pub fn x0(&self) -> FWord {
2076
3.65k
        self.data.header().x0.get()
2077
3.65k
    }
2078
2079
    /// Start point (p₀) y coordinate.
2080
3.65k
    pub fn y0(&self) -> FWord {
2081
3.65k
        self.data.header().y0.get()
2082
3.65k
    }
2083
2084
    /// End point (p₁) x coordinate.
2085
3.65k
    pub fn x1(&self) -> FWord {
2086
3.65k
        self.data.header().x1.get()
2087
3.65k
    }
2088
2089
    /// End point (p₁) y coordinate.
2090
3.65k
    pub fn y1(&self) -> FWord {
2091
3.65k
        self.data.header().y1.get()
2092
3.65k
    }
2093
2094
    /// Rotation point (p₂) x coordinate.
2095
3.65k
    pub fn x2(&self) -> FWord {
2096
3.65k
        self.data.header().x2.get()
2097
3.65k
    }
2098
2099
    /// Rotation point (p₂) y coordinate.
2100
3.65k
    pub fn y2(&self) -> FWord {
2101
3.65k
        self.data.header().y2.get()
2102
3.65k
    }
2103
2104
0
    pub fn format_byte_range(&self) -> Range<usize> {
2105
0
        let start = 0usize;
2106
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2107
0
        start..end
2108
0
    }
2109
2110
0
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2111
0
        let start = self.format_byte_range().end;
2112
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2113
0
        start..end
2114
0
    }
2115
2116
0
    pub fn x0_byte_range(&self) -> Range<usize> {
2117
0
        let start = self.color_line_offset_byte_range().end;
2118
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2119
0
        start..end
2120
0
    }
2121
2122
0
    pub fn y0_byte_range(&self) -> Range<usize> {
2123
0
        let start = self.x0_byte_range().end;
2124
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2125
0
        start..end
2126
0
    }
2127
2128
0
    pub fn x1_byte_range(&self) -> Range<usize> {
2129
0
        let start = self.y0_byte_range().end;
2130
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2131
0
        start..end
2132
0
    }
2133
2134
0
    pub fn y1_byte_range(&self) -> Range<usize> {
2135
0
        let start = self.x1_byte_range().end;
2136
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2137
0
        start..end
2138
0
    }
2139
2140
0
    pub fn x2_byte_range(&self) -> Range<usize> {
2141
0
        let start = self.y1_byte_range().end;
2142
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2143
0
        start..end
2144
0
    }
2145
2146
0
    pub fn y2_byte_range(&self) -> Range<usize> {
2147
0
        let start = self.x2_byte_range().end;
2148
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2149
0
        start..end
2150
0
    }
2151
}
2152
2153
impl Format<u8> for PaintVarLinearGradient<'_> {
2154
    const FORMAT: u8 = 5;
2155
}
2156
2157
impl<'a> MinByteRange<'a> for PaintVarLinearGradient<'a> {
2158
0
    fn min_byte_range(&self) -> Range<usize> {
2159
0
        0..self.var_index_base_byte_range().end
2160
0
    }
2161
0
    fn min_table_bytes(&self) -> &'a [u8] {
2162
0
        let range = self.min_byte_range();
2163
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2164
0
    }
2165
}
2166
2167
impl ReadArgs for PaintVarLinearGradient<'_> {
2168
    type Args = ();
2169
}
2170
2171
impl<'a> FontRead<'a> for PaintVarLinearGradient<'a> {
2172
5.51k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2173
        #[allow(clippy::absurd_extreme_comparisons)]
2174
5.51k
        if data.len() < Self::MIN_SIZE {
2175
476
            return Err(ReadError::OutOfBounds);
2176
5.04k
        }
2177
5.04k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2178
0
            return Err(ReadError::OutOfBounds);
2179
        };
2180
5.04k
        Ok(Self { data })
2181
5.51k
    }
2182
}
2183
2184
/// The fields at the start of the table, which are read directly.
2185
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2186
#[repr(C, packed)]
2187
#[doc(hidden)]
2188
pub struct PaintVarLinearGradientFixedHeader {
2189
    pub format: u8,
2190
    pub color_line_offset: BigEndian<Offset24>,
2191
    pub x0: BigEndian<FWord>,
2192
    pub y0: BigEndian<FWord>,
2193
    pub x1: BigEndian<FWord>,
2194
    pub y1: BigEndian<FWord>,
2195
    pub x2: BigEndian<FWord>,
2196
    pub y2: BigEndian<FWord>,
2197
    pub var_index_base: BigEndian<u32>,
2198
}
2199
2200
#[allow(clippy::absurd_extreme_comparisons)]
2201
const _: () = assert!(
2202
    std::mem::size_of::<PaintVarLinearGradientFixedHeader>() <= PaintVarLinearGradient::MIN_SIZE
2203
);
2204
2205
/// [PaintVarLinearGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-4-and-5-paintlineargradient-paintvarlineargradient) table
2206
#[derive(Clone)]
2207
pub struct PaintVarLinearGradient<'a> {
2208
    data: TableDataRef<'a, PaintVarLinearGradientFixedHeader>,
2209
}
2210
2211
#[allow(clippy::needless_lifetimes)]
2212
impl<'a> PaintVarLinearGradient<'a> {
2213
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
2214
        + Offset24::RAW_BYTE_LEN
2215
        + FWord::RAW_BYTE_LEN
2216
        + FWord::RAW_BYTE_LEN
2217
        + FWord::RAW_BYTE_LEN
2218
        + FWord::RAW_BYTE_LEN
2219
        + FWord::RAW_BYTE_LEN
2220
        + FWord::RAW_BYTE_LEN
2221
        + u32::RAW_BYTE_LEN);
2222
    basic_table_impls!(impl_the_methods);
2223
2224
    /// Set to 5.
2225
0
    pub fn format(&self) -> u8 {
2226
0
        self.data.header().format
2227
0
    }
2228
2229
    /// Offset to VarColorLine table.
2230
5.02k
    pub fn color_line_offset(&self) -> Offset24 {
2231
5.02k
        self.data.header().color_line_offset.get()
2232
5.02k
    }
2233
2234
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2235
5.02k
    pub fn color_line(&self) -> Result<VarColorLine<'a>, ReadError> {
2236
5.02k
        let data = self.offset_data();
2237
5.02k
        self.color_line_offset().resolve(data)
2238
5.02k
    }
2239
2240
    /// Start point (p₀) x coordinate. For variation, use
2241
    /// varIndexBase + 0.
2242
3.53k
    pub fn x0(&self) -> FWord {
2243
3.53k
        self.data.header().x0.get()
2244
3.53k
    }
2245
2246
    /// Start point (p₀) y coordinate. For variation, use
2247
    /// varIndexBase + 1.
2248
3.53k
    pub fn y0(&self) -> FWord {
2249
3.53k
        self.data.header().y0.get()
2250
3.53k
    }
2251
2252
    /// End point (p₁) x coordinate. For variation, use varIndexBase
2253
    /// + 2.
2254
3.53k
    pub fn x1(&self) -> FWord {
2255
3.53k
        self.data.header().x1.get()
2256
3.53k
    }
2257
2258
    /// End point (p₁) y coordinate. For variation, use varIndexBase
2259
    /// + 3.
2260
3.53k
    pub fn y1(&self) -> FWord {
2261
3.53k
        self.data.header().y1.get()
2262
3.53k
    }
2263
2264
    /// Rotation point (p₂) x coordinate. For variation, use
2265
    /// varIndexBase + 4.
2266
3.53k
    pub fn x2(&self) -> FWord {
2267
3.53k
        self.data.header().x2.get()
2268
3.53k
    }
2269
2270
    /// Rotation point (p₂) y coordinate. For variation, use
2271
    /// varIndexBase + 5.
2272
3.53k
    pub fn y2(&self) -> FWord {
2273
3.53k
        self.data.header().y2.get()
2274
3.53k
    }
2275
2276
    /// Base index into DeltaSetIndexMap.
2277
3.53k
    pub fn var_index_base(&self) -> u32 {
2278
3.53k
        self.data.header().var_index_base.get()
2279
3.53k
    }
2280
2281
0
    pub fn format_byte_range(&self) -> Range<usize> {
2282
0
        let start = 0usize;
2283
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2284
0
        start..end
2285
0
    }
2286
2287
0
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2288
0
        let start = self.format_byte_range().end;
2289
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2290
0
        start..end
2291
0
    }
2292
2293
0
    pub fn x0_byte_range(&self) -> Range<usize> {
2294
0
        let start = self.color_line_offset_byte_range().end;
2295
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2296
0
        start..end
2297
0
    }
2298
2299
0
    pub fn y0_byte_range(&self) -> Range<usize> {
2300
0
        let start = self.x0_byte_range().end;
2301
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2302
0
        start..end
2303
0
    }
2304
2305
0
    pub fn x1_byte_range(&self) -> Range<usize> {
2306
0
        let start = self.y0_byte_range().end;
2307
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2308
0
        start..end
2309
0
    }
2310
2311
0
    pub fn y1_byte_range(&self) -> Range<usize> {
2312
0
        let start = self.x1_byte_range().end;
2313
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2314
0
        start..end
2315
0
    }
2316
2317
0
    pub fn x2_byte_range(&self) -> Range<usize> {
2318
0
        let start = self.y1_byte_range().end;
2319
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2320
0
        start..end
2321
0
    }
2322
2323
0
    pub fn y2_byte_range(&self) -> Range<usize> {
2324
0
        let start = self.x2_byte_range().end;
2325
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2326
0
        start..end
2327
0
    }
2328
2329
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
2330
0
        let start = self.y2_byte_range().end;
2331
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
2332
0
        start..end
2333
0
    }
2334
}
2335
2336
impl Format<u8> for PaintRadialGradient<'_> {
2337
    const FORMAT: u8 = 6;
2338
}
2339
2340
impl<'a> MinByteRange<'a> for PaintRadialGradient<'a> {
2341
0
    fn min_byte_range(&self) -> Range<usize> {
2342
0
        0..self.radius1_byte_range().end
2343
0
    }
2344
0
    fn min_table_bytes(&self) -> &'a [u8] {
2345
0
        let range = self.min_byte_range();
2346
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2347
0
    }
2348
}
2349
2350
impl ReadArgs for PaintRadialGradient<'_> {
2351
    type Args = ();
2352
}
2353
2354
impl<'a> FontRead<'a> for PaintRadialGradient<'a> {
2355
6.41k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2356
        #[allow(clippy::absurd_extreme_comparisons)]
2357
6.41k
        if data.len() < Self::MIN_SIZE {
2358
457
            return Err(ReadError::OutOfBounds);
2359
5.96k
        }
2360
5.96k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2361
0
            return Err(ReadError::OutOfBounds);
2362
        };
2363
5.96k
        Ok(Self { data })
2364
6.41k
    }
2365
}
2366
2367
/// The fields at the start of the table, which are read directly.
2368
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2369
#[repr(C, packed)]
2370
#[doc(hidden)]
2371
pub struct PaintRadialGradientFixedHeader {
2372
    pub format: u8,
2373
    pub color_line_offset: BigEndian<Offset24>,
2374
    pub x0: BigEndian<FWord>,
2375
    pub y0: BigEndian<FWord>,
2376
    pub radius0: BigEndian<UfWord>,
2377
    pub x1: BigEndian<FWord>,
2378
    pub y1: BigEndian<FWord>,
2379
    pub radius1: BigEndian<UfWord>,
2380
}
2381
2382
#[allow(clippy::absurd_extreme_comparisons)]
2383
const _: () =
2384
    assert!(std::mem::size_of::<PaintRadialGradientFixedHeader>() <= PaintRadialGradient::MIN_SIZE);
2385
2386
/// [PaintRadialGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-6-and-7-paintradialgradient-paintvarradialgradient) table
2387
#[derive(Clone)]
2388
pub struct PaintRadialGradient<'a> {
2389
    data: TableDataRef<'a, PaintRadialGradientFixedHeader>,
2390
}
2391
2392
#[allow(clippy::needless_lifetimes)]
2393
impl<'a> PaintRadialGradient<'a> {
2394
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
2395
        + Offset24::RAW_BYTE_LEN
2396
        + FWord::RAW_BYTE_LEN
2397
        + FWord::RAW_BYTE_LEN
2398
        + UfWord::RAW_BYTE_LEN
2399
        + FWord::RAW_BYTE_LEN
2400
        + FWord::RAW_BYTE_LEN
2401
        + UfWord::RAW_BYTE_LEN);
2402
    basic_table_impls!(impl_the_methods);
2403
2404
    /// Set to 6.
2405
0
    pub fn format(&self) -> u8 {
2406
0
        self.data.header().format
2407
0
    }
2408
2409
    /// Offset to ColorLine table.
2410
5.96k
    pub fn color_line_offset(&self) -> Offset24 {
2411
5.96k
        self.data.header().color_line_offset.get()
2412
5.96k
    }
2413
2414
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2415
5.96k
    pub fn color_line(&self) -> Result<ColorLine<'a>, ReadError> {
2416
5.96k
        let data = self.offset_data();
2417
5.96k
        self.color_line_offset().resolve(data)
2418
5.96k
    }
2419
2420
    /// Start circle center x coordinate.
2421
4.76k
    pub fn x0(&self) -> FWord {
2422
4.76k
        self.data.header().x0.get()
2423
4.76k
    }
2424
2425
    /// Start circle center y coordinate.
2426
4.76k
    pub fn y0(&self) -> FWord {
2427
4.76k
        self.data.header().y0.get()
2428
4.76k
    }
2429
2430
    /// Start circle radius.
2431
4.76k
    pub fn radius0(&self) -> UfWord {
2432
4.76k
        self.data.header().radius0.get()
2433
4.76k
    }
2434
2435
    /// End circle center x coordinate.
2436
4.76k
    pub fn x1(&self) -> FWord {
2437
4.76k
        self.data.header().x1.get()
2438
4.76k
    }
2439
2440
    /// End circle center y coordinate.
2441
4.76k
    pub fn y1(&self) -> FWord {
2442
4.76k
        self.data.header().y1.get()
2443
4.76k
    }
2444
2445
    /// End circle radius.
2446
4.76k
    pub fn radius1(&self) -> UfWord {
2447
4.76k
        self.data.header().radius1.get()
2448
4.76k
    }
2449
2450
0
    pub fn format_byte_range(&self) -> Range<usize> {
2451
0
        let start = 0usize;
2452
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2453
0
        start..end
2454
0
    }
2455
2456
0
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2457
0
        let start = self.format_byte_range().end;
2458
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2459
0
        start..end
2460
0
    }
2461
2462
0
    pub fn x0_byte_range(&self) -> Range<usize> {
2463
0
        let start = self.color_line_offset_byte_range().end;
2464
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2465
0
        start..end
2466
0
    }
2467
2468
0
    pub fn y0_byte_range(&self) -> Range<usize> {
2469
0
        let start = self.x0_byte_range().end;
2470
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2471
0
        start..end
2472
0
    }
2473
2474
0
    pub fn radius0_byte_range(&self) -> Range<usize> {
2475
0
        let start = self.y0_byte_range().end;
2476
0
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
2477
0
        start..end
2478
0
    }
2479
2480
0
    pub fn x1_byte_range(&self) -> Range<usize> {
2481
0
        let start = self.radius0_byte_range().end;
2482
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2483
0
        start..end
2484
0
    }
2485
2486
0
    pub fn y1_byte_range(&self) -> Range<usize> {
2487
0
        let start = self.x1_byte_range().end;
2488
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2489
0
        start..end
2490
0
    }
2491
2492
0
    pub fn radius1_byte_range(&self) -> Range<usize> {
2493
0
        let start = self.y1_byte_range().end;
2494
0
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
2495
0
        start..end
2496
0
    }
2497
}
2498
2499
impl Format<u8> for PaintVarRadialGradient<'_> {
2500
    const FORMAT: u8 = 7;
2501
}
2502
2503
impl<'a> MinByteRange<'a> for PaintVarRadialGradient<'a> {
2504
0
    fn min_byte_range(&self) -> Range<usize> {
2505
0
        0..self.var_index_base_byte_range().end
2506
0
    }
2507
0
    fn min_table_bytes(&self) -> &'a [u8] {
2508
0
        let range = self.min_byte_range();
2509
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2510
0
    }
2511
}
2512
2513
impl ReadArgs for PaintVarRadialGradient<'_> {
2514
    type Args = ();
2515
}
2516
2517
impl<'a> FontRead<'a> for PaintVarRadialGradient<'a> {
2518
3.66k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2519
        #[allow(clippy::absurd_extreme_comparisons)]
2520
3.66k
        if data.len() < Self::MIN_SIZE {
2521
462
            return Err(ReadError::OutOfBounds);
2522
3.20k
        }
2523
3.20k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2524
0
            return Err(ReadError::OutOfBounds);
2525
        };
2526
3.20k
        Ok(Self { data })
2527
3.66k
    }
2528
}
2529
2530
/// The fields at the start of the table, which are read directly.
2531
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2532
#[repr(C, packed)]
2533
#[doc(hidden)]
2534
pub struct PaintVarRadialGradientFixedHeader {
2535
    pub format: u8,
2536
    pub color_line_offset: BigEndian<Offset24>,
2537
    pub x0: BigEndian<FWord>,
2538
    pub y0: BigEndian<FWord>,
2539
    pub radius0: BigEndian<UfWord>,
2540
    pub x1: BigEndian<FWord>,
2541
    pub y1: BigEndian<FWord>,
2542
    pub radius1: BigEndian<UfWord>,
2543
    pub var_index_base: BigEndian<u32>,
2544
}
2545
2546
#[allow(clippy::absurd_extreme_comparisons)]
2547
const _: () = assert!(
2548
    std::mem::size_of::<PaintVarRadialGradientFixedHeader>() <= PaintVarRadialGradient::MIN_SIZE
2549
);
2550
2551
/// [PaintVarRadialGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-6-and-7-paintradialgradient-paintvarradialgradient) table
2552
#[derive(Clone)]
2553
pub struct PaintVarRadialGradient<'a> {
2554
    data: TableDataRef<'a, PaintVarRadialGradientFixedHeader>,
2555
}
2556
2557
#[allow(clippy::needless_lifetimes)]
2558
impl<'a> PaintVarRadialGradient<'a> {
2559
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
2560
        + Offset24::RAW_BYTE_LEN
2561
        + FWord::RAW_BYTE_LEN
2562
        + FWord::RAW_BYTE_LEN
2563
        + UfWord::RAW_BYTE_LEN
2564
        + FWord::RAW_BYTE_LEN
2565
        + FWord::RAW_BYTE_LEN
2566
        + UfWord::RAW_BYTE_LEN
2567
        + u32::RAW_BYTE_LEN);
2568
    basic_table_impls!(impl_the_methods);
2569
2570
    /// Set to 7.
2571
0
    pub fn format(&self) -> u8 {
2572
0
        self.data.header().format
2573
0
    }
2574
2575
    /// Offset to VarColorLine table.
2576
3.20k
    pub fn color_line_offset(&self) -> Offset24 {
2577
3.20k
        self.data.header().color_line_offset.get()
2578
3.20k
    }
2579
2580
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2581
3.20k
    pub fn color_line(&self) -> Result<VarColorLine<'a>, ReadError> {
2582
3.20k
        let data = self.offset_data();
2583
3.20k
        self.color_line_offset().resolve(data)
2584
3.20k
    }
2585
2586
    /// Start circle center x coordinate. For variation, use
2587
    /// varIndexBase + 0.
2588
1.31k
    pub fn x0(&self) -> FWord {
2589
1.31k
        self.data.header().x0.get()
2590
1.31k
    }
2591
2592
    /// Start circle center y coordinate. For variation, use
2593
    /// varIndexBase + 1.
2594
1.31k
    pub fn y0(&self) -> FWord {
2595
1.31k
        self.data.header().y0.get()
2596
1.31k
    }
2597
2598
    /// Start circle radius. For variation, use varIndexBase + 2.
2599
1.31k
    pub fn radius0(&self) -> UfWord {
2600
1.31k
        self.data.header().radius0.get()
2601
1.31k
    }
2602
2603
    /// End circle center x coordinate. For variation, use varIndexBase
2604
    /// + 3.
2605
1.31k
    pub fn x1(&self) -> FWord {
2606
1.31k
        self.data.header().x1.get()
2607
1.31k
    }
2608
2609
    /// End circle center y coordinate. For variation, use varIndexBase
2610
    /// + 4.
2611
1.31k
    pub fn y1(&self) -> FWord {
2612
1.31k
        self.data.header().y1.get()
2613
1.31k
    }
2614
2615
    /// End circle radius. For variation, use varIndexBase + 5.
2616
1.31k
    pub fn radius1(&self) -> UfWord {
2617
1.31k
        self.data.header().radius1.get()
2618
1.31k
    }
2619
2620
    /// Base index into DeltaSetIndexMap.
2621
1.31k
    pub fn var_index_base(&self) -> u32 {
2622
1.31k
        self.data.header().var_index_base.get()
2623
1.31k
    }
2624
2625
0
    pub fn format_byte_range(&self) -> Range<usize> {
2626
0
        let start = 0usize;
2627
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2628
0
        start..end
2629
0
    }
2630
2631
0
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2632
0
        let start = self.format_byte_range().end;
2633
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2634
0
        start..end
2635
0
    }
2636
2637
0
    pub fn x0_byte_range(&self) -> Range<usize> {
2638
0
        let start = self.color_line_offset_byte_range().end;
2639
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2640
0
        start..end
2641
0
    }
2642
2643
0
    pub fn y0_byte_range(&self) -> Range<usize> {
2644
0
        let start = self.x0_byte_range().end;
2645
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2646
0
        start..end
2647
0
    }
2648
2649
0
    pub fn radius0_byte_range(&self) -> Range<usize> {
2650
0
        let start = self.y0_byte_range().end;
2651
0
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
2652
0
        start..end
2653
0
    }
2654
2655
0
    pub fn x1_byte_range(&self) -> Range<usize> {
2656
0
        let start = self.radius0_byte_range().end;
2657
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2658
0
        start..end
2659
0
    }
2660
2661
0
    pub fn y1_byte_range(&self) -> Range<usize> {
2662
0
        let start = self.x1_byte_range().end;
2663
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2664
0
        start..end
2665
0
    }
2666
2667
0
    pub fn radius1_byte_range(&self) -> Range<usize> {
2668
0
        let start = self.y1_byte_range().end;
2669
0
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
2670
0
        start..end
2671
0
    }
2672
2673
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
2674
0
        let start = self.radius1_byte_range().end;
2675
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
2676
0
        start..end
2677
0
    }
2678
}
2679
2680
impl Format<u8> for PaintSweepGradient<'_> {
2681
    const FORMAT: u8 = 8;
2682
}
2683
2684
impl<'a> MinByteRange<'a> for PaintSweepGradient<'a> {
2685
0
    fn min_byte_range(&self) -> Range<usize> {
2686
0
        0..self.end_angle_byte_range().end
2687
0
    }
2688
0
    fn min_table_bytes(&self) -> &'a [u8] {
2689
0
        let range = self.min_byte_range();
2690
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2691
0
    }
2692
}
2693
2694
impl ReadArgs for PaintSweepGradient<'_> {
2695
    type Args = ();
2696
}
2697
2698
impl<'a> FontRead<'a> for PaintSweepGradient<'a> {
2699
16.7k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2700
        #[allow(clippy::absurd_extreme_comparisons)]
2701
16.7k
        if data.len() < Self::MIN_SIZE {
2702
712
            return Err(ReadError::OutOfBounds);
2703
16.0k
        }
2704
16.0k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2705
0
            return Err(ReadError::OutOfBounds);
2706
        };
2707
16.0k
        Ok(Self { data })
2708
16.7k
    }
2709
}
2710
2711
/// The fields at the start of the table, which are read directly.
2712
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2713
#[repr(C, packed)]
2714
#[doc(hidden)]
2715
pub struct PaintSweepGradientFixedHeader {
2716
    pub format: u8,
2717
    pub color_line_offset: BigEndian<Offset24>,
2718
    pub center_x: BigEndian<FWord>,
2719
    pub center_y: BigEndian<FWord>,
2720
    pub start_angle: BigEndian<F2Dot14>,
2721
    pub end_angle: BigEndian<F2Dot14>,
2722
}
2723
2724
#[allow(clippy::absurd_extreme_comparisons)]
2725
const _: () =
2726
    assert!(std::mem::size_of::<PaintSweepGradientFixedHeader>() <= PaintSweepGradient::MIN_SIZE);
2727
2728
/// [PaintSweepGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-8-and-9-paintsweepgradient-paintvarsweepgradient) table
2729
#[derive(Clone)]
2730
pub struct PaintSweepGradient<'a> {
2731
    data: TableDataRef<'a, PaintSweepGradientFixedHeader>,
2732
}
2733
2734
#[allow(clippy::needless_lifetimes)]
2735
impl<'a> PaintSweepGradient<'a> {
2736
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
2737
        + Offset24::RAW_BYTE_LEN
2738
        + FWord::RAW_BYTE_LEN
2739
        + FWord::RAW_BYTE_LEN
2740
        + F2Dot14::RAW_BYTE_LEN
2741
        + F2Dot14::RAW_BYTE_LEN);
2742
    basic_table_impls!(impl_the_methods);
2743
2744
    /// Set to 8.
2745
0
    pub fn format(&self) -> u8 {
2746
0
        self.data.header().format
2747
0
    }
2748
2749
    /// Offset to ColorLine table.
2750
14.6k
    pub fn color_line_offset(&self) -> Offset24 {
2751
14.6k
        self.data.header().color_line_offset.get()
2752
14.6k
    }
2753
2754
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2755
14.6k
    pub fn color_line(&self) -> Result<ColorLine<'a>, ReadError> {
2756
14.6k
        let data = self.offset_data();
2757
14.6k
        self.color_line_offset().resolve(data)
2758
14.6k
    }
2759
2760
    /// Center x coordinate.
2761
13.3k
    pub fn center_x(&self) -> FWord {
2762
13.3k
        self.data.header().center_x.get()
2763
13.3k
    }
2764
2765
    /// Center y coordinate.
2766
13.3k
    pub fn center_y(&self) -> FWord {
2767
13.3k
        self.data.header().center_y.get()
2768
13.3k
    }
2769
2770
    /// Start of the angular range of the gradient, 180° in
2771
    /// counter-clockwise degrees per 1.0 of value.
2772
13.3k
    pub fn start_angle(&self) -> F2Dot14 {
2773
13.3k
        self.data.header().start_angle.get()
2774
13.3k
    }
2775
2776
    /// End of the angular range of the gradient, 180° in
2777
    /// counter-clockwise degrees per 1.0 of value.
2778
13.3k
    pub fn end_angle(&self) -> F2Dot14 {
2779
13.3k
        self.data.header().end_angle.get()
2780
13.3k
    }
2781
2782
0
    pub fn format_byte_range(&self) -> Range<usize> {
2783
0
        let start = 0usize;
2784
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2785
0
        start..end
2786
0
    }
2787
2788
0
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2789
0
        let start = self.format_byte_range().end;
2790
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2791
0
        start..end
2792
0
    }
2793
2794
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
2795
0
        let start = self.color_line_offset_byte_range().end;
2796
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2797
0
        start..end
2798
0
    }
2799
2800
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
2801
0
        let start = self.center_x_byte_range().end;
2802
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2803
0
        start..end
2804
0
    }
2805
2806
0
    pub fn start_angle_byte_range(&self) -> Range<usize> {
2807
0
        let start = self.center_y_byte_range().end;
2808
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
2809
0
        start..end
2810
0
    }
2811
2812
0
    pub fn end_angle_byte_range(&self) -> Range<usize> {
2813
0
        let start = self.start_angle_byte_range().end;
2814
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
2815
0
        start..end
2816
0
    }
2817
}
2818
2819
impl Format<u8> for PaintVarSweepGradient<'_> {
2820
    const FORMAT: u8 = 9;
2821
}
2822
2823
impl<'a> MinByteRange<'a> for PaintVarSweepGradient<'a> {
2824
0
    fn min_byte_range(&self) -> Range<usize> {
2825
0
        0..self.var_index_base_byte_range().end
2826
0
    }
2827
0
    fn min_table_bytes(&self) -> &'a [u8] {
2828
0
        let range = self.min_byte_range();
2829
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2830
0
    }
2831
}
2832
2833
impl ReadArgs for PaintVarSweepGradient<'_> {
2834
    type Args = ();
2835
}
2836
2837
impl<'a> FontRead<'a> for PaintVarSweepGradient<'a> {
2838
4.51k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2839
        #[allow(clippy::absurd_extreme_comparisons)]
2840
4.51k
        if data.len() < Self::MIN_SIZE {
2841
716
            return Err(ReadError::OutOfBounds);
2842
3.80k
        }
2843
3.80k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2844
0
            return Err(ReadError::OutOfBounds);
2845
        };
2846
3.80k
        Ok(Self { data })
2847
4.51k
    }
2848
}
2849
2850
/// The fields at the start of the table, which are read directly.
2851
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
2852
#[repr(C, packed)]
2853
#[doc(hidden)]
2854
pub struct PaintVarSweepGradientFixedHeader {
2855
    pub format: u8,
2856
    pub color_line_offset: BigEndian<Offset24>,
2857
    pub center_x: BigEndian<FWord>,
2858
    pub center_y: BigEndian<FWord>,
2859
    pub start_angle: BigEndian<F2Dot14>,
2860
    pub end_angle: BigEndian<F2Dot14>,
2861
    pub var_index_base: BigEndian<u32>,
2862
}
2863
2864
#[allow(clippy::absurd_extreme_comparisons)]
2865
const _: () = assert!(
2866
    std::mem::size_of::<PaintVarSweepGradientFixedHeader>() <= PaintVarSweepGradient::MIN_SIZE
2867
);
2868
2869
/// [PaintVarSweepGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-8-and-9-paintsweepgradient-paintvarsweepgradient) table
2870
#[derive(Clone)]
2871
pub struct PaintVarSweepGradient<'a> {
2872
    data: TableDataRef<'a, PaintVarSweepGradientFixedHeader>,
2873
}
2874
2875
#[allow(clippy::needless_lifetimes)]
2876
impl<'a> PaintVarSweepGradient<'a> {
2877
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
2878
        + Offset24::RAW_BYTE_LEN
2879
        + FWord::RAW_BYTE_LEN
2880
        + FWord::RAW_BYTE_LEN
2881
        + F2Dot14::RAW_BYTE_LEN
2882
        + F2Dot14::RAW_BYTE_LEN
2883
        + u32::RAW_BYTE_LEN);
2884
    basic_table_impls!(impl_the_methods);
2885
2886
    /// Set to 9.
2887
0
    pub fn format(&self) -> u8 {
2888
0
        self.data.header().format
2889
0
    }
2890
2891
    /// Offset to VarColorLine table.
2892
3.80k
    pub fn color_line_offset(&self) -> Offset24 {
2893
3.80k
        self.data.header().color_line_offset.get()
2894
3.80k
    }
2895
2896
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2897
3.80k
    pub fn color_line(&self) -> Result<VarColorLine<'a>, ReadError> {
2898
3.80k
        let data = self.offset_data();
2899
3.80k
        self.color_line_offset().resolve(data)
2900
3.80k
    }
2901
2902
    /// Center x coordinate. For variation, use varIndexBase + 0.
2903
1.87k
    pub fn center_x(&self) -> FWord {
2904
1.87k
        self.data.header().center_x.get()
2905
1.87k
    }
2906
2907
    /// Center y coordinate. For variation, use varIndexBase + 1.
2908
1.87k
    pub fn center_y(&self) -> FWord {
2909
1.87k
        self.data.header().center_y.get()
2910
1.87k
    }
2911
2912
    /// Start of the angular range of the gradient, 180° in
2913
    /// counter-clockwise degrees per 1.0 of value. For variation, use
2914
    /// varIndexBase + 2.
2915
1.87k
    pub fn start_angle(&self) -> F2Dot14 {
2916
1.87k
        self.data.header().start_angle.get()
2917
1.87k
    }
2918
2919
    /// End of the angular range of the gradient, 180° in
2920
    /// counter-clockwise degrees per 1.0 of value. For variation, use
2921
    /// varIndexBase + 3.
2922
1.87k
    pub fn end_angle(&self) -> F2Dot14 {
2923
1.87k
        self.data.header().end_angle.get()
2924
1.87k
    }
2925
2926
    /// Base index into DeltaSetIndexMap.
2927
1.87k
    pub fn var_index_base(&self) -> u32 {
2928
1.87k
        self.data.header().var_index_base.get()
2929
1.87k
    }
2930
2931
0
    pub fn format_byte_range(&self) -> Range<usize> {
2932
0
        let start = 0usize;
2933
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2934
0
        start..end
2935
0
    }
2936
2937
0
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2938
0
        let start = self.format_byte_range().end;
2939
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2940
0
        start..end
2941
0
    }
2942
2943
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
2944
0
        let start = self.color_line_offset_byte_range().end;
2945
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2946
0
        start..end
2947
0
    }
2948
2949
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
2950
0
        let start = self.center_x_byte_range().end;
2951
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2952
0
        start..end
2953
0
    }
2954
2955
0
    pub fn start_angle_byte_range(&self) -> Range<usize> {
2956
0
        let start = self.center_y_byte_range().end;
2957
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
2958
0
        start..end
2959
0
    }
2960
2961
0
    pub fn end_angle_byte_range(&self) -> Range<usize> {
2962
0
        let start = self.start_angle_byte_range().end;
2963
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
2964
0
        start..end
2965
0
    }
2966
2967
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
2968
0
        let start = self.end_angle_byte_range().end;
2969
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
2970
0
        start..end
2971
0
    }
2972
}
2973
2974
impl Format<u8> for PaintGlyph<'_> {
2975
    const FORMAT: u8 = 10;
2976
}
2977
2978
impl<'a> MinByteRange<'a> for PaintGlyph<'a> {
2979
0
    fn min_byte_range(&self) -> Range<usize> {
2980
0
        0..self.glyph_id_byte_range().end
2981
0
    }
2982
0
    fn min_table_bytes(&self) -> &'a [u8] {
2983
0
        let range = self.min_byte_range();
2984
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2985
0
    }
2986
}
2987
2988
impl ReadArgs for PaintGlyph<'_> {
2989
    type Args = ();
2990
}
2991
2992
impl<'a> FontRead<'a> for PaintGlyph<'a> {
2993
8.53k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2994
        #[allow(clippy::absurd_extreme_comparisons)]
2995
8.53k
        if data.len() < Self::MIN_SIZE {
2996
716
            return Err(ReadError::OutOfBounds);
2997
7.82k
        }
2998
7.82k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2999
0
            return Err(ReadError::OutOfBounds);
3000
        };
3001
7.82k
        Ok(Self { data })
3002
8.53k
    }
3003
}
3004
3005
/// The fields at the start of the table, which are read directly.
3006
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3007
#[repr(C, packed)]
3008
#[doc(hidden)]
3009
pub struct PaintGlyphFixedHeader {
3010
    pub format: u8,
3011
    pub paint_offset: BigEndian<Offset24>,
3012
    pub glyph_id: BigEndian<GlyphId16>,
3013
}
3014
3015
#[allow(clippy::absurd_extreme_comparisons)]
3016
const _: () = assert!(std::mem::size_of::<PaintGlyphFixedHeader>() <= PaintGlyph::MIN_SIZE);
3017
3018
/// [PaintGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-10-paintglyph) table
3019
#[derive(Clone)]
3020
pub struct PaintGlyph<'a> {
3021
    data: TableDataRef<'a, PaintGlyphFixedHeader>,
3022
}
3023
3024
#[allow(clippy::needless_lifetimes)]
3025
impl<'a> PaintGlyph<'a> {
3026
    pub const MIN_SIZE: usize =
3027
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN);
3028
    basic_table_impls!(impl_the_methods);
3029
3030
    /// Set to 10.
3031
0
    pub fn format(&self) -> u8 {
3032
0
        self.data.header().format
3033
0
    }
3034
3035
    /// Offset to a Paint table.
3036
7.82k
    pub fn paint_offset(&self) -> Offset24 {
3037
7.82k
        self.data.header().paint_offset.get()
3038
7.82k
    }
3039
3040
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3041
7.82k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3042
7.82k
        let data = self.offset_data();
3043
7.82k
        self.paint_offset().resolve(data)
3044
7.82k
    }
3045
3046
    /// Glyph ID for the source outline.
3047
7.82k
    pub fn glyph_id(&self) -> GlyphId16 {
3048
7.82k
        self.data.header().glyph_id.get()
3049
7.82k
    }
3050
3051
0
    pub fn format_byte_range(&self) -> Range<usize> {
3052
0
        let start = 0usize;
3053
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3054
0
        start..end
3055
0
    }
3056
3057
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3058
0
        let start = self.format_byte_range().end;
3059
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3060
0
        start..end
3061
0
    }
3062
3063
0
    pub fn glyph_id_byte_range(&self) -> Range<usize> {
3064
0
        let start = self.paint_offset_byte_range().end;
3065
0
        let end = start.saturating_add(GlyphId16::RAW_BYTE_LEN);
3066
0
        start..end
3067
0
    }
3068
}
3069
3070
impl Format<u8> for PaintGlyph2<'_> {
3071
    const FORMAT: u8 = 33;
3072
}
3073
3074
impl<'a> MinByteRange<'a> for PaintGlyph2<'a> {
3075
0
    fn min_byte_range(&self) -> Range<usize> {
3076
0
        0..self.glyph_id_byte_range().end
3077
0
    }
3078
0
    fn min_table_bytes(&self) -> &'a [u8] {
3079
0
        let range = self.min_byte_range();
3080
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3081
0
    }
3082
}
3083
3084
impl ReadArgs for PaintGlyph2<'_> {
3085
    type Args = ();
3086
}
3087
3088
impl<'a> FontRead<'a> for PaintGlyph2<'a> {
3089
5.83k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3090
        #[allow(clippy::absurd_extreme_comparisons)]
3091
5.83k
        if data.len() < Self::MIN_SIZE {
3092
425
            return Err(ReadError::OutOfBounds);
3093
5.41k
        }
3094
5.41k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3095
0
            return Err(ReadError::OutOfBounds);
3096
        };
3097
5.41k
        Ok(Self { data })
3098
5.83k
    }
3099
}
3100
3101
/// The fields at the start of the table, which are read directly.
3102
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3103
#[repr(C, packed)]
3104
#[doc(hidden)]
3105
pub struct PaintGlyph2FixedHeader {
3106
    pub format: u8,
3107
    pub paint_offset: BigEndian<Offset24>,
3108
    pub glyph_id: BigEndian<GlyphId24>,
3109
}
3110
3111
#[allow(clippy::absurd_extreme_comparisons)]
3112
const _: () = assert!(std::mem::size_of::<PaintGlyph2FixedHeader>() <= PaintGlyph2::MIN_SIZE);
3113
3114
/// PaintGlyph2, format 33 (ISO/IEC 14496-22:2026).
3115
#[derive(Clone)]
3116
pub struct PaintGlyph2<'a> {
3117
    data: TableDataRef<'a, PaintGlyph2FixedHeader>,
3118
}
3119
3120
#[allow(clippy::needless_lifetimes)]
3121
impl<'a> PaintGlyph2<'a> {
3122
    pub const MIN_SIZE: usize =
3123
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + GlyphId24::RAW_BYTE_LEN);
3124
    basic_table_impls!(impl_the_methods);
3125
3126
    /// Set to 33.
3127
0
    pub fn format(&self) -> u8 {
3128
0
        self.data.header().format
3129
0
    }
3130
3131
    /// Offset to a Paint table.
3132
5.39k
    pub fn paint_offset(&self) -> Offset24 {
3133
5.39k
        self.data.header().paint_offset.get()
3134
5.39k
    }
3135
3136
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3137
5.39k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3138
5.39k
        let data = self.offset_data();
3139
5.39k
        self.paint_offset().resolve(data)
3140
5.39k
    }
3141
3142
    /// Glyph ID for the source outline.
3143
5.39k
    pub fn glyph_id(&self) -> GlyphId24 {
3144
5.39k
        self.data.header().glyph_id.get()
3145
5.39k
    }
3146
3147
0
    pub fn format_byte_range(&self) -> Range<usize> {
3148
0
        let start = 0usize;
3149
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3150
0
        start..end
3151
0
    }
3152
3153
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3154
0
        let start = self.format_byte_range().end;
3155
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3156
0
        start..end
3157
0
    }
3158
3159
0
    pub fn glyph_id_byte_range(&self) -> Range<usize> {
3160
0
        let start = self.paint_offset_byte_range().end;
3161
0
        let end = start.saturating_add(GlyphId24::RAW_BYTE_LEN);
3162
0
        start..end
3163
0
    }
3164
}
3165
3166
impl Format<u8> for PaintColrGlyph<'_> {
3167
    const FORMAT: u8 = 11;
3168
}
3169
3170
impl<'a> MinByteRange<'a> for PaintColrGlyph<'a> {
3171
0
    fn min_byte_range(&self) -> Range<usize> {
3172
0
        0..self.glyph_id_byte_range().end
3173
0
    }
3174
0
    fn min_table_bytes(&self) -> &'a [u8] {
3175
0
        let range = self.min_byte_range();
3176
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3177
0
    }
3178
}
3179
3180
impl ReadArgs for PaintColrGlyph<'_> {
3181
    type Args = ();
3182
}
3183
3184
impl<'a> FontRead<'a> for PaintColrGlyph<'a> {
3185
2.40k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3186
        #[allow(clippy::absurd_extreme_comparisons)]
3187
2.40k
        if data.len() < Self::MIN_SIZE {
3188
34
            return Err(ReadError::OutOfBounds);
3189
2.36k
        }
3190
2.36k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3191
0
            return Err(ReadError::OutOfBounds);
3192
        };
3193
2.36k
        Ok(Self { data })
3194
2.40k
    }
3195
}
3196
3197
/// The fields at the start of the table, which are read directly.
3198
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3199
#[repr(C, packed)]
3200
#[doc(hidden)]
3201
pub struct PaintColrGlyphFixedHeader {
3202
    pub format: u8,
3203
    pub glyph_id: BigEndian<GlyphId16>,
3204
}
3205
3206
#[allow(clippy::absurd_extreme_comparisons)]
3207
const _: () = assert!(std::mem::size_of::<PaintColrGlyphFixedHeader>() <= PaintColrGlyph::MIN_SIZE);
3208
3209
/// [PaintColrGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-11-paintcolrglyph) table
3210
#[derive(Clone)]
3211
pub struct PaintColrGlyph<'a> {
3212
    data: TableDataRef<'a, PaintColrGlyphFixedHeader>,
3213
}
3214
3215
#[allow(clippy::needless_lifetimes)]
3216
impl<'a> PaintColrGlyph<'a> {
3217
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN);
3218
    basic_table_impls!(impl_the_methods);
3219
3220
    /// Set to 11.
3221
0
    pub fn format(&self) -> u8 {
3222
0
        self.data.header().format
3223
0
    }
3224
3225
    /// Glyph ID for a BaseGlyphList base glyph.
3226
1.56k
    pub fn glyph_id(&self) -> GlyphId16 {
3227
1.56k
        self.data.header().glyph_id.get()
3228
1.56k
    }
3229
3230
0
    pub fn format_byte_range(&self) -> Range<usize> {
3231
0
        let start = 0usize;
3232
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3233
0
        start..end
3234
0
    }
3235
3236
0
    pub fn glyph_id_byte_range(&self) -> Range<usize> {
3237
0
        let start = self.format_byte_range().end;
3238
0
        let end = start.saturating_add(GlyphId16::RAW_BYTE_LEN);
3239
0
        start..end
3240
0
    }
3241
}
3242
3243
impl Format<u8> for PaintTransform<'_> {
3244
    const FORMAT: u8 = 12;
3245
}
3246
3247
impl<'a> MinByteRange<'a> for PaintTransform<'a> {
3248
0
    fn min_byte_range(&self) -> Range<usize> {
3249
0
        0..self.transform_offset_byte_range().end
3250
0
    }
3251
0
    fn min_table_bytes(&self) -> &'a [u8] {
3252
0
        let range = self.min_byte_range();
3253
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3254
0
    }
3255
}
3256
3257
impl ReadArgs for PaintTransform<'_> {
3258
    type Args = ();
3259
}
3260
3261
impl<'a> FontRead<'a> for PaintTransform<'a> {
3262
4.16k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3263
        #[allow(clippy::absurd_extreme_comparisons)]
3264
4.16k
        if data.len() < Self::MIN_SIZE {
3265
718
            return Err(ReadError::OutOfBounds);
3266
3.44k
        }
3267
3.44k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3268
0
            return Err(ReadError::OutOfBounds);
3269
        };
3270
3.44k
        Ok(Self { data })
3271
4.16k
    }
3272
}
3273
3274
/// The fields at the start of the table, which are read directly.
3275
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3276
#[repr(C, packed)]
3277
#[doc(hidden)]
3278
pub struct PaintTransformFixedHeader {
3279
    pub format: u8,
3280
    pub paint_offset: BigEndian<Offset24>,
3281
    pub transform_offset: BigEndian<Offset24>,
3282
}
3283
3284
#[allow(clippy::absurd_extreme_comparisons)]
3285
const _: () = assert!(std::mem::size_of::<PaintTransformFixedHeader>() <= PaintTransform::MIN_SIZE);
3286
3287
/// [PaintTransform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) table
3288
#[derive(Clone)]
3289
pub struct PaintTransform<'a> {
3290
    data: TableDataRef<'a, PaintTransformFixedHeader>,
3291
}
3292
3293
#[allow(clippy::needless_lifetimes)]
3294
impl<'a> PaintTransform<'a> {
3295
    pub const MIN_SIZE: usize =
3296
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN);
3297
    basic_table_impls!(impl_the_methods);
3298
3299
    /// Set to 12.
3300
0
    pub fn format(&self) -> u8 {
3301
0
        self.data.header().format
3302
0
    }
3303
3304
    /// Offset to a Paint subtable.
3305
1.52k
    pub fn paint_offset(&self) -> Offset24 {
3306
1.52k
        self.data.header().paint_offset.get()
3307
1.52k
    }
3308
3309
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3310
1.52k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3311
1.52k
        let data = self.offset_data();
3312
1.52k
        self.paint_offset().resolve(data)
3313
1.52k
    }
3314
3315
    /// Offset to an Affine2x3 table.
3316
3.44k
    pub fn transform_offset(&self) -> Offset24 {
3317
3.44k
        self.data.header().transform_offset.get()
3318
3.44k
    }
3319
3320
    /// Attempt to resolve [`transform_offset`][Self::transform_offset].
3321
3.44k
    pub fn transform(&self) -> Result<Affine2x3<'a>, ReadError> {
3322
3.44k
        let data = self.offset_data();
3323
3.44k
        self.transform_offset().resolve(data)
3324
3.44k
    }
3325
3326
0
    pub fn format_byte_range(&self) -> Range<usize> {
3327
0
        let start = 0usize;
3328
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3329
0
        start..end
3330
0
    }
3331
3332
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3333
0
        let start = self.format_byte_range().end;
3334
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3335
0
        start..end
3336
0
    }
3337
3338
0
    pub fn transform_offset_byte_range(&self) -> Range<usize> {
3339
0
        let start = self.paint_offset_byte_range().end;
3340
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3341
0
        start..end
3342
0
    }
3343
}
3344
3345
impl Format<u8> for PaintVarTransform<'_> {
3346
    const FORMAT: u8 = 13;
3347
}
3348
3349
impl<'a> MinByteRange<'a> for PaintVarTransform<'a> {
3350
0
    fn min_byte_range(&self) -> Range<usize> {
3351
0
        0..self.transform_offset_byte_range().end
3352
0
    }
3353
0
    fn min_table_bytes(&self) -> &'a [u8] {
3354
0
        let range = self.min_byte_range();
3355
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3356
0
    }
3357
}
3358
3359
impl ReadArgs for PaintVarTransform<'_> {
3360
    type Args = ();
3361
}
3362
3363
impl<'a> FontRead<'a> for PaintVarTransform<'a> {
3364
3.19k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3365
        #[allow(clippy::absurd_extreme_comparisons)]
3366
3.19k
        if data.len() < Self::MIN_SIZE {
3367
711
            return Err(ReadError::OutOfBounds);
3368
2.48k
        }
3369
2.48k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3370
0
            return Err(ReadError::OutOfBounds);
3371
        };
3372
2.48k
        Ok(Self { data })
3373
3.19k
    }
3374
}
3375
3376
/// The fields at the start of the table, which are read directly.
3377
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3378
#[repr(C, packed)]
3379
#[doc(hidden)]
3380
pub struct PaintVarTransformFixedHeader {
3381
    pub format: u8,
3382
    pub paint_offset: BigEndian<Offset24>,
3383
    pub transform_offset: BigEndian<Offset24>,
3384
}
3385
3386
#[allow(clippy::absurd_extreme_comparisons)]
3387
const _: () =
3388
    assert!(std::mem::size_of::<PaintVarTransformFixedHeader>() <= PaintVarTransform::MIN_SIZE);
3389
3390
/// [PaintVarTransform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) table
3391
#[derive(Clone)]
3392
pub struct PaintVarTransform<'a> {
3393
    data: TableDataRef<'a, PaintVarTransformFixedHeader>,
3394
}
3395
3396
#[allow(clippy::needless_lifetimes)]
3397
impl<'a> PaintVarTransform<'a> {
3398
    pub const MIN_SIZE: usize =
3399
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN);
3400
    basic_table_impls!(impl_the_methods);
3401
3402
    /// Set to 13.
3403
0
    pub fn format(&self) -> u8 {
3404
0
        self.data.header().format
3405
0
    }
3406
3407
    /// Offset to a Paint subtable.
3408
515
    pub fn paint_offset(&self) -> Offset24 {
3409
515
        self.data.header().paint_offset.get()
3410
515
    }
3411
3412
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3413
515
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3414
515
        let data = self.offset_data();
3415
515
        self.paint_offset().resolve(data)
3416
515
    }
3417
3418
    /// Offset to a VarAffine2x3 table.
3419
2.46k
    pub fn transform_offset(&self) -> Offset24 {
3420
2.46k
        self.data.header().transform_offset.get()
3421
2.46k
    }
3422
3423
    /// Attempt to resolve [`transform_offset`][Self::transform_offset].
3424
2.46k
    pub fn transform(&self) -> Result<VarAffine2x3<'a>, ReadError> {
3425
2.46k
        let data = self.offset_data();
3426
2.46k
        self.transform_offset().resolve(data)
3427
2.46k
    }
3428
3429
0
    pub fn format_byte_range(&self) -> Range<usize> {
3430
0
        let start = 0usize;
3431
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3432
0
        start..end
3433
0
    }
3434
3435
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3436
0
        let start = self.format_byte_range().end;
3437
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3438
0
        start..end
3439
0
    }
3440
3441
0
    pub fn transform_offset_byte_range(&self) -> Range<usize> {
3442
0
        let start = self.paint_offset_byte_range().end;
3443
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3444
0
        start..end
3445
0
    }
3446
}
3447
3448
impl<'a> MinByteRange<'a> for Affine2x3<'a> {
3449
0
    fn min_byte_range(&self) -> Range<usize> {
3450
0
        0..self.dy_byte_range().end
3451
0
    }
3452
0
    fn min_table_bytes(&self) -> &'a [u8] {
3453
0
        let range = self.min_byte_range();
3454
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3455
0
    }
3456
}
3457
3458
impl ReadArgs for Affine2x3<'_> {
3459
    type Args = ();
3460
}
3461
3462
impl<'a> FontRead<'a> for Affine2x3<'a> {
3463
1.99k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3464
        #[allow(clippy::absurd_extreme_comparisons)]
3465
1.99k
        if data.len() < Self::MIN_SIZE {
3466
466
            return Err(ReadError::OutOfBounds);
3467
1.52k
        }
3468
1.52k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3469
0
            return Err(ReadError::OutOfBounds);
3470
        };
3471
1.52k
        Ok(Self { data })
3472
1.99k
    }
3473
}
3474
3475
/// The fields at the start of the table, which are read directly.
3476
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3477
#[repr(C, packed)]
3478
#[doc(hidden)]
3479
pub struct Affine2x3FixedHeader {
3480
    pub xx: BigEndian<Fixed>,
3481
    pub yx: BigEndian<Fixed>,
3482
    pub xy: BigEndian<Fixed>,
3483
    pub yy: BigEndian<Fixed>,
3484
    pub dx: BigEndian<Fixed>,
3485
    pub dy: BigEndian<Fixed>,
3486
}
3487
3488
#[allow(clippy::absurd_extreme_comparisons)]
3489
const _: () = assert!(std::mem::size_of::<Affine2x3FixedHeader>() <= Affine2x3::MIN_SIZE);
3490
3491
/// [Affine2x3](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) record
3492
#[derive(Clone)]
3493
pub struct Affine2x3<'a> {
3494
    data: TableDataRef<'a, Affine2x3FixedHeader>,
3495
}
3496
3497
#[allow(clippy::needless_lifetimes)]
3498
impl<'a> Affine2x3<'a> {
3499
    pub const MIN_SIZE: usize = (Fixed::RAW_BYTE_LEN
3500
        + Fixed::RAW_BYTE_LEN
3501
        + Fixed::RAW_BYTE_LEN
3502
        + Fixed::RAW_BYTE_LEN
3503
        + Fixed::RAW_BYTE_LEN
3504
        + Fixed::RAW_BYTE_LEN);
3505
    basic_table_impls!(impl_the_methods);
3506
3507
    /// x-component of transformed x-basis vector.
3508
750
    pub fn xx(&self) -> Fixed {
3509
750
        self.data.header().xx.get()
3510
750
    }
3511
3512
    /// y-component of transformed x-basis vector.
3513
750
    pub fn yx(&self) -> Fixed {
3514
750
        self.data.header().yx.get()
3515
750
    }
3516
3517
    /// x-component of transformed y-basis vector.
3518
750
    pub fn xy(&self) -> Fixed {
3519
750
        self.data.header().xy.get()
3520
750
    }
3521
3522
    /// y-component of transformed y-basis vector.
3523
750
    pub fn yy(&self) -> Fixed {
3524
750
        self.data.header().yy.get()
3525
750
    }
3526
3527
    /// Translation in x direction.
3528
750
    pub fn dx(&self) -> Fixed {
3529
750
        self.data.header().dx.get()
3530
750
    }
3531
3532
    /// Translation in y direction.
3533
750
    pub fn dy(&self) -> Fixed {
3534
750
        self.data.header().dy.get()
3535
750
    }
3536
3537
0
    pub fn xx_byte_range(&self) -> Range<usize> {
3538
0
        let start = 0usize;
3539
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3540
0
        start..end
3541
0
    }
3542
3543
0
    pub fn yx_byte_range(&self) -> Range<usize> {
3544
0
        let start = self.xx_byte_range().end;
3545
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3546
0
        start..end
3547
0
    }
3548
3549
0
    pub fn xy_byte_range(&self) -> Range<usize> {
3550
0
        let start = self.yx_byte_range().end;
3551
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3552
0
        start..end
3553
0
    }
3554
3555
0
    pub fn yy_byte_range(&self) -> Range<usize> {
3556
0
        let start = self.xy_byte_range().end;
3557
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3558
0
        start..end
3559
0
    }
3560
3561
0
    pub fn dx_byte_range(&self) -> Range<usize> {
3562
0
        let start = self.yy_byte_range().end;
3563
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3564
0
        start..end
3565
0
    }
3566
3567
0
    pub fn dy_byte_range(&self) -> Range<usize> {
3568
0
        let start = self.dx_byte_range().end;
3569
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3570
0
        start..end
3571
0
    }
3572
}
3573
3574
const _: () = assert!(FontData::default_data_long_enough(Affine2x3::MIN_SIZE));
3575
3576
impl Default for Affine2x3<'_> {
3577
0
    fn default() -> Self {
3578
        Self {
3579
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
3580
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3581
        }
3582
0
    }
3583
}
3584
3585
impl<'a> MinByteRange<'a> for VarAffine2x3<'a> {
3586
0
    fn min_byte_range(&self) -> Range<usize> {
3587
0
        0..self.var_index_base_byte_range().end
3588
0
    }
3589
0
    fn min_table_bytes(&self) -> &'a [u8] {
3590
0
        let range = self.min_byte_range();
3591
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3592
0
    }
3593
}
3594
3595
impl ReadArgs for VarAffine2x3<'_> {
3596
    type Args = ();
3597
}
3598
3599
impl<'a> FontRead<'a> for VarAffine2x3<'a> {
3600
1.23k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3601
        #[allow(clippy::absurd_extreme_comparisons)]
3602
1.23k
        if data.len() < Self::MIN_SIZE {
3603
718
            return Err(ReadError::OutOfBounds);
3604
515
        }
3605
515
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3606
0
            return Err(ReadError::OutOfBounds);
3607
        };
3608
515
        Ok(Self { data })
3609
1.23k
    }
3610
}
3611
3612
/// The fields at the start of the table, which are read directly.
3613
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3614
#[repr(C, packed)]
3615
#[doc(hidden)]
3616
pub struct VarAffine2x3FixedHeader {
3617
    pub xx: BigEndian<Fixed>,
3618
    pub yx: BigEndian<Fixed>,
3619
    pub xy: BigEndian<Fixed>,
3620
    pub yy: BigEndian<Fixed>,
3621
    pub dx: BigEndian<Fixed>,
3622
    pub dy: BigEndian<Fixed>,
3623
    pub var_index_base: BigEndian<u32>,
3624
}
3625
3626
#[allow(clippy::absurd_extreme_comparisons)]
3627
const _: () = assert!(std::mem::size_of::<VarAffine2x3FixedHeader>() <= VarAffine2x3::MIN_SIZE);
3628
3629
/// [VarAffine2x3](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) record
3630
#[derive(Clone)]
3631
pub struct VarAffine2x3<'a> {
3632
    data: TableDataRef<'a, VarAffine2x3FixedHeader>,
3633
}
3634
3635
#[allow(clippy::needless_lifetimes)]
3636
impl<'a> VarAffine2x3<'a> {
3637
    pub const MIN_SIZE: usize = (Fixed::RAW_BYTE_LEN
3638
        + Fixed::RAW_BYTE_LEN
3639
        + Fixed::RAW_BYTE_LEN
3640
        + Fixed::RAW_BYTE_LEN
3641
        + Fixed::RAW_BYTE_LEN
3642
        + Fixed::RAW_BYTE_LEN
3643
        + u32::RAW_BYTE_LEN);
3644
    basic_table_impls!(impl_the_methods);
3645
3646
    /// x-component of transformed x-basis vector. For variation, use
3647
    /// varIndexBase + 0.
3648
36
    pub fn xx(&self) -> Fixed {
3649
36
        self.data.header().xx.get()
3650
36
    }
3651
3652
    /// y-component of transformed x-basis vector. For variation, use
3653
    /// varIndexBase + 1.
3654
36
    pub fn yx(&self) -> Fixed {
3655
36
        self.data.header().yx.get()
3656
36
    }
3657
3658
    /// x-component of transformed y-basis vector. For variation, use
3659
    /// varIndexBase + 2.
3660
36
    pub fn xy(&self) -> Fixed {
3661
36
        self.data.header().xy.get()
3662
36
    }
3663
3664
    /// y-component of transformed y-basis vector. For variation, use
3665
    /// varIndexBase + 3.
3666
36
    pub fn yy(&self) -> Fixed {
3667
36
        self.data.header().yy.get()
3668
36
    }
3669
3670
    /// Translation in x direction. For variation, use varIndexBase + 4.
3671
36
    pub fn dx(&self) -> Fixed {
3672
36
        self.data.header().dx.get()
3673
36
    }
3674
3675
    /// Translation in y direction. For variation, use varIndexBase + 5.
3676
36
    pub fn dy(&self) -> Fixed {
3677
36
        self.data.header().dy.get()
3678
36
    }
3679
3680
    /// Base index into DeltaSetIndexMap.
3681
36
    pub fn var_index_base(&self) -> u32 {
3682
36
        self.data.header().var_index_base.get()
3683
36
    }
3684
3685
0
    pub fn xx_byte_range(&self) -> Range<usize> {
3686
0
        let start = 0usize;
3687
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3688
0
        start..end
3689
0
    }
3690
3691
0
    pub fn yx_byte_range(&self) -> Range<usize> {
3692
0
        let start = self.xx_byte_range().end;
3693
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3694
0
        start..end
3695
0
    }
3696
3697
0
    pub fn xy_byte_range(&self) -> Range<usize> {
3698
0
        let start = self.yx_byte_range().end;
3699
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3700
0
        start..end
3701
0
    }
3702
3703
0
    pub fn yy_byte_range(&self) -> Range<usize> {
3704
0
        let start = self.xy_byte_range().end;
3705
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3706
0
        start..end
3707
0
    }
3708
3709
0
    pub fn dx_byte_range(&self) -> Range<usize> {
3710
0
        let start = self.yy_byte_range().end;
3711
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3712
0
        start..end
3713
0
    }
3714
3715
0
    pub fn dy_byte_range(&self) -> Range<usize> {
3716
0
        let start = self.dx_byte_range().end;
3717
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3718
0
        start..end
3719
0
    }
3720
3721
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
3722
0
        let start = self.dy_byte_range().end;
3723
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
3724
0
        start..end
3725
0
    }
3726
}
3727
3728
const _: () = assert!(FontData::default_data_long_enough(VarAffine2x3::MIN_SIZE));
3729
3730
impl Default for VarAffine2x3<'_> {
3731
0
    fn default() -> Self {
3732
        Self {
3733
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
3734
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3735
        }
3736
0
    }
3737
}
3738
3739
impl Format<u8> for PaintTranslate<'_> {
3740
    const FORMAT: u8 = 14;
3741
}
3742
3743
impl<'a> MinByteRange<'a> for PaintTranslate<'a> {
3744
0
    fn min_byte_range(&self) -> Range<usize> {
3745
0
        0..self.dy_byte_range().end
3746
0
    }
3747
0
    fn min_table_bytes(&self) -> &'a [u8] {
3748
0
        let range = self.min_byte_range();
3749
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3750
0
    }
3751
}
3752
3753
impl ReadArgs for PaintTranslate<'_> {
3754
    type Args = ();
3755
}
3756
3757
impl<'a> FontRead<'a> for PaintTranslate<'a> {
3758
2.51k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3759
        #[allow(clippy::absurd_extreme_comparisons)]
3760
2.51k
        if data.len() < Self::MIN_SIZE {
3761
710
            return Err(ReadError::OutOfBounds);
3762
1.80k
        }
3763
1.80k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3764
0
            return Err(ReadError::OutOfBounds);
3765
        };
3766
1.80k
        Ok(Self { data })
3767
2.51k
    }
3768
}
3769
3770
/// The fields at the start of the table, which are read directly.
3771
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3772
#[repr(C, packed)]
3773
#[doc(hidden)]
3774
pub struct PaintTranslateFixedHeader {
3775
    pub format: u8,
3776
    pub paint_offset: BigEndian<Offset24>,
3777
    pub dx: BigEndian<FWord>,
3778
    pub dy: BigEndian<FWord>,
3779
}
3780
3781
#[allow(clippy::absurd_extreme_comparisons)]
3782
const _: () = assert!(std::mem::size_of::<PaintTranslateFixedHeader>() <= PaintTranslate::MIN_SIZE);
3783
3784
/// [PaintTranslate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-14-and-15-painttranslate-paintvartranslate) table
3785
#[derive(Clone)]
3786
pub struct PaintTranslate<'a> {
3787
    data: TableDataRef<'a, PaintTranslateFixedHeader>,
3788
}
3789
3790
#[allow(clippy::needless_lifetimes)]
3791
impl<'a> PaintTranslate<'a> {
3792
    pub const MIN_SIZE: usize =
3793
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + FWord::RAW_BYTE_LEN + FWord::RAW_BYTE_LEN);
3794
    basic_table_impls!(impl_the_methods);
3795
3796
    /// Set to 14.
3797
0
    pub fn format(&self) -> u8 {
3798
0
        self.data.header().format
3799
0
    }
3800
3801
    /// Offset to a Paint subtable.
3802
1.80k
    pub fn paint_offset(&self) -> Offset24 {
3803
1.80k
        self.data.header().paint_offset.get()
3804
1.80k
    }
3805
3806
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3807
1.80k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3808
1.80k
        let data = self.offset_data();
3809
1.80k
        self.paint_offset().resolve(data)
3810
1.80k
    }
3811
3812
    /// Translation in x direction.
3813
1.80k
    pub fn dx(&self) -> FWord {
3814
1.80k
        self.data.header().dx.get()
3815
1.80k
    }
3816
3817
    /// Translation in y direction.
3818
1.80k
    pub fn dy(&self) -> FWord {
3819
1.80k
        self.data.header().dy.get()
3820
1.80k
    }
3821
3822
0
    pub fn format_byte_range(&self) -> Range<usize> {
3823
0
        let start = 0usize;
3824
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3825
0
        start..end
3826
0
    }
3827
3828
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3829
0
        let start = self.format_byte_range().end;
3830
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3831
0
        start..end
3832
0
    }
3833
3834
0
    pub fn dx_byte_range(&self) -> Range<usize> {
3835
0
        let start = self.paint_offset_byte_range().end;
3836
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
3837
0
        start..end
3838
0
    }
3839
3840
0
    pub fn dy_byte_range(&self) -> Range<usize> {
3841
0
        let start = self.dx_byte_range().end;
3842
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
3843
0
        start..end
3844
0
    }
3845
}
3846
3847
impl Format<u8> for PaintVarTranslate<'_> {
3848
    const FORMAT: u8 = 15;
3849
}
3850
3851
impl<'a> MinByteRange<'a> for PaintVarTranslate<'a> {
3852
0
    fn min_byte_range(&self) -> Range<usize> {
3853
0
        0..self.var_index_base_byte_range().end
3854
0
    }
3855
0
    fn min_table_bytes(&self) -> &'a [u8] {
3856
0
        let range = self.min_byte_range();
3857
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3858
0
    }
3859
}
3860
3861
impl ReadArgs for PaintVarTranslate<'_> {
3862
    type Args = ();
3863
}
3864
3865
impl<'a> FontRead<'a> for PaintVarTranslate<'a> {
3866
2.81k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3867
        #[allow(clippy::absurd_extreme_comparisons)]
3868
2.81k
        if data.len() < Self::MIN_SIZE {
3869
458
            return Err(ReadError::OutOfBounds);
3870
2.36k
        }
3871
2.36k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3872
0
            return Err(ReadError::OutOfBounds);
3873
        };
3874
2.36k
        Ok(Self { data })
3875
2.81k
    }
3876
}
3877
3878
/// The fields at the start of the table, which are read directly.
3879
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
3880
#[repr(C, packed)]
3881
#[doc(hidden)]
3882
pub struct PaintVarTranslateFixedHeader {
3883
    pub format: u8,
3884
    pub paint_offset: BigEndian<Offset24>,
3885
    pub dx: BigEndian<FWord>,
3886
    pub dy: BigEndian<FWord>,
3887
    pub var_index_base: BigEndian<u32>,
3888
}
3889
3890
#[allow(clippy::absurd_extreme_comparisons)]
3891
const _: () =
3892
    assert!(std::mem::size_of::<PaintVarTranslateFixedHeader>() <= PaintVarTranslate::MIN_SIZE);
3893
3894
/// [PaintVarTranslate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-14-and-15-painttranslate-paintvartranslate) table
3895
#[derive(Clone)]
3896
pub struct PaintVarTranslate<'a> {
3897
    data: TableDataRef<'a, PaintVarTranslateFixedHeader>,
3898
}
3899
3900
#[allow(clippy::needless_lifetimes)]
3901
impl<'a> PaintVarTranslate<'a> {
3902
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
3903
        + Offset24::RAW_BYTE_LEN
3904
        + FWord::RAW_BYTE_LEN
3905
        + FWord::RAW_BYTE_LEN
3906
        + u32::RAW_BYTE_LEN);
3907
    basic_table_impls!(impl_the_methods);
3908
3909
    /// Set to 15.
3910
0
    pub fn format(&self) -> u8 {
3911
0
        self.data.header().format
3912
0
    }
3913
3914
    /// Offset to a Paint subtable.
3915
2.36k
    pub fn paint_offset(&self) -> Offset24 {
3916
2.36k
        self.data.header().paint_offset.get()
3917
2.36k
    }
3918
3919
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3920
2.36k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3921
2.36k
        let data = self.offset_data();
3922
2.36k
        self.paint_offset().resolve(data)
3923
2.36k
    }
3924
3925
    /// Translation in x direction. For variation, use varIndexBase + 0.
3926
2.36k
    pub fn dx(&self) -> FWord {
3927
2.36k
        self.data.header().dx.get()
3928
2.36k
    }
3929
3930
    /// Translation in y direction. For variation, use varIndexBase + 1.
3931
2.36k
    pub fn dy(&self) -> FWord {
3932
2.36k
        self.data.header().dy.get()
3933
2.36k
    }
3934
3935
    /// Base index into DeltaSetIndexMap.
3936
2.36k
    pub fn var_index_base(&self) -> u32 {
3937
2.36k
        self.data.header().var_index_base.get()
3938
2.36k
    }
3939
3940
0
    pub fn format_byte_range(&self) -> Range<usize> {
3941
0
        let start = 0usize;
3942
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3943
0
        start..end
3944
0
    }
3945
3946
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3947
0
        let start = self.format_byte_range().end;
3948
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3949
0
        start..end
3950
0
    }
3951
3952
0
    pub fn dx_byte_range(&self) -> Range<usize> {
3953
0
        let start = self.paint_offset_byte_range().end;
3954
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
3955
0
        start..end
3956
0
    }
3957
3958
0
    pub fn dy_byte_range(&self) -> Range<usize> {
3959
0
        let start = self.dx_byte_range().end;
3960
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
3961
0
        start..end
3962
0
    }
3963
3964
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
3965
0
        let start = self.dy_byte_range().end;
3966
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
3967
0
        start..end
3968
0
    }
3969
}
3970
3971
impl Format<u8> for PaintScale<'_> {
3972
    const FORMAT: u8 = 16;
3973
}
3974
3975
impl<'a> MinByteRange<'a> for PaintScale<'a> {
3976
0
    fn min_byte_range(&self) -> Range<usize> {
3977
0
        0..self.scale_y_byte_range().end
3978
0
    }
3979
0
    fn min_table_bytes(&self) -> &'a [u8] {
3980
0
        let range = self.min_byte_range();
3981
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3982
0
    }
3983
}
3984
3985
impl ReadArgs for PaintScale<'_> {
3986
    type Args = ();
3987
}
3988
3989
impl<'a> FontRead<'a> for PaintScale<'a> {
3990
3.08k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3991
        #[allow(clippy::absurd_extreme_comparisons)]
3992
3.08k
        if data.len() < Self::MIN_SIZE {
3993
716
            return Err(ReadError::OutOfBounds);
3994
2.37k
        }
3995
2.37k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3996
0
            return Err(ReadError::OutOfBounds);
3997
        };
3998
2.37k
        Ok(Self { data })
3999
3.08k
    }
4000
}
4001
4002
/// The fields at the start of the table, which are read directly.
4003
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4004
#[repr(C, packed)]
4005
#[doc(hidden)]
4006
pub struct PaintScaleFixedHeader {
4007
    pub format: u8,
4008
    pub paint_offset: BigEndian<Offset24>,
4009
    pub scale_x: BigEndian<F2Dot14>,
4010
    pub scale_y: BigEndian<F2Dot14>,
4011
}
4012
4013
#[allow(clippy::absurd_extreme_comparisons)]
4014
const _: () = assert!(std::mem::size_of::<PaintScaleFixedHeader>() <= PaintScale::MIN_SIZE);
4015
4016
/// [PaintScale](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table
4017
#[derive(Clone)]
4018
pub struct PaintScale<'a> {
4019
    data: TableDataRef<'a, PaintScaleFixedHeader>,
4020
}
4021
4022
#[allow(clippy::needless_lifetimes)]
4023
impl<'a> PaintScale<'a> {
4024
    pub const MIN_SIZE: usize =
4025
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN);
4026
    basic_table_impls!(impl_the_methods);
4027
4028
    /// Set to 16.
4029
0
    pub fn format(&self) -> u8 {
4030
0
        self.data.header().format
4031
0
    }
4032
4033
    /// Offset to a Paint subtable.
4034
2.37k
    pub fn paint_offset(&self) -> Offset24 {
4035
2.37k
        self.data.header().paint_offset.get()
4036
2.37k
    }
4037
4038
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4039
2.37k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4040
2.37k
        let data = self.offset_data();
4041
2.37k
        self.paint_offset().resolve(data)
4042
2.37k
    }
4043
4044
    /// Scale factor in x direction.
4045
2.37k
    pub fn scale_x(&self) -> F2Dot14 {
4046
2.37k
        self.data.header().scale_x.get()
4047
2.37k
    }
4048
4049
    /// Scale factor in y direction.
4050
2.37k
    pub fn scale_y(&self) -> F2Dot14 {
4051
2.37k
        self.data.header().scale_y.get()
4052
2.37k
    }
4053
4054
0
    pub fn format_byte_range(&self) -> Range<usize> {
4055
0
        let start = 0usize;
4056
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4057
0
        start..end
4058
0
    }
4059
4060
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4061
0
        let start = self.format_byte_range().end;
4062
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4063
0
        start..end
4064
0
    }
4065
4066
0
    pub fn scale_x_byte_range(&self) -> Range<usize> {
4067
0
        let start = self.paint_offset_byte_range().end;
4068
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4069
0
        start..end
4070
0
    }
4071
4072
0
    pub fn scale_y_byte_range(&self) -> Range<usize> {
4073
0
        let start = self.scale_x_byte_range().end;
4074
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4075
0
        start..end
4076
0
    }
4077
}
4078
4079
impl Format<u8> for PaintVarScale<'_> {
4080
    const FORMAT: u8 = 17;
4081
}
4082
4083
impl<'a> MinByteRange<'a> for PaintVarScale<'a> {
4084
0
    fn min_byte_range(&self) -> Range<usize> {
4085
0
        0..self.var_index_base_byte_range().end
4086
0
    }
4087
0
    fn min_table_bytes(&self) -> &'a [u8] {
4088
0
        let range = self.min_byte_range();
4089
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4090
0
    }
4091
}
4092
4093
impl ReadArgs for PaintVarScale<'_> {
4094
    type Args = ();
4095
}
4096
4097
impl<'a> FontRead<'a> for PaintVarScale<'a> {
4098
1.92k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4099
        #[allow(clippy::absurd_extreme_comparisons)]
4100
1.92k
        if data.len() < Self::MIN_SIZE {
4101
458
            return Err(ReadError::OutOfBounds);
4102
1.46k
        }
4103
1.46k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4104
0
            return Err(ReadError::OutOfBounds);
4105
        };
4106
1.46k
        Ok(Self { data })
4107
1.92k
    }
4108
}
4109
4110
/// The fields at the start of the table, which are read directly.
4111
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4112
#[repr(C, packed)]
4113
#[doc(hidden)]
4114
pub struct PaintVarScaleFixedHeader {
4115
    pub format: u8,
4116
    pub paint_offset: BigEndian<Offset24>,
4117
    pub scale_x: BigEndian<F2Dot14>,
4118
    pub scale_y: BigEndian<F2Dot14>,
4119
    pub var_index_base: BigEndian<u32>,
4120
}
4121
4122
#[allow(clippy::absurd_extreme_comparisons)]
4123
const _: () = assert!(std::mem::size_of::<PaintVarScaleFixedHeader>() <= PaintVarScale::MIN_SIZE);
4124
4125
/// [PaintVarScale](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table
4126
#[derive(Clone)]
4127
pub struct PaintVarScale<'a> {
4128
    data: TableDataRef<'a, PaintVarScaleFixedHeader>,
4129
}
4130
4131
#[allow(clippy::needless_lifetimes)]
4132
impl<'a> PaintVarScale<'a> {
4133
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
4134
        + Offset24::RAW_BYTE_LEN
4135
        + F2Dot14::RAW_BYTE_LEN
4136
        + F2Dot14::RAW_BYTE_LEN
4137
        + u32::RAW_BYTE_LEN);
4138
    basic_table_impls!(impl_the_methods);
4139
4140
    /// Set to 17.
4141
0
    pub fn format(&self) -> u8 {
4142
0
        self.data.header().format
4143
0
    }
4144
4145
    /// Offset to a Paint subtable.
4146
1.46k
    pub fn paint_offset(&self) -> Offset24 {
4147
1.46k
        self.data.header().paint_offset.get()
4148
1.46k
    }
4149
4150
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4151
1.46k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4152
1.46k
        let data = self.offset_data();
4153
1.46k
        self.paint_offset().resolve(data)
4154
1.46k
    }
4155
4156
    /// Scale factor in x direction. For variation, use varIndexBase +
4157
    /// 0.
4158
1.46k
    pub fn scale_x(&self) -> F2Dot14 {
4159
1.46k
        self.data.header().scale_x.get()
4160
1.46k
    }
4161
4162
    /// Scale factor in y direction. For variation, use varIndexBase +
4163
    /// 1.
4164
1.46k
    pub fn scale_y(&self) -> F2Dot14 {
4165
1.46k
        self.data.header().scale_y.get()
4166
1.46k
    }
4167
4168
    /// Base index into DeltaSetIndexMap.
4169
1.46k
    pub fn var_index_base(&self) -> u32 {
4170
1.46k
        self.data.header().var_index_base.get()
4171
1.46k
    }
4172
4173
0
    pub fn format_byte_range(&self) -> Range<usize> {
4174
0
        let start = 0usize;
4175
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4176
0
        start..end
4177
0
    }
4178
4179
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4180
0
        let start = self.format_byte_range().end;
4181
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4182
0
        start..end
4183
0
    }
4184
4185
0
    pub fn scale_x_byte_range(&self) -> Range<usize> {
4186
0
        let start = self.paint_offset_byte_range().end;
4187
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4188
0
        start..end
4189
0
    }
4190
4191
0
    pub fn scale_y_byte_range(&self) -> Range<usize> {
4192
0
        let start = self.scale_x_byte_range().end;
4193
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4194
0
        start..end
4195
0
    }
4196
4197
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
4198
0
        let start = self.scale_y_byte_range().end;
4199
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4200
0
        start..end
4201
0
    }
4202
}
4203
4204
impl Format<u8> for PaintScaleAroundCenter<'_> {
4205
    const FORMAT: u8 = 18;
4206
}
4207
4208
impl<'a> MinByteRange<'a> for PaintScaleAroundCenter<'a> {
4209
0
    fn min_byte_range(&self) -> Range<usize> {
4210
0
        0..self.center_y_byte_range().end
4211
0
    }
4212
0
    fn min_table_bytes(&self) -> &'a [u8] {
4213
0
        let range = self.min_byte_range();
4214
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4215
0
    }
4216
}
4217
4218
impl ReadArgs for PaintScaleAroundCenter<'_> {
4219
    type Args = ();
4220
}
4221
4222
impl<'a> FontRead<'a> for PaintScaleAroundCenter<'a> {
4223
2.07k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4224
        #[allow(clippy::absurd_extreme_comparisons)]
4225
2.07k
        if data.len() < Self::MIN_SIZE {
4226
457
            return Err(ReadError::OutOfBounds);
4227
1.61k
        }
4228
1.61k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4229
0
            return Err(ReadError::OutOfBounds);
4230
        };
4231
1.61k
        Ok(Self { data })
4232
2.07k
    }
4233
}
4234
4235
/// The fields at the start of the table, which are read directly.
4236
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4237
#[repr(C, packed)]
4238
#[doc(hidden)]
4239
pub struct PaintScaleAroundCenterFixedHeader {
4240
    pub format: u8,
4241
    pub paint_offset: BigEndian<Offset24>,
4242
    pub scale_x: BigEndian<F2Dot14>,
4243
    pub scale_y: BigEndian<F2Dot14>,
4244
    pub center_x: BigEndian<FWord>,
4245
    pub center_y: BigEndian<FWord>,
4246
}
4247
4248
#[allow(clippy::absurd_extreme_comparisons)]
4249
const _: () = assert!(
4250
    std::mem::size_of::<PaintScaleAroundCenterFixedHeader>() <= PaintScaleAroundCenter::MIN_SIZE
4251
);
4252
4253
/// [PaintScaleAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table
4254
#[derive(Clone)]
4255
pub struct PaintScaleAroundCenter<'a> {
4256
    data: TableDataRef<'a, PaintScaleAroundCenterFixedHeader>,
4257
}
4258
4259
#[allow(clippy::needless_lifetimes)]
4260
impl<'a> PaintScaleAroundCenter<'a> {
4261
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
4262
        + Offset24::RAW_BYTE_LEN
4263
        + F2Dot14::RAW_BYTE_LEN
4264
        + F2Dot14::RAW_BYTE_LEN
4265
        + FWord::RAW_BYTE_LEN
4266
        + FWord::RAW_BYTE_LEN);
4267
    basic_table_impls!(impl_the_methods);
4268
4269
    /// Set to 18.
4270
0
    pub fn format(&self) -> u8 {
4271
0
        self.data.header().format
4272
0
    }
4273
4274
    /// Offset to a Paint subtable.
4275
1.61k
    pub fn paint_offset(&self) -> Offset24 {
4276
1.61k
        self.data.header().paint_offset.get()
4277
1.61k
    }
4278
4279
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4280
1.61k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4281
1.61k
        let data = self.offset_data();
4282
1.61k
        self.paint_offset().resolve(data)
4283
1.61k
    }
4284
4285
    /// Scale factor in x direction.
4286
1.61k
    pub fn scale_x(&self) -> F2Dot14 {
4287
1.61k
        self.data.header().scale_x.get()
4288
1.61k
    }
4289
4290
    /// Scale factor in y direction.
4291
1.61k
    pub fn scale_y(&self) -> F2Dot14 {
4292
1.61k
        self.data.header().scale_y.get()
4293
1.61k
    }
4294
4295
    /// x coordinate for the center of scaling.
4296
1.61k
    pub fn center_x(&self) -> FWord {
4297
1.61k
        self.data.header().center_x.get()
4298
1.61k
    }
4299
4300
    /// y coordinate for the center of scaling.
4301
1.61k
    pub fn center_y(&self) -> FWord {
4302
1.61k
        self.data.header().center_y.get()
4303
1.61k
    }
4304
4305
0
    pub fn format_byte_range(&self) -> Range<usize> {
4306
0
        let start = 0usize;
4307
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4308
0
        start..end
4309
0
    }
4310
4311
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4312
0
        let start = self.format_byte_range().end;
4313
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4314
0
        start..end
4315
0
    }
4316
4317
0
    pub fn scale_x_byte_range(&self) -> Range<usize> {
4318
0
        let start = self.paint_offset_byte_range().end;
4319
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4320
0
        start..end
4321
0
    }
4322
4323
0
    pub fn scale_y_byte_range(&self) -> Range<usize> {
4324
0
        let start = self.scale_x_byte_range().end;
4325
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4326
0
        start..end
4327
0
    }
4328
4329
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
4330
0
        let start = self.scale_y_byte_range().end;
4331
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4332
0
        start..end
4333
0
    }
4334
4335
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
4336
0
        let start = self.center_x_byte_range().end;
4337
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4338
0
        start..end
4339
0
    }
4340
}
4341
4342
impl Format<u8> for PaintVarScaleAroundCenter<'_> {
4343
    const FORMAT: u8 = 19;
4344
}
4345
4346
impl<'a> MinByteRange<'a> for PaintVarScaleAroundCenter<'a> {
4347
0
    fn min_byte_range(&self) -> Range<usize> {
4348
0
        0..self.var_index_base_byte_range().end
4349
0
    }
4350
0
    fn min_table_bytes(&self) -> &'a [u8] {
4351
0
        let range = self.min_byte_range();
4352
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4353
0
    }
4354
}
4355
4356
impl ReadArgs for PaintVarScaleAroundCenter<'_> {
4357
    type Args = ();
4358
}
4359
4360
impl<'a> FontRead<'a> for PaintVarScaleAroundCenter<'a> {
4361
3.32k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4362
        #[allow(clippy::absurd_extreme_comparisons)]
4363
3.32k
        if data.len() < Self::MIN_SIZE {
4364
711
            return Err(ReadError::OutOfBounds);
4365
2.60k
        }
4366
2.60k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4367
0
            return Err(ReadError::OutOfBounds);
4368
        };
4369
2.60k
        Ok(Self { data })
4370
3.32k
    }
4371
}
4372
4373
/// The fields at the start of the table, which are read directly.
4374
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4375
#[repr(C, packed)]
4376
#[doc(hidden)]
4377
pub struct PaintVarScaleAroundCenterFixedHeader {
4378
    pub format: u8,
4379
    pub paint_offset: BigEndian<Offset24>,
4380
    pub scale_x: BigEndian<F2Dot14>,
4381
    pub scale_y: BigEndian<F2Dot14>,
4382
    pub center_x: BigEndian<FWord>,
4383
    pub center_y: BigEndian<FWord>,
4384
    pub var_index_base: BigEndian<u32>,
4385
}
4386
4387
#[allow(clippy::absurd_extreme_comparisons)]
4388
const _: () = assert!(
4389
    std::mem::size_of::<PaintVarScaleAroundCenterFixedHeader>()
4390
        <= PaintVarScaleAroundCenter::MIN_SIZE
4391
);
4392
4393
/// [PaintVarScaleAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table
4394
#[derive(Clone)]
4395
pub struct PaintVarScaleAroundCenter<'a> {
4396
    data: TableDataRef<'a, PaintVarScaleAroundCenterFixedHeader>,
4397
}
4398
4399
#[allow(clippy::needless_lifetimes)]
4400
impl<'a> PaintVarScaleAroundCenter<'a> {
4401
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
4402
        + Offset24::RAW_BYTE_LEN
4403
        + F2Dot14::RAW_BYTE_LEN
4404
        + F2Dot14::RAW_BYTE_LEN
4405
        + FWord::RAW_BYTE_LEN
4406
        + FWord::RAW_BYTE_LEN
4407
        + u32::RAW_BYTE_LEN);
4408
    basic_table_impls!(impl_the_methods);
4409
4410
    /// Set to 19.
4411
0
    pub fn format(&self) -> u8 {
4412
0
        self.data.header().format
4413
0
    }
4414
4415
    /// Offset to a Paint subtable.
4416
2.57k
    pub fn paint_offset(&self) -> Offset24 {
4417
2.57k
        self.data.header().paint_offset.get()
4418
2.57k
    }
4419
4420
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4421
2.57k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4422
2.57k
        let data = self.offset_data();
4423
2.57k
        self.paint_offset().resolve(data)
4424
2.57k
    }
4425
4426
    /// Scale factor in x direction. For variation, use varIndexBase +
4427
    /// 0.
4428
2.57k
    pub fn scale_x(&self) -> F2Dot14 {
4429
2.57k
        self.data.header().scale_x.get()
4430
2.57k
    }
4431
4432
    /// Scale factor in y direction. For variation, use varIndexBase +
4433
    /// 1.
4434
2.57k
    pub fn scale_y(&self) -> F2Dot14 {
4435
2.57k
        self.data.header().scale_y.get()
4436
2.57k
    }
4437
4438
    /// x coordinate for the center of scaling. For variation, use
4439
    /// varIndexBase + 2.
4440
2.57k
    pub fn center_x(&self) -> FWord {
4441
2.57k
        self.data.header().center_x.get()
4442
2.57k
    }
4443
4444
    /// y coordinate for the center of scaling. For variation, use
4445
    /// varIndexBase + 3.
4446
2.57k
    pub fn center_y(&self) -> FWord {
4447
2.57k
        self.data.header().center_y.get()
4448
2.57k
    }
4449
4450
    /// Base index into DeltaSetIndexMap.
4451
2.57k
    pub fn var_index_base(&self) -> u32 {
4452
2.57k
        self.data.header().var_index_base.get()
4453
2.57k
    }
4454
4455
0
    pub fn format_byte_range(&self) -> Range<usize> {
4456
0
        let start = 0usize;
4457
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4458
0
        start..end
4459
0
    }
4460
4461
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4462
0
        let start = self.format_byte_range().end;
4463
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4464
0
        start..end
4465
0
    }
4466
4467
0
    pub fn scale_x_byte_range(&self) -> Range<usize> {
4468
0
        let start = self.paint_offset_byte_range().end;
4469
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4470
0
        start..end
4471
0
    }
4472
4473
0
    pub fn scale_y_byte_range(&self) -> Range<usize> {
4474
0
        let start = self.scale_x_byte_range().end;
4475
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4476
0
        start..end
4477
0
    }
4478
4479
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
4480
0
        let start = self.scale_y_byte_range().end;
4481
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4482
0
        start..end
4483
0
    }
4484
4485
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
4486
0
        let start = self.center_x_byte_range().end;
4487
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4488
0
        start..end
4489
0
    }
4490
4491
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
4492
0
        let start = self.center_y_byte_range().end;
4493
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4494
0
        start..end
4495
0
    }
4496
}
4497
4498
impl Format<u8> for PaintScaleUniform<'_> {
4499
    const FORMAT: u8 = 20;
4500
}
4501
4502
impl<'a> MinByteRange<'a> for PaintScaleUniform<'a> {
4503
0
    fn min_byte_range(&self) -> Range<usize> {
4504
0
        0..self.scale_byte_range().end
4505
0
    }
4506
0
    fn min_table_bytes(&self) -> &'a [u8] {
4507
0
        let range = self.min_byte_range();
4508
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4509
0
    }
4510
}
4511
4512
impl ReadArgs for PaintScaleUniform<'_> {
4513
    type Args = ();
4514
}
4515
4516
impl<'a> FontRead<'a> for PaintScaleUniform<'a> {
4517
2.59k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4518
        #[allow(clippy::absurd_extreme_comparisons)]
4519
2.59k
        if data.len() < Self::MIN_SIZE {
4520
680
            return Err(ReadError::OutOfBounds);
4521
1.91k
        }
4522
1.91k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4523
0
            return Err(ReadError::OutOfBounds);
4524
        };
4525
1.91k
        Ok(Self { data })
4526
2.59k
    }
4527
}
4528
4529
/// The fields at the start of the table, which are read directly.
4530
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4531
#[repr(C, packed)]
4532
#[doc(hidden)]
4533
pub struct PaintScaleUniformFixedHeader {
4534
    pub format: u8,
4535
    pub paint_offset: BigEndian<Offset24>,
4536
    pub scale: BigEndian<F2Dot14>,
4537
}
4538
4539
#[allow(clippy::absurd_extreme_comparisons)]
4540
const _: () =
4541
    assert!(std::mem::size_of::<PaintScaleUniformFixedHeader>() <= PaintScaleUniform::MIN_SIZE);
4542
4543
/// [PaintScaleUniform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table
4544
#[derive(Clone)]
4545
pub struct PaintScaleUniform<'a> {
4546
    data: TableDataRef<'a, PaintScaleUniformFixedHeader>,
4547
}
4548
4549
#[allow(clippy::needless_lifetimes)]
4550
impl<'a> PaintScaleUniform<'a> {
4551
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN);
4552
    basic_table_impls!(impl_the_methods);
4553
4554
    /// Set to 20.
4555
0
    pub fn format(&self) -> u8 {
4556
0
        self.data.header().format
4557
0
    }
4558
4559
    /// Offset to a Paint subtable.
4560
1.91k
    pub fn paint_offset(&self) -> Offset24 {
4561
1.91k
        self.data.header().paint_offset.get()
4562
1.91k
    }
4563
4564
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4565
1.91k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4566
1.91k
        let data = self.offset_data();
4567
1.91k
        self.paint_offset().resolve(data)
4568
1.91k
    }
4569
4570
    /// Scale factor in x and y directions.
4571
1.91k
    pub fn scale(&self) -> F2Dot14 {
4572
1.91k
        self.data.header().scale.get()
4573
1.91k
    }
4574
4575
0
    pub fn format_byte_range(&self) -> Range<usize> {
4576
0
        let start = 0usize;
4577
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4578
0
        start..end
4579
0
    }
4580
4581
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4582
0
        let start = self.format_byte_range().end;
4583
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4584
0
        start..end
4585
0
    }
4586
4587
0
    pub fn scale_byte_range(&self) -> Range<usize> {
4588
0
        let start = self.paint_offset_byte_range().end;
4589
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4590
0
        start..end
4591
0
    }
4592
}
4593
4594
impl Format<u8> for PaintVarScaleUniform<'_> {
4595
    const FORMAT: u8 = 21;
4596
}
4597
4598
impl<'a> MinByteRange<'a> for PaintVarScaleUniform<'a> {
4599
0
    fn min_byte_range(&self) -> Range<usize> {
4600
0
        0..self.var_index_base_byte_range().end
4601
0
    }
4602
0
    fn min_table_bytes(&self) -> &'a [u8] {
4603
0
        let range = self.min_byte_range();
4604
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4605
0
    }
4606
}
4607
4608
impl ReadArgs for PaintVarScaleUniform<'_> {
4609
    type Args = ();
4610
}
4611
4612
impl<'a> FontRead<'a> for PaintVarScaleUniform<'a> {
4613
3.07k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4614
        #[allow(clippy::absurd_extreme_comparisons)]
4615
3.07k
        if data.len() < Self::MIN_SIZE {
4616
457
            return Err(ReadError::OutOfBounds);
4617
2.61k
        }
4618
2.61k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4619
0
            return Err(ReadError::OutOfBounds);
4620
        };
4621
2.61k
        Ok(Self { data })
4622
3.07k
    }
4623
}
4624
4625
/// The fields at the start of the table, which are read directly.
4626
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4627
#[repr(C, packed)]
4628
#[doc(hidden)]
4629
pub struct PaintVarScaleUniformFixedHeader {
4630
    pub format: u8,
4631
    pub paint_offset: BigEndian<Offset24>,
4632
    pub scale: BigEndian<F2Dot14>,
4633
    pub var_index_base: BigEndian<u32>,
4634
}
4635
4636
#[allow(clippy::absurd_extreme_comparisons)]
4637
const _: () = assert!(
4638
    std::mem::size_of::<PaintVarScaleUniformFixedHeader>() <= PaintVarScaleUniform::MIN_SIZE
4639
);
4640
4641
/// [PaintVarScaleUniform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table
4642
#[derive(Clone)]
4643
pub struct PaintVarScaleUniform<'a> {
4644
    data: TableDataRef<'a, PaintVarScaleUniformFixedHeader>,
4645
}
4646
4647
#[allow(clippy::needless_lifetimes)]
4648
impl<'a> PaintVarScaleUniform<'a> {
4649
    pub const MIN_SIZE: usize =
4650
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
4651
    basic_table_impls!(impl_the_methods);
4652
4653
    /// Set to 21.
4654
0
    pub fn format(&self) -> u8 {
4655
0
        self.data.header().format
4656
0
    }
4657
4658
    /// Offset to a Paint subtable.
4659
2.61k
    pub fn paint_offset(&self) -> Offset24 {
4660
2.61k
        self.data.header().paint_offset.get()
4661
2.61k
    }
4662
4663
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4664
2.61k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4665
2.61k
        let data = self.offset_data();
4666
2.61k
        self.paint_offset().resolve(data)
4667
2.61k
    }
4668
4669
    /// Scale factor in x and y directions. For variation, use
4670
    /// varIndexBase + 0.
4671
2.61k
    pub fn scale(&self) -> F2Dot14 {
4672
2.61k
        self.data.header().scale.get()
4673
2.61k
    }
4674
4675
    /// Base index into DeltaSetIndexMap.
4676
2.61k
    pub fn var_index_base(&self) -> u32 {
4677
2.61k
        self.data.header().var_index_base.get()
4678
2.61k
    }
4679
4680
0
    pub fn format_byte_range(&self) -> Range<usize> {
4681
0
        let start = 0usize;
4682
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4683
0
        start..end
4684
0
    }
4685
4686
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4687
0
        let start = self.format_byte_range().end;
4688
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4689
0
        start..end
4690
0
    }
4691
4692
0
    pub fn scale_byte_range(&self) -> Range<usize> {
4693
0
        let start = self.paint_offset_byte_range().end;
4694
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4695
0
        start..end
4696
0
    }
4697
4698
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
4699
0
        let start = self.scale_byte_range().end;
4700
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4701
0
        start..end
4702
0
    }
4703
}
4704
4705
impl Format<u8> for PaintScaleUniformAroundCenter<'_> {
4706
    const FORMAT: u8 = 22;
4707
}
4708
4709
impl<'a> MinByteRange<'a> for PaintScaleUniformAroundCenter<'a> {
4710
0
    fn min_byte_range(&self) -> Range<usize> {
4711
0
        0..self.center_y_byte_range().end
4712
0
    }
4713
0
    fn min_table_bytes(&self) -> &'a [u8] {
4714
0
        let range = self.min_byte_range();
4715
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4716
0
    }
4717
}
4718
4719
impl ReadArgs for PaintScaleUniformAroundCenter<'_> {
4720
    type Args = ();
4721
}
4722
4723
impl<'a> FontRead<'a> for PaintScaleUniformAroundCenter<'a> {
4724
2.22k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4725
        #[allow(clippy::absurd_extreme_comparisons)]
4726
2.22k
        if data.len() < Self::MIN_SIZE {
4727
714
            return Err(ReadError::OutOfBounds);
4728
1.51k
        }
4729
1.51k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4730
0
            return Err(ReadError::OutOfBounds);
4731
        };
4732
1.51k
        Ok(Self { data })
4733
2.22k
    }
4734
}
4735
4736
/// The fields at the start of the table, which are read directly.
4737
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4738
#[repr(C, packed)]
4739
#[doc(hidden)]
4740
pub struct PaintScaleUniformAroundCenterFixedHeader {
4741
    pub format: u8,
4742
    pub paint_offset: BigEndian<Offset24>,
4743
    pub scale: BigEndian<F2Dot14>,
4744
    pub center_x: BigEndian<FWord>,
4745
    pub center_y: BigEndian<FWord>,
4746
}
4747
4748
#[allow(clippy::absurd_extreme_comparisons)]
4749
const _: () = assert!(
4750
    std::mem::size_of::<PaintScaleUniformAroundCenterFixedHeader>()
4751
        <= PaintScaleUniformAroundCenter::MIN_SIZE
4752
);
4753
4754
/// [PaintScaleUniformAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table
4755
#[derive(Clone)]
4756
pub struct PaintScaleUniformAroundCenter<'a> {
4757
    data: TableDataRef<'a, PaintScaleUniformAroundCenterFixedHeader>,
4758
}
4759
4760
#[allow(clippy::needless_lifetimes)]
4761
impl<'a> PaintScaleUniformAroundCenter<'a> {
4762
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
4763
        + Offset24::RAW_BYTE_LEN
4764
        + F2Dot14::RAW_BYTE_LEN
4765
        + FWord::RAW_BYTE_LEN
4766
        + FWord::RAW_BYTE_LEN);
4767
    basic_table_impls!(impl_the_methods);
4768
4769
    /// Set to 22.
4770
0
    pub fn format(&self) -> u8 {
4771
0
        self.data.header().format
4772
0
    }
4773
4774
    /// Offset to a Paint subtable.
4775
1.50k
    pub fn paint_offset(&self) -> Offset24 {
4776
1.50k
        self.data.header().paint_offset.get()
4777
1.50k
    }
4778
4779
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4780
1.50k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4781
1.50k
        let data = self.offset_data();
4782
1.50k
        self.paint_offset().resolve(data)
4783
1.50k
    }
4784
4785
    /// Scale factor in x and y directions.
4786
1.50k
    pub fn scale(&self) -> F2Dot14 {
4787
1.50k
        self.data.header().scale.get()
4788
1.50k
    }
4789
4790
    /// x coordinate for the center of scaling.
4791
1.50k
    pub fn center_x(&self) -> FWord {
4792
1.50k
        self.data.header().center_x.get()
4793
1.50k
    }
4794
4795
    /// y coordinate for the center of scaling.
4796
1.50k
    pub fn center_y(&self) -> FWord {
4797
1.50k
        self.data.header().center_y.get()
4798
1.50k
    }
4799
4800
0
    pub fn format_byte_range(&self) -> Range<usize> {
4801
0
        let start = 0usize;
4802
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4803
0
        start..end
4804
0
    }
4805
4806
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4807
0
        let start = self.format_byte_range().end;
4808
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4809
0
        start..end
4810
0
    }
4811
4812
0
    pub fn scale_byte_range(&self) -> Range<usize> {
4813
0
        let start = self.paint_offset_byte_range().end;
4814
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4815
0
        start..end
4816
0
    }
4817
4818
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
4819
0
        let start = self.scale_byte_range().end;
4820
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4821
0
        start..end
4822
0
    }
4823
4824
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
4825
0
        let start = self.center_x_byte_range().end;
4826
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4827
0
        start..end
4828
0
    }
4829
}
4830
4831
impl Format<u8> for PaintVarScaleUniformAroundCenter<'_> {
4832
    const FORMAT: u8 = 23;
4833
}
4834
4835
impl<'a> MinByteRange<'a> for PaintVarScaleUniformAroundCenter<'a> {
4836
0
    fn min_byte_range(&self) -> Range<usize> {
4837
0
        0..self.var_index_base_byte_range().end
4838
0
    }
4839
0
    fn min_table_bytes(&self) -> &'a [u8] {
4840
0
        let range = self.min_byte_range();
4841
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4842
0
    }
4843
}
4844
4845
impl ReadArgs for PaintVarScaleUniformAroundCenter<'_> {
4846
    type Args = ();
4847
}
4848
4849
impl<'a> FontRead<'a> for PaintVarScaleUniformAroundCenter<'a> {
4850
2.41k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4851
        #[allow(clippy::absurd_extreme_comparisons)]
4852
2.41k
        if data.len() < Self::MIN_SIZE {
4853
716
            return Err(ReadError::OutOfBounds);
4854
1.69k
        }
4855
1.69k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4856
0
            return Err(ReadError::OutOfBounds);
4857
        };
4858
1.69k
        Ok(Self { data })
4859
2.41k
    }
4860
}
4861
4862
/// The fields at the start of the table, which are read directly.
4863
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
4864
#[repr(C, packed)]
4865
#[doc(hidden)]
4866
pub struct PaintVarScaleUniformAroundCenterFixedHeader {
4867
    pub format: u8,
4868
    pub paint_offset: BigEndian<Offset24>,
4869
    pub scale: BigEndian<F2Dot14>,
4870
    pub center_x: BigEndian<FWord>,
4871
    pub center_y: BigEndian<FWord>,
4872
    pub var_index_base: BigEndian<u32>,
4873
}
4874
4875
#[allow(clippy::absurd_extreme_comparisons)]
4876
const _: () = assert!(
4877
    std::mem::size_of::<PaintVarScaleUniformAroundCenterFixedHeader>()
4878
        <= PaintVarScaleUniformAroundCenter::MIN_SIZE
4879
);
4880
4881
/// [PaintVarScaleUniformAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table
4882
#[derive(Clone)]
4883
pub struct PaintVarScaleUniformAroundCenter<'a> {
4884
    data: TableDataRef<'a, PaintVarScaleUniformAroundCenterFixedHeader>,
4885
}
4886
4887
#[allow(clippy::needless_lifetimes)]
4888
impl<'a> PaintVarScaleUniformAroundCenter<'a> {
4889
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
4890
        + Offset24::RAW_BYTE_LEN
4891
        + F2Dot14::RAW_BYTE_LEN
4892
        + FWord::RAW_BYTE_LEN
4893
        + FWord::RAW_BYTE_LEN
4894
        + u32::RAW_BYTE_LEN);
4895
    basic_table_impls!(impl_the_methods);
4896
4897
    /// Set to 23.
4898
0
    pub fn format(&self) -> u8 {
4899
0
        self.data.header().format
4900
0
    }
4901
4902
    /// Offset to a Paint subtable.
4903
1.69k
    pub fn paint_offset(&self) -> Offset24 {
4904
1.69k
        self.data.header().paint_offset.get()
4905
1.69k
    }
4906
4907
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4908
1.69k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4909
1.69k
        let data = self.offset_data();
4910
1.69k
        self.paint_offset().resolve(data)
4911
1.69k
    }
4912
4913
    /// Scale factor in x and y directions. For variation, use
4914
    /// varIndexBase + 0.
4915
1.69k
    pub fn scale(&self) -> F2Dot14 {
4916
1.69k
        self.data.header().scale.get()
4917
1.69k
    }
4918
4919
    /// x coordinate for the center of scaling. For variation, use
4920
    /// varIndexBase + 1.
4921
1.69k
    pub fn center_x(&self) -> FWord {
4922
1.69k
        self.data.header().center_x.get()
4923
1.69k
    }
4924
4925
    /// y coordinate for the center of scaling. For variation, use
4926
    /// varIndexBase + 2.
4927
1.69k
    pub fn center_y(&self) -> FWord {
4928
1.69k
        self.data.header().center_y.get()
4929
1.69k
    }
4930
4931
    /// Base index into DeltaSetIndexMap.
4932
1.69k
    pub fn var_index_base(&self) -> u32 {
4933
1.69k
        self.data.header().var_index_base.get()
4934
1.69k
    }
4935
4936
0
    pub fn format_byte_range(&self) -> Range<usize> {
4937
0
        let start = 0usize;
4938
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4939
0
        start..end
4940
0
    }
4941
4942
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4943
0
        let start = self.format_byte_range().end;
4944
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4945
0
        start..end
4946
0
    }
4947
4948
0
    pub fn scale_byte_range(&self) -> Range<usize> {
4949
0
        let start = self.paint_offset_byte_range().end;
4950
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4951
0
        start..end
4952
0
    }
4953
4954
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
4955
0
        let start = self.scale_byte_range().end;
4956
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4957
0
        start..end
4958
0
    }
4959
4960
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
4961
0
        let start = self.center_x_byte_range().end;
4962
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4963
0
        start..end
4964
0
    }
4965
4966
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
4967
0
        let start = self.center_y_byte_range().end;
4968
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4969
0
        start..end
4970
0
    }
4971
}
4972
4973
impl Format<u8> for PaintRotate<'_> {
4974
    const FORMAT: u8 = 24;
4975
}
4976
4977
impl<'a> MinByteRange<'a> for PaintRotate<'a> {
4978
0
    fn min_byte_range(&self) -> Range<usize> {
4979
0
        0..self.angle_byte_range().end
4980
0
    }
4981
0
    fn min_table_bytes(&self) -> &'a [u8] {
4982
0
        let range = self.min_byte_range();
4983
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4984
0
    }
4985
}
4986
4987
impl ReadArgs for PaintRotate<'_> {
4988
    type Args = ();
4989
}
4990
4991
impl<'a> FontRead<'a> for PaintRotate<'a> {
4992
3.36k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4993
        #[allow(clippy::absurd_extreme_comparisons)]
4994
3.36k
        if data.len() < Self::MIN_SIZE {
4995
681
            return Err(ReadError::OutOfBounds);
4996
2.68k
        }
4997
2.68k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4998
0
            return Err(ReadError::OutOfBounds);
4999
        };
5000
2.68k
        Ok(Self { data })
5001
3.36k
    }
5002
}
5003
5004
/// The fields at the start of the table, which are read directly.
5005
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5006
#[repr(C, packed)]
5007
#[doc(hidden)]
5008
pub struct PaintRotateFixedHeader {
5009
    pub format: u8,
5010
    pub paint_offset: BigEndian<Offset24>,
5011
    pub angle: BigEndian<F2Dot14>,
5012
}
5013
5014
#[allow(clippy::absurd_extreme_comparisons)]
5015
const _: () = assert!(std::mem::size_of::<PaintRotateFixedHeader>() <= PaintRotate::MIN_SIZE);
5016
5017
/// [PaintRotate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table
5018
#[derive(Clone)]
5019
pub struct PaintRotate<'a> {
5020
    data: TableDataRef<'a, PaintRotateFixedHeader>,
5021
}
5022
5023
#[allow(clippy::needless_lifetimes)]
5024
impl<'a> PaintRotate<'a> {
5025
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN);
5026
    basic_table_impls!(impl_the_methods);
5027
5028
    /// Set to 24.
5029
0
    pub fn format(&self) -> u8 {
5030
0
        self.data.header().format
5031
0
    }
5032
5033
    /// Offset to a Paint subtable.
5034
2.68k
    pub fn paint_offset(&self) -> Offset24 {
5035
2.68k
        self.data.header().paint_offset.get()
5036
2.68k
    }
5037
5038
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5039
2.68k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5040
2.68k
        let data = self.offset_data();
5041
2.68k
        self.paint_offset().resolve(data)
5042
2.68k
    }
5043
5044
    /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of
5045
    /// value.
5046
2.68k
    pub fn angle(&self) -> F2Dot14 {
5047
2.68k
        self.data.header().angle.get()
5048
2.68k
    }
5049
5050
0
    pub fn format_byte_range(&self) -> Range<usize> {
5051
0
        let start = 0usize;
5052
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5053
0
        start..end
5054
0
    }
5055
5056
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5057
0
        let start = self.format_byte_range().end;
5058
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5059
0
        start..end
5060
0
    }
5061
5062
0
    pub fn angle_byte_range(&self) -> Range<usize> {
5063
0
        let start = self.paint_offset_byte_range().end;
5064
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5065
0
        start..end
5066
0
    }
5067
}
5068
5069
impl Format<u8> for PaintVarRotate<'_> {
5070
    const FORMAT: u8 = 25;
5071
}
5072
5073
impl<'a> MinByteRange<'a> for PaintVarRotate<'a> {
5074
0
    fn min_byte_range(&self) -> Range<usize> {
5075
0
        0..self.var_index_base_byte_range().end
5076
0
    }
5077
0
    fn min_table_bytes(&self) -> &'a [u8] {
5078
0
        let range = self.min_byte_range();
5079
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5080
0
    }
5081
}
5082
5083
impl ReadArgs for PaintVarRotate<'_> {
5084
    type Args = ();
5085
}
5086
5087
impl<'a> FontRead<'a> for PaintVarRotate<'a> {
5088
2.26k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5089
        #[allow(clippy::absurd_extreme_comparisons)]
5090
2.26k
        if data.len() < Self::MIN_SIZE {
5091
711
            return Err(ReadError::OutOfBounds);
5092
1.55k
        }
5093
1.55k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5094
0
            return Err(ReadError::OutOfBounds);
5095
        };
5096
1.55k
        Ok(Self { data })
5097
2.26k
    }
5098
}
5099
5100
/// The fields at the start of the table, which are read directly.
5101
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5102
#[repr(C, packed)]
5103
#[doc(hidden)]
5104
pub struct PaintVarRotateFixedHeader {
5105
    pub format: u8,
5106
    pub paint_offset: BigEndian<Offset24>,
5107
    pub angle: BigEndian<F2Dot14>,
5108
    pub var_index_base: BigEndian<u32>,
5109
}
5110
5111
#[allow(clippy::absurd_extreme_comparisons)]
5112
const _: () = assert!(std::mem::size_of::<PaintVarRotateFixedHeader>() <= PaintVarRotate::MIN_SIZE);
5113
5114
/// [PaintVarRotate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table
5115
#[derive(Clone)]
5116
pub struct PaintVarRotate<'a> {
5117
    data: TableDataRef<'a, PaintVarRotateFixedHeader>,
5118
}
5119
5120
#[allow(clippy::needless_lifetimes)]
5121
impl<'a> PaintVarRotate<'a> {
5122
    pub const MIN_SIZE: usize =
5123
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
5124
    basic_table_impls!(impl_the_methods);
5125
5126
    /// Set to 25.
5127
0
    pub fn format(&self) -> u8 {
5128
0
        self.data.header().format
5129
0
    }
5130
5131
    /// Offset to a Paint subtable.
5132
1.55k
    pub fn paint_offset(&self) -> Offset24 {
5133
1.55k
        self.data.header().paint_offset.get()
5134
1.55k
    }
5135
5136
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5137
1.55k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5138
1.55k
        let data = self.offset_data();
5139
1.55k
        self.paint_offset().resolve(data)
5140
1.55k
    }
5141
5142
    /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of
5143
    /// value. For variation, use varIndexBase + 0.
5144
1.55k
    pub fn angle(&self) -> F2Dot14 {
5145
1.55k
        self.data.header().angle.get()
5146
1.55k
    }
5147
5148
    /// Base index into DeltaSetIndexMap.
5149
1.55k
    pub fn var_index_base(&self) -> u32 {
5150
1.55k
        self.data.header().var_index_base.get()
5151
1.55k
    }
5152
5153
0
    pub fn format_byte_range(&self) -> Range<usize> {
5154
0
        let start = 0usize;
5155
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5156
0
        start..end
5157
0
    }
5158
5159
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5160
0
        let start = self.format_byte_range().end;
5161
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5162
0
        start..end
5163
0
    }
5164
5165
0
    pub fn angle_byte_range(&self) -> Range<usize> {
5166
0
        let start = self.paint_offset_byte_range().end;
5167
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5168
0
        start..end
5169
0
    }
5170
5171
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
5172
0
        let start = self.angle_byte_range().end;
5173
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5174
0
        start..end
5175
0
    }
5176
}
5177
5178
impl Format<u8> for PaintRotateAroundCenter<'_> {
5179
    const FORMAT: u8 = 26;
5180
}
5181
5182
impl<'a> MinByteRange<'a> for PaintRotateAroundCenter<'a> {
5183
0
    fn min_byte_range(&self) -> Range<usize> {
5184
0
        0..self.center_y_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 PaintRotateAroundCenter<'_> {
5193
    type Args = ();
5194
}
5195
5196
impl<'a> FontRead<'a> for PaintRotateAroundCenter<'a> {
5197
2.70k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5198
        #[allow(clippy::absurd_extreme_comparisons)]
5199
2.70k
        if data.len() < Self::MIN_SIZE {
5200
457
            return Err(ReadError::OutOfBounds);
5201
2.24k
        }
5202
2.24k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5203
0
            return Err(ReadError::OutOfBounds);
5204
        };
5205
2.24k
        Ok(Self { data })
5206
2.70k
    }
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 PaintRotateAroundCenterFixedHeader {
5214
    pub format: u8,
5215
    pub paint_offset: BigEndian<Offset24>,
5216
    pub angle: BigEndian<F2Dot14>,
5217
    pub center_x: BigEndian<FWord>,
5218
    pub center_y: BigEndian<FWord>,
5219
}
5220
5221
#[allow(clippy::absurd_extreme_comparisons)]
5222
const _: () = assert!(
5223
    std::mem::size_of::<PaintRotateAroundCenterFixedHeader>() <= PaintRotateAroundCenter::MIN_SIZE
5224
);
5225
5226
/// [PaintRotateAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table
5227
#[derive(Clone)]
5228
pub struct PaintRotateAroundCenter<'a> {
5229
    data: TableDataRef<'a, PaintRotateAroundCenterFixedHeader>,
5230
}
5231
5232
#[allow(clippy::needless_lifetimes)]
5233
impl<'a> PaintRotateAroundCenter<'a> {
5234
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
5235
        + Offset24::RAW_BYTE_LEN
5236
        + F2Dot14::RAW_BYTE_LEN
5237
        + FWord::RAW_BYTE_LEN
5238
        + FWord::RAW_BYTE_LEN);
5239
    basic_table_impls!(impl_the_methods);
5240
5241
    /// Set to 26.
5242
0
    pub fn format(&self) -> u8 {
5243
0
        self.data.header().format
5244
0
    }
5245
5246
    /// Offset to a Paint subtable.
5247
2.24k
    pub fn paint_offset(&self) -> Offset24 {
5248
2.24k
        self.data.header().paint_offset.get()
5249
2.24k
    }
5250
5251
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5252
2.24k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5253
2.24k
        let data = self.offset_data();
5254
2.24k
        self.paint_offset().resolve(data)
5255
2.24k
    }
5256
5257
    /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of
5258
    /// value.
5259
2.24k
    pub fn angle(&self) -> F2Dot14 {
5260
2.24k
        self.data.header().angle.get()
5261
2.24k
    }
5262
5263
    /// x coordinate for the center of rotation.
5264
2.24k
    pub fn center_x(&self) -> FWord {
5265
2.24k
        self.data.header().center_x.get()
5266
2.24k
    }
5267
5268
    /// y coordinate for the center of rotation.
5269
2.24k
    pub fn center_y(&self) -> FWord {
5270
2.24k
        self.data.header().center_y.get()
5271
2.24k
    }
5272
5273
0
    pub fn format_byte_range(&self) -> Range<usize> {
5274
0
        let start = 0usize;
5275
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5276
0
        start..end
5277
0
    }
5278
5279
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5280
0
        let start = self.format_byte_range().end;
5281
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5282
0
        start..end
5283
0
    }
5284
5285
0
    pub fn angle_byte_range(&self) -> Range<usize> {
5286
0
        let start = self.paint_offset_byte_range().end;
5287
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5288
0
        start..end
5289
0
    }
5290
5291
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
5292
0
        let start = self.angle_byte_range().end;
5293
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5294
0
        start..end
5295
0
    }
5296
5297
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
5298
0
        let start = self.center_x_byte_range().end;
5299
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5300
0
        start..end
5301
0
    }
5302
}
5303
5304
impl Format<u8> for PaintVarRotateAroundCenter<'_> {
5305
    const FORMAT: u8 = 27;
5306
}
5307
5308
impl<'a> MinByteRange<'a> for PaintVarRotateAroundCenter<'a> {
5309
0
    fn min_byte_range(&self) -> Range<usize> {
5310
0
        0..self.var_index_base_byte_range().end
5311
0
    }
5312
0
    fn min_table_bytes(&self) -> &'a [u8] {
5313
0
        let range = self.min_byte_range();
5314
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5315
0
    }
5316
}
5317
5318
impl ReadArgs for PaintVarRotateAroundCenter<'_> {
5319
    type Args = ();
5320
}
5321
5322
impl<'a> FontRead<'a> for PaintVarRotateAroundCenter<'a> {
5323
2.82k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5324
        #[allow(clippy::absurd_extreme_comparisons)]
5325
2.82k
        if data.len() < Self::MIN_SIZE {
5326
711
            return Err(ReadError::OutOfBounds);
5327
2.11k
        }
5328
2.11k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5329
0
            return Err(ReadError::OutOfBounds);
5330
        };
5331
2.11k
        Ok(Self { data })
5332
2.82k
    }
5333
}
5334
5335
/// The fields at the start of the table, which are read directly.
5336
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5337
#[repr(C, packed)]
5338
#[doc(hidden)]
5339
pub struct PaintVarRotateAroundCenterFixedHeader {
5340
    pub format: u8,
5341
    pub paint_offset: BigEndian<Offset24>,
5342
    pub angle: BigEndian<F2Dot14>,
5343
    pub center_x: BigEndian<FWord>,
5344
    pub center_y: BigEndian<FWord>,
5345
    pub var_index_base: BigEndian<u32>,
5346
}
5347
5348
#[allow(clippy::absurd_extreme_comparisons)]
5349
const _: () = assert!(
5350
    std::mem::size_of::<PaintVarRotateAroundCenterFixedHeader>()
5351
        <= PaintVarRotateAroundCenter::MIN_SIZE
5352
);
5353
5354
/// [PaintVarRotateAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table
5355
#[derive(Clone)]
5356
pub struct PaintVarRotateAroundCenter<'a> {
5357
    data: TableDataRef<'a, PaintVarRotateAroundCenterFixedHeader>,
5358
}
5359
5360
#[allow(clippy::needless_lifetimes)]
5361
impl<'a> PaintVarRotateAroundCenter<'a> {
5362
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
5363
        + Offset24::RAW_BYTE_LEN
5364
        + F2Dot14::RAW_BYTE_LEN
5365
        + FWord::RAW_BYTE_LEN
5366
        + FWord::RAW_BYTE_LEN
5367
        + u32::RAW_BYTE_LEN);
5368
    basic_table_impls!(impl_the_methods);
5369
5370
    /// Set to 27.
5371
0
    pub fn format(&self) -> u8 {
5372
0
        self.data.header().format
5373
0
    }
5374
5375
    /// Offset to a Paint subtable.
5376
2.11k
    pub fn paint_offset(&self) -> Offset24 {
5377
2.11k
        self.data.header().paint_offset.get()
5378
2.11k
    }
5379
5380
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5381
2.11k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5382
2.11k
        let data = self.offset_data();
5383
2.11k
        self.paint_offset().resolve(data)
5384
2.11k
    }
5385
5386
    /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of
5387
    /// value. For variation, use varIndexBase + 0.
5388
2.11k
    pub fn angle(&self) -> F2Dot14 {
5389
2.11k
        self.data.header().angle.get()
5390
2.11k
    }
5391
5392
    /// x coordinate for the center of rotation. For variation, use
5393
    /// varIndexBase + 1.
5394
2.11k
    pub fn center_x(&self) -> FWord {
5395
2.11k
        self.data.header().center_x.get()
5396
2.11k
    }
5397
5398
    /// y coordinate for the center of rotation. For variation, use
5399
    /// varIndexBase + 2.
5400
2.11k
    pub fn center_y(&self) -> FWord {
5401
2.11k
        self.data.header().center_y.get()
5402
2.11k
    }
5403
5404
    /// Base index into DeltaSetIndexMap.
5405
2.11k
    pub fn var_index_base(&self) -> u32 {
5406
2.11k
        self.data.header().var_index_base.get()
5407
2.11k
    }
5408
5409
0
    pub fn format_byte_range(&self) -> Range<usize> {
5410
0
        let start = 0usize;
5411
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5412
0
        start..end
5413
0
    }
5414
5415
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5416
0
        let start = self.format_byte_range().end;
5417
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5418
0
        start..end
5419
0
    }
5420
5421
0
    pub fn angle_byte_range(&self) -> Range<usize> {
5422
0
        let start = self.paint_offset_byte_range().end;
5423
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5424
0
        start..end
5425
0
    }
5426
5427
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
5428
0
        let start = self.angle_byte_range().end;
5429
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5430
0
        start..end
5431
0
    }
5432
5433
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
5434
0
        let start = self.center_x_byte_range().end;
5435
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5436
0
        start..end
5437
0
    }
5438
5439
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
5440
0
        let start = self.center_y_byte_range().end;
5441
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5442
0
        start..end
5443
0
    }
5444
}
5445
5446
impl Format<u8> for PaintSkew<'_> {
5447
    const FORMAT: u8 = 28;
5448
}
5449
5450
impl<'a> MinByteRange<'a> for PaintSkew<'a> {
5451
0
    fn min_byte_range(&self) -> Range<usize> {
5452
0
        0..self.y_skew_angle_byte_range().end
5453
0
    }
5454
0
    fn min_table_bytes(&self) -> &'a [u8] {
5455
0
        let range = self.min_byte_range();
5456
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5457
0
    }
5458
}
5459
5460
impl ReadArgs for PaintSkew<'_> {
5461
    type Args = ();
5462
}
5463
5464
impl<'a> FontRead<'a> for PaintSkew<'a> {
5465
3.06k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5466
        #[allow(clippy::absurd_extreme_comparisons)]
5467
3.06k
        if data.len() < Self::MIN_SIZE {
5468
712
            return Err(ReadError::OutOfBounds);
5469
2.34k
        }
5470
2.34k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5471
0
            return Err(ReadError::OutOfBounds);
5472
        };
5473
2.34k
        Ok(Self { data })
5474
3.06k
    }
5475
}
5476
5477
/// The fields at the start of the table, which are read directly.
5478
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5479
#[repr(C, packed)]
5480
#[doc(hidden)]
5481
pub struct PaintSkewFixedHeader {
5482
    pub format: u8,
5483
    pub paint_offset: BigEndian<Offset24>,
5484
    pub x_skew_angle: BigEndian<F2Dot14>,
5485
    pub y_skew_angle: BigEndian<F2Dot14>,
5486
}
5487
5488
#[allow(clippy::absurd_extreme_comparisons)]
5489
const _: () = assert!(std::mem::size_of::<PaintSkewFixedHeader>() <= PaintSkew::MIN_SIZE);
5490
5491
/// [PaintSkew](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table
5492
#[derive(Clone)]
5493
pub struct PaintSkew<'a> {
5494
    data: TableDataRef<'a, PaintSkewFixedHeader>,
5495
}
5496
5497
#[allow(clippy::needless_lifetimes)]
5498
impl<'a> PaintSkew<'a> {
5499
    pub const MIN_SIZE: usize =
5500
        (u8::RAW_BYTE_LEN + Offset24::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN);
5501
    basic_table_impls!(impl_the_methods);
5502
5503
    /// Set to 28.
5504
0
    pub fn format(&self) -> u8 {
5505
0
        self.data.header().format
5506
0
    }
5507
5508
    /// Offset to a Paint subtable.
5509
2.34k
    pub fn paint_offset(&self) -> Offset24 {
5510
2.34k
        self.data.header().paint_offset.get()
5511
2.34k
    }
5512
5513
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5514
2.34k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5515
2.34k
        let data = self.offset_data();
5516
2.34k
        self.paint_offset().resolve(data)
5517
2.34k
    }
5518
5519
    /// Angle of skew in the direction of the x-axis, 180° in
5520
    /// counter-clockwise degrees per 1.0 of value.
5521
2.34k
    pub fn x_skew_angle(&self) -> F2Dot14 {
5522
2.34k
        self.data.header().x_skew_angle.get()
5523
2.34k
    }
5524
5525
    /// Angle of skew in the direction of the y-axis, 180° in
5526
    /// counter-clockwise degrees per 1.0 of value.
5527
2.34k
    pub fn y_skew_angle(&self) -> F2Dot14 {
5528
2.34k
        self.data.header().y_skew_angle.get()
5529
2.34k
    }
5530
5531
0
    pub fn format_byte_range(&self) -> Range<usize> {
5532
0
        let start = 0usize;
5533
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5534
0
        start..end
5535
0
    }
5536
5537
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5538
0
        let start = self.format_byte_range().end;
5539
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5540
0
        start..end
5541
0
    }
5542
5543
0
    pub fn x_skew_angle_byte_range(&self) -> Range<usize> {
5544
0
        let start = self.paint_offset_byte_range().end;
5545
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5546
0
        start..end
5547
0
    }
5548
5549
0
    pub fn y_skew_angle_byte_range(&self) -> Range<usize> {
5550
0
        let start = self.x_skew_angle_byte_range().end;
5551
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5552
0
        start..end
5553
0
    }
5554
}
5555
5556
impl Format<u8> for PaintVarSkew<'_> {
5557
    const FORMAT: u8 = 29;
5558
}
5559
5560
impl<'a> MinByteRange<'a> for PaintVarSkew<'a> {
5561
0
    fn min_byte_range(&self) -> Range<usize> {
5562
0
        0..self.var_index_base_byte_range().end
5563
0
    }
5564
0
    fn min_table_bytes(&self) -> &'a [u8] {
5565
0
        let range = self.min_byte_range();
5566
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5567
0
    }
5568
}
5569
5570
impl ReadArgs for PaintVarSkew<'_> {
5571
    type Args = ();
5572
}
5573
5574
impl<'a> FontRead<'a> for PaintVarSkew<'a> {
5575
2.56k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5576
        #[allow(clippy::absurd_extreme_comparisons)]
5577
2.56k
        if data.len() < Self::MIN_SIZE {
5578
461
            return Err(ReadError::OutOfBounds);
5579
2.10k
        }
5580
2.10k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5581
0
            return Err(ReadError::OutOfBounds);
5582
        };
5583
2.10k
        Ok(Self { data })
5584
2.56k
    }
5585
}
5586
5587
/// The fields at the start of the table, which are read directly.
5588
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5589
#[repr(C, packed)]
5590
#[doc(hidden)]
5591
pub struct PaintVarSkewFixedHeader {
5592
    pub format: u8,
5593
    pub paint_offset: BigEndian<Offset24>,
5594
    pub x_skew_angle: BigEndian<F2Dot14>,
5595
    pub y_skew_angle: BigEndian<F2Dot14>,
5596
    pub var_index_base: BigEndian<u32>,
5597
}
5598
5599
#[allow(clippy::absurd_extreme_comparisons)]
5600
const _: () = assert!(std::mem::size_of::<PaintVarSkewFixedHeader>() <= PaintVarSkew::MIN_SIZE);
5601
5602
/// [PaintVarSkew](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table
5603
#[derive(Clone)]
5604
pub struct PaintVarSkew<'a> {
5605
    data: TableDataRef<'a, PaintVarSkewFixedHeader>,
5606
}
5607
5608
#[allow(clippy::needless_lifetimes)]
5609
impl<'a> PaintVarSkew<'a> {
5610
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
5611
        + Offset24::RAW_BYTE_LEN
5612
        + F2Dot14::RAW_BYTE_LEN
5613
        + F2Dot14::RAW_BYTE_LEN
5614
        + u32::RAW_BYTE_LEN);
5615
    basic_table_impls!(impl_the_methods);
5616
5617
    /// Set to 29.
5618
0
    pub fn format(&self) -> u8 {
5619
0
        self.data.header().format
5620
0
    }
5621
5622
    /// Offset to a Paint subtable.
5623
2.10k
    pub fn paint_offset(&self) -> Offset24 {
5624
2.10k
        self.data.header().paint_offset.get()
5625
2.10k
    }
5626
5627
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5628
2.10k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5629
2.10k
        let data = self.offset_data();
5630
2.10k
        self.paint_offset().resolve(data)
5631
2.10k
    }
5632
5633
    /// Angle of skew in the direction of the x-axis, 180° ┬░ in
5634
    /// counter-clockwise degrees per 1.0 of value. For variation, use
5635
    /// varIndexBase + 0.
5636
2.10k
    pub fn x_skew_angle(&self) -> F2Dot14 {
5637
2.10k
        self.data.header().x_skew_angle.get()
5638
2.10k
    }
5639
5640
    /// Angle of skew in the direction of the y-axis, 180° in
5641
    /// counter-clockwise degrees per 1.0 of value. For variation, use
5642
    /// varIndexBase + 1.
5643
2.10k
    pub fn y_skew_angle(&self) -> F2Dot14 {
5644
2.10k
        self.data.header().y_skew_angle.get()
5645
2.10k
    }
5646
5647
    /// Base index into DeltaSetIndexMap.
5648
2.10k
    pub fn var_index_base(&self) -> u32 {
5649
2.10k
        self.data.header().var_index_base.get()
5650
2.10k
    }
5651
5652
0
    pub fn format_byte_range(&self) -> Range<usize> {
5653
0
        let start = 0usize;
5654
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5655
0
        start..end
5656
0
    }
5657
5658
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5659
0
        let start = self.format_byte_range().end;
5660
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5661
0
        start..end
5662
0
    }
5663
5664
0
    pub fn x_skew_angle_byte_range(&self) -> Range<usize> {
5665
0
        let start = self.paint_offset_byte_range().end;
5666
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5667
0
        start..end
5668
0
    }
5669
5670
0
    pub fn y_skew_angle_byte_range(&self) -> Range<usize> {
5671
0
        let start = self.x_skew_angle_byte_range().end;
5672
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5673
0
        start..end
5674
0
    }
5675
5676
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
5677
0
        let start = self.y_skew_angle_byte_range().end;
5678
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5679
0
        start..end
5680
0
    }
5681
}
5682
5683
impl Format<u8> for PaintSkewAroundCenter<'_> {
5684
    const FORMAT: u8 = 30;
5685
}
5686
5687
impl<'a> MinByteRange<'a> for PaintSkewAroundCenter<'a> {
5688
0
    fn min_byte_range(&self) -> Range<usize> {
5689
0
        0..self.center_y_byte_range().end
5690
0
    }
5691
0
    fn min_table_bytes(&self) -> &'a [u8] {
5692
0
        let range = self.min_byte_range();
5693
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5694
0
    }
5695
}
5696
5697
impl ReadArgs for PaintSkewAroundCenter<'_> {
5698
    type Args = ();
5699
}
5700
5701
impl<'a> FontRead<'a> for PaintSkewAroundCenter<'a> {
5702
2.06k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5703
        #[allow(clippy::absurd_extreme_comparisons)]
5704
2.06k
        if data.len() < Self::MIN_SIZE {
5705
711
            return Err(ReadError::OutOfBounds);
5706
1.35k
        }
5707
1.35k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5708
0
            return Err(ReadError::OutOfBounds);
5709
        };
5710
1.35k
        Ok(Self { data })
5711
2.06k
    }
5712
}
5713
5714
/// The fields at the start of the table, which are read directly.
5715
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5716
#[repr(C, packed)]
5717
#[doc(hidden)]
5718
pub struct PaintSkewAroundCenterFixedHeader {
5719
    pub format: u8,
5720
    pub paint_offset: BigEndian<Offset24>,
5721
    pub x_skew_angle: BigEndian<F2Dot14>,
5722
    pub y_skew_angle: BigEndian<F2Dot14>,
5723
    pub center_x: BigEndian<FWord>,
5724
    pub center_y: BigEndian<FWord>,
5725
}
5726
5727
#[allow(clippy::absurd_extreme_comparisons)]
5728
const _: () = assert!(
5729
    std::mem::size_of::<PaintSkewAroundCenterFixedHeader>() <= PaintSkewAroundCenter::MIN_SIZE
5730
);
5731
5732
/// [PaintSkewAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table
5733
#[derive(Clone)]
5734
pub struct PaintSkewAroundCenter<'a> {
5735
    data: TableDataRef<'a, PaintSkewAroundCenterFixedHeader>,
5736
}
5737
5738
#[allow(clippy::needless_lifetimes)]
5739
impl<'a> PaintSkewAroundCenter<'a> {
5740
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
5741
        + Offset24::RAW_BYTE_LEN
5742
        + F2Dot14::RAW_BYTE_LEN
5743
        + F2Dot14::RAW_BYTE_LEN
5744
        + FWord::RAW_BYTE_LEN
5745
        + FWord::RAW_BYTE_LEN);
5746
    basic_table_impls!(impl_the_methods);
5747
5748
    /// Set to 30.
5749
0
    pub fn format(&self) -> u8 {
5750
0
        self.data.header().format
5751
0
    }
5752
5753
    /// Offset to a Paint subtable.
5754
1.35k
    pub fn paint_offset(&self) -> Offset24 {
5755
1.35k
        self.data.header().paint_offset.get()
5756
1.35k
    }
5757
5758
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5759
1.35k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5760
1.35k
        let data = self.offset_data();
5761
1.35k
        self.paint_offset().resolve(data)
5762
1.35k
    }
5763
5764
    /// Angle of skew in the direction of the x-axis, 180° in
5765
    /// counter-clockwise degrees per 1.0 of value.
5766
1.35k
    pub fn x_skew_angle(&self) -> F2Dot14 {
5767
1.35k
        self.data.header().x_skew_angle.get()
5768
1.35k
    }
5769
5770
    /// Angle of skew in the direction of the y-axis, 180° in
5771
    /// counter-clockwise degrees per 1.0 of value.
5772
1.35k
    pub fn y_skew_angle(&self) -> F2Dot14 {
5773
1.35k
        self.data.header().y_skew_angle.get()
5774
1.35k
    }
5775
5776
    /// x coordinate for the center of rotation.
5777
1.35k
    pub fn center_x(&self) -> FWord {
5778
1.35k
        self.data.header().center_x.get()
5779
1.35k
    }
5780
5781
    /// y coordinate for the center of rotation.
5782
1.35k
    pub fn center_y(&self) -> FWord {
5783
1.35k
        self.data.header().center_y.get()
5784
1.35k
    }
5785
5786
0
    pub fn format_byte_range(&self) -> Range<usize> {
5787
0
        let start = 0usize;
5788
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5789
0
        start..end
5790
0
    }
5791
5792
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5793
0
        let start = self.format_byte_range().end;
5794
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5795
0
        start..end
5796
0
    }
5797
5798
0
    pub fn x_skew_angle_byte_range(&self) -> Range<usize> {
5799
0
        let start = self.paint_offset_byte_range().end;
5800
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5801
0
        start..end
5802
0
    }
5803
5804
0
    pub fn y_skew_angle_byte_range(&self) -> Range<usize> {
5805
0
        let start = self.x_skew_angle_byte_range().end;
5806
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5807
0
        start..end
5808
0
    }
5809
5810
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
5811
0
        let start = self.y_skew_angle_byte_range().end;
5812
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5813
0
        start..end
5814
0
    }
5815
5816
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
5817
0
        let start = self.center_x_byte_range().end;
5818
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5819
0
        start..end
5820
0
    }
5821
}
5822
5823
impl Format<u8> for PaintVarSkewAroundCenter<'_> {
5824
    const FORMAT: u8 = 31;
5825
}
5826
5827
impl<'a> MinByteRange<'a> for PaintVarSkewAroundCenter<'a> {
5828
0
    fn min_byte_range(&self) -> Range<usize> {
5829
0
        0..self.var_index_base_byte_range().end
5830
0
    }
5831
0
    fn min_table_bytes(&self) -> &'a [u8] {
5832
0
        let range = self.min_byte_range();
5833
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5834
0
    }
5835
}
5836
5837
impl ReadArgs for PaintVarSkewAroundCenter<'_> {
5838
    type Args = ();
5839
}
5840
5841
impl<'a> FontRead<'a> for PaintVarSkewAroundCenter<'a> {
5842
2.95k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5843
        #[allow(clippy::absurd_extreme_comparisons)]
5844
2.95k
        if data.len() < Self::MIN_SIZE {
5845
714
            return Err(ReadError::OutOfBounds);
5846
2.24k
        }
5847
2.24k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5848
0
            return Err(ReadError::OutOfBounds);
5849
        };
5850
2.24k
        Ok(Self { data })
5851
2.95k
    }
5852
}
5853
5854
/// The fields at the start of the table, which are read directly.
5855
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
5856
#[repr(C, packed)]
5857
#[doc(hidden)]
5858
pub struct PaintVarSkewAroundCenterFixedHeader {
5859
    pub format: u8,
5860
    pub paint_offset: BigEndian<Offset24>,
5861
    pub x_skew_angle: BigEndian<F2Dot14>,
5862
    pub y_skew_angle: BigEndian<F2Dot14>,
5863
    pub center_x: BigEndian<FWord>,
5864
    pub center_y: BigEndian<FWord>,
5865
    pub var_index_base: BigEndian<u32>,
5866
}
5867
5868
#[allow(clippy::absurd_extreme_comparisons)]
5869
const _: () = assert!(
5870
    std::mem::size_of::<PaintVarSkewAroundCenterFixedHeader>()
5871
        <= PaintVarSkewAroundCenter::MIN_SIZE
5872
);
5873
5874
/// [PaintVarSkewAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table
5875
#[derive(Clone)]
5876
pub struct PaintVarSkewAroundCenter<'a> {
5877
    data: TableDataRef<'a, PaintVarSkewAroundCenterFixedHeader>,
5878
}
5879
5880
#[allow(clippy::needless_lifetimes)]
5881
impl<'a> PaintVarSkewAroundCenter<'a> {
5882
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
5883
        + Offset24::RAW_BYTE_LEN
5884
        + F2Dot14::RAW_BYTE_LEN
5885
        + F2Dot14::RAW_BYTE_LEN
5886
        + FWord::RAW_BYTE_LEN
5887
        + FWord::RAW_BYTE_LEN
5888
        + u32::RAW_BYTE_LEN);
5889
    basic_table_impls!(impl_the_methods);
5890
5891
    /// Set to 31.
5892
0
    pub fn format(&self) -> u8 {
5893
0
        self.data.header().format
5894
0
    }
5895
5896
    /// Offset to a Paint subtable.
5897
2.24k
    pub fn paint_offset(&self) -> Offset24 {
5898
2.24k
        self.data.header().paint_offset.get()
5899
2.24k
    }
5900
5901
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5902
2.24k
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5903
2.24k
        let data = self.offset_data();
5904
2.24k
        self.paint_offset().resolve(data)
5905
2.24k
    }
5906
5907
    /// Angle of skew in the direction of the x-axis, 180° in
5908
    /// counter-clockwise degrees per 1.0 of value. For variation, use
5909
    /// varIndexBase + 0.
5910
2.24k
    pub fn x_skew_angle(&self) -> F2Dot14 {
5911
2.24k
        self.data.header().x_skew_angle.get()
5912
2.24k
    }
5913
5914
    /// Angle of skew in the direction of the y-axis, 180° in
5915
    /// counter-clockwise degrees per 1.0 of value. For variation, use
5916
    /// varIndexBase + 1.
5917
2.24k
    pub fn y_skew_angle(&self) -> F2Dot14 {
5918
2.24k
        self.data.header().y_skew_angle.get()
5919
2.24k
    }
5920
5921
    /// x coordinate for the center of rotation. For variation, use
5922
    /// varIndexBase + 2.
5923
2.24k
    pub fn center_x(&self) -> FWord {
5924
2.24k
        self.data.header().center_x.get()
5925
2.24k
    }
5926
5927
    /// y coordinate for the center of rotation. For variation, use
5928
    /// varIndexBase + 3.
5929
2.24k
    pub fn center_y(&self) -> FWord {
5930
2.24k
        self.data.header().center_y.get()
5931
2.24k
    }
5932
5933
    /// Base index into DeltaSetIndexMap.
5934
2.24k
    pub fn var_index_base(&self) -> u32 {
5935
2.24k
        self.data.header().var_index_base.get()
5936
2.24k
    }
5937
5938
0
    pub fn format_byte_range(&self) -> Range<usize> {
5939
0
        let start = 0usize;
5940
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5941
0
        start..end
5942
0
    }
5943
5944
0
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5945
0
        let start = self.format_byte_range().end;
5946
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5947
0
        start..end
5948
0
    }
5949
5950
0
    pub fn x_skew_angle_byte_range(&self) -> Range<usize> {
5951
0
        let start = self.paint_offset_byte_range().end;
5952
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5953
0
        start..end
5954
0
    }
5955
5956
0
    pub fn y_skew_angle_byte_range(&self) -> Range<usize> {
5957
0
        let start = self.x_skew_angle_byte_range().end;
5958
0
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5959
0
        start..end
5960
0
    }
5961
5962
0
    pub fn center_x_byte_range(&self) -> Range<usize> {
5963
0
        let start = self.y_skew_angle_byte_range().end;
5964
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5965
0
        start..end
5966
0
    }
5967
5968
0
    pub fn center_y_byte_range(&self) -> Range<usize> {
5969
0
        let start = self.center_x_byte_range().end;
5970
0
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5971
0
        start..end
5972
0
    }
5973
5974
0
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
5975
0
        let start = self.center_y_byte_range().end;
5976
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5977
0
        start..end
5978
0
    }
5979
}
5980
5981
impl Format<u8> for PaintComposite<'_> {
5982
    const FORMAT: u8 = 32;
5983
}
5984
5985
impl<'a> MinByteRange<'a> for PaintComposite<'a> {
5986
0
    fn min_byte_range(&self) -> Range<usize> {
5987
0
        0..self.backdrop_paint_offset_byte_range().end
5988
0
    }
5989
0
    fn min_table_bytes(&self) -> &'a [u8] {
5990
0
        let range = self.min_byte_range();
5991
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5992
0
    }
5993
}
5994
5995
impl ReadArgs for PaintComposite<'_> {
5996
    type Args = ();
5997
}
5998
5999
impl<'a> FontRead<'a> for PaintComposite<'a> {
6000
37.1k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6001
        #[allow(clippy::absurd_extreme_comparisons)]
6002
37.1k
        if data.len() < Self::MIN_SIZE {
6003
463
            return Err(ReadError::OutOfBounds);
6004
36.7k
        }
6005
36.7k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6006
0
            return Err(ReadError::OutOfBounds);
6007
        };
6008
36.7k
        Ok(Self { data })
6009
37.1k
    }
6010
}
6011
6012
/// The fields at the start of the table, which are read directly.
6013
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
6014
#[repr(C, packed)]
6015
#[doc(hidden)]
6016
pub struct PaintCompositeFixedHeader {
6017
    pub format: u8,
6018
    pub source_paint_offset: BigEndian<Offset24>,
6019
    pub composite_mode: BigEndian<CompositeMode>,
6020
    pub backdrop_paint_offset: BigEndian<Offset24>,
6021
}
6022
6023
#[allow(clippy::absurd_extreme_comparisons)]
6024
const _: () = assert!(std::mem::size_of::<PaintCompositeFixedHeader>() <= PaintComposite::MIN_SIZE);
6025
6026
/// [PaintComposite](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite) table
6027
#[derive(Clone)]
6028
pub struct PaintComposite<'a> {
6029
    data: TableDataRef<'a, PaintCompositeFixedHeader>,
6030
}
6031
6032
#[allow(clippy::needless_lifetimes)]
6033
impl<'a> PaintComposite<'a> {
6034
    pub const MIN_SIZE: usize = (u8::RAW_BYTE_LEN
6035
        + Offset24::RAW_BYTE_LEN
6036
        + CompositeMode::RAW_BYTE_LEN
6037
        + Offset24::RAW_BYTE_LEN);
6038
    basic_table_impls!(impl_the_methods);
6039
6040
    /// Set to 32.
6041
0
    pub fn format(&self) -> u8 {
6042
0
        self.data.header().format
6043
0
    }
6044
6045
    /// Offset to a source Paint table.
6046
36.4k
    pub fn source_paint_offset(&self) -> Offset24 {
6047
36.4k
        self.data.header().source_paint_offset.get()
6048
36.4k
    }
6049
6050
    /// Attempt to resolve [`source_paint_offset`][Self::source_paint_offset].
6051
36.4k
    pub fn source_paint(&self) -> Result<Paint<'a>, ReadError> {
6052
36.4k
        let data = self.offset_data();
6053
36.4k
        self.source_paint_offset().resolve(data)
6054
36.4k
    }
6055
6056
    /// A CompositeMode enumeration value.
6057
32.4k
    pub fn composite_mode(&self) -> CompositeMode {
6058
32.4k
        self.data.header().composite_mode.get()
6059
32.4k
    }
6060
6061
    /// Offset to a backdrop Paint table.
6062
32.4k
    pub fn backdrop_paint_offset(&self) -> Offset24 {
6063
32.4k
        self.data.header().backdrop_paint_offset.get()
6064
32.4k
    }
6065
6066
    /// Attempt to resolve [`backdrop_paint_offset`][Self::backdrop_paint_offset].
6067
32.4k
    pub fn backdrop_paint(&self) -> Result<Paint<'a>, ReadError> {
6068
32.4k
        let data = self.offset_data();
6069
32.4k
        self.backdrop_paint_offset().resolve(data)
6070
32.4k
    }
6071
6072
0
    pub fn format_byte_range(&self) -> Range<usize> {
6073
0
        let start = 0usize;
6074
0
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
6075
0
        start..end
6076
0
    }
6077
6078
0
    pub fn source_paint_offset_byte_range(&self) -> Range<usize> {
6079
0
        let start = self.format_byte_range().end;
6080
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
6081
0
        start..end
6082
0
    }
6083
6084
0
    pub fn composite_mode_byte_range(&self) -> Range<usize> {
6085
0
        let start = self.source_paint_offset_byte_range().end;
6086
0
        let end = start.saturating_add(CompositeMode::RAW_BYTE_LEN);
6087
0
        start..end
6088
0
    }
6089
6090
0
    pub fn backdrop_paint_offset_byte_range(&self) -> Range<usize> {
6091
0
        let start = self.composite_mode_byte_range().end;
6092
0
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
6093
0
        start..end
6094
0
    }
6095
}
6096
6097
/// How a composite paint combines its source and backdrop paint graphs.
6098
///
6099
/// `Src` refers to the source; `Dest` refers to the backdrop (destination).
6100
/// Porter-Duff modes control their contributions using alpha coverage. Blend
6101
/// modes combine their colors, then use source-over compositing. Separable blend
6102
/// modes operate on each RGB component; the HSL modes combine hue, saturation,
6103
/// and luminosity from the two colors.
6104
///
6105
/// See the [OpenType specification](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite)
6106
/// and [Compositing and Blending Level 1](https://www.w3.org/TR/compositing-1/)
6107
/// for the compositing and blending formulas.
6108
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
6109
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6110
#[repr(u8)]
6111
#[allow(clippy::manual_non_exhaustive)]
6112
pub enum CompositeMode {
6113
    /// Produce transparent black, discarding both inputs.
6114
    Clear = 0,
6115
    /// Keep only the source.
6116
    Src = 1,
6117
    /// Keep only the backdrop.
6118
    Dest = 2,
6119
    /// Draw the source over the backdrop using ordinary alpha compositing.
6120
    #[default]
6121
    SrcOver = 3,
6122
    /// Draw the backdrop over the source using ordinary alpha compositing.
6123
    DestOver = 4,
6124
    /// Keep the source, masked by the backdrop's alpha.
6125
    SrcIn = 5,
6126
    /// Keep the backdrop, masked by the source's alpha.
6127
    DestIn = 6,
6128
    /// Keep the source, masked by the inverse of the backdrop's alpha.
6129
    SrcOut = 7,
6130
    /// Keep the backdrop, masked by the inverse of the source's alpha.
6131
    DestOut = 8,
6132
    /// Draw the source over the backdrop, retaining the backdrop's alpha coverage.
6133
    SrcAtop = 9,
6134
    /// Draw the backdrop over the source, retaining the source's alpha coverage.
6135
    DestAtop = 10,
6136
    /// Combine each input masked by the inverse of the other input's alpha.
6137
    Xor = 11,
6138
    /// Add the premultiplied colors and alpha values of both inputs.
6139
    Plus = 12,
6140
    /// Multiply the inverted color components, then invert the result.
6141
    Screen = 13,
6142
    /// Multiply or screen depending on the backdrop component's brightness.
6143
    Overlay = 14,
6144
    /// Select the smaller of each pair of color components.
6145
    Darken = 15,
6146
    /// Select the larger of each pair of color components.
6147
    Lighten = 16,
6148
    /// Brighten the backdrop according to the source, with black leaving it unchanged.
6149
    ColorDodge = 17,
6150
    /// Darken the backdrop according to the source, with white leaving it unchanged.
6151
    ColorBurn = 18,
6152
    /// Multiply or screen depending on the source component's brightness.
6153
    HardLight = 19,
6154
    /// Gently darken or brighten the backdrop according to the source.
6155
    SoftLight = 20,
6156
    /// Take the absolute difference between corresponding color components.
6157
    Difference = 21,
6158
    /// Produce an effect similar to difference, with lower contrast.
6159
    Exclusion = 22,
6160
    /// Multiply corresponding color components.
6161
    Multiply = 23,
6162
    /// Use the source hue with the backdrop saturation and luminosity.
6163
    HslHue = 24,
6164
    /// Use the source saturation with the backdrop hue and luminosity.
6165
    HslSaturation = 25,
6166
    /// Use the source hue and saturation with the backdrop luminosity.
6167
    HslColor = 26,
6168
    /// Use the source luminosity with the backdrop hue and saturation.
6169
    HslLuminosity = 27,
6170
    #[doc(hidden)]
6171
    /// If font data is malformed we will map unknown values to this variant
6172
    Unknown,
6173
}
6174
6175
impl CompositeMode {
6176
    /// Create from a raw scalar.
6177
    ///
6178
    /// This will never fail; unknown values will be mapped to the `Unknown` variant
6179
32.4k
    pub fn new(raw: u8) -> Self {
6180
32.4k
        match raw {
6181
2.42k
            0 => Self::Clear,
6182
232
            1 => Self::Src,
6183
258
            2 => Self::Dest,
6184
0
            3 => Self::SrcOver,
6185
0
            4 => Self::DestOver,
6186
384
            5 => Self::SrcIn,
6187
69
            6 => Self::DestIn,
6188
196
            7 => Self::SrcOut,
6189
851
            8 => Self::DestOut,
6190
0
            9 => Self::SrcAtop,
6191
0
            10 => Self::DestAtop,
6192
0
            11 => Self::Xor,
6193
0
            12 => Self::Plus,
6194
0
            13 => Self::Screen,
6195
0
            14 => Self::Overlay,
6196
0
            15 => Self::Darken,
6197
0
            16 => Self::Lighten,
6198
0
            17 => Self::ColorDodge,
6199
0
            18 => Self::ColorBurn,
6200
0
            19 => Self::HardLight,
6201
0
            20 => Self::SoftLight,
6202
0
            21 => Self::Difference,
6203
0
            22 => Self::Exclusion,
6204
0
            23 => Self::Multiply,
6205
3.02k
            24 => Self::HslHue,
6206
0
            25 => Self::HslSaturation,
6207
655
            26 => Self::HslColor,
6208
0
            27 => Self::HslLuminosity,
6209
24.3k
            _ => Self::Unknown,
6210
        }
6211
32.4k
    }
6212
}
6213
6214
impl font_types::Scalar for CompositeMode {
6215
    type Raw = <u8 as font_types::Scalar>::Raw;
6216
0
    fn to_raw(self) -> Self::Raw {
6217
0
        (self as u8).to_raw()
6218
0
    }
6219
32.4k
    fn from_raw(raw: Self::Raw) -> Self {
6220
32.4k
        let t = <u8>::from_raw(raw);
6221
32.4k
        Self::new(t)
6222
32.4k
    }
6223
}