Coverage Report

Created: 2026-11-11 07:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/read-fonts/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
    fn min_byte_range(&self) -> Range<usize> {
10
        0..self.num_layer_records_byte_range().end
11
    }
12
    fn min_table_bytes(&self) -> &'a [u8] {
13
        let range = self.min_byte_range();
14
        self.offset_data().as_bytes().get(range).unwrap_or_default()
15
    }
16
}
17
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
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
        if data.len() < Self::MIN_SIZE {
31
            return Err(ReadError::OutOfBounds);
32
        }
33
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
            return Err(ReadError::OutOfBounds);
35
        };
36
        Ok(Self { data })
37
    }
38
}
39
40
/// 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
    pub fn version(&self) -> u16 {
72
        self.data.header().version.get()
73
    }
74
75
    /// Number of BaseGlyph records; may be 0 in a version 1 table.
76
    pub fn num_base_glyph_records(&self) -> u16 {
77
        self.data.header().num_base_glyph_records.get()
78
    }
79
80
    /// Offset to baseGlyphRecords array (may be NULL).
81
    pub fn base_glyph_records_offset(&self) -> Nullable<Offset32> {
82
        self.data.header().base_glyph_records_offset.get()
83
    }
84
85
    /// Attempt to resolve [`base_glyph_records_offset`][Self::base_glyph_records_offset].
86
    pub fn base_glyph_records(&self) -> Option<Result<&'a [BaseGlyph], ReadError>> {
87
        let data = self.offset_data();
88
        let args = self.num_base_glyph_records();
89
        self.base_glyph_records_offset()
90
            .resolve_with_args(data, args)
91
    }
92
93
    /// Offset to layerRecords array (may be NULL).
94
    pub fn layer_records_offset(&self) -> Nullable<Offset32> {
95
        self.data.header().layer_records_offset.get()
96
    }
97
98
    /// Attempt to resolve [`layer_records_offset`][Self::layer_records_offset].
99
    pub fn layer_records(&self) -> Option<Result<&'a [Layer], ReadError>> {
100
        let data = self.offset_data();
101
        let args = self.num_layer_records();
102
        self.layer_records_offset().resolve_with_args(data, args)
103
    }
104
105
    /// Number of Layer records; may be 0 in a version 1 table.
106
    pub fn num_layer_records(&self) -> u16 {
107
        self.data.header().num_layer_records.get()
108
    }
109
110
    /// Offset to BaseGlyphList table.
111
    pub fn base_glyph_list_offset(&self) -> Option<Nullable<Offset32>> {
112
        let range = self.base_glyph_list_offset_byte_range();
113
        (!range.is_empty())
114
            .then(|| self.offset_data().read_at(range.start).ok())
115
            .flatten()
116
    }
117
118
    /// Attempt to resolve [`base_glyph_list_offset`][Self::base_glyph_list_offset].
119
    pub fn base_glyph_list(&self) -> Option<Result<BaseGlyphList<'a>, ReadError>> {
120
        let data = self.offset_data();
121
        self.base_glyph_list_offset().map(|x| x.resolve(data))?
122
    }
123
124
    /// Offset to LayerList table (may be NULL).
125
    pub fn layer_list_offset(&self) -> Option<Nullable<Offset32>> {
126
        let range = self.layer_list_offset_byte_range();
127
        (!range.is_empty())
128
            .then(|| self.offset_data().read_at(range.start).ok())
129
            .flatten()
130
    }
131
132
    /// Attempt to resolve [`layer_list_offset`][Self::layer_list_offset].
133
    pub fn layer_list(&self) -> Option<Result<LayerList<'a>, ReadError>> {
134
        let data = self.offset_data();
135
        self.layer_list_offset().map(|x| x.resolve(data))?
136
    }
137
138
    /// Offset to ClipList table (may be NULL).
139
    pub fn clip_list_offset(&self) -> Option<Nullable<Offset32>> {
140
        let range = self.clip_list_offset_byte_range();
141
        (!range.is_empty())
142
            .then(|| self.offset_data().read_at(range.start).ok())
143
            .flatten()
144
    }
145
146
    /// Attempt to resolve [`clip_list_offset`][Self::clip_list_offset].
147
    pub fn clip_list(&self) -> Option<Result<ClipList<'a>, ReadError>> {
148
        let data = self.offset_data();
149
        self.clip_list_offset().map(|x| x.resolve(data))?
150
    }
151
152
    /// Offset to DeltaSetIndexMap table (may be NULL).
153
    pub fn var_index_map_offset(&self) -> Option<Nullable<Offset32>> {
154
        let range = self.var_index_map_offset_byte_range();
155
        (!range.is_empty())
156
            .then(|| self.offset_data().read_at(range.start).ok())
157
            .flatten()
158
    }
159
160
    /// Attempt to resolve [`var_index_map_offset`][Self::var_index_map_offset].
161
    pub fn var_index_map(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
162
        let data = self.offset_data();
163
        self.var_index_map_offset().map(|x| x.resolve(data))?
164
    }
165
166
    /// Offset to ItemVariationStore (may be NULL).
167
    pub fn item_variation_store_offset(&self) -> Option<Nullable<Offset32>> {
168
        let range = self.item_variation_store_offset_byte_range();
169
        (!range.is_empty())
170
            .then(|| self.offset_data().read_at(range.start).ok())
171
            .flatten()
172
    }
173
174
    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
175
    pub fn item_variation_store(&self) -> Option<Result<ItemVariationStore<'a>, ReadError>> {
176
        let data = self.offset_data();
177
        self.item_variation_store_offset()
178
            .map(|x| x.resolve(data))?
179
    }
180
181
    pub fn version_byte_range(&self) -> Range<usize> {
182
        let start = 0usize;
183
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
184
        start..end
185
    }
186
187
    pub fn num_base_glyph_records_byte_range(&self) -> Range<usize> {
188
        let start = self.version_byte_range().end;
189
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
190
        start..end
191
    }
192
193
    pub fn base_glyph_records_offset_byte_range(&self) -> Range<usize> {
194
        let start = self.num_base_glyph_records_byte_range().end;
195
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
196
        start..end
197
    }
198
199
    pub fn layer_records_offset_byte_range(&self) -> Range<usize> {
200
        let start = self.base_glyph_records_offset_byte_range().end;
201
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
202
        start..end
203
    }
204
205
    pub fn num_layer_records_byte_range(&self) -> Range<usize> {
206
        let start = self.layer_records_offset_byte_range().end;
207
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
208
        start..end
209
    }
210
211
    pub fn base_glyph_list_offset_byte_range(&self) -> Range<usize> {
212
        let start = self.num_layer_records_byte_range().end;
213
        let end = if self.version().compatible(1u16) {
214
            start.saturating_add(Offset32::RAW_BYTE_LEN)
215
        } else {
216
            start
217
        };
218
        start..end
219
    }
220
221
    pub fn layer_list_offset_byte_range(&self) -> Range<usize> {
222
        let start = self.base_glyph_list_offset_byte_range().end;
223
        let end = if self.version().compatible(1u16) {
224
            start.saturating_add(Offset32::RAW_BYTE_LEN)
225
        } else {
226
            start
227
        };
228
        start..end
229
    }
230
231
    pub fn clip_list_offset_byte_range(&self) -> Range<usize> {
232
        let start = self.layer_list_offset_byte_range().end;
233
        let end = if self.version().compatible(1u16) {
234
            start.saturating_add(Offset32::RAW_BYTE_LEN)
235
        } else {
236
            start
237
        };
238
        start..end
239
    }
240
241
    pub fn var_index_map_offset_byte_range(&self) -> Range<usize> {
242
        let start = self.clip_list_offset_byte_range().end;
243
        let end = if self.version().compatible(1u16) {
244
            start.saturating_add(Offset32::RAW_BYTE_LEN)
245
        } else {
246
            start
247
        };
248
        start..end
249
    }
250
251
    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
252
        let start = self.var_index_map_offset_byte_range().end;
253
        let end = if self.version().compatible(1u16) {
254
            start.saturating_add(Offset32::RAW_BYTE_LEN)
255
        } else {
256
            start
257
        };
258
        start..end
259
    }
260
}
261
262
const _: () = assert!(FontData::default_data_long_enough(Colr::MIN_SIZE));
263
264
impl Default for Colr<'_> {
265
    fn default() -> Self {
266
        Self {
267
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
268
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
269
        }
270
    }
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
    pub fn glyph_id(&self) -> GlyphId16 {
289
        self.glyph_id.get()
290
    }
291
292
    /// Index (base 0) into the layerRecords array.
293
    pub fn first_layer_index(&self) -> u16 {
294
        self.first_layer_index.get()
295
    }
296
297
    /// Number of color layers associated with this glyph.
298
    pub fn num_layers(&self) -> u16 {
299
        self.num_layers.get()
300
    }
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
    pub fn glyph_id(&self) -> GlyphId16 {
321
        self.glyph_id.get()
322
    }
323
324
    /// Index (base 0) for a palette entry in the CPAL table.
325
    pub fn palette_index(&self) -> u16 {
326
        self.palette_index.get()
327
    }
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
    fn min_byte_range(&self) -> Range<usize> {
336
        0..self.base_glyph_paint_records_byte_range().end
337
    }
338
    fn min_table_bytes(&self) -> &'a [u8] {
339
        let range = self.min_byte_range();
340
        self.offset_data().as_bytes().get(range).unwrap_or_default()
341
    }
342
}
343
344
impl ReadArgs for BaseGlyphList<'_> {
345
    type Args = ();
346
}
347
348
impl<'a> FontRead<'a> for BaseGlyphList<'a> {
349
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
350
        #[allow(clippy::absurd_extreme_comparisons)]
351
        if data.len() < Self::MIN_SIZE {
352
            return Err(ReadError::OutOfBounds);
353
        }
354
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
355
            return Err(ReadError::OutOfBounds);
356
        };
357
        Ok(Self { data })
358
    }
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
    pub fn num_base_glyph_paint_records(&self) -> u32 {
384
        self.data.header().num_base_glyph_paint_records.get()
385
    }
386
387
    pub fn base_glyph_paint_records(&self) -> &'a [BaseGlyphPaint] {
388
        let range = self.base_glyph_paint_records_byte_range();
389
        self.offset_data()
390
            .read_array(range)
391
            .ok()
392
            .unwrap_or_default()
393
    }
394
395
    pub fn num_base_glyph_paint_records_byte_range(&self) -> Range<usize> {
396
        let start = 0usize;
397
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
398
        start..end
399
    }
400
401
    pub fn base_glyph_paint_records_byte_range(&self) -> Range<usize> {
402
        let num_base_glyph_paint_records = self.num_base_glyph_paint_records();
403
        let start = self.num_base_glyph_paint_records_byte_range().end;
404
        let end = start.saturating_add(
405
            (transforms::to_usize(num_base_glyph_paint_records))
406
                .saturating_mul(BaseGlyphPaint::RAW_BYTE_LEN),
407
        );
408
        start..end
409
    }
410
}
411
412
const _: () = assert!(FontData::default_data_long_enough(BaseGlyphList::MIN_SIZE));
413
414
impl Default for BaseGlyphList<'_> {
415
    fn default() -> Self {
416
        Self {
417
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
418
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
419
        }
420
    }
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
    pub fn glyph_id(&self) -> GlyphId16 {
437
        self.glyph_id.get()
438
    }
439
440
    /// Offset to a Paint table, from the beginning of the [`BaseGlyphList`] table.
441
    pub fn paint_offset(&self) -> Offset32 {
442
        self.paint_offset.get()
443
    }
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
    pub fn paint<'a>(&self, data: FontData<'a>) -> Result<Paint<'a>, ReadError> {
450
        self.paint_offset().resolve(data)
451
    }
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
    fn min_byte_range(&self) -> Range<usize> {
460
        0..self.paint_offsets_byte_range().end
461
    }
462
    fn min_table_bytes(&self) -> &'a [u8] {
463
        let range = self.min_byte_range();
464
        self.offset_data().as_bytes().get(range).unwrap_or_default()
465
    }
466
}
467
468
impl ReadArgs for LayerList<'_> {
469
    type Args = ();
470
}
471
472
impl<'a> FontRead<'a> for LayerList<'a> {
473
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
474
        #[allow(clippy::absurd_extreme_comparisons)]
475
        if data.len() < Self::MIN_SIZE {
476
            return Err(ReadError::OutOfBounds);
477
        }
478
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
479
            return Err(ReadError::OutOfBounds);
480
        };
481
        Ok(Self { data })
482
    }
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
    pub fn num_layers(&self) -> u32 {
508
        self.data.header().num_layers.get()
509
    }
510
511
    /// Offsets to Paint tables.
512
    pub fn paint_offsets(&self) -> &'a [BigEndian<Offset32>] {
513
        let range = self.paint_offsets_byte_range();
514
        self.offset_data()
515
            .read_array(range)
516
            .ok()
517
            .unwrap_or_default()
518
    }
519
520
    /// A dynamically resolving wrapper for [`paint_offsets`][Self::paint_offsets].
521
    pub fn paints(&self) -> ArrayOfOffsets<'a, Paint<'a>, Offset32> {
522
        let data = self.offset_data();
523
        let offsets = self.paint_offsets();
524
        ArrayOfOffsets::new(offsets, data, ())
525
    }
526
527
    pub fn num_layers_byte_range(&self) -> Range<usize> {
528
        let start = 0usize;
529
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
530
        start..end
531
    }
532
533
    pub fn paint_offsets_byte_range(&self) -> Range<usize> {
534
        let num_layers = self.num_layers();
535
        let start = self.num_layers_byte_range().end;
536
        let end = start.saturating_add(
537
            (transforms::to_usize(num_layers)).saturating_mul(Offset32::RAW_BYTE_LEN),
538
        );
539
        start..end
540
    }
541
}
542
543
const _: () = assert!(FontData::default_data_long_enough(LayerList::MIN_SIZE));
544
545
impl Default for LayerList<'_> {
546
    fn default() -> Self {
547
        Self {
548
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
549
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
550
        }
551
    }
552
}
553
554
impl<'a> MinByteRange<'a> for ClipList<'a> {
555
    fn min_byte_range(&self) -> Range<usize> {
556
        0..self.clips_byte_range().end
557
    }
558
    fn min_table_bytes(&self) -> &'a [u8] {
559
        let range = self.min_byte_range();
560
        self.offset_data().as_bytes().get(range).unwrap_or_default()
561
    }
562
}
563
564
impl ReadArgs for ClipList<'_> {
565
    type Args = ();
566
}
567
568
impl<'a> FontRead<'a> for ClipList<'a> {
569
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
570
        #[allow(clippy::absurd_extreme_comparisons)]
571
        if data.len() < Self::MIN_SIZE {
572
            return Err(ReadError::OutOfBounds);
573
        }
574
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
575
            return Err(ReadError::OutOfBounds);
576
        };
577
        Ok(Self { data })
578
    }
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
    pub fn format(&self) -> u8 {
606
        self.data.header().format
607
    }
608
609
    /// Number of Clip records.
610
    pub fn num_clips(&self) -> u32 {
611
        self.data.header().num_clips.get()
612
    }
613
614
    /// Clip records. Sorted by startGlyphID.
615
    pub fn clips(&self) -> &'a [Clip] {
616
        let range = self.clips_byte_range();
617
        self.offset_data()
618
            .read_array(range)
619
            .ok()
620
            .unwrap_or_default()
621
    }
622
623
    pub fn format_byte_range(&self) -> Range<usize> {
624
        let start = 0usize;
625
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
626
        start..end
627
    }
628
629
    pub fn num_clips_byte_range(&self) -> Range<usize> {
630
        let start = self.format_byte_range().end;
631
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
632
        start..end
633
    }
634
635
    pub fn clips_byte_range(&self) -> Range<usize> {
636
        let num_clips = self.num_clips();
637
        let start = self.num_clips_byte_range().end;
638
        let end = start
639
            .saturating_add((transforms::to_usize(num_clips)).saturating_mul(Clip::RAW_BYTE_LEN));
640
        start..end
641
    }
642
}
643
644
const _: () = assert!(FontData::default_data_long_enough(ClipList::MIN_SIZE));
645
646
impl Default for ClipList<'_> {
647
    fn default() -> Self {
648
        Self {
649
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
650
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
651
        }
652
    }
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
    pub fn start_glyph_id(&self) -> GlyphId16 {
671
        self.start_glyph_id.get()
672
    }
673
674
    /// Last glyph ID in the range.
675
    pub fn end_glyph_id(&self) -> GlyphId16 {
676
        self.end_glyph_id.get()
677
    }
678
679
    /// Offset to a ClipBox table, from the beginning of the [`ClipList`] table.
680
    pub fn clip_box_offset(&self) -> Offset24 {
681
        self.clip_box_offset.get()
682
    }
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
    pub fn clip_box<'a>(&self, data: FontData<'a>) -> Result<ClipBox<'a>, ReadError> {
689
        self.clip_box_offset().resolve(data)
690
    }
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
    fn default() -> Self {
707
        Self::Format1(Default::default())
708
    }
709
}
710
711
impl<'a> ClipBox<'a> {
712
    ///Return the `FontData` used to resolve offsets for this table.
713
    pub fn offset_data(&self) -> FontData<'a> {
714
        match self {
715
            Self::Format1(item) => item.offset_data(),
716
            Self::Format2(item) => item.offset_data(),
717
        }
718
    }
719
720
    /// Set to 1.
721
    pub fn format(&self) -> u8 {
722
        match self {
723
            Self::Format1(item) => item.format(),
724
            Self::Format2(item) => item.format(),
725
        }
726
    }
727
728
    /// Minimum x of clip box.
729
    pub fn x_min(&self) -> FWord {
730
        match self {
731
            Self::Format1(item) => item.x_min(),
732
            Self::Format2(item) => item.x_min(),
733
        }
734
    }
735
736
    /// Minimum y of clip box.
737
    pub fn y_min(&self) -> FWord {
738
        match self {
739
            Self::Format1(item) => item.y_min(),
740
            Self::Format2(item) => item.y_min(),
741
        }
742
    }
743
744
    /// Maximum x of clip box.
745
    pub fn x_max(&self) -> FWord {
746
        match self {
747
            Self::Format1(item) => item.x_max(),
748
            Self::Format2(item) => item.x_max(),
749
        }
750
    }
751
752
    /// Maximum y of clip box.
753
    pub fn y_max(&self) -> FWord {
754
        match self {
755
            Self::Format1(item) => item.y_max(),
756
            Self::Format2(item) => item.y_max(),
757
        }
758
    }
759
}
760
761
impl ReadArgs for ClipBox<'_> {
762
    type Args = ();
763
}
764
765
impl<'a> FontRead<'a> for ClipBox<'a> {
766
    #[inline]
767
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
768
0
        let format: u8 = data.read_at(0usize)?;
769
0
        match format {
770
0
            ClipBoxFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
771
0
            ClipBoxFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
772
0
            other => Err(ReadError::InvalidFormat(other.into())),
773
        }
774
0
    }
775
}
776
777
impl<'a> MinByteRange<'a> for ClipBox<'a> {
778
    fn min_byte_range(&self) -> Range<usize> {
779
        match self {
780
            Self::Format1(item) => item.min_byte_range(),
781
            Self::Format2(item) => item.min_byte_range(),
782
        }
783
    }
784
    fn min_table_bytes(&self) -> &'a [u8] {
785
        match self {
786
            Self::Format1(item) => item.min_table_bytes(),
787
            Self::Format2(item) => item.min_table_bytes(),
788
        }
789
    }
790
}
791
792
impl Format<u8> for ClipBoxFormat1<'_> {
793
    const FORMAT: u8 = 1;
794
}
795
796
impl<'a> MinByteRange<'a> for ClipBoxFormat1<'a> {
797
    fn min_byte_range(&self) -> Range<usize> {
798
        0..self.y_max_byte_range().end
799
    }
800
    fn min_table_bytes(&self) -> &'a [u8] {
801
        let range = self.min_byte_range();
802
        self.offset_data().as_bytes().get(range).unwrap_or_default()
803
    }
804
}
805
806
impl ReadArgs for ClipBoxFormat1<'_> {
807
    type Args = ();
808
}
809
810
impl<'a> FontRead<'a> for ClipBoxFormat1<'a> {
811
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
812
        #[allow(clippy::absurd_extreme_comparisons)]
813
        if data.len() < Self::MIN_SIZE {
814
            return Err(ReadError::OutOfBounds);
815
        }
816
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
817
            return Err(ReadError::OutOfBounds);
818
        };
819
        Ok(Self { data })
820
    }
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
    pub fn format(&self) -> u8 {
855
        self.data.header().format
856
    }
857
858
    /// Minimum x of clip box.
859
    pub fn x_min(&self) -> FWord {
860
        self.data.header().x_min.get()
861
    }
862
863
    /// Minimum y of clip box.
864
    pub fn y_min(&self) -> FWord {
865
        self.data.header().y_min.get()
866
    }
867
868
    /// Maximum x of clip box.
869
    pub fn x_max(&self) -> FWord {
870
        self.data.header().x_max.get()
871
    }
872
873
    /// Maximum y of clip box.
874
    pub fn y_max(&self) -> FWord {
875
        self.data.header().y_max.get()
876
    }
877
878
    pub fn format_byte_range(&self) -> Range<usize> {
879
        let start = 0usize;
880
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
881
        start..end
882
    }
883
884
    pub fn x_min_byte_range(&self) -> Range<usize> {
885
        let start = self.format_byte_range().end;
886
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
887
        start..end
888
    }
889
890
    pub fn y_min_byte_range(&self) -> Range<usize> {
891
        let start = self.x_min_byte_range().end;
892
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
893
        start..end
894
    }
895
896
    pub fn x_max_byte_range(&self) -> Range<usize> {
897
        let start = self.y_min_byte_range().end;
898
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
899
        start..end
900
    }
901
902
    pub fn y_max_byte_range(&self) -> Range<usize> {
903
        let start = self.x_max_byte_range().end;
904
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
905
        start..end
906
    }
907
}
908
909
const _: () = assert!(FontData::default_data_long_enough(ClipBoxFormat1::MIN_SIZE));
910
911
impl Default for ClipBoxFormat1<'_> {
912
    fn default() -> Self {
913
        Self {
914
            data: TableDataRef::new(FontData::default_format_1_u8_table_data().as_bytes())
915
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
916
        }
917
    }
918
}
919
920
impl Format<u8> for ClipBoxFormat2<'_> {
921
    const FORMAT: u8 = 2;
922
}
923
924
impl<'a> MinByteRange<'a> for ClipBoxFormat2<'a> {
925
    fn min_byte_range(&self) -> Range<usize> {
926
        0..self.var_index_base_byte_range().end
927
    }
928
    fn min_table_bytes(&self) -> &'a [u8] {
929
        let range = self.min_byte_range();
930
        self.offset_data().as_bytes().get(range).unwrap_or_default()
931
    }
932
}
933
934
impl ReadArgs for ClipBoxFormat2<'_> {
935
    type Args = ();
936
}
937
938
impl<'a> FontRead<'a> for ClipBoxFormat2<'a> {
939
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
940
        #[allow(clippy::absurd_extreme_comparisons)]
941
        if data.len() < Self::MIN_SIZE {
942
            return Err(ReadError::OutOfBounds);
943
        }
944
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
945
            return Err(ReadError::OutOfBounds);
946
        };
947
        Ok(Self { data })
948
    }
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
    pub fn format(&self) -> u8 {
985
        self.data.header().format
986
    }
987
988
    /// Minimum x of clip box. For variation, use varIndexBase + 0.
989
    pub fn x_min(&self) -> FWord {
990
        self.data.header().x_min.get()
991
    }
992
993
    /// Minimum y of clip box. For variation, use varIndexBase + 1.
994
    pub fn y_min(&self) -> FWord {
995
        self.data.header().y_min.get()
996
    }
997
998
    /// Maximum x of clip box. For variation, use varIndexBase + 2.
999
    pub fn x_max(&self) -> FWord {
1000
        self.data.header().x_max.get()
1001
    }
1002
1003
    /// Maximum y of clip box. For variation, use varIndexBase + 3.
1004
    pub fn y_max(&self) -> FWord {
1005
        self.data.header().y_max.get()
1006
    }
1007
1008
    /// Base index into DeltaSetIndexMap.
1009
    pub fn var_index_base(&self) -> u32 {
1010
        self.data.header().var_index_base.get()
1011
    }
1012
1013
    pub fn format_byte_range(&self) -> Range<usize> {
1014
        let start = 0usize;
1015
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1016
        start..end
1017
    }
1018
1019
    pub fn x_min_byte_range(&self) -> Range<usize> {
1020
        let start = self.format_byte_range().end;
1021
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
1022
        start..end
1023
    }
1024
1025
    pub fn y_min_byte_range(&self) -> Range<usize> {
1026
        let start = self.x_min_byte_range().end;
1027
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
1028
        start..end
1029
    }
1030
1031
    pub fn x_max_byte_range(&self) -> Range<usize> {
1032
        let start = self.y_min_byte_range().end;
1033
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
1034
        start..end
1035
    }
1036
1037
    pub fn y_max_byte_range(&self) -> Range<usize> {
1038
        let start = self.x_max_byte_range().end;
1039
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
1040
        start..end
1041
    }
1042
1043
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
1044
        let start = self.y_max_byte_range().end;
1045
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
1046
        start..end
1047
    }
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
    pub fn palette_index(&self) -> u16 {
1064
        self.palette_index.get()
1065
    }
1066
1067
    /// Alpha value.
1068
    pub fn alpha(&self) -> F2Dot14 {
1069
        self.alpha.get()
1070
    }
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
    pub fn palette_index(&self) -> u16 {
1093
        self.palette_index.get()
1094
    }
1095
1096
    /// Alpha value. For variation, use varIndexBase + 0.
1097
    pub fn alpha(&self) -> F2Dot14 {
1098
        self.alpha.get()
1099
    }
1100
1101
    /// Base index into DeltaSetIndexMap.
1102
    pub fn var_index_base(&self) -> u32 {
1103
        self.var_index_base.get()
1104
    }
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
    pub fn stop_offset(&self) -> F2Dot14 {
1127
        self.stop_offset.get()
1128
    }
1129
1130
    /// Index for a CPAL palette entry.
1131
    pub fn palette_index(&self) -> u16 {
1132
        self.palette_index.get()
1133
    }
1134
1135
    /// Alpha value.
1136
    pub fn alpha(&self) -> F2Dot14 {
1137
        self.alpha.get()
1138
    }
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
    pub fn stop_offset(&self) -> F2Dot14 {
1163
        self.stop_offset.get()
1164
    }
1165
1166
    /// Index for a CPAL palette entry.
1167
    pub fn palette_index(&self) -> u16 {
1168
        self.palette_index.get()
1169
    }
1170
1171
    /// Alpha value. For variation, use varIndexBase + 1.
1172
    pub fn alpha(&self) -> F2Dot14 {
1173
        self.alpha.get()
1174
    }
1175
1176
    /// Base index into DeltaSetIndexMap.
1177
    pub fn var_index_base(&self) -> u32 {
1178
        self.var_index_base.get()
1179
    }
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
    fn min_byte_range(&self) -> Range<usize> {
1189
        0..self.color_stops_byte_range().end
1190
    }
1191
    fn min_table_bytes(&self) -> &'a [u8] {
1192
        let range = self.min_byte_range();
1193
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1194
    }
1195
}
1196
1197
impl ReadArgs for ColorLine<'_> {
1198
    type Args = ();
1199
}
1200
1201
impl<'a> FontRead<'a> for ColorLine<'a> {
1202
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1203
        #[allow(clippy::absurd_extreme_comparisons)]
1204
        if data.len() < Self::MIN_SIZE {
1205
            return Err(ReadError::OutOfBounds);
1206
        }
1207
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1208
            return Err(ReadError::OutOfBounds);
1209
        };
1210
        Ok(Self { data })
1211
    }
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
    pub fn extend(&self) -> Extend {
1239
        self.data.header().extend.get()
1240
    }
1241
1242
    /// Number of ColorStop records.
1243
    pub fn num_stops(&self) -> u16 {
1244
        self.data.header().num_stops.get()
1245
    }
1246
1247
    pub fn color_stops(&self) -> &'a [ColorStop] {
1248
        let range = self.color_stops_byte_range();
1249
        self.offset_data()
1250
            .read_array(range)
1251
            .ok()
1252
            .unwrap_or_default()
1253
    }
1254
1255
    pub fn extend_byte_range(&self) -> Range<usize> {
1256
        let start = 0usize;
1257
        let end = start.saturating_add(Extend::RAW_BYTE_LEN);
1258
        start..end
1259
    }
1260
1261
    pub fn num_stops_byte_range(&self) -> Range<usize> {
1262
        let start = self.extend_byte_range().end;
1263
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1264
        start..end
1265
    }
1266
1267
    pub fn color_stops_byte_range(&self) -> Range<usize> {
1268
        let num_stops = self.num_stops();
1269
        let start = self.num_stops_byte_range().end;
1270
        let end = start.saturating_add(
1271
            (transforms::to_usize(num_stops)).saturating_mul(ColorStop::RAW_BYTE_LEN),
1272
        );
1273
        start..end
1274
    }
1275
}
1276
1277
const _: () = assert!(FontData::default_data_long_enough(ColorLine::MIN_SIZE));
1278
1279
impl Default for ColorLine<'_> {
1280
    fn default() -> Self {
1281
        Self {
1282
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1283
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1284
        }
1285
    }
1286
}
1287
1288
impl<'a> MinByteRange<'a> for VarColorLine<'a> {
1289
    fn min_byte_range(&self) -> Range<usize> {
1290
        0..self.color_stops_byte_range().end
1291
    }
1292
    fn min_table_bytes(&self) -> &'a [u8] {
1293
        let range = self.min_byte_range();
1294
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1295
    }
1296
}
1297
1298
impl ReadArgs for VarColorLine<'_> {
1299
    type Args = ();
1300
}
1301
1302
impl<'a> FontRead<'a> for VarColorLine<'a> {
1303
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1304
        #[allow(clippy::absurd_extreme_comparisons)]
1305
        if data.len() < Self::MIN_SIZE {
1306
            return Err(ReadError::OutOfBounds);
1307
        }
1308
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1309
            return Err(ReadError::OutOfBounds);
1310
        };
1311
        Ok(Self { data })
1312
    }
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
    pub fn extend(&self) -> Extend {
1340
        self.data.header().extend.get()
1341
    }
1342
1343
    /// Number of ColorStop records.
1344
    pub fn num_stops(&self) -> u16 {
1345
        self.data.header().num_stops.get()
1346
    }
1347
1348
    /// Allows for variations.
1349
    pub fn color_stops(&self) -> &'a [VarColorStop] {
1350
        let range = self.color_stops_byte_range();
1351
        self.offset_data()
1352
            .read_array(range)
1353
            .ok()
1354
            .unwrap_or_default()
1355
    }
1356
1357
    pub fn extend_byte_range(&self) -> Range<usize> {
1358
        let start = 0usize;
1359
        let end = start.saturating_add(Extend::RAW_BYTE_LEN);
1360
        start..end
1361
    }
1362
1363
    pub fn num_stops_byte_range(&self) -> Range<usize> {
1364
        let start = self.extend_byte_range().end;
1365
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1366
        start..end
1367
    }
1368
1369
    pub fn color_stops_byte_range(&self) -> Range<usize> {
1370
        let num_stops = self.num_stops();
1371
        let start = self.num_stops_byte_range().end;
1372
        let end = start.saturating_add(
1373
            (transforms::to_usize(num_stops)).saturating_mul(VarColorStop::RAW_BYTE_LEN),
1374
        );
1375
        start..end
1376
    }
1377
}
1378
1379
const _: () = assert!(FontData::default_data_long_enough(VarColorLine::MIN_SIZE));
1380
1381
impl Default for VarColorLine<'_> {
1382
    fn default() -> Self {
1383
        Self {
1384
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
1385
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1386
        }
1387
    }
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
    pub fn new(raw: u8) -> Self {
1418
        match raw {
1419
            0 => Self::Pad,
1420
            1 => Self::Repeat,
1421
            2 => Self::Reflect,
1422
            _ => Self::Unknown,
1423
        }
1424
    }
1425
}
1426
1427
impl font_types::Scalar for Extend {
1428
    type Raw = <u8 as font_types::Scalar>::Raw;
1429
    fn to_raw(self) -> Self::Raw {
1430
        (self as u8).to_raw()
1431
    }
1432
    fn from_raw(raw: Self::Raw) -> Self {
1433
        let t = <u8>::from_raw(raw);
1434
        Self::new(t)
1435
    }
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
    fn default() -> Self {
1478
        Self::ColrLayers(Default::default())
1479
    }
1480
}
1481
1482
impl<'a> Paint<'a> {
1483
    ///Return the `FontData` used to resolve offsets for this table.
1484
    pub fn offset_data(&self) -> FontData<'a> {
1485
        match self {
1486
            Self::ColrLayers(item) => item.offset_data(),
1487
            Self::Solid(item) => item.offset_data(),
1488
            Self::VarSolid(item) => item.offset_data(),
1489
            Self::LinearGradient(item) => item.offset_data(),
1490
            Self::VarLinearGradient(item) => item.offset_data(),
1491
            Self::RadialGradient(item) => item.offset_data(),
1492
            Self::VarRadialGradient(item) => item.offset_data(),
1493
            Self::SweepGradient(item) => item.offset_data(),
1494
            Self::VarSweepGradient(item) => item.offset_data(),
1495
            Self::Glyph(item) => item.offset_data(),
1496
            Self::ColrGlyph(item) => item.offset_data(),
1497
            Self::Transform(item) => item.offset_data(),
1498
            Self::VarTransform(item) => item.offset_data(),
1499
            Self::Translate(item) => item.offset_data(),
1500
            Self::VarTranslate(item) => item.offset_data(),
1501
            Self::Scale(item) => item.offset_data(),
1502
            Self::VarScale(item) => item.offset_data(),
1503
            Self::ScaleAroundCenter(item) => item.offset_data(),
1504
            Self::VarScaleAroundCenter(item) => item.offset_data(),
1505
            Self::ScaleUniform(item) => item.offset_data(),
1506
            Self::VarScaleUniform(item) => item.offset_data(),
1507
            Self::ScaleUniformAroundCenter(item) => item.offset_data(),
1508
            Self::VarScaleUniformAroundCenter(item) => item.offset_data(),
1509
            Self::Rotate(item) => item.offset_data(),
1510
            Self::VarRotate(item) => item.offset_data(),
1511
            Self::RotateAroundCenter(item) => item.offset_data(),
1512
            Self::VarRotateAroundCenter(item) => item.offset_data(),
1513
            Self::Skew(item) => item.offset_data(),
1514
            Self::VarSkew(item) => item.offset_data(),
1515
            Self::SkewAroundCenter(item) => item.offset_data(),
1516
            Self::VarSkewAroundCenter(item) => item.offset_data(),
1517
            Self::Composite(item) => item.offset_data(),
1518
            Self::Glyph2(item) => item.offset_data(),
1519
        }
1520
    }
1521
1522
    /// Set to 1.
1523
    pub fn format(&self) -> u8 {
1524
        match self {
1525
            Self::ColrLayers(item) => item.format(),
1526
            Self::Solid(item) => item.format(),
1527
            Self::VarSolid(item) => item.format(),
1528
            Self::LinearGradient(item) => item.format(),
1529
            Self::VarLinearGradient(item) => item.format(),
1530
            Self::RadialGradient(item) => item.format(),
1531
            Self::VarRadialGradient(item) => item.format(),
1532
            Self::SweepGradient(item) => item.format(),
1533
            Self::VarSweepGradient(item) => item.format(),
1534
            Self::Glyph(item) => item.format(),
1535
            Self::ColrGlyph(item) => item.format(),
1536
            Self::Transform(item) => item.format(),
1537
            Self::VarTransform(item) => item.format(),
1538
            Self::Translate(item) => item.format(),
1539
            Self::VarTranslate(item) => item.format(),
1540
            Self::Scale(item) => item.format(),
1541
            Self::VarScale(item) => item.format(),
1542
            Self::ScaleAroundCenter(item) => item.format(),
1543
            Self::VarScaleAroundCenter(item) => item.format(),
1544
            Self::ScaleUniform(item) => item.format(),
1545
            Self::VarScaleUniform(item) => item.format(),
1546
            Self::ScaleUniformAroundCenter(item) => item.format(),
1547
            Self::VarScaleUniformAroundCenter(item) => item.format(),
1548
            Self::Rotate(item) => item.format(),
1549
            Self::VarRotate(item) => item.format(),
1550
            Self::RotateAroundCenter(item) => item.format(),
1551
            Self::VarRotateAroundCenter(item) => item.format(),
1552
            Self::Skew(item) => item.format(),
1553
            Self::VarSkew(item) => item.format(),
1554
            Self::SkewAroundCenter(item) => item.format(),
1555
            Self::VarSkewAroundCenter(item) => item.format(),
1556
            Self::Composite(item) => item.format(),
1557
            Self::Glyph2(item) => item.format(),
1558
        }
1559
    }
1560
}
1561
1562
impl ReadArgs for Paint<'_> {
1563
    type Args = ();
1564
}
1565
1566
impl<'a> FontRead<'a> for Paint<'a> {
1567
    #[inline]
1568
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1569
0
        let format: u8 = data.read_at(0usize)?;
1570
0
        match format {
1571
0
            PaintColrLayers::FORMAT => Ok(Self::ColrLayers(FontRead::read(data)?)),
1572
0
            PaintSolid::FORMAT => Ok(Self::Solid(FontRead::read(data)?)),
1573
0
            PaintVarSolid::FORMAT => Ok(Self::VarSolid(FontRead::read(data)?)),
1574
0
            PaintLinearGradient::FORMAT => Ok(Self::LinearGradient(FontRead::read(data)?)),
1575
0
            PaintVarLinearGradient::FORMAT => Ok(Self::VarLinearGradient(FontRead::read(data)?)),
1576
0
            PaintRadialGradient::FORMAT => Ok(Self::RadialGradient(FontRead::read(data)?)),
1577
0
            PaintVarRadialGradient::FORMAT => Ok(Self::VarRadialGradient(FontRead::read(data)?)),
1578
0
            PaintSweepGradient::FORMAT => Ok(Self::SweepGradient(FontRead::read(data)?)),
1579
0
            PaintVarSweepGradient::FORMAT => Ok(Self::VarSweepGradient(FontRead::read(data)?)),
1580
0
            PaintGlyph::FORMAT => Ok(Self::Glyph(FontRead::read(data)?)),
1581
0
            PaintColrGlyph::FORMAT => Ok(Self::ColrGlyph(FontRead::read(data)?)),
1582
0
            PaintTransform::FORMAT => Ok(Self::Transform(FontRead::read(data)?)),
1583
0
            PaintVarTransform::FORMAT => Ok(Self::VarTransform(FontRead::read(data)?)),
1584
0
            PaintTranslate::FORMAT => Ok(Self::Translate(FontRead::read(data)?)),
1585
0
            PaintVarTranslate::FORMAT => Ok(Self::VarTranslate(FontRead::read(data)?)),
1586
0
            PaintScale::FORMAT => Ok(Self::Scale(FontRead::read(data)?)),
1587
0
            PaintVarScale::FORMAT => Ok(Self::VarScale(FontRead::read(data)?)),
1588
0
            PaintScaleAroundCenter::FORMAT => Ok(Self::ScaleAroundCenter(FontRead::read(data)?)),
1589
0
            PaintVarScaleAroundCenter::FORMAT => {
1590
0
                Ok(Self::VarScaleAroundCenter(FontRead::read(data)?))
1591
            }
1592
0
            PaintScaleUniform::FORMAT => Ok(Self::ScaleUniform(FontRead::read(data)?)),
1593
0
            PaintVarScaleUniform::FORMAT => Ok(Self::VarScaleUniform(FontRead::read(data)?)),
1594
0
            PaintScaleUniformAroundCenter::FORMAT => {
1595
0
                Ok(Self::ScaleUniformAroundCenter(FontRead::read(data)?))
1596
            }
1597
0
            PaintVarScaleUniformAroundCenter::FORMAT => {
1598
0
                Ok(Self::VarScaleUniformAroundCenter(FontRead::read(data)?))
1599
            }
1600
0
            PaintRotate::FORMAT => Ok(Self::Rotate(FontRead::read(data)?)),
1601
0
            PaintVarRotate::FORMAT => Ok(Self::VarRotate(FontRead::read(data)?)),
1602
0
            PaintRotateAroundCenter::FORMAT => Ok(Self::RotateAroundCenter(FontRead::read(data)?)),
1603
0
            PaintVarRotateAroundCenter::FORMAT => {
1604
0
                Ok(Self::VarRotateAroundCenter(FontRead::read(data)?))
1605
            }
1606
0
            PaintSkew::FORMAT => Ok(Self::Skew(FontRead::read(data)?)),
1607
0
            PaintVarSkew::FORMAT => Ok(Self::VarSkew(FontRead::read(data)?)),
1608
0
            PaintSkewAroundCenter::FORMAT => Ok(Self::SkewAroundCenter(FontRead::read(data)?)),
1609
0
            PaintVarSkewAroundCenter::FORMAT => {
1610
0
                Ok(Self::VarSkewAroundCenter(FontRead::read(data)?))
1611
            }
1612
0
            PaintComposite::FORMAT => Ok(Self::Composite(FontRead::read(data)?)),
1613
0
            PaintGlyph2::FORMAT => Ok(Self::Glyph2(FontRead::read(data)?)),
1614
0
            other => Err(ReadError::InvalidFormat(other.into())),
1615
        }
1616
0
    }
1617
}
1618
1619
impl<'a> MinByteRange<'a> for Paint<'a> {
1620
    fn min_byte_range(&self) -> Range<usize> {
1621
        match self {
1622
            Self::ColrLayers(item) => item.min_byte_range(),
1623
            Self::Solid(item) => item.min_byte_range(),
1624
            Self::VarSolid(item) => item.min_byte_range(),
1625
            Self::LinearGradient(item) => item.min_byte_range(),
1626
            Self::VarLinearGradient(item) => item.min_byte_range(),
1627
            Self::RadialGradient(item) => item.min_byte_range(),
1628
            Self::VarRadialGradient(item) => item.min_byte_range(),
1629
            Self::SweepGradient(item) => item.min_byte_range(),
1630
            Self::VarSweepGradient(item) => item.min_byte_range(),
1631
            Self::Glyph(item) => item.min_byte_range(),
1632
            Self::ColrGlyph(item) => item.min_byte_range(),
1633
            Self::Transform(item) => item.min_byte_range(),
1634
            Self::VarTransform(item) => item.min_byte_range(),
1635
            Self::Translate(item) => item.min_byte_range(),
1636
            Self::VarTranslate(item) => item.min_byte_range(),
1637
            Self::Scale(item) => item.min_byte_range(),
1638
            Self::VarScale(item) => item.min_byte_range(),
1639
            Self::ScaleAroundCenter(item) => item.min_byte_range(),
1640
            Self::VarScaleAroundCenter(item) => item.min_byte_range(),
1641
            Self::ScaleUniform(item) => item.min_byte_range(),
1642
            Self::VarScaleUniform(item) => item.min_byte_range(),
1643
            Self::ScaleUniformAroundCenter(item) => item.min_byte_range(),
1644
            Self::VarScaleUniformAroundCenter(item) => item.min_byte_range(),
1645
            Self::Rotate(item) => item.min_byte_range(),
1646
            Self::VarRotate(item) => item.min_byte_range(),
1647
            Self::RotateAroundCenter(item) => item.min_byte_range(),
1648
            Self::VarRotateAroundCenter(item) => item.min_byte_range(),
1649
            Self::Skew(item) => item.min_byte_range(),
1650
            Self::VarSkew(item) => item.min_byte_range(),
1651
            Self::SkewAroundCenter(item) => item.min_byte_range(),
1652
            Self::VarSkewAroundCenter(item) => item.min_byte_range(),
1653
            Self::Composite(item) => item.min_byte_range(),
1654
            Self::Glyph2(item) => item.min_byte_range(),
1655
        }
1656
    }
1657
    fn min_table_bytes(&self) -> &'a [u8] {
1658
        match self {
1659
            Self::ColrLayers(item) => item.min_table_bytes(),
1660
            Self::Solid(item) => item.min_table_bytes(),
1661
            Self::VarSolid(item) => item.min_table_bytes(),
1662
            Self::LinearGradient(item) => item.min_table_bytes(),
1663
            Self::VarLinearGradient(item) => item.min_table_bytes(),
1664
            Self::RadialGradient(item) => item.min_table_bytes(),
1665
            Self::VarRadialGradient(item) => item.min_table_bytes(),
1666
            Self::SweepGradient(item) => item.min_table_bytes(),
1667
            Self::VarSweepGradient(item) => item.min_table_bytes(),
1668
            Self::Glyph(item) => item.min_table_bytes(),
1669
            Self::ColrGlyph(item) => item.min_table_bytes(),
1670
            Self::Transform(item) => item.min_table_bytes(),
1671
            Self::VarTransform(item) => item.min_table_bytes(),
1672
            Self::Translate(item) => item.min_table_bytes(),
1673
            Self::VarTranslate(item) => item.min_table_bytes(),
1674
            Self::Scale(item) => item.min_table_bytes(),
1675
            Self::VarScale(item) => item.min_table_bytes(),
1676
            Self::ScaleAroundCenter(item) => item.min_table_bytes(),
1677
            Self::VarScaleAroundCenter(item) => item.min_table_bytes(),
1678
            Self::ScaleUniform(item) => item.min_table_bytes(),
1679
            Self::VarScaleUniform(item) => item.min_table_bytes(),
1680
            Self::ScaleUniformAroundCenter(item) => item.min_table_bytes(),
1681
            Self::VarScaleUniformAroundCenter(item) => item.min_table_bytes(),
1682
            Self::Rotate(item) => item.min_table_bytes(),
1683
            Self::VarRotate(item) => item.min_table_bytes(),
1684
            Self::RotateAroundCenter(item) => item.min_table_bytes(),
1685
            Self::VarRotateAroundCenter(item) => item.min_table_bytes(),
1686
            Self::Skew(item) => item.min_table_bytes(),
1687
            Self::VarSkew(item) => item.min_table_bytes(),
1688
            Self::SkewAroundCenter(item) => item.min_table_bytes(),
1689
            Self::VarSkewAroundCenter(item) => item.min_table_bytes(),
1690
            Self::Composite(item) => item.min_table_bytes(),
1691
            Self::Glyph2(item) => item.min_table_bytes(),
1692
        }
1693
    }
1694
}
1695
1696
impl Format<u8> for PaintColrLayers<'_> {
1697
    const FORMAT: u8 = 1;
1698
}
1699
1700
impl<'a> MinByteRange<'a> for PaintColrLayers<'a> {
1701
    fn min_byte_range(&self) -> Range<usize> {
1702
        0..self.first_layer_index_byte_range().end
1703
    }
1704
    fn min_table_bytes(&self) -> &'a [u8] {
1705
        let range = self.min_byte_range();
1706
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1707
    }
1708
}
1709
1710
impl ReadArgs for PaintColrLayers<'_> {
1711
    type Args = ();
1712
}
1713
1714
impl<'a> FontRead<'a> for PaintColrLayers<'a> {
1715
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1716
        #[allow(clippy::absurd_extreme_comparisons)]
1717
        if data.len() < Self::MIN_SIZE {
1718
            return Err(ReadError::OutOfBounds);
1719
        }
1720
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1721
            return Err(ReadError::OutOfBounds);
1722
        };
1723
        Ok(Self { data })
1724
    }
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
    pub fn format(&self) -> u8 {
1754
        self.data.header().format
1755
    }
1756
1757
    /// Number of offsets to paint tables to read from LayerList.
1758
    pub fn num_layers(&self) -> u8 {
1759
        self.data.header().num_layers
1760
    }
1761
1762
    /// Index (base 0) into the LayerList.
1763
    pub fn first_layer_index(&self) -> u32 {
1764
        self.data.header().first_layer_index.get()
1765
    }
1766
1767
    pub fn format_byte_range(&self) -> Range<usize> {
1768
        let start = 0usize;
1769
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1770
        start..end
1771
    }
1772
1773
    pub fn num_layers_byte_range(&self) -> Range<usize> {
1774
        let start = self.format_byte_range().end;
1775
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1776
        start..end
1777
    }
1778
1779
    pub fn first_layer_index_byte_range(&self) -> Range<usize> {
1780
        let start = self.num_layers_byte_range().end;
1781
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
1782
        start..end
1783
    }
1784
}
1785
1786
const _: () = assert!(FontData::default_data_long_enough(
1787
    PaintColrLayers::MIN_SIZE
1788
));
1789
1790
impl Default for PaintColrLayers<'_> {
1791
    fn default() -> Self {
1792
        Self {
1793
            data: TableDataRef::new(FontData::default_format_1_u8_table_data().as_bytes())
1794
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
1795
        }
1796
    }
1797
}
1798
1799
impl Format<u8> for PaintSolid<'_> {
1800
    const FORMAT: u8 = 2;
1801
}
1802
1803
impl<'a> MinByteRange<'a> for PaintSolid<'a> {
1804
    fn min_byte_range(&self) -> Range<usize> {
1805
        0..self.alpha_byte_range().end
1806
    }
1807
    fn min_table_bytes(&self) -> &'a [u8] {
1808
        let range = self.min_byte_range();
1809
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1810
    }
1811
}
1812
1813
impl ReadArgs for PaintSolid<'_> {
1814
    type Args = ();
1815
}
1816
1817
impl<'a> FontRead<'a> for PaintSolid<'a> {
1818
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1819
        #[allow(clippy::absurd_extreme_comparisons)]
1820
        if data.len() < Self::MIN_SIZE {
1821
            return Err(ReadError::OutOfBounds);
1822
        }
1823
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1824
            return Err(ReadError::OutOfBounds);
1825
        };
1826
        Ok(Self { data })
1827
    }
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
    pub fn format(&self) -> u8 {
1856
        self.data.header().format
1857
    }
1858
1859
    /// Index for a CPAL palette entry.
1860
    pub fn palette_index(&self) -> u16 {
1861
        self.data.header().palette_index.get()
1862
    }
1863
1864
    /// Alpha value.
1865
    pub fn alpha(&self) -> F2Dot14 {
1866
        self.data.header().alpha.get()
1867
    }
1868
1869
    pub fn format_byte_range(&self) -> Range<usize> {
1870
        let start = 0usize;
1871
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1872
        start..end
1873
    }
1874
1875
    pub fn palette_index_byte_range(&self) -> Range<usize> {
1876
        let start = self.format_byte_range().end;
1877
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1878
        start..end
1879
    }
1880
1881
    pub fn alpha_byte_range(&self) -> Range<usize> {
1882
        let start = self.palette_index_byte_range().end;
1883
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
1884
        start..end
1885
    }
1886
}
1887
1888
impl Format<u8> for PaintVarSolid<'_> {
1889
    const FORMAT: u8 = 3;
1890
}
1891
1892
impl<'a> MinByteRange<'a> for PaintVarSolid<'a> {
1893
    fn min_byte_range(&self) -> Range<usize> {
1894
        0..self.var_index_base_byte_range().end
1895
    }
1896
    fn min_table_bytes(&self) -> &'a [u8] {
1897
        let range = self.min_byte_range();
1898
        self.offset_data().as_bytes().get(range).unwrap_or_default()
1899
    }
1900
}
1901
1902
impl ReadArgs for PaintVarSolid<'_> {
1903
    type Args = ();
1904
}
1905
1906
impl<'a> FontRead<'a> for PaintVarSolid<'a> {
1907
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
1908
        #[allow(clippy::absurd_extreme_comparisons)]
1909
        if data.len() < Self::MIN_SIZE {
1910
            return Err(ReadError::OutOfBounds);
1911
        }
1912
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
1913
            return Err(ReadError::OutOfBounds);
1914
        };
1915
        Ok(Self { data })
1916
    }
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
    pub fn format(&self) -> u8 {
1947
        self.data.header().format
1948
    }
1949
1950
    /// Index for a CPAL palette entry.
1951
    pub fn palette_index(&self) -> u16 {
1952
        self.data.header().palette_index.get()
1953
    }
1954
1955
    /// Alpha value. For variation, use varIndexBase + 0.
1956
    pub fn alpha(&self) -> F2Dot14 {
1957
        self.data.header().alpha.get()
1958
    }
1959
1960
    /// Base index into DeltaSetIndexMap.
1961
    pub fn var_index_base(&self) -> u32 {
1962
        self.data.header().var_index_base.get()
1963
    }
1964
1965
    pub fn format_byte_range(&self) -> Range<usize> {
1966
        let start = 0usize;
1967
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
1968
        start..end
1969
    }
1970
1971
    pub fn palette_index_byte_range(&self) -> Range<usize> {
1972
        let start = self.format_byte_range().end;
1973
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
1974
        start..end
1975
    }
1976
1977
    pub fn alpha_byte_range(&self) -> Range<usize> {
1978
        let start = self.palette_index_byte_range().end;
1979
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
1980
        start..end
1981
    }
1982
1983
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
1984
        let start = self.alpha_byte_range().end;
1985
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
1986
        start..end
1987
    }
1988
}
1989
1990
impl Format<u8> for PaintLinearGradient<'_> {
1991
    const FORMAT: u8 = 4;
1992
}
1993
1994
impl<'a> MinByteRange<'a> for PaintLinearGradient<'a> {
1995
    fn min_byte_range(&self) -> Range<usize> {
1996
        0..self.y2_byte_range().end
1997
    }
1998
    fn min_table_bytes(&self) -> &'a [u8] {
1999
        let range = self.min_byte_range();
2000
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2001
    }
2002
}
2003
2004
impl ReadArgs for PaintLinearGradient<'_> {
2005
    type Args = ();
2006
}
2007
2008
impl<'a> FontRead<'a> for PaintLinearGradient<'a> {
2009
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2010
        #[allow(clippy::absurd_extreme_comparisons)]
2011
        if data.len() < Self::MIN_SIZE {
2012
            return Err(ReadError::OutOfBounds);
2013
        }
2014
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2015
            return Err(ReadError::OutOfBounds);
2016
        };
2017
        Ok(Self { data })
2018
    }
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
    pub fn format(&self) -> u8 {
2060
        self.data.header().format
2061
    }
2062
2063
    /// Offset to ColorLine table.
2064
    pub fn color_line_offset(&self) -> Offset24 {
2065
        self.data.header().color_line_offset.get()
2066
    }
2067
2068
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2069
    pub fn color_line(&self) -> Result<ColorLine<'a>, ReadError> {
2070
        let data = self.offset_data();
2071
        self.color_line_offset().resolve(data)
2072
    }
2073
2074
    /// Start point (p₀) x coordinate.
2075
    pub fn x0(&self) -> FWord {
2076
        self.data.header().x0.get()
2077
    }
2078
2079
    /// Start point (p₀) y coordinate.
2080
    pub fn y0(&self) -> FWord {
2081
        self.data.header().y0.get()
2082
    }
2083
2084
    /// End point (p₁) x coordinate.
2085
    pub fn x1(&self) -> FWord {
2086
        self.data.header().x1.get()
2087
    }
2088
2089
    /// End point (p₁) y coordinate.
2090
    pub fn y1(&self) -> FWord {
2091
        self.data.header().y1.get()
2092
    }
2093
2094
    /// Rotation point (p₂) x coordinate.
2095
    pub fn x2(&self) -> FWord {
2096
        self.data.header().x2.get()
2097
    }
2098
2099
    /// Rotation point (p₂) y coordinate.
2100
    pub fn y2(&self) -> FWord {
2101
        self.data.header().y2.get()
2102
    }
2103
2104
    pub fn format_byte_range(&self) -> Range<usize> {
2105
        let start = 0usize;
2106
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2107
        start..end
2108
    }
2109
2110
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2111
        let start = self.format_byte_range().end;
2112
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2113
        start..end
2114
    }
2115
2116
    pub fn x0_byte_range(&self) -> Range<usize> {
2117
        let start = self.color_line_offset_byte_range().end;
2118
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2119
        start..end
2120
    }
2121
2122
    pub fn y0_byte_range(&self) -> Range<usize> {
2123
        let start = self.x0_byte_range().end;
2124
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2125
        start..end
2126
    }
2127
2128
    pub fn x1_byte_range(&self) -> Range<usize> {
2129
        let start = self.y0_byte_range().end;
2130
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2131
        start..end
2132
    }
2133
2134
    pub fn y1_byte_range(&self) -> Range<usize> {
2135
        let start = self.x1_byte_range().end;
2136
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2137
        start..end
2138
    }
2139
2140
    pub fn x2_byte_range(&self) -> Range<usize> {
2141
        let start = self.y1_byte_range().end;
2142
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2143
        start..end
2144
    }
2145
2146
    pub fn y2_byte_range(&self) -> Range<usize> {
2147
        let start = self.x2_byte_range().end;
2148
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2149
        start..end
2150
    }
2151
}
2152
2153
impl Format<u8> for PaintVarLinearGradient<'_> {
2154
    const FORMAT: u8 = 5;
2155
}
2156
2157
impl<'a> MinByteRange<'a> for PaintVarLinearGradient<'a> {
2158
    fn min_byte_range(&self) -> Range<usize> {
2159
        0..self.var_index_base_byte_range().end
2160
    }
2161
    fn min_table_bytes(&self) -> &'a [u8] {
2162
        let range = self.min_byte_range();
2163
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2164
    }
2165
}
2166
2167
impl ReadArgs for PaintVarLinearGradient<'_> {
2168
    type Args = ();
2169
}
2170
2171
impl<'a> FontRead<'a> for PaintVarLinearGradient<'a> {
2172
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2173
        #[allow(clippy::absurd_extreme_comparisons)]
2174
        if data.len() < Self::MIN_SIZE {
2175
            return Err(ReadError::OutOfBounds);
2176
        }
2177
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2178
            return Err(ReadError::OutOfBounds);
2179
        };
2180
        Ok(Self { data })
2181
    }
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
    pub fn format(&self) -> u8 {
2226
        self.data.header().format
2227
    }
2228
2229
    /// Offset to VarColorLine table.
2230
    pub fn color_line_offset(&self) -> Offset24 {
2231
        self.data.header().color_line_offset.get()
2232
    }
2233
2234
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2235
    pub fn color_line(&self) -> Result<VarColorLine<'a>, ReadError> {
2236
        let data = self.offset_data();
2237
        self.color_line_offset().resolve(data)
2238
    }
2239
2240
    /// Start point (p₀) x coordinate. For variation, use
2241
    /// varIndexBase + 0.
2242
    pub fn x0(&self) -> FWord {
2243
        self.data.header().x0.get()
2244
    }
2245
2246
    /// Start point (p₀) y coordinate. For variation, use
2247
    /// varIndexBase + 1.
2248
    pub fn y0(&self) -> FWord {
2249
        self.data.header().y0.get()
2250
    }
2251
2252
    /// End point (p₁) x coordinate. For variation, use varIndexBase
2253
    /// + 2.
2254
    pub fn x1(&self) -> FWord {
2255
        self.data.header().x1.get()
2256
    }
2257
2258
    /// End point (p₁) y coordinate. For variation, use varIndexBase
2259
    /// + 3.
2260
    pub fn y1(&self) -> FWord {
2261
        self.data.header().y1.get()
2262
    }
2263
2264
    /// Rotation point (p₂) x coordinate. For variation, use
2265
    /// varIndexBase + 4.
2266
    pub fn x2(&self) -> FWord {
2267
        self.data.header().x2.get()
2268
    }
2269
2270
    /// Rotation point (p₂) y coordinate. For variation, use
2271
    /// varIndexBase + 5.
2272
    pub fn y2(&self) -> FWord {
2273
        self.data.header().y2.get()
2274
    }
2275
2276
    /// Base index into DeltaSetIndexMap.
2277
    pub fn var_index_base(&self) -> u32 {
2278
        self.data.header().var_index_base.get()
2279
    }
2280
2281
    pub fn format_byte_range(&self) -> Range<usize> {
2282
        let start = 0usize;
2283
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2284
        start..end
2285
    }
2286
2287
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2288
        let start = self.format_byte_range().end;
2289
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2290
        start..end
2291
    }
2292
2293
    pub fn x0_byte_range(&self) -> Range<usize> {
2294
        let start = self.color_line_offset_byte_range().end;
2295
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2296
        start..end
2297
    }
2298
2299
    pub fn y0_byte_range(&self) -> Range<usize> {
2300
        let start = self.x0_byte_range().end;
2301
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2302
        start..end
2303
    }
2304
2305
    pub fn x1_byte_range(&self) -> Range<usize> {
2306
        let start = self.y0_byte_range().end;
2307
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2308
        start..end
2309
    }
2310
2311
    pub fn y1_byte_range(&self) -> Range<usize> {
2312
        let start = self.x1_byte_range().end;
2313
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2314
        start..end
2315
    }
2316
2317
    pub fn x2_byte_range(&self) -> Range<usize> {
2318
        let start = self.y1_byte_range().end;
2319
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2320
        start..end
2321
    }
2322
2323
    pub fn y2_byte_range(&self) -> Range<usize> {
2324
        let start = self.x2_byte_range().end;
2325
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2326
        start..end
2327
    }
2328
2329
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
2330
        let start = self.y2_byte_range().end;
2331
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
2332
        start..end
2333
    }
2334
}
2335
2336
impl Format<u8> for PaintRadialGradient<'_> {
2337
    const FORMAT: u8 = 6;
2338
}
2339
2340
impl<'a> MinByteRange<'a> for PaintRadialGradient<'a> {
2341
    fn min_byte_range(&self) -> Range<usize> {
2342
        0..self.radius1_byte_range().end
2343
    }
2344
    fn min_table_bytes(&self) -> &'a [u8] {
2345
        let range = self.min_byte_range();
2346
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2347
    }
2348
}
2349
2350
impl ReadArgs for PaintRadialGradient<'_> {
2351
    type Args = ();
2352
}
2353
2354
impl<'a> FontRead<'a> for PaintRadialGradient<'a> {
2355
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2356
        #[allow(clippy::absurd_extreme_comparisons)]
2357
        if data.len() < Self::MIN_SIZE {
2358
            return Err(ReadError::OutOfBounds);
2359
        }
2360
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2361
            return Err(ReadError::OutOfBounds);
2362
        };
2363
        Ok(Self { data })
2364
    }
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
    pub fn format(&self) -> u8 {
2406
        self.data.header().format
2407
    }
2408
2409
    /// Offset to ColorLine table.
2410
    pub fn color_line_offset(&self) -> Offset24 {
2411
        self.data.header().color_line_offset.get()
2412
    }
2413
2414
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2415
    pub fn color_line(&self) -> Result<ColorLine<'a>, ReadError> {
2416
        let data = self.offset_data();
2417
        self.color_line_offset().resolve(data)
2418
    }
2419
2420
    /// Start circle center x coordinate.
2421
    pub fn x0(&self) -> FWord {
2422
        self.data.header().x0.get()
2423
    }
2424
2425
    /// Start circle center y coordinate.
2426
    pub fn y0(&self) -> FWord {
2427
        self.data.header().y0.get()
2428
    }
2429
2430
    /// Start circle radius.
2431
    pub fn radius0(&self) -> UfWord {
2432
        self.data.header().radius0.get()
2433
    }
2434
2435
    /// End circle center x coordinate.
2436
    pub fn x1(&self) -> FWord {
2437
        self.data.header().x1.get()
2438
    }
2439
2440
    /// End circle center y coordinate.
2441
    pub fn y1(&self) -> FWord {
2442
        self.data.header().y1.get()
2443
    }
2444
2445
    /// End circle radius.
2446
    pub fn radius1(&self) -> UfWord {
2447
        self.data.header().radius1.get()
2448
    }
2449
2450
    pub fn format_byte_range(&self) -> Range<usize> {
2451
        let start = 0usize;
2452
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2453
        start..end
2454
    }
2455
2456
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2457
        let start = self.format_byte_range().end;
2458
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2459
        start..end
2460
    }
2461
2462
    pub fn x0_byte_range(&self) -> Range<usize> {
2463
        let start = self.color_line_offset_byte_range().end;
2464
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2465
        start..end
2466
    }
2467
2468
    pub fn y0_byte_range(&self) -> Range<usize> {
2469
        let start = self.x0_byte_range().end;
2470
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2471
        start..end
2472
    }
2473
2474
    pub fn radius0_byte_range(&self) -> Range<usize> {
2475
        let start = self.y0_byte_range().end;
2476
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
2477
        start..end
2478
    }
2479
2480
    pub fn x1_byte_range(&self) -> Range<usize> {
2481
        let start = self.radius0_byte_range().end;
2482
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2483
        start..end
2484
    }
2485
2486
    pub fn y1_byte_range(&self) -> Range<usize> {
2487
        let start = self.x1_byte_range().end;
2488
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2489
        start..end
2490
    }
2491
2492
    pub fn radius1_byte_range(&self) -> Range<usize> {
2493
        let start = self.y1_byte_range().end;
2494
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
2495
        start..end
2496
    }
2497
}
2498
2499
impl Format<u8> for PaintVarRadialGradient<'_> {
2500
    const FORMAT: u8 = 7;
2501
}
2502
2503
impl<'a> MinByteRange<'a> for PaintVarRadialGradient<'a> {
2504
    fn min_byte_range(&self) -> Range<usize> {
2505
        0..self.var_index_base_byte_range().end
2506
    }
2507
    fn min_table_bytes(&self) -> &'a [u8] {
2508
        let range = self.min_byte_range();
2509
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2510
    }
2511
}
2512
2513
impl ReadArgs for PaintVarRadialGradient<'_> {
2514
    type Args = ();
2515
}
2516
2517
impl<'a> FontRead<'a> for PaintVarRadialGradient<'a> {
2518
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2519
        #[allow(clippy::absurd_extreme_comparisons)]
2520
        if data.len() < Self::MIN_SIZE {
2521
            return Err(ReadError::OutOfBounds);
2522
        }
2523
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2524
            return Err(ReadError::OutOfBounds);
2525
        };
2526
        Ok(Self { data })
2527
    }
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
    pub fn format(&self) -> u8 {
2572
        self.data.header().format
2573
    }
2574
2575
    /// Offset to VarColorLine table.
2576
    pub fn color_line_offset(&self) -> Offset24 {
2577
        self.data.header().color_line_offset.get()
2578
    }
2579
2580
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2581
    pub fn color_line(&self) -> Result<VarColorLine<'a>, ReadError> {
2582
        let data = self.offset_data();
2583
        self.color_line_offset().resolve(data)
2584
    }
2585
2586
    /// Start circle center x coordinate. For variation, use
2587
    /// varIndexBase + 0.
2588
    pub fn x0(&self) -> FWord {
2589
        self.data.header().x0.get()
2590
    }
2591
2592
    /// Start circle center y coordinate. For variation, use
2593
    /// varIndexBase + 1.
2594
    pub fn y0(&self) -> FWord {
2595
        self.data.header().y0.get()
2596
    }
2597
2598
    /// Start circle radius. For variation, use varIndexBase + 2.
2599
    pub fn radius0(&self) -> UfWord {
2600
        self.data.header().radius0.get()
2601
    }
2602
2603
    /// End circle center x coordinate. For variation, use varIndexBase
2604
    /// + 3.
2605
    pub fn x1(&self) -> FWord {
2606
        self.data.header().x1.get()
2607
    }
2608
2609
    /// End circle center y coordinate. For variation, use varIndexBase
2610
    /// + 4.
2611
    pub fn y1(&self) -> FWord {
2612
        self.data.header().y1.get()
2613
    }
2614
2615
    /// End circle radius. For variation, use varIndexBase + 5.
2616
    pub fn radius1(&self) -> UfWord {
2617
        self.data.header().radius1.get()
2618
    }
2619
2620
    /// Base index into DeltaSetIndexMap.
2621
    pub fn var_index_base(&self) -> u32 {
2622
        self.data.header().var_index_base.get()
2623
    }
2624
2625
    pub fn format_byte_range(&self) -> Range<usize> {
2626
        let start = 0usize;
2627
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2628
        start..end
2629
    }
2630
2631
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2632
        let start = self.format_byte_range().end;
2633
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2634
        start..end
2635
    }
2636
2637
    pub fn x0_byte_range(&self) -> Range<usize> {
2638
        let start = self.color_line_offset_byte_range().end;
2639
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2640
        start..end
2641
    }
2642
2643
    pub fn y0_byte_range(&self) -> Range<usize> {
2644
        let start = self.x0_byte_range().end;
2645
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2646
        start..end
2647
    }
2648
2649
    pub fn radius0_byte_range(&self) -> Range<usize> {
2650
        let start = self.y0_byte_range().end;
2651
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
2652
        start..end
2653
    }
2654
2655
    pub fn x1_byte_range(&self) -> Range<usize> {
2656
        let start = self.radius0_byte_range().end;
2657
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2658
        start..end
2659
    }
2660
2661
    pub fn y1_byte_range(&self) -> Range<usize> {
2662
        let start = self.x1_byte_range().end;
2663
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2664
        start..end
2665
    }
2666
2667
    pub fn radius1_byte_range(&self) -> Range<usize> {
2668
        let start = self.y1_byte_range().end;
2669
        let end = start.saturating_add(UfWord::RAW_BYTE_LEN);
2670
        start..end
2671
    }
2672
2673
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
2674
        let start = self.radius1_byte_range().end;
2675
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
2676
        start..end
2677
    }
2678
}
2679
2680
impl Format<u8> for PaintSweepGradient<'_> {
2681
    const FORMAT: u8 = 8;
2682
}
2683
2684
impl<'a> MinByteRange<'a> for PaintSweepGradient<'a> {
2685
    fn min_byte_range(&self) -> Range<usize> {
2686
        0..self.end_angle_byte_range().end
2687
    }
2688
    fn min_table_bytes(&self) -> &'a [u8] {
2689
        let range = self.min_byte_range();
2690
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2691
    }
2692
}
2693
2694
impl ReadArgs for PaintSweepGradient<'_> {
2695
    type Args = ();
2696
}
2697
2698
impl<'a> FontRead<'a> for PaintSweepGradient<'a> {
2699
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2700
        #[allow(clippy::absurd_extreme_comparisons)]
2701
        if data.len() < Self::MIN_SIZE {
2702
            return Err(ReadError::OutOfBounds);
2703
        }
2704
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2705
            return Err(ReadError::OutOfBounds);
2706
        };
2707
        Ok(Self { data })
2708
    }
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
    pub fn format(&self) -> u8 {
2746
        self.data.header().format
2747
    }
2748
2749
    /// Offset to ColorLine table.
2750
    pub fn color_line_offset(&self) -> Offset24 {
2751
        self.data.header().color_line_offset.get()
2752
    }
2753
2754
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2755
    pub fn color_line(&self) -> Result<ColorLine<'a>, ReadError> {
2756
        let data = self.offset_data();
2757
        self.color_line_offset().resolve(data)
2758
    }
2759
2760
    /// Center x coordinate.
2761
    pub fn center_x(&self) -> FWord {
2762
        self.data.header().center_x.get()
2763
    }
2764
2765
    /// Center y coordinate.
2766
    pub fn center_y(&self) -> FWord {
2767
        self.data.header().center_y.get()
2768
    }
2769
2770
    /// Start of the angular range of the gradient, 180° in
2771
    /// counter-clockwise degrees per 1.0 of value.
2772
    pub fn start_angle(&self) -> F2Dot14 {
2773
        self.data.header().start_angle.get()
2774
    }
2775
2776
    /// End of the angular range of the gradient, 180° in
2777
    /// counter-clockwise degrees per 1.0 of value.
2778
    pub fn end_angle(&self) -> F2Dot14 {
2779
        self.data.header().end_angle.get()
2780
    }
2781
2782
    pub fn format_byte_range(&self) -> Range<usize> {
2783
        let start = 0usize;
2784
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2785
        start..end
2786
    }
2787
2788
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2789
        let start = self.format_byte_range().end;
2790
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2791
        start..end
2792
    }
2793
2794
    pub fn center_x_byte_range(&self) -> Range<usize> {
2795
        let start = self.color_line_offset_byte_range().end;
2796
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2797
        start..end
2798
    }
2799
2800
    pub fn center_y_byte_range(&self) -> Range<usize> {
2801
        let start = self.center_x_byte_range().end;
2802
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2803
        start..end
2804
    }
2805
2806
    pub fn start_angle_byte_range(&self) -> Range<usize> {
2807
        let start = self.center_y_byte_range().end;
2808
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
2809
        start..end
2810
    }
2811
2812
    pub fn end_angle_byte_range(&self) -> Range<usize> {
2813
        let start = self.start_angle_byte_range().end;
2814
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
2815
        start..end
2816
    }
2817
}
2818
2819
impl Format<u8> for PaintVarSweepGradient<'_> {
2820
    const FORMAT: u8 = 9;
2821
}
2822
2823
impl<'a> MinByteRange<'a> for PaintVarSweepGradient<'a> {
2824
    fn min_byte_range(&self) -> Range<usize> {
2825
        0..self.var_index_base_byte_range().end
2826
    }
2827
    fn min_table_bytes(&self) -> &'a [u8] {
2828
        let range = self.min_byte_range();
2829
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2830
    }
2831
}
2832
2833
impl ReadArgs for PaintVarSweepGradient<'_> {
2834
    type Args = ();
2835
}
2836
2837
impl<'a> FontRead<'a> for PaintVarSweepGradient<'a> {
2838
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2839
        #[allow(clippy::absurd_extreme_comparisons)]
2840
        if data.len() < Self::MIN_SIZE {
2841
            return Err(ReadError::OutOfBounds);
2842
        }
2843
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2844
            return Err(ReadError::OutOfBounds);
2845
        };
2846
        Ok(Self { data })
2847
    }
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
    pub fn format(&self) -> u8 {
2888
        self.data.header().format
2889
    }
2890
2891
    /// Offset to VarColorLine table.
2892
    pub fn color_line_offset(&self) -> Offset24 {
2893
        self.data.header().color_line_offset.get()
2894
    }
2895
2896
    /// Attempt to resolve [`color_line_offset`][Self::color_line_offset].
2897
    pub fn color_line(&self) -> Result<VarColorLine<'a>, ReadError> {
2898
        let data = self.offset_data();
2899
        self.color_line_offset().resolve(data)
2900
    }
2901
2902
    /// Center x coordinate. For variation, use varIndexBase + 0.
2903
    pub fn center_x(&self) -> FWord {
2904
        self.data.header().center_x.get()
2905
    }
2906
2907
    /// Center y coordinate. For variation, use varIndexBase + 1.
2908
    pub fn center_y(&self) -> FWord {
2909
        self.data.header().center_y.get()
2910
    }
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
    pub fn start_angle(&self) -> F2Dot14 {
2916
        self.data.header().start_angle.get()
2917
    }
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
    pub fn end_angle(&self) -> F2Dot14 {
2923
        self.data.header().end_angle.get()
2924
    }
2925
2926
    /// Base index into DeltaSetIndexMap.
2927
    pub fn var_index_base(&self) -> u32 {
2928
        self.data.header().var_index_base.get()
2929
    }
2930
2931
    pub fn format_byte_range(&self) -> Range<usize> {
2932
        let start = 0usize;
2933
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
2934
        start..end
2935
    }
2936
2937
    pub fn color_line_offset_byte_range(&self) -> Range<usize> {
2938
        let start = self.format_byte_range().end;
2939
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
2940
        start..end
2941
    }
2942
2943
    pub fn center_x_byte_range(&self) -> Range<usize> {
2944
        let start = self.color_line_offset_byte_range().end;
2945
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2946
        start..end
2947
    }
2948
2949
    pub fn center_y_byte_range(&self) -> Range<usize> {
2950
        let start = self.center_x_byte_range().end;
2951
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
2952
        start..end
2953
    }
2954
2955
    pub fn start_angle_byte_range(&self) -> Range<usize> {
2956
        let start = self.center_y_byte_range().end;
2957
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
2958
        start..end
2959
    }
2960
2961
    pub fn end_angle_byte_range(&self) -> Range<usize> {
2962
        let start = self.start_angle_byte_range().end;
2963
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
2964
        start..end
2965
    }
2966
2967
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
2968
        let start = self.end_angle_byte_range().end;
2969
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
2970
        start..end
2971
    }
2972
}
2973
2974
impl Format<u8> for PaintGlyph<'_> {
2975
    const FORMAT: u8 = 10;
2976
}
2977
2978
impl<'a> MinByteRange<'a> for PaintGlyph<'a> {
2979
    fn min_byte_range(&self) -> Range<usize> {
2980
        0..self.glyph_id_byte_range().end
2981
    }
2982
    fn min_table_bytes(&self) -> &'a [u8] {
2983
        let range = self.min_byte_range();
2984
        self.offset_data().as_bytes().get(range).unwrap_or_default()
2985
    }
2986
}
2987
2988
impl ReadArgs for PaintGlyph<'_> {
2989
    type Args = ();
2990
}
2991
2992
impl<'a> FontRead<'a> for PaintGlyph<'a> {
2993
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
2994
        #[allow(clippy::absurd_extreme_comparisons)]
2995
        if data.len() < Self::MIN_SIZE {
2996
            return Err(ReadError::OutOfBounds);
2997
        }
2998
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
2999
            return Err(ReadError::OutOfBounds);
3000
        };
3001
        Ok(Self { data })
3002
    }
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
    pub fn format(&self) -> u8 {
3032
        self.data.header().format
3033
    }
3034
3035
    /// Offset to a Paint table.
3036
    pub fn paint_offset(&self) -> Offset24 {
3037
        self.data.header().paint_offset.get()
3038
    }
3039
3040
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3041
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3042
        let data = self.offset_data();
3043
        self.paint_offset().resolve(data)
3044
    }
3045
3046
    /// Glyph ID for the source outline.
3047
    pub fn glyph_id(&self) -> GlyphId16 {
3048
        self.data.header().glyph_id.get()
3049
    }
3050
3051
    pub fn format_byte_range(&self) -> Range<usize> {
3052
        let start = 0usize;
3053
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3054
        start..end
3055
    }
3056
3057
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3058
        let start = self.format_byte_range().end;
3059
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3060
        start..end
3061
    }
3062
3063
    pub fn glyph_id_byte_range(&self) -> Range<usize> {
3064
        let start = self.paint_offset_byte_range().end;
3065
        let end = start.saturating_add(GlyphId16::RAW_BYTE_LEN);
3066
        start..end
3067
    }
3068
}
3069
3070
impl Format<u8> for PaintGlyph2<'_> {
3071
    const FORMAT: u8 = 33;
3072
}
3073
3074
impl<'a> MinByteRange<'a> for PaintGlyph2<'a> {
3075
    fn min_byte_range(&self) -> Range<usize> {
3076
        0..self.glyph_id_byte_range().end
3077
    }
3078
    fn min_table_bytes(&self) -> &'a [u8] {
3079
        let range = self.min_byte_range();
3080
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3081
    }
3082
}
3083
3084
impl ReadArgs for PaintGlyph2<'_> {
3085
    type Args = ();
3086
}
3087
3088
impl<'a> FontRead<'a> for PaintGlyph2<'a> {
3089
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3090
        #[allow(clippy::absurd_extreme_comparisons)]
3091
        if data.len() < Self::MIN_SIZE {
3092
            return Err(ReadError::OutOfBounds);
3093
        }
3094
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3095
            return Err(ReadError::OutOfBounds);
3096
        };
3097
        Ok(Self { data })
3098
    }
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
    pub fn format(&self) -> u8 {
3128
        self.data.header().format
3129
    }
3130
3131
    /// Offset to a Paint table.
3132
    pub fn paint_offset(&self) -> Offset24 {
3133
        self.data.header().paint_offset.get()
3134
    }
3135
3136
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3137
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3138
        let data = self.offset_data();
3139
        self.paint_offset().resolve(data)
3140
    }
3141
3142
    /// Glyph ID for the source outline.
3143
    pub fn glyph_id(&self) -> GlyphId24 {
3144
        self.data.header().glyph_id.get()
3145
    }
3146
3147
    pub fn format_byte_range(&self) -> Range<usize> {
3148
        let start = 0usize;
3149
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3150
        start..end
3151
    }
3152
3153
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3154
        let start = self.format_byte_range().end;
3155
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3156
        start..end
3157
    }
3158
3159
    pub fn glyph_id_byte_range(&self) -> Range<usize> {
3160
        let start = self.paint_offset_byte_range().end;
3161
        let end = start.saturating_add(GlyphId24::RAW_BYTE_LEN);
3162
        start..end
3163
    }
3164
}
3165
3166
impl Format<u8> for PaintColrGlyph<'_> {
3167
    const FORMAT: u8 = 11;
3168
}
3169
3170
impl<'a> MinByteRange<'a> for PaintColrGlyph<'a> {
3171
    fn min_byte_range(&self) -> Range<usize> {
3172
        0..self.glyph_id_byte_range().end
3173
    }
3174
    fn min_table_bytes(&self) -> &'a [u8] {
3175
        let range = self.min_byte_range();
3176
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3177
    }
3178
}
3179
3180
impl ReadArgs for PaintColrGlyph<'_> {
3181
    type Args = ();
3182
}
3183
3184
impl<'a> FontRead<'a> for PaintColrGlyph<'a> {
3185
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3186
        #[allow(clippy::absurd_extreme_comparisons)]
3187
        if data.len() < Self::MIN_SIZE {
3188
            return Err(ReadError::OutOfBounds);
3189
        }
3190
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3191
            return Err(ReadError::OutOfBounds);
3192
        };
3193
        Ok(Self { data })
3194
    }
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
    pub fn format(&self) -> u8 {
3222
        self.data.header().format
3223
    }
3224
3225
    /// Glyph ID for a BaseGlyphList base glyph.
3226
    pub fn glyph_id(&self) -> GlyphId16 {
3227
        self.data.header().glyph_id.get()
3228
    }
3229
3230
    pub fn format_byte_range(&self) -> Range<usize> {
3231
        let start = 0usize;
3232
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3233
        start..end
3234
    }
3235
3236
    pub fn glyph_id_byte_range(&self) -> Range<usize> {
3237
        let start = self.format_byte_range().end;
3238
        let end = start.saturating_add(GlyphId16::RAW_BYTE_LEN);
3239
        start..end
3240
    }
3241
}
3242
3243
impl Format<u8> for PaintTransform<'_> {
3244
    const FORMAT: u8 = 12;
3245
}
3246
3247
impl<'a> MinByteRange<'a> for PaintTransform<'a> {
3248
    fn min_byte_range(&self) -> Range<usize> {
3249
        0..self.transform_offset_byte_range().end
3250
    }
3251
    fn min_table_bytes(&self) -> &'a [u8] {
3252
        let range = self.min_byte_range();
3253
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3254
    }
3255
}
3256
3257
impl ReadArgs for PaintTransform<'_> {
3258
    type Args = ();
3259
}
3260
3261
impl<'a> FontRead<'a> for PaintTransform<'a> {
3262
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3263
        #[allow(clippy::absurd_extreme_comparisons)]
3264
        if data.len() < Self::MIN_SIZE {
3265
            return Err(ReadError::OutOfBounds);
3266
        }
3267
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3268
            return Err(ReadError::OutOfBounds);
3269
        };
3270
        Ok(Self { data })
3271
    }
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
    pub fn format(&self) -> u8 {
3301
        self.data.header().format
3302
    }
3303
3304
    /// Offset to a Paint subtable.
3305
    pub fn paint_offset(&self) -> Offset24 {
3306
        self.data.header().paint_offset.get()
3307
    }
3308
3309
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3310
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3311
        let data = self.offset_data();
3312
        self.paint_offset().resolve(data)
3313
    }
3314
3315
    /// Offset to an Affine2x3 table.
3316
    pub fn transform_offset(&self) -> Offset24 {
3317
        self.data.header().transform_offset.get()
3318
    }
3319
3320
    /// Attempt to resolve [`transform_offset`][Self::transform_offset].
3321
    pub fn transform(&self) -> Result<Affine2x3<'a>, ReadError> {
3322
        let data = self.offset_data();
3323
        self.transform_offset().resolve(data)
3324
    }
3325
3326
    pub fn format_byte_range(&self) -> Range<usize> {
3327
        let start = 0usize;
3328
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3329
        start..end
3330
    }
3331
3332
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3333
        let start = self.format_byte_range().end;
3334
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3335
        start..end
3336
    }
3337
3338
    pub fn transform_offset_byte_range(&self) -> Range<usize> {
3339
        let start = self.paint_offset_byte_range().end;
3340
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3341
        start..end
3342
    }
3343
}
3344
3345
impl Format<u8> for PaintVarTransform<'_> {
3346
    const FORMAT: u8 = 13;
3347
}
3348
3349
impl<'a> MinByteRange<'a> for PaintVarTransform<'a> {
3350
    fn min_byte_range(&self) -> Range<usize> {
3351
        0..self.transform_offset_byte_range().end
3352
    }
3353
    fn min_table_bytes(&self) -> &'a [u8] {
3354
        let range = self.min_byte_range();
3355
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3356
    }
3357
}
3358
3359
impl ReadArgs for PaintVarTransform<'_> {
3360
    type Args = ();
3361
}
3362
3363
impl<'a> FontRead<'a> for PaintVarTransform<'a> {
3364
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3365
        #[allow(clippy::absurd_extreme_comparisons)]
3366
        if data.len() < Self::MIN_SIZE {
3367
            return Err(ReadError::OutOfBounds);
3368
        }
3369
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3370
            return Err(ReadError::OutOfBounds);
3371
        };
3372
        Ok(Self { data })
3373
    }
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
    pub fn format(&self) -> u8 {
3404
        self.data.header().format
3405
    }
3406
3407
    /// Offset to a Paint subtable.
3408
    pub fn paint_offset(&self) -> Offset24 {
3409
        self.data.header().paint_offset.get()
3410
    }
3411
3412
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3413
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3414
        let data = self.offset_data();
3415
        self.paint_offset().resolve(data)
3416
    }
3417
3418
    /// Offset to a VarAffine2x3 table.
3419
    pub fn transform_offset(&self) -> Offset24 {
3420
        self.data.header().transform_offset.get()
3421
    }
3422
3423
    /// Attempt to resolve [`transform_offset`][Self::transform_offset].
3424
    pub fn transform(&self) -> Result<VarAffine2x3<'a>, ReadError> {
3425
        let data = self.offset_data();
3426
        self.transform_offset().resolve(data)
3427
    }
3428
3429
    pub fn format_byte_range(&self) -> Range<usize> {
3430
        let start = 0usize;
3431
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3432
        start..end
3433
    }
3434
3435
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3436
        let start = self.format_byte_range().end;
3437
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3438
        start..end
3439
    }
3440
3441
    pub fn transform_offset_byte_range(&self) -> Range<usize> {
3442
        let start = self.paint_offset_byte_range().end;
3443
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3444
        start..end
3445
    }
3446
}
3447
3448
impl<'a> MinByteRange<'a> for Affine2x3<'a> {
3449
    fn min_byte_range(&self) -> Range<usize> {
3450
        0..self.dy_byte_range().end
3451
    }
3452
    fn min_table_bytes(&self) -> &'a [u8] {
3453
        let range = self.min_byte_range();
3454
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3455
    }
3456
}
3457
3458
impl ReadArgs for Affine2x3<'_> {
3459
    type Args = ();
3460
}
3461
3462
impl<'a> FontRead<'a> for Affine2x3<'a> {
3463
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3464
        #[allow(clippy::absurd_extreme_comparisons)]
3465
        if data.len() < Self::MIN_SIZE {
3466
            return Err(ReadError::OutOfBounds);
3467
        }
3468
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3469
            return Err(ReadError::OutOfBounds);
3470
        };
3471
        Ok(Self { data })
3472
    }
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
    pub fn xx(&self) -> Fixed {
3509
        self.data.header().xx.get()
3510
    }
3511
3512
    /// y-component of transformed x-basis vector.
3513
    pub fn yx(&self) -> Fixed {
3514
        self.data.header().yx.get()
3515
    }
3516
3517
    /// x-component of transformed y-basis vector.
3518
    pub fn xy(&self) -> Fixed {
3519
        self.data.header().xy.get()
3520
    }
3521
3522
    /// y-component of transformed y-basis vector.
3523
    pub fn yy(&self) -> Fixed {
3524
        self.data.header().yy.get()
3525
    }
3526
3527
    /// Translation in x direction.
3528
    pub fn dx(&self) -> Fixed {
3529
        self.data.header().dx.get()
3530
    }
3531
3532
    /// Translation in y direction.
3533
    pub fn dy(&self) -> Fixed {
3534
        self.data.header().dy.get()
3535
    }
3536
3537
    pub fn xx_byte_range(&self) -> Range<usize> {
3538
        let start = 0usize;
3539
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3540
        start..end
3541
    }
3542
3543
    pub fn yx_byte_range(&self) -> Range<usize> {
3544
        let start = self.xx_byte_range().end;
3545
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3546
        start..end
3547
    }
3548
3549
    pub fn xy_byte_range(&self) -> Range<usize> {
3550
        let start = self.yx_byte_range().end;
3551
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3552
        start..end
3553
    }
3554
3555
    pub fn yy_byte_range(&self) -> Range<usize> {
3556
        let start = self.xy_byte_range().end;
3557
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3558
        start..end
3559
    }
3560
3561
    pub fn dx_byte_range(&self) -> Range<usize> {
3562
        let start = self.yy_byte_range().end;
3563
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3564
        start..end
3565
    }
3566
3567
    pub fn dy_byte_range(&self) -> Range<usize> {
3568
        let start = self.dx_byte_range().end;
3569
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3570
        start..end
3571
    }
3572
}
3573
3574
const _: () = assert!(FontData::default_data_long_enough(Affine2x3::MIN_SIZE));
3575
3576
impl Default for Affine2x3<'_> {
3577
    fn default() -> Self {
3578
        Self {
3579
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
3580
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3581
        }
3582
    }
3583
}
3584
3585
impl<'a> MinByteRange<'a> for VarAffine2x3<'a> {
3586
    fn min_byte_range(&self) -> Range<usize> {
3587
        0..self.var_index_base_byte_range().end
3588
    }
3589
    fn min_table_bytes(&self) -> &'a [u8] {
3590
        let range = self.min_byte_range();
3591
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3592
    }
3593
}
3594
3595
impl ReadArgs for VarAffine2x3<'_> {
3596
    type Args = ();
3597
}
3598
3599
impl<'a> FontRead<'a> for VarAffine2x3<'a> {
3600
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3601
        #[allow(clippy::absurd_extreme_comparisons)]
3602
        if data.len() < Self::MIN_SIZE {
3603
            return Err(ReadError::OutOfBounds);
3604
        }
3605
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3606
            return Err(ReadError::OutOfBounds);
3607
        };
3608
        Ok(Self { data })
3609
    }
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
    pub fn xx(&self) -> Fixed {
3649
        self.data.header().xx.get()
3650
    }
3651
3652
    /// y-component of transformed x-basis vector. For variation, use
3653
    /// varIndexBase + 1.
3654
    pub fn yx(&self) -> Fixed {
3655
        self.data.header().yx.get()
3656
    }
3657
3658
    /// x-component of transformed y-basis vector. For variation, use
3659
    /// varIndexBase + 2.
3660
    pub fn xy(&self) -> Fixed {
3661
        self.data.header().xy.get()
3662
    }
3663
3664
    /// y-component of transformed y-basis vector. For variation, use
3665
    /// varIndexBase + 3.
3666
    pub fn yy(&self) -> Fixed {
3667
        self.data.header().yy.get()
3668
    }
3669
3670
    /// Translation in x direction. For variation, use varIndexBase + 4.
3671
    pub fn dx(&self) -> Fixed {
3672
        self.data.header().dx.get()
3673
    }
3674
3675
    /// Translation in y direction. For variation, use varIndexBase + 5.
3676
    pub fn dy(&self) -> Fixed {
3677
        self.data.header().dy.get()
3678
    }
3679
3680
    /// Base index into DeltaSetIndexMap.
3681
    pub fn var_index_base(&self) -> u32 {
3682
        self.data.header().var_index_base.get()
3683
    }
3684
3685
    pub fn xx_byte_range(&self) -> Range<usize> {
3686
        let start = 0usize;
3687
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3688
        start..end
3689
    }
3690
3691
    pub fn yx_byte_range(&self) -> Range<usize> {
3692
        let start = self.xx_byte_range().end;
3693
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3694
        start..end
3695
    }
3696
3697
    pub fn xy_byte_range(&self) -> Range<usize> {
3698
        let start = self.yx_byte_range().end;
3699
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3700
        start..end
3701
    }
3702
3703
    pub fn yy_byte_range(&self) -> Range<usize> {
3704
        let start = self.xy_byte_range().end;
3705
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3706
        start..end
3707
    }
3708
3709
    pub fn dx_byte_range(&self) -> Range<usize> {
3710
        let start = self.yy_byte_range().end;
3711
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3712
        start..end
3713
    }
3714
3715
    pub fn dy_byte_range(&self) -> Range<usize> {
3716
        let start = self.dx_byte_range().end;
3717
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
3718
        start..end
3719
    }
3720
3721
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
3722
        let start = self.dy_byte_range().end;
3723
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
3724
        start..end
3725
    }
3726
}
3727
3728
const _: () = assert!(FontData::default_data_long_enough(VarAffine2x3::MIN_SIZE));
3729
3730
impl Default for VarAffine2x3<'_> {
3731
    fn default() -> Self {
3732
        Self {
3733
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
3734
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
3735
        }
3736
    }
3737
}
3738
3739
impl Format<u8> for PaintTranslate<'_> {
3740
    const FORMAT: u8 = 14;
3741
}
3742
3743
impl<'a> MinByteRange<'a> for PaintTranslate<'a> {
3744
    fn min_byte_range(&self) -> Range<usize> {
3745
        0..self.dy_byte_range().end
3746
    }
3747
    fn min_table_bytes(&self) -> &'a [u8] {
3748
        let range = self.min_byte_range();
3749
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3750
    }
3751
}
3752
3753
impl ReadArgs for PaintTranslate<'_> {
3754
    type Args = ();
3755
}
3756
3757
impl<'a> FontRead<'a> for PaintTranslate<'a> {
3758
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3759
        #[allow(clippy::absurd_extreme_comparisons)]
3760
        if data.len() < Self::MIN_SIZE {
3761
            return Err(ReadError::OutOfBounds);
3762
        }
3763
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3764
            return Err(ReadError::OutOfBounds);
3765
        };
3766
        Ok(Self { data })
3767
    }
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
    pub fn format(&self) -> u8 {
3798
        self.data.header().format
3799
    }
3800
3801
    /// Offset to a Paint subtable.
3802
    pub fn paint_offset(&self) -> Offset24 {
3803
        self.data.header().paint_offset.get()
3804
    }
3805
3806
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3807
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3808
        let data = self.offset_data();
3809
        self.paint_offset().resolve(data)
3810
    }
3811
3812
    /// Translation in x direction.
3813
    pub fn dx(&self) -> FWord {
3814
        self.data.header().dx.get()
3815
    }
3816
3817
    /// Translation in y direction.
3818
    pub fn dy(&self) -> FWord {
3819
        self.data.header().dy.get()
3820
    }
3821
3822
    pub fn format_byte_range(&self) -> Range<usize> {
3823
        let start = 0usize;
3824
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3825
        start..end
3826
    }
3827
3828
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3829
        let start = self.format_byte_range().end;
3830
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3831
        start..end
3832
    }
3833
3834
    pub fn dx_byte_range(&self) -> Range<usize> {
3835
        let start = self.paint_offset_byte_range().end;
3836
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
3837
        start..end
3838
    }
3839
3840
    pub fn dy_byte_range(&self) -> Range<usize> {
3841
        let start = self.dx_byte_range().end;
3842
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
3843
        start..end
3844
    }
3845
}
3846
3847
impl Format<u8> for PaintVarTranslate<'_> {
3848
    const FORMAT: u8 = 15;
3849
}
3850
3851
impl<'a> MinByteRange<'a> for PaintVarTranslate<'a> {
3852
    fn min_byte_range(&self) -> Range<usize> {
3853
        0..self.var_index_base_byte_range().end
3854
    }
3855
    fn min_table_bytes(&self) -> &'a [u8] {
3856
        let range = self.min_byte_range();
3857
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3858
    }
3859
}
3860
3861
impl ReadArgs for PaintVarTranslate<'_> {
3862
    type Args = ();
3863
}
3864
3865
impl<'a> FontRead<'a> for PaintVarTranslate<'a> {
3866
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3867
        #[allow(clippy::absurd_extreme_comparisons)]
3868
        if data.len() < Self::MIN_SIZE {
3869
            return Err(ReadError::OutOfBounds);
3870
        }
3871
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3872
            return Err(ReadError::OutOfBounds);
3873
        };
3874
        Ok(Self { data })
3875
    }
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
    pub fn format(&self) -> u8 {
3911
        self.data.header().format
3912
    }
3913
3914
    /// Offset to a Paint subtable.
3915
    pub fn paint_offset(&self) -> Offset24 {
3916
        self.data.header().paint_offset.get()
3917
    }
3918
3919
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
3920
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
3921
        let data = self.offset_data();
3922
        self.paint_offset().resolve(data)
3923
    }
3924
3925
    /// Translation in x direction. For variation, use varIndexBase + 0.
3926
    pub fn dx(&self) -> FWord {
3927
        self.data.header().dx.get()
3928
    }
3929
3930
    /// Translation in y direction. For variation, use varIndexBase + 1.
3931
    pub fn dy(&self) -> FWord {
3932
        self.data.header().dy.get()
3933
    }
3934
3935
    /// Base index into DeltaSetIndexMap.
3936
    pub fn var_index_base(&self) -> u32 {
3937
        self.data.header().var_index_base.get()
3938
    }
3939
3940
    pub fn format_byte_range(&self) -> Range<usize> {
3941
        let start = 0usize;
3942
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
3943
        start..end
3944
    }
3945
3946
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
3947
        let start = self.format_byte_range().end;
3948
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
3949
        start..end
3950
    }
3951
3952
    pub fn dx_byte_range(&self) -> Range<usize> {
3953
        let start = self.paint_offset_byte_range().end;
3954
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
3955
        start..end
3956
    }
3957
3958
    pub fn dy_byte_range(&self) -> Range<usize> {
3959
        let start = self.dx_byte_range().end;
3960
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
3961
        start..end
3962
    }
3963
3964
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
3965
        let start = self.dy_byte_range().end;
3966
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
3967
        start..end
3968
    }
3969
}
3970
3971
impl Format<u8> for PaintScale<'_> {
3972
    const FORMAT: u8 = 16;
3973
}
3974
3975
impl<'a> MinByteRange<'a> for PaintScale<'a> {
3976
    fn min_byte_range(&self) -> Range<usize> {
3977
        0..self.scale_y_byte_range().end
3978
    }
3979
    fn min_table_bytes(&self) -> &'a [u8] {
3980
        let range = self.min_byte_range();
3981
        self.offset_data().as_bytes().get(range).unwrap_or_default()
3982
    }
3983
}
3984
3985
impl ReadArgs for PaintScale<'_> {
3986
    type Args = ();
3987
}
3988
3989
impl<'a> FontRead<'a> for PaintScale<'a> {
3990
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
3991
        #[allow(clippy::absurd_extreme_comparisons)]
3992
        if data.len() < Self::MIN_SIZE {
3993
            return Err(ReadError::OutOfBounds);
3994
        }
3995
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
3996
            return Err(ReadError::OutOfBounds);
3997
        };
3998
        Ok(Self { data })
3999
    }
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
    pub fn format(&self) -> u8 {
4030
        self.data.header().format
4031
    }
4032
4033
    /// Offset to a Paint subtable.
4034
    pub fn paint_offset(&self) -> Offset24 {
4035
        self.data.header().paint_offset.get()
4036
    }
4037
4038
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4039
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4040
        let data = self.offset_data();
4041
        self.paint_offset().resolve(data)
4042
    }
4043
4044
    /// Scale factor in x direction.
4045
    pub fn scale_x(&self) -> F2Dot14 {
4046
        self.data.header().scale_x.get()
4047
    }
4048
4049
    /// Scale factor in y direction.
4050
    pub fn scale_y(&self) -> F2Dot14 {
4051
        self.data.header().scale_y.get()
4052
    }
4053
4054
    pub fn format_byte_range(&self) -> Range<usize> {
4055
        let start = 0usize;
4056
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4057
        start..end
4058
    }
4059
4060
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4061
        let start = self.format_byte_range().end;
4062
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4063
        start..end
4064
    }
4065
4066
    pub fn scale_x_byte_range(&self) -> Range<usize> {
4067
        let start = self.paint_offset_byte_range().end;
4068
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4069
        start..end
4070
    }
4071
4072
    pub fn scale_y_byte_range(&self) -> Range<usize> {
4073
        let start = self.scale_x_byte_range().end;
4074
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4075
        start..end
4076
    }
4077
}
4078
4079
impl Format<u8> for PaintVarScale<'_> {
4080
    const FORMAT: u8 = 17;
4081
}
4082
4083
impl<'a> MinByteRange<'a> for PaintVarScale<'a> {
4084
    fn min_byte_range(&self) -> Range<usize> {
4085
        0..self.var_index_base_byte_range().end
4086
    }
4087
    fn min_table_bytes(&self) -> &'a [u8] {
4088
        let range = self.min_byte_range();
4089
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4090
    }
4091
}
4092
4093
impl ReadArgs for PaintVarScale<'_> {
4094
    type Args = ();
4095
}
4096
4097
impl<'a> FontRead<'a> for PaintVarScale<'a> {
4098
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4099
        #[allow(clippy::absurd_extreme_comparisons)]
4100
        if data.len() < Self::MIN_SIZE {
4101
            return Err(ReadError::OutOfBounds);
4102
        }
4103
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4104
            return Err(ReadError::OutOfBounds);
4105
        };
4106
        Ok(Self { data })
4107
    }
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
    pub fn format(&self) -> u8 {
4142
        self.data.header().format
4143
    }
4144
4145
    /// Offset to a Paint subtable.
4146
    pub fn paint_offset(&self) -> Offset24 {
4147
        self.data.header().paint_offset.get()
4148
    }
4149
4150
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4151
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4152
        let data = self.offset_data();
4153
        self.paint_offset().resolve(data)
4154
    }
4155
4156
    /// Scale factor in x direction. For variation, use varIndexBase +
4157
    /// 0.
4158
    pub fn scale_x(&self) -> F2Dot14 {
4159
        self.data.header().scale_x.get()
4160
    }
4161
4162
    /// Scale factor in y direction. For variation, use varIndexBase +
4163
    /// 1.
4164
    pub fn scale_y(&self) -> F2Dot14 {
4165
        self.data.header().scale_y.get()
4166
    }
4167
4168
    /// Base index into DeltaSetIndexMap.
4169
    pub fn var_index_base(&self) -> u32 {
4170
        self.data.header().var_index_base.get()
4171
    }
4172
4173
    pub fn format_byte_range(&self) -> Range<usize> {
4174
        let start = 0usize;
4175
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4176
        start..end
4177
    }
4178
4179
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4180
        let start = self.format_byte_range().end;
4181
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4182
        start..end
4183
    }
4184
4185
    pub fn scale_x_byte_range(&self) -> Range<usize> {
4186
        let start = self.paint_offset_byte_range().end;
4187
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4188
        start..end
4189
    }
4190
4191
    pub fn scale_y_byte_range(&self) -> Range<usize> {
4192
        let start = self.scale_x_byte_range().end;
4193
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4194
        start..end
4195
    }
4196
4197
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
4198
        let start = self.scale_y_byte_range().end;
4199
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4200
        start..end
4201
    }
4202
}
4203
4204
impl Format<u8> for PaintScaleAroundCenter<'_> {
4205
    const FORMAT: u8 = 18;
4206
}
4207
4208
impl<'a> MinByteRange<'a> for PaintScaleAroundCenter<'a> {
4209
    fn min_byte_range(&self) -> Range<usize> {
4210
        0..self.center_y_byte_range().end
4211
    }
4212
    fn min_table_bytes(&self) -> &'a [u8] {
4213
        let range = self.min_byte_range();
4214
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4215
    }
4216
}
4217
4218
impl ReadArgs for PaintScaleAroundCenter<'_> {
4219
    type Args = ();
4220
}
4221
4222
impl<'a> FontRead<'a> for PaintScaleAroundCenter<'a> {
4223
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4224
        #[allow(clippy::absurd_extreme_comparisons)]
4225
        if data.len() < Self::MIN_SIZE {
4226
            return Err(ReadError::OutOfBounds);
4227
        }
4228
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4229
            return Err(ReadError::OutOfBounds);
4230
        };
4231
        Ok(Self { data })
4232
    }
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
    pub fn format(&self) -> u8 {
4271
        self.data.header().format
4272
    }
4273
4274
    /// Offset to a Paint subtable.
4275
    pub fn paint_offset(&self) -> Offset24 {
4276
        self.data.header().paint_offset.get()
4277
    }
4278
4279
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4280
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4281
        let data = self.offset_data();
4282
        self.paint_offset().resolve(data)
4283
    }
4284
4285
    /// Scale factor in x direction.
4286
    pub fn scale_x(&self) -> F2Dot14 {
4287
        self.data.header().scale_x.get()
4288
    }
4289
4290
    /// Scale factor in y direction.
4291
    pub fn scale_y(&self) -> F2Dot14 {
4292
        self.data.header().scale_y.get()
4293
    }
4294
4295
    /// x coordinate for the center of scaling.
4296
    pub fn center_x(&self) -> FWord {
4297
        self.data.header().center_x.get()
4298
    }
4299
4300
    /// y coordinate for the center of scaling.
4301
    pub fn center_y(&self) -> FWord {
4302
        self.data.header().center_y.get()
4303
    }
4304
4305
    pub fn format_byte_range(&self) -> Range<usize> {
4306
        let start = 0usize;
4307
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4308
        start..end
4309
    }
4310
4311
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4312
        let start = self.format_byte_range().end;
4313
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4314
        start..end
4315
    }
4316
4317
    pub fn scale_x_byte_range(&self) -> Range<usize> {
4318
        let start = self.paint_offset_byte_range().end;
4319
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4320
        start..end
4321
    }
4322
4323
    pub fn scale_y_byte_range(&self) -> Range<usize> {
4324
        let start = self.scale_x_byte_range().end;
4325
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4326
        start..end
4327
    }
4328
4329
    pub fn center_x_byte_range(&self) -> Range<usize> {
4330
        let start = self.scale_y_byte_range().end;
4331
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4332
        start..end
4333
    }
4334
4335
    pub fn center_y_byte_range(&self) -> Range<usize> {
4336
        let start = self.center_x_byte_range().end;
4337
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4338
        start..end
4339
    }
4340
}
4341
4342
impl Format<u8> for PaintVarScaleAroundCenter<'_> {
4343
    const FORMAT: u8 = 19;
4344
}
4345
4346
impl<'a> MinByteRange<'a> for PaintVarScaleAroundCenter<'a> {
4347
    fn min_byte_range(&self) -> Range<usize> {
4348
        0..self.var_index_base_byte_range().end
4349
    }
4350
    fn min_table_bytes(&self) -> &'a [u8] {
4351
        let range = self.min_byte_range();
4352
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4353
    }
4354
}
4355
4356
impl ReadArgs for PaintVarScaleAroundCenter<'_> {
4357
    type Args = ();
4358
}
4359
4360
impl<'a> FontRead<'a> for PaintVarScaleAroundCenter<'a> {
4361
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4362
        #[allow(clippy::absurd_extreme_comparisons)]
4363
        if data.len() < Self::MIN_SIZE {
4364
            return Err(ReadError::OutOfBounds);
4365
        }
4366
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4367
            return Err(ReadError::OutOfBounds);
4368
        };
4369
        Ok(Self { data })
4370
    }
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
    pub fn format(&self) -> u8 {
4412
        self.data.header().format
4413
    }
4414
4415
    /// Offset to a Paint subtable.
4416
    pub fn paint_offset(&self) -> Offset24 {
4417
        self.data.header().paint_offset.get()
4418
    }
4419
4420
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4421
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4422
        let data = self.offset_data();
4423
        self.paint_offset().resolve(data)
4424
    }
4425
4426
    /// Scale factor in x direction. For variation, use varIndexBase +
4427
    /// 0.
4428
    pub fn scale_x(&self) -> F2Dot14 {
4429
        self.data.header().scale_x.get()
4430
    }
4431
4432
    /// Scale factor in y direction. For variation, use varIndexBase +
4433
    /// 1.
4434
    pub fn scale_y(&self) -> F2Dot14 {
4435
        self.data.header().scale_y.get()
4436
    }
4437
4438
    /// x coordinate for the center of scaling. For variation, use
4439
    /// varIndexBase + 2.
4440
    pub fn center_x(&self) -> FWord {
4441
        self.data.header().center_x.get()
4442
    }
4443
4444
    /// y coordinate for the center of scaling. For variation, use
4445
    /// varIndexBase + 3.
4446
    pub fn center_y(&self) -> FWord {
4447
        self.data.header().center_y.get()
4448
    }
4449
4450
    /// Base index into DeltaSetIndexMap.
4451
    pub fn var_index_base(&self) -> u32 {
4452
        self.data.header().var_index_base.get()
4453
    }
4454
4455
    pub fn format_byte_range(&self) -> Range<usize> {
4456
        let start = 0usize;
4457
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4458
        start..end
4459
    }
4460
4461
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4462
        let start = self.format_byte_range().end;
4463
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4464
        start..end
4465
    }
4466
4467
    pub fn scale_x_byte_range(&self) -> Range<usize> {
4468
        let start = self.paint_offset_byte_range().end;
4469
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4470
        start..end
4471
    }
4472
4473
    pub fn scale_y_byte_range(&self) -> Range<usize> {
4474
        let start = self.scale_x_byte_range().end;
4475
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4476
        start..end
4477
    }
4478
4479
    pub fn center_x_byte_range(&self) -> Range<usize> {
4480
        let start = self.scale_y_byte_range().end;
4481
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4482
        start..end
4483
    }
4484
4485
    pub fn center_y_byte_range(&self) -> Range<usize> {
4486
        let start = self.center_x_byte_range().end;
4487
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4488
        start..end
4489
    }
4490
4491
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
4492
        let start = self.center_y_byte_range().end;
4493
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4494
        start..end
4495
    }
4496
}
4497
4498
impl Format<u8> for PaintScaleUniform<'_> {
4499
    const FORMAT: u8 = 20;
4500
}
4501
4502
impl<'a> MinByteRange<'a> for PaintScaleUniform<'a> {
4503
    fn min_byte_range(&self) -> Range<usize> {
4504
        0..self.scale_byte_range().end
4505
    }
4506
    fn min_table_bytes(&self) -> &'a [u8] {
4507
        let range = self.min_byte_range();
4508
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4509
    }
4510
}
4511
4512
impl ReadArgs for PaintScaleUniform<'_> {
4513
    type Args = ();
4514
}
4515
4516
impl<'a> FontRead<'a> for PaintScaleUniform<'a> {
4517
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4518
        #[allow(clippy::absurd_extreme_comparisons)]
4519
        if data.len() < Self::MIN_SIZE {
4520
            return Err(ReadError::OutOfBounds);
4521
        }
4522
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4523
            return Err(ReadError::OutOfBounds);
4524
        };
4525
        Ok(Self { data })
4526
    }
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
    pub fn format(&self) -> u8 {
4556
        self.data.header().format
4557
    }
4558
4559
    /// Offset to a Paint subtable.
4560
    pub fn paint_offset(&self) -> Offset24 {
4561
        self.data.header().paint_offset.get()
4562
    }
4563
4564
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4565
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4566
        let data = self.offset_data();
4567
        self.paint_offset().resolve(data)
4568
    }
4569
4570
    /// Scale factor in x and y directions.
4571
    pub fn scale(&self) -> F2Dot14 {
4572
        self.data.header().scale.get()
4573
    }
4574
4575
    pub fn format_byte_range(&self) -> Range<usize> {
4576
        let start = 0usize;
4577
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4578
        start..end
4579
    }
4580
4581
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4582
        let start = self.format_byte_range().end;
4583
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4584
        start..end
4585
    }
4586
4587
    pub fn scale_byte_range(&self) -> Range<usize> {
4588
        let start = self.paint_offset_byte_range().end;
4589
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4590
        start..end
4591
    }
4592
}
4593
4594
impl Format<u8> for PaintVarScaleUniform<'_> {
4595
    const FORMAT: u8 = 21;
4596
}
4597
4598
impl<'a> MinByteRange<'a> for PaintVarScaleUniform<'a> {
4599
    fn min_byte_range(&self) -> Range<usize> {
4600
        0..self.var_index_base_byte_range().end
4601
    }
4602
    fn min_table_bytes(&self) -> &'a [u8] {
4603
        let range = self.min_byte_range();
4604
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4605
    }
4606
}
4607
4608
impl ReadArgs for PaintVarScaleUniform<'_> {
4609
    type Args = ();
4610
}
4611
4612
impl<'a> FontRead<'a> for PaintVarScaleUniform<'a> {
4613
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4614
        #[allow(clippy::absurd_extreme_comparisons)]
4615
        if data.len() < Self::MIN_SIZE {
4616
            return Err(ReadError::OutOfBounds);
4617
        }
4618
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4619
            return Err(ReadError::OutOfBounds);
4620
        };
4621
        Ok(Self { data })
4622
    }
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
    pub fn format(&self) -> u8 {
4655
        self.data.header().format
4656
    }
4657
4658
    /// Offset to a Paint subtable.
4659
    pub fn paint_offset(&self) -> Offset24 {
4660
        self.data.header().paint_offset.get()
4661
    }
4662
4663
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4664
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4665
        let data = self.offset_data();
4666
        self.paint_offset().resolve(data)
4667
    }
4668
4669
    /// Scale factor in x and y directions. For variation, use
4670
    /// varIndexBase + 0.
4671
    pub fn scale(&self) -> F2Dot14 {
4672
        self.data.header().scale.get()
4673
    }
4674
4675
    /// Base index into DeltaSetIndexMap.
4676
    pub fn var_index_base(&self) -> u32 {
4677
        self.data.header().var_index_base.get()
4678
    }
4679
4680
    pub fn format_byte_range(&self) -> Range<usize> {
4681
        let start = 0usize;
4682
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4683
        start..end
4684
    }
4685
4686
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4687
        let start = self.format_byte_range().end;
4688
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4689
        start..end
4690
    }
4691
4692
    pub fn scale_byte_range(&self) -> Range<usize> {
4693
        let start = self.paint_offset_byte_range().end;
4694
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4695
        start..end
4696
    }
4697
4698
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
4699
        let start = self.scale_byte_range().end;
4700
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4701
        start..end
4702
    }
4703
}
4704
4705
impl Format<u8> for PaintScaleUniformAroundCenter<'_> {
4706
    const FORMAT: u8 = 22;
4707
}
4708
4709
impl<'a> MinByteRange<'a> for PaintScaleUniformAroundCenter<'a> {
4710
    fn min_byte_range(&self) -> Range<usize> {
4711
        0..self.center_y_byte_range().end
4712
    }
4713
    fn min_table_bytes(&self) -> &'a [u8] {
4714
        let range = self.min_byte_range();
4715
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4716
    }
4717
}
4718
4719
impl ReadArgs for PaintScaleUniformAroundCenter<'_> {
4720
    type Args = ();
4721
}
4722
4723
impl<'a> FontRead<'a> for PaintScaleUniformAroundCenter<'a> {
4724
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4725
        #[allow(clippy::absurd_extreme_comparisons)]
4726
        if data.len() < Self::MIN_SIZE {
4727
            return Err(ReadError::OutOfBounds);
4728
        }
4729
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4730
            return Err(ReadError::OutOfBounds);
4731
        };
4732
        Ok(Self { data })
4733
    }
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
    pub fn format(&self) -> u8 {
4771
        self.data.header().format
4772
    }
4773
4774
    /// Offset to a Paint subtable.
4775
    pub fn paint_offset(&self) -> Offset24 {
4776
        self.data.header().paint_offset.get()
4777
    }
4778
4779
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4780
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4781
        let data = self.offset_data();
4782
        self.paint_offset().resolve(data)
4783
    }
4784
4785
    /// Scale factor in x and y directions.
4786
    pub fn scale(&self) -> F2Dot14 {
4787
        self.data.header().scale.get()
4788
    }
4789
4790
    /// x coordinate for the center of scaling.
4791
    pub fn center_x(&self) -> FWord {
4792
        self.data.header().center_x.get()
4793
    }
4794
4795
    /// y coordinate for the center of scaling.
4796
    pub fn center_y(&self) -> FWord {
4797
        self.data.header().center_y.get()
4798
    }
4799
4800
    pub fn format_byte_range(&self) -> Range<usize> {
4801
        let start = 0usize;
4802
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4803
        start..end
4804
    }
4805
4806
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4807
        let start = self.format_byte_range().end;
4808
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4809
        start..end
4810
    }
4811
4812
    pub fn scale_byte_range(&self) -> Range<usize> {
4813
        let start = self.paint_offset_byte_range().end;
4814
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4815
        start..end
4816
    }
4817
4818
    pub fn center_x_byte_range(&self) -> Range<usize> {
4819
        let start = self.scale_byte_range().end;
4820
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4821
        start..end
4822
    }
4823
4824
    pub fn center_y_byte_range(&self) -> Range<usize> {
4825
        let start = self.center_x_byte_range().end;
4826
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4827
        start..end
4828
    }
4829
}
4830
4831
impl Format<u8> for PaintVarScaleUniformAroundCenter<'_> {
4832
    const FORMAT: u8 = 23;
4833
}
4834
4835
impl<'a> MinByteRange<'a> for PaintVarScaleUniformAroundCenter<'a> {
4836
    fn min_byte_range(&self) -> Range<usize> {
4837
        0..self.var_index_base_byte_range().end
4838
    }
4839
    fn min_table_bytes(&self) -> &'a [u8] {
4840
        let range = self.min_byte_range();
4841
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4842
    }
4843
}
4844
4845
impl ReadArgs for PaintVarScaleUniformAroundCenter<'_> {
4846
    type Args = ();
4847
}
4848
4849
impl<'a> FontRead<'a> for PaintVarScaleUniformAroundCenter<'a> {
4850
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4851
        #[allow(clippy::absurd_extreme_comparisons)]
4852
        if data.len() < Self::MIN_SIZE {
4853
            return Err(ReadError::OutOfBounds);
4854
        }
4855
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4856
            return Err(ReadError::OutOfBounds);
4857
        };
4858
        Ok(Self { data })
4859
    }
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
    pub fn format(&self) -> u8 {
4899
        self.data.header().format
4900
    }
4901
4902
    /// Offset to a Paint subtable.
4903
    pub fn paint_offset(&self) -> Offset24 {
4904
        self.data.header().paint_offset.get()
4905
    }
4906
4907
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
4908
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
4909
        let data = self.offset_data();
4910
        self.paint_offset().resolve(data)
4911
    }
4912
4913
    /// Scale factor in x and y directions. For variation, use
4914
    /// varIndexBase + 0.
4915
    pub fn scale(&self) -> F2Dot14 {
4916
        self.data.header().scale.get()
4917
    }
4918
4919
    /// x coordinate for the center of scaling. For variation, use
4920
    /// varIndexBase + 1.
4921
    pub fn center_x(&self) -> FWord {
4922
        self.data.header().center_x.get()
4923
    }
4924
4925
    /// y coordinate for the center of scaling. For variation, use
4926
    /// varIndexBase + 2.
4927
    pub fn center_y(&self) -> FWord {
4928
        self.data.header().center_y.get()
4929
    }
4930
4931
    /// Base index into DeltaSetIndexMap.
4932
    pub fn var_index_base(&self) -> u32 {
4933
        self.data.header().var_index_base.get()
4934
    }
4935
4936
    pub fn format_byte_range(&self) -> Range<usize> {
4937
        let start = 0usize;
4938
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
4939
        start..end
4940
    }
4941
4942
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
4943
        let start = self.format_byte_range().end;
4944
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
4945
        start..end
4946
    }
4947
4948
    pub fn scale_byte_range(&self) -> Range<usize> {
4949
        let start = self.paint_offset_byte_range().end;
4950
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
4951
        start..end
4952
    }
4953
4954
    pub fn center_x_byte_range(&self) -> Range<usize> {
4955
        let start = self.scale_byte_range().end;
4956
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4957
        start..end
4958
    }
4959
4960
    pub fn center_y_byte_range(&self) -> Range<usize> {
4961
        let start = self.center_x_byte_range().end;
4962
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
4963
        start..end
4964
    }
4965
4966
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
4967
        let start = self.center_y_byte_range().end;
4968
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
4969
        start..end
4970
    }
4971
}
4972
4973
impl Format<u8> for PaintRotate<'_> {
4974
    const FORMAT: u8 = 24;
4975
}
4976
4977
impl<'a> MinByteRange<'a> for PaintRotate<'a> {
4978
    fn min_byte_range(&self) -> Range<usize> {
4979
        0..self.angle_byte_range().end
4980
    }
4981
    fn min_table_bytes(&self) -> &'a [u8] {
4982
        let range = self.min_byte_range();
4983
        self.offset_data().as_bytes().get(range).unwrap_or_default()
4984
    }
4985
}
4986
4987
impl ReadArgs for PaintRotate<'_> {
4988
    type Args = ();
4989
}
4990
4991
impl<'a> FontRead<'a> for PaintRotate<'a> {
4992
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
4993
        #[allow(clippy::absurd_extreme_comparisons)]
4994
        if data.len() < Self::MIN_SIZE {
4995
            return Err(ReadError::OutOfBounds);
4996
        }
4997
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
4998
            return Err(ReadError::OutOfBounds);
4999
        };
5000
        Ok(Self { data })
5001
    }
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
    pub fn format(&self) -> u8 {
5030
        self.data.header().format
5031
    }
5032
5033
    /// Offset to a Paint subtable.
5034
    pub fn paint_offset(&self) -> Offset24 {
5035
        self.data.header().paint_offset.get()
5036
    }
5037
5038
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5039
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5040
        let data = self.offset_data();
5041
        self.paint_offset().resolve(data)
5042
    }
5043
5044
    /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of
5045
    /// value.
5046
    pub fn angle(&self) -> F2Dot14 {
5047
        self.data.header().angle.get()
5048
    }
5049
5050
    pub fn format_byte_range(&self) -> Range<usize> {
5051
        let start = 0usize;
5052
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5053
        start..end
5054
    }
5055
5056
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5057
        let start = self.format_byte_range().end;
5058
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5059
        start..end
5060
    }
5061
5062
    pub fn angle_byte_range(&self) -> Range<usize> {
5063
        let start = self.paint_offset_byte_range().end;
5064
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5065
        start..end
5066
    }
5067
}
5068
5069
impl Format<u8> for PaintVarRotate<'_> {
5070
    const FORMAT: u8 = 25;
5071
}
5072
5073
impl<'a> MinByteRange<'a> for PaintVarRotate<'a> {
5074
    fn min_byte_range(&self) -> Range<usize> {
5075
        0..self.var_index_base_byte_range().end
5076
    }
5077
    fn min_table_bytes(&self) -> &'a [u8] {
5078
        let range = self.min_byte_range();
5079
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5080
    }
5081
}
5082
5083
impl ReadArgs for PaintVarRotate<'_> {
5084
    type Args = ();
5085
}
5086
5087
impl<'a> FontRead<'a> for PaintVarRotate<'a> {
5088
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5089
        #[allow(clippy::absurd_extreme_comparisons)]
5090
        if data.len() < Self::MIN_SIZE {
5091
            return Err(ReadError::OutOfBounds);
5092
        }
5093
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5094
            return Err(ReadError::OutOfBounds);
5095
        };
5096
        Ok(Self { data })
5097
    }
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
    pub fn format(&self) -> u8 {
5128
        self.data.header().format
5129
    }
5130
5131
    /// Offset to a Paint subtable.
5132
    pub fn paint_offset(&self) -> Offset24 {
5133
        self.data.header().paint_offset.get()
5134
    }
5135
5136
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5137
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5138
        let data = self.offset_data();
5139
        self.paint_offset().resolve(data)
5140
    }
5141
5142
    /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of
5143
    /// value. For variation, use varIndexBase + 0.
5144
    pub fn angle(&self) -> F2Dot14 {
5145
        self.data.header().angle.get()
5146
    }
5147
5148
    /// Base index into DeltaSetIndexMap.
5149
    pub fn var_index_base(&self) -> u32 {
5150
        self.data.header().var_index_base.get()
5151
    }
5152
5153
    pub fn format_byte_range(&self) -> Range<usize> {
5154
        let start = 0usize;
5155
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5156
        start..end
5157
    }
5158
5159
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5160
        let start = self.format_byte_range().end;
5161
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5162
        start..end
5163
    }
5164
5165
    pub fn angle_byte_range(&self) -> Range<usize> {
5166
        let start = self.paint_offset_byte_range().end;
5167
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5168
        start..end
5169
    }
5170
5171
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
5172
        let start = self.angle_byte_range().end;
5173
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5174
        start..end
5175
    }
5176
}
5177
5178
impl Format<u8> for PaintRotateAroundCenter<'_> {
5179
    const FORMAT: u8 = 26;
5180
}
5181
5182
impl<'a> MinByteRange<'a> for PaintRotateAroundCenter<'a> {
5183
    fn min_byte_range(&self) -> Range<usize> {
5184
        0..self.center_y_byte_range().end
5185
    }
5186
    fn min_table_bytes(&self) -> &'a [u8] {
5187
        let range = self.min_byte_range();
5188
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5189
    }
5190
}
5191
5192
impl ReadArgs for PaintRotateAroundCenter<'_> {
5193
    type Args = ();
5194
}
5195
5196
impl<'a> FontRead<'a> for PaintRotateAroundCenter<'a> {
5197
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5198
        #[allow(clippy::absurd_extreme_comparisons)]
5199
        if data.len() < Self::MIN_SIZE {
5200
            return Err(ReadError::OutOfBounds);
5201
        }
5202
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5203
            return Err(ReadError::OutOfBounds);
5204
        };
5205
        Ok(Self { data })
5206
    }
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
    pub fn format(&self) -> u8 {
5243
        self.data.header().format
5244
    }
5245
5246
    /// Offset to a Paint subtable.
5247
    pub fn paint_offset(&self) -> Offset24 {
5248
        self.data.header().paint_offset.get()
5249
    }
5250
5251
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5252
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5253
        let data = self.offset_data();
5254
        self.paint_offset().resolve(data)
5255
    }
5256
5257
    /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of
5258
    /// value.
5259
    pub fn angle(&self) -> F2Dot14 {
5260
        self.data.header().angle.get()
5261
    }
5262
5263
    /// x coordinate for the center of rotation.
5264
    pub fn center_x(&self) -> FWord {
5265
        self.data.header().center_x.get()
5266
    }
5267
5268
    /// y coordinate for the center of rotation.
5269
    pub fn center_y(&self) -> FWord {
5270
        self.data.header().center_y.get()
5271
    }
5272
5273
    pub fn format_byte_range(&self) -> Range<usize> {
5274
        let start = 0usize;
5275
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5276
        start..end
5277
    }
5278
5279
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5280
        let start = self.format_byte_range().end;
5281
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5282
        start..end
5283
    }
5284
5285
    pub fn angle_byte_range(&self) -> Range<usize> {
5286
        let start = self.paint_offset_byte_range().end;
5287
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5288
        start..end
5289
    }
5290
5291
    pub fn center_x_byte_range(&self) -> Range<usize> {
5292
        let start = self.angle_byte_range().end;
5293
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5294
        start..end
5295
    }
5296
5297
    pub fn center_y_byte_range(&self) -> Range<usize> {
5298
        let start = self.center_x_byte_range().end;
5299
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5300
        start..end
5301
    }
5302
}
5303
5304
impl Format<u8> for PaintVarRotateAroundCenter<'_> {
5305
    const FORMAT: u8 = 27;
5306
}
5307
5308
impl<'a> MinByteRange<'a> for PaintVarRotateAroundCenter<'a> {
5309
    fn min_byte_range(&self) -> Range<usize> {
5310
        0..self.var_index_base_byte_range().end
5311
    }
5312
    fn min_table_bytes(&self) -> &'a [u8] {
5313
        let range = self.min_byte_range();
5314
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5315
    }
5316
}
5317
5318
impl ReadArgs for PaintVarRotateAroundCenter<'_> {
5319
    type Args = ();
5320
}
5321
5322
impl<'a> FontRead<'a> for PaintVarRotateAroundCenter<'a> {
5323
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5324
        #[allow(clippy::absurd_extreme_comparisons)]
5325
        if data.len() < Self::MIN_SIZE {
5326
            return Err(ReadError::OutOfBounds);
5327
        }
5328
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5329
            return Err(ReadError::OutOfBounds);
5330
        };
5331
        Ok(Self { data })
5332
    }
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
    pub fn format(&self) -> u8 {
5372
        self.data.header().format
5373
    }
5374
5375
    /// Offset to a Paint subtable.
5376
    pub fn paint_offset(&self) -> Offset24 {
5377
        self.data.header().paint_offset.get()
5378
    }
5379
5380
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5381
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5382
        let data = self.offset_data();
5383
        self.paint_offset().resolve(data)
5384
    }
5385
5386
    /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of
5387
    /// value. For variation, use varIndexBase + 0.
5388
    pub fn angle(&self) -> F2Dot14 {
5389
        self.data.header().angle.get()
5390
    }
5391
5392
    /// x coordinate for the center of rotation. For variation, use
5393
    /// varIndexBase + 1.
5394
    pub fn center_x(&self) -> FWord {
5395
        self.data.header().center_x.get()
5396
    }
5397
5398
    /// y coordinate for the center of rotation. For variation, use
5399
    /// varIndexBase + 2.
5400
    pub fn center_y(&self) -> FWord {
5401
        self.data.header().center_y.get()
5402
    }
5403
5404
    /// Base index into DeltaSetIndexMap.
5405
    pub fn var_index_base(&self) -> u32 {
5406
        self.data.header().var_index_base.get()
5407
    }
5408
5409
    pub fn format_byte_range(&self) -> Range<usize> {
5410
        let start = 0usize;
5411
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5412
        start..end
5413
    }
5414
5415
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5416
        let start = self.format_byte_range().end;
5417
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5418
        start..end
5419
    }
5420
5421
    pub fn angle_byte_range(&self) -> Range<usize> {
5422
        let start = self.paint_offset_byte_range().end;
5423
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5424
        start..end
5425
    }
5426
5427
    pub fn center_x_byte_range(&self) -> Range<usize> {
5428
        let start = self.angle_byte_range().end;
5429
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5430
        start..end
5431
    }
5432
5433
    pub fn center_y_byte_range(&self) -> Range<usize> {
5434
        let start = self.center_x_byte_range().end;
5435
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5436
        start..end
5437
    }
5438
5439
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
5440
        let start = self.center_y_byte_range().end;
5441
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5442
        start..end
5443
    }
5444
}
5445
5446
impl Format<u8> for PaintSkew<'_> {
5447
    const FORMAT: u8 = 28;
5448
}
5449
5450
impl<'a> MinByteRange<'a> for PaintSkew<'a> {
5451
    fn min_byte_range(&self) -> Range<usize> {
5452
        0..self.y_skew_angle_byte_range().end
5453
    }
5454
    fn min_table_bytes(&self) -> &'a [u8] {
5455
        let range = self.min_byte_range();
5456
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5457
    }
5458
}
5459
5460
impl ReadArgs for PaintSkew<'_> {
5461
    type Args = ();
5462
}
5463
5464
impl<'a> FontRead<'a> for PaintSkew<'a> {
5465
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5466
        #[allow(clippy::absurd_extreme_comparisons)]
5467
        if data.len() < Self::MIN_SIZE {
5468
            return Err(ReadError::OutOfBounds);
5469
        }
5470
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5471
            return Err(ReadError::OutOfBounds);
5472
        };
5473
        Ok(Self { data })
5474
    }
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
    pub fn format(&self) -> u8 {
5505
        self.data.header().format
5506
    }
5507
5508
    /// Offset to a Paint subtable.
5509
    pub fn paint_offset(&self) -> Offset24 {
5510
        self.data.header().paint_offset.get()
5511
    }
5512
5513
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5514
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5515
        let data = self.offset_data();
5516
        self.paint_offset().resolve(data)
5517
    }
5518
5519
    /// Angle of skew in the direction of the x-axis, 180° in
5520
    /// counter-clockwise degrees per 1.0 of value.
5521
    pub fn x_skew_angle(&self) -> F2Dot14 {
5522
        self.data.header().x_skew_angle.get()
5523
    }
5524
5525
    /// Angle of skew in the direction of the y-axis, 180° in
5526
    /// counter-clockwise degrees per 1.0 of value.
5527
    pub fn y_skew_angle(&self) -> F2Dot14 {
5528
        self.data.header().y_skew_angle.get()
5529
    }
5530
5531
    pub fn format_byte_range(&self) -> Range<usize> {
5532
        let start = 0usize;
5533
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5534
        start..end
5535
    }
5536
5537
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5538
        let start = self.format_byte_range().end;
5539
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5540
        start..end
5541
    }
5542
5543
    pub fn x_skew_angle_byte_range(&self) -> Range<usize> {
5544
        let start = self.paint_offset_byte_range().end;
5545
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5546
        start..end
5547
    }
5548
5549
    pub fn y_skew_angle_byte_range(&self) -> Range<usize> {
5550
        let start = self.x_skew_angle_byte_range().end;
5551
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5552
        start..end
5553
    }
5554
}
5555
5556
impl Format<u8> for PaintVarSkew<'_> {
5557
    const FORMAT: u8 = 29;
5558
}
5559
5560
impl<'a> MinByteRange<'a> for PaintVarSkew<'a> {
5561
    fn min_byte_range(&self) -> Range<usize> {
5562
        0..self.var_index_base_byte_range().end
5563
    }
5564
    fn min_table_bytes(&self) -> &'a [u8] {
5565
        let range = self.min_byte_range();
5566
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5567
    }
5568
}
5569
5570
impl ReadArgs for PaintVarSkew<'_> {
5571
    type Args = ();
5572
}
5573
5574
impl<'a> FontRead<'a> for PaintVarSkew<'a> {
5575
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5576
        #[allow(clippy::absurd_extreme_comparisons)]
5577
        if data.len() < Self::MIN_SIZE {
5578
            return Err(ReadError::OutOfBounds);
5579
        }
5580
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5581
            return Err(ReadError::OutOfBounds);
5582
        };
5583
        Ok(Self { data })
5584
    }
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
    pub fn format(&self) -> u8 {
5619
        self.data.header().format
5620
    }
5621
5622
    /// Offset to a Paint subtable.
5623
    pub fn paint_offset(&self) -> Offset24 {
5624
        self.data.header().paint_offset.get()
5625
    }
5626
5627
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5628
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5629
        let data = self.offset_data();
5630
        self.paint_offset().resolve(data)
5631
    }
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
    pub fn x_skew_angle(&self) -> F2Dot14 {
5637
        self.data.header().x_skew_angle.get()
5638
    }
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
    pub fn y_skew_angle(&self) -> F2Dot14 {
5644
        self.data.header().y_skew_angle.get()
5645
    }
5646
5647
    /// Base index into DeltaSetIndexMap.
5648
    pub fn var_index_base(&self) -> u32 {
5649
        self.data.header().var_index_base.get()
5650
    }
5651
5652
    pub fn format_byte_range(&self) -> Range<usize> {
5653
        let start = 0usize;
5654
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5655
        start..end
5656
    }
5657
5658
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5659
        let start = self.format_byte_range().end;
5660
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5661
        start..end
5662
    }
5663
5664
    pub fn x_skew_angle_byte_range(&self) -> Range<usize> {
5665
        let start = self.paint_offset_byte_range().end;
5666
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5667
        start..end
5668
    }
5669
5670
    pub fn y_skew_angle_byte_range(&self) -> Range<usize> {
5671
        let start = self.x_skew_angle_byte_range().end;
5672
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5673
        start..end
5674
    }
5675
5676
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
5677
        let start = self.y_skew_angle_byte_range().end;
5678
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5679
        start..end
5680
    }
5681
}
5682
5683
impl Format<u8> for PaintSkewAroundCenter<'_> {
5684
    const FORMAT: u8 = 30;
5685
}
5686
5687
impl<'a> MinByteRange<'a> for PaintSkewAroundCenter<'a> {
5688
    fn min_byte_range(&self) -> Range<usize> {
5689
        0..self.center_y_byte_range().end
5690
    }
5691
    fn min_table_bytes(&self) -> &'a [u8] {
5692
        let range = self.min_byte_range();
5693
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5694
    }
5695
}
5696
5697
impl ReadArgs for PaintSkewAroundCenter<'_> {
5698
    type Args = ();
5699
}
5700
5701
impl<'a> FontRead<'a> for PaintSkewAroundCenter<'a> {
5702
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5703
        #[allow(clippy::absurd_extreme_comparisons)]
5704
        if data.len() < Self::MIN_SIZE {
5705
            return Err(ReadError::OutOfBounds);
5706
        }
5707
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5708
            return Err(ReadError::OutOfBounds);
5709
        };
5710
        Ok(Self { data })
5711
    }
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
    pub fn format(&self) -> u8 {
5750
        self.data.header().format
5751
    }
5752
5753
    /// Offset to a Paint subtable.
5754
    pub fn paint_offset(&self) -> Offset24 {
5755
        self.data.header().paint_offset.get()
5756
    }
5757
5758
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5759
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5760
        let data = self.offset_data();
5761
        self.paint_offset().resolve(data)
5762
    }
5763
5764
    /// Angle of skew in the direction of the x-axis, 180° in
5765
    /// counter-clockwise degrees per 1.0 of value.
5766
    pub fn x_skew_angle(&self) -> F2Dot14 {
5767
        self.data.header().x_skew_angle.get()
5768
    }
5769
5770
    /// Angle of skew in the direction of the y-axis, 180° in
5771
    /// counter-clockwise degrees per 1.0 of value.
5772
    pub fn y_skew_angle(&self) -> F2Dot14 {
5773
        self.data.header().y_skew_angle.get()
5774
    }
5775
5776
    /// x coordinate for the center of rotation.
5777
    pub fn center_x(&self) -> FWord {
5778
        self.data.header().center_x.get()
5779
    }
5780
5781
    /// y coordinate for the center of rotation.
5782
    pub fn center_y(&self) -> FWord {
5783
        self.data.header().center_y.get()
5784
    }
5785
5786
    pub fn format_byte_range(&self) -> Range<usize> {
5787
        let start = 0usize;
5788
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5789
        start..end
5790
    }
5791
5792
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5793
        let start = self.format_byte_range().end;
5794
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5795
        start..end
5796
    }
5797
5798
    pub fn x_skew_angle_byte_range(&self) -> Range<usize> {
5799
        let start = self.paint_offset_byte_range().end;
5800
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5801
        start..end
5802
    }
5803
5804
    pub fn y_skew_angle_byte_range(&self) -> Range<usize> {
5805
        let start = self.x_skew_angle_byte_range().end;
5806
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5807
        start..end
5808
    }
5809
5810
    pub fn center_x_byte_range(&self) -> Range<usize> {
5811
        let start = self.y_skew_angle_byte_range().end;
5812
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5813
        start..end
5814
    }
5815
5816
    pub fn center_y_byte_range(&self) -> Range<usize> {
5817
        let start = self.center_x_byte_range().end;
5818
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5819
        start..end
5820
    }
5821
}
5822
5823
impl Format<u8> for PaintVarSkewAroundCenter<'_> {
5824
    const FORMAT: u8 = 31;
5825
}
5826
5827
impl<'a> MinByteRange<'a> for PaintVarSkewAroundCenter<'a> {
5828
    fn min_byte_range(&self) -> Range<usize> {
5829
        0..self.var_index_base_byte_range().end
5830
    }
5831
    fn min_table_bytes(&self) -> &'a [u8] {
5832
        let range = self.min_byte_range();
5833
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5834
    }
5835
}
5836
5837
impl ReadArgs for PaintVarSkewAroundCenter<'_> {
5838
    type Args = ();
5839
}
5840
5841
impl<'a> FontRead<'a> for PaintVarSkewAroundCenter<'a> {
5842
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
5843
        #[allow(clippy::absurd_extreme_comparisons)]
5844
        if data.len() < Self::MIN_SIZE {
5845
            return Err(ReadError::OutOfBounds);
5846
        }
5847
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
5848
            return Err(ReadError::OutOfBounds);
5849
        };
5850
        Ok(Self { data })
5851
    }
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
    pub fn format(&self) -> u8 {
5893
        self.data.header().format
5894
    }
5895
5896
    /// Offset to a Paint subtable.
5897
    pub fn paint_offset(&self) -> Offset24 {
5898
        self.data.header().paint_offset.get()
5899
    }
5900
5901
    /// Attempt to resolve [`paint_offset`][Self::paint_offset].
5902
    pub fn paint(&self) -> Result<Paint<'a>, ReadError> {
5903
        let data = self.offset_data();
5904
        self.paint_offset().resolve(data)
5905
    }
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
    pub fn x_skew_angle(&self) -> F2Dot14 {
5911
        self.data.header().x_skew_angle.get()
5912
    }
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
    pub fn y_skew_angle(&self) -> F2Dot14 {
5918
        self.data.header().y_skew_angle.get()
5919
    }
5920
5921
    /// x coordinate for the center of rotation. For variation, use
5922
    /// varIndexBase + 2.
5923
    pub fn center_x(&self) -> FWord {
5924
        self.data.header().center_x.get()
5925
    }
5926
5927
    /// y coordinate for the center of rotation. For variation, use
5928
    /// varIndexBase + 3.
5929
    pub fn center_y(&self) -> FWord {
5930
        self.data.header().center_y.get()
5931
    }
5932
5933
    /// Base index into DeltaSetIndexMap.
5934
    pub fn var_index_base(&self) -> u32 {
5935
        self.data.header().var_index_base.get()
5936
    }
5937
5938
    pub fn format_byte_range(&self) -> Range<usize> {
5939
        let start = 0usize;
5940
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
5941
        start..end
5942
    }
5943
5944
    pub fn paint_offset_byte_range(&self) -> Range<usize> {
5945
        let start = self.format_byte_range().end;
5946
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
5947
        start..end
5948
    }
5949
5950
    pub fn x_skew_angle_byte_range(&self) -> Range<usize> {
5951
        let start = self.paint_offset_byte_range().end;
5952
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5953
        start..end
5954
    }
5955
5956
    pub fn y_skew_angle_byte_range(&self) -> Range<usize> {
5957
        let start = self.x_skew_angle_byte_range().end;
5958
        let end = start.saturating_add(F2Dot14::RAW_BYTE_LEN);
5959
        start..end
5960
    }
5961
5962
    pub fn center_x_byte_range(&self) -> Range<usize> {
5963
        let start = self.y_skew_angle_byte_range().end;
5964
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5965
        start..end
5966
    }
5967
5968
    pub fn center_y_byte_range(&self) -> Range<usize> {
5969
        let start = self.center_x_byte_range().end;
5970
        let end = start.saturating_add(FWord::RAW_BYTE_LEN);
5971
        start..end
5972
    }
5973
5974
    pub fn var_index_base_byte_range(&self) -> Range<usize> {
5975
        let start = self.center_y_byte_range().end;
5976
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
5977
        start..end
5978
    }
5979
}
5980
5981
impl Format<u8> for PaintComposite<'_> {
5982
    const FORMAT: u8 = 32;
5983
}
5984
5985
impl<'a> MinByteRange<'a> for PaintComposite<'a> {
5986
    fn min_byte_range(&self) -> Range<usize> {
5987
        0..self.backdrop_paint_offset_byte_range().end
5988
    }
5989
    fn min_table_bytes(&self) -> &'a [u8] {
5990
        let range = self.min_byte_range();
5991
        self.offset_data().as_bytes().get(range).unwrap_or_default()
5992
    }
5993
}
5994
5995
impl ReadArgs for PaintComposite<'_> {
5996
    type Args = ();
5997
}
5998
5999
impl<'a> FontRead<'a> for PaintComposite<'a> {
6000
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
6001
        #[allow(clippy::absurd_extreme_comparisons)]
6002
        if data.len() < Self::MIN_SIZE {
6003
            return Err(ReadError::OutOfBounds);
6004
        }
6005
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
6006
            return Err(ReadError::OutOfBounds);
6007
        };
6008
        Ok(Self { data })
6009
    }
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
    pub fn format(&self) -> u8 {
6042
        self.data.header().format
6043
    }
6044
6045
    /// Offset to a source Paint table.
6046
    pub fn source_paint_offset(&self) -> Offset24 {
6047
        self.data.header().source_paint_offset.get()
6048
    }
6049
6050
    /// Attempt to resolve [`source_paint_offset`][Self::source_paint_offset].
6051
    pub fn source_paint(&self) -> Result<Paint<'a>, ReadError> {
6052
        let data = self.offset_data();
6053
        self.source_paint_offset().resolve(data)
6054
    }
6055
6056
    /// A CompositeMode enumeration value.
6057
    pub fn composite_mode(&self) -> CompositeMode {
6058
        self.data.header().composite_mode.get()
6059
    }
6060
6061
    /// Offset to a backdrop Paint table.
6062
    pub fn backdrop_paint_offset(&self) -> Offset24 {
6063
        self.data.header().backdrop_paint_offset.get()
6064
    }
6065
6066
    /// Attempt to resolve [`backdrop_paint_offset`][Self::backdrop_paint_offset].
6067
    pub fn backdrop_paint(&self) -> Result<Paint<'a>, ReadError> {
6068
        let data = self.offset_data();
6069
        self.backdrop_paint_offset().resolve(data)
6070
    }
6071
6072
    pub fn format_byte_range(&self) -> Range<usize> {
6073
        let start = 0usize;
6074
        let end = start.saturating_add(u8::RAW_BYTE_LEN);
6075
        start..end
6076
    }
6077
6078
    pub fn source_paint_offset_byte_range(&self) -> Range<usize> {
6079
        let start = self.format_byte_range().end;
6080
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
6081
        start..end
6082
    }
6083
6084
    pub fn composite_mode_byte_range(&self) -> Range<usize> {
6085
        let start = self.source_paint_offset_byte_range().end;
6086
        let end = start.saturating_add(CompositeMode::RAW_BYTE_LEN);
6087
        start..end
6088
    }
6089
6090
    pub fn backdrop_paint_offset_byte_range(&self) -> Range<usize> {
6091
        let start = self.composite_mode_byte_range().end;
6092
        let end = start.saturating_add(Offset24::RAW_BYTE_LEN);
6093
        start..end
6094
    }
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
    pub fn new(raw: u8) -> Self {
6180
        match raw {
6181
            0 => Self::Clear,
6182
            1 => Self::Src,
6183
            2 => Self::Dest,
6184
            3 => Self::SrcOver,
6185
            4 => Self::DestOver,
6186
            5 => Self::SrcIn,
6187
            6 => Self::DestIn,
6188
            7 => Self::SrcOut,
6189
            8 => Self::DestOut,
6190
            9 => Self::SrcAtop,
6191
            10 => Self::DestAtop,
6192
            11 => Self::Xor,
6193
            12 => Self::Plus,
6194
            13 => Self::Screen,
6195
            14 => Self::Overlay,
6196
            15 => Self::Darken,
6197
            16 => Self::Lighten,
6198
            17 => Self::ColorDodge,
6199
            18 => Self::ColorBurn,
6200
            19 => Self::HardLight,
6201
            20 => Self::SoftLight,
6202
            21 => Self::Difference,
6203
            22 => Self::Exclusion,
6204
            23 => Self::Multiply,
6205
            24 => Self::HslHue,
6206
            25 => Self::HslSaturation,
6207
            26 => Self::HslColor,
6208
            27 => Self::HslLuminosity,
6209
            _ => Self::Unknown,
6210
        }
6211
    }
6212
}
6213
6214
impl font_types::Scalar for CompositeMode {
6215
    type Raw = <u8 as font_types::Scalar>::Raw;
6216
    fn to_raw(self) -> Self::Raw {
6217
        (self as u8).to_raw()
6218
    }
6219
    fn from_raw(raw: Self::Raw) -> Self {
6220
        let t = <u8>::from_raw(raw);
6221
        Self::new(t)
6222
    }
6223
}