Coverage Report

Created: 2026-12-01 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.47.0/generated/generated_stat.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 Stat<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.offset_to_axis_value_offsets_byte_range().end
11
0
    }
12
0
    fn min_table_bytes(&self) -> &'a [u8] {
13
0
        let range = self.min_byte_range();
14
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
15
0
    }
16
}
17
18
impl TopLevelTable for Stat<'_> {
19
    /// `STAT`
20
    const TAG: Tag = Tag::new(b"STAT");
21
}
22
23
impl ReadArgs for Stat<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Stat<'a> {
28
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
0
        if data.len() < Self::MIN_SIZE {
31
0
            return Err(ReadError::OutOfBounds);
32
0
        }
33
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
0
        Ok(Self { data })
37
0
    }
38
}
39
40
/// The fields at the start of the table, which are read directly.
41
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42
#[repr(C, packed)]
43
#[doc(hidden)]
44
pub struct StatFixedHeader {
45
    pub version: BigEndian<MajorMinor>,
46
    pub design_axis_size: BigEndian<u16>,
47
    pub design_axis_count: BigEndian<u16>,
48
    pub design_axes_offset: BigEndian<Offset32>,
49
    pub axis_value_count: BigEndian<u16>,
50
    pub offset_to_axis_value_offsets: BigEndian<Nullable<Offset32>>,
51
}
52
53
#[allow(clippy::absurd_extreme_comparisons)]
54
const _: () = assert!(std::mem::size_of::<StatFixedHeader>() <= Stat::MIN_SIZE);
55
56
/// [STAT](https://docs.microsoft.com/en-us/typography/opentype/spec/stat) (Style Attributes Table)
57
#[derive(Clone)]
58
pub struct Stat<'a> {
59
    data: TableDataRef<'a, StatFixedHeader>,
60
}
61
62
#[allow(clippy::needless_lifetimes)]
63
impl<'a> Stat<'a> {
64
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
65
        + u16::RAW_BYTE_LEN
66
        + u16::RAW_BYTE_LEN
67
        + Offset32::RAW_BYTE_LEN
68
        + u16::RAW_BYTE_LEN
69
        + Offset32::RAW_BYTE_LEN);
70
    basic_table_impls!(impl_the_methods);
71
72
    /// Major/minor version number. Set to 1.2 for new fonts.
73
0
    pub fn version(&self) -> MajorMinor {
74
0
        self.data.header().version.get()
75
0
    }
76
77
    /// The size in bytes of each axis record.
78
0
    pub fn design_axis_size(&self) -> u16 {
79
0
        self.data.header().design_axis_size.get()
80
0
    }
81
82
    /// The number of axis records. In a font with an 'fvar' table,
83
    /// this value must be greater than or equal to the axisCount value
84
    /// in the 'fvar' table. In all fonts, must be greater than zero if
85
    /// axisValueCount is greater than zero.
86
0
    pub fn design_axis_count(&self) -> u16 {
87
0
        self.data.header().design_axis_count.get()
88
0
    }
89
90
    /// Offset in bytes from the beginning of the STAT table to the
91
    /// start of the design axes array. If designAxisCount is zero, set
92
    /// to zero; if designAxisCount is greater than zero, must be
93
    /// greater than zero.
94
0
    pub fn design_axes_offset(&self) -> Offset32 {
95
0
        self.data.header().design_axes_offset.get()
96
0
    }
97
98
    /// Attempt to resolve [`design_axes_offset`][Self::design_axes_offset].
99
0
    pub fn design_axes(&self) -> Result<&'a [AxisRecord], ReadError> {
100
0
        let data = self.offset_data();
101
0
        let args = self.design_axis_count();
102
0
        self.design_axes_offset().resolve_with_args(data, args)
103
0
    }
104
105
    /// The number of axis value tables.
106
0
    pub fn axis_value_count(&self) -> u16 {
107
0
        self.data.header().axis_value_count.get()
108
0
    }
109
110
    /// Offset in bytes from the beginning of the STAT table to the
111
    /// start of the design axes value offsets array. If axisValueCount
112
    /// is zero, set to zero; if axisValueCount is greater than zero,
113
    /// must be greater than zero.
114
0
    pub fn offset_to_axis_value_offsets(&self) -> Nullable<Offset32> {
115
0
        self.data.header().offset_to_axis_value_offsets.get()
116
0
    }
117
118
    /// Attempt to resolve [`offset_to_axis_value_offsets`][Self::offset_to_axis_value_offsets].
119
0
    pub fn offset_to_axis_values(&self) -> Option<Result<AxisValueArray<'a>, ReadError>> {
120
0
        let data = self.offset_data();
121
0
        let args = self.axis_value_count();
122
0
        self.offset_to_axis_value_offsets()
123
0
            .resolve_with_args(data, args)
124
0
    }
125
126
    /// Name ID used as fallback when projection of names into a
127
    /// particular font model produces a subfamily name containing only
128
    /// elidable elements.
129
0
    pub fn elided_fallback_name_id(&self) -> Option<NameId> {
130
0
        let range = self.elided_fallback_name_id_byte_range();
131
0
        (!range.is_empty())
132
0
            .then(|| self.offset_data().read_at(range.start).ok())
133
0
            .flatten()
134
0
    }
135
136
0
    pub fn version_byte_range(&self) -> Range<usize> {
137
0
        let start = 0usize;
138
0
        let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
139
0
        start..end
140
0
    }
141
142
0
    pub fn design_axis_size_byte_range(&self) -> Range<usize> {
143
0
        let start = self.version_byte_range().end;
144
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
145
0
        start..end
146
0
    }
147
148
0
    pub fn design_axis_count_byte_range(&self) -> Range<usize> {
149
0
        let start = self.design_axis_size_byte_range().end;
150
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
151
0
        start..end
152
0
    }
153
154
0
    pub fn design_axes_offset_byte_range(&self) -> Range<usize> {
155
0
        let start = self.design_axis_count_byte_range().end;
156
0
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
157
0
        start..end
158
0
    }
159
160
0
    pub fn axis_value_count_byte_range(&self) -> Range<usize> {
161
0
        let start = self.design_axes_offset_byte_range().end;
162
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
163
0
        start..end
164
0
    }
165
166
0
    pub fn offset_to_axis_value_offsets_byte_range(&self) -> Range<usize> {
167
0
        let start = self.axis_value_count_byte_range().end;
168
0
        let end = start.saturating_add(Offset32::RAW_BYTE_LEN);
169
0
        start..end
170
0
    }
171
172
0
    pub fn elided_fallback_name_id_byte_range(&self) -> Range<usize> {
173
0
        let start = self.offset_to_axis_value_offsets_byte_range().end;
174
0
        let end = if self.version().compatible((1u16, 1u16)) {
175
0
            start.saturating_add(NameId::RAW_BYTE_LEN)
176
        } else {
177
0
            start
178
        };
179
0
        start..end
180
0
    }
181
}
182
183
const _: () = assert!(FontData::default_data_long_enough(Stat::MIN_SIZE));
184
185
impl Default for Stat<'_> {
186
0
    fn default() -> Self {
187
        Self {
188
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
189
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
190
        }
191
0
    }
192
}
193
194
/// [Axis Records](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-records)
195
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
196
#[repr(C)]
197
#[repr(packed)]
198
pub struct AxisRecord {
199
    /// A tag identifying the axis of design variation.
200
    pub axis_tag: BigEndian<Tag>,
201
    /// The name ID for entries in the 'name' table that provide a
202
    /// display string for this axis.
203
    pub axis_name_id: BigEndian<NameId>,
204
    /// A value that applications can use to determine primary sorting
205
    /// of face names, or for ordering of labels when composing family
206
    /// or face names.
207
    pub axis_ordering: BigEndian<u16>,
208
}
209
210
impl AxisRecord {
211
    /// A tag identifying the axis of design variation.
212
0
    pub fn axis_tag(&self) -> Tag {
213
0
        self.axis_tag.get()
214
0
    }
215
216
    /// The name ID for entries in the 'name' table that provide a
217
    /// display string for this axis.
218
0
    pub fn axis_name_id(&self) -> NameId {
219
0
        self.axis_name_id.get()
220
0
    }
221
222
    /// A value that applications can use to determine primary sorting
223
    /// of face names, or for ordering of labels when composing family
224
    /// or face names.
225
0
    pub fn axis_ordering(&self) -> u16 {
226
0
        self.axis_ordering.get()
227
0
    }
228
}
229
230
impl FixedSize for AxisRecord {
231
    const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + NameId::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
232
}
233
234
impl<'a> MinByteRange<'a> for AxisValueArray<'a> {
235
0
    fn min_byte_range(&self) -> Range<usize> {
236
0
        0..self.axis_value_offsets_byte_range().end
237
0
    }
238
0
    fn min_table_bytes(&self) -> &'a [u8] {
239
0
        let range = self.min_byte_range();
240
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
241
0
    }
242
}
243
244
impl ReadArgs for AxisValueArray<'_> {
245
    type Args = u16;
246
}
247
248
impl<'a> FontRead<'a> for AxisValueArray<'a> {
249
0
    fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> {
250
0
        let axis_value_count = args;
251
252
        #[allow(clippy::absurd_extreme_comparisons)]
253
0
        if data.len() < Self::MIN_SIZE {
254
0
            return Err(ReadError::OutOfBounds);
255
0
        }
256
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
257
0
            return Err(ReadError::OutOfBounds);
258
        };
259
0
        Ok(Self {
260
0
            data,
261
0
            axis_value_count,
262
0
        })
263
0
    }
264
}
265
266
impl<'a> AxisValueArray<'a> {
267
    /// A constructor that requires additional arguments.
268
    ///
269
    /// This type requires some external state in order to be
270
    /// parsed.
271
0
    pub fn read(data: FontData<'a>, axis_value_count: u16) -> Result<Self, ReadError> {
272
0
        let args = axis_value_count;
273
0
        Self::read_with_args(data, args)
274
0
    }
275
}
276
277
/// The fields at the start of the table, which are read directly.
278
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
279
#[repr(C, packed)]
280
#[doc(hidden)]
281
pub struct AxisValueArrayFixedHeader {}
282
283
#[allow(clippy::absurd_extreme_comparisons)]
284
const _: () = assert!(std::mem::size_of::<AxisValueArrayFixedHeader>() <= AxisValueArray::MIN_SIZE);
285
286
/// An array of [AxisValue] tables.
287
#[derive(Clone)]
288
pub struct AxisValueArray<'a> {
289
    data: TableDataRef<'a, AxisValueArrayFixedHeader>,
290
    axis_value_count: u16,
291
}
292
293
#[allow(clippy::needless_lifetimes)]
294
impl<'a> AxisValueArray<'a> {
295
    pub const MIN_SIZE: usize = 0;
296
    basic_table_impls!(impl_the_methods);
297
298
    /// Array of offsets to axis value tables, in bytes from the start
299
    /// of the axis value offsets array.
300
0
    pub fn axis_value_offsets(&self) -> &'a [BigEndian<Offset16>] {
301
0
        let range = self.axis_value_offsets_byte_range();
302
0
        self.offset_data()
303
0
            .read_array(range)
304
0
            .ok()
305
0
            .unwrap_or_default()
306
0
    }
307
308
    /// A dynamically resolving wrapper for [`axis_value_offsets`][Self::axis_value_offsets].
309
0
    pub fn axis_values(&self) -> ArrayOfOffsets<'a, AxisValue<'a>, Offset16> {
310
0
        let data = self.offset_data();
311
0
        let offsets = self.axis_value_offsets();
312
0
        ArrayOfOffsets::new(offsets, data, ())
313
0
    }
314
315
0
    pub(crate) fn axis_value_count(&self) -> u16 {
316
0
        self.axis_value_count
317
0
    }
318
319
0
    pub fn axis_value_offsets_byte_range(&self) -> Range<usize> {
320
0
        let axis_value_count = self.axis_value_count();
321
0
        let start = 0usize;
322
0
        let end = start.saturating_add(
323
0
            (transforms::to_usize(axis_value_count)).saturating_mul(Offset16::RAW_BYTE_LEN),
324
        );
325
0
        start..end
326
0
    }
327
}
328
329
#[allow(clippy::absurd_extreme_comparisons)]
330
const _: () = assert!(FontData::default_data_long_enough(AxisValueArray::MIN_SIZE));
331
332
impl Default for AxisValueArray<'_> {
333
0
    fn default() -> Self {
334
        Self {
335
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
336
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
337
0
            axis_value_count: Default::default(),
338
        }
339
0
    }
340
}
341
342
/// [Axis Value Tables](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-tables)
343
#[derive(Clone)]
344
pub enum AxisValue<'a> {
345
    Format1(AxisValueFormat1<'a>),
346
    Format2(AxisValueFormat2<'a>),
347
    Format3(AxisValueFormat3<'a>),
348
    Format4(AxisValueFormat4<'a>),
349
}
350
351
impl Default for AxisValue<'_> {
352
0
    fn default() -> Self {
353
0
        Self::Format1(Default::default())
354
0
    }
355
}
356
357
impl<'a> AxisValue<'a> {
358
    ///Return the `FontData` used to resolve offsets for this table.
359
0
    pub fn offset_data(&self) -> FontData<'a> {
360
0
        match self {
361
0
            Self::Format1(item) => item.offset_data(),
362
0
            Self::Format2(item) => item.offset_data(),
363
0
            Self::Format3(item) => item.offset_data(),
364
0
            Self::Format4(item) => item.offset_data(),
365
        }
366
0
    }
367
368
    /// Format identifier — set to 1.
369
0
    pub fn format(&self) -> u16 {
370
0
        match self {
371
0
            Self::Format1(item) => item.format(),
372
0
            Self::Format2(item) => item.format(),
373
0
            Self::Format3(item) => item.format(),
374
0
            Self::Format4(item) => item.format(),
375
        }
376
0
    }
377
378
    /// Flags — see below for details.
379
0
    pub fn flags(&self) -> AxisValueTableFlags {
380
0
        match self {
381
0
            Self::Format1(item) => item.flags(),
382
0
            Self::Format2(item) => item.flags(),
383
0
            Self::Format3(item) => item.flags(),
384
0
            Self::Format4(item) => item.flags(),
385
        }
386
0
    }
387
388
    /// The name ID for entries in the 'name' table that provide a
389
    /// display string for this attribute value.
390
0
    pub fn value_name_id(&self) -> NameId {
391
0
        match self {
392
0
            Self::Format1(item) => item.value_name_id(),
393
0
            Self::Format2(item) => item.value_name_id(),
394
0
            Self::Format3(item) => item.value_name_id(),
395
0
            Self::Format4(item) => item.value_name_id(),
396
        }
397
0
    }
398
}
399
400
impl ReadArgs for AxisValue<'_> {
401
    type Args = ();
402
}
403
404
impl<'a> FontRead<'a> for AxisValue<'a> {
405
    #[inline]
406
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
407
0
        let format: u16 = data.read_at(0usize)?;
408
0
        match format {
409
0
            AxisValueFormat1::FORMAT => Ok(Self::Format1(FontRead::read(data)?)),
410
0
            AxisValueFormat2::FORMAT => Ok(Self::Format2(FontRead::read(data)?)),
411
0
            AxisValueFormat3::FORMAT => Ok(Self::Format3(FontRead::read(data)?)),
412
0
            AxisValueFormat4::FORMAT => Ok(Self::Format4(FontRead::read(data)?)),
413
0
            other => Err(ReadError::InvalidFormat(other.into())),
414
        }
415
0
    }
416
}
417
418
impl<'a> MinByteRange<'a> for AxisValue<'a> {
419
0
    fn min_byte_range(&self) -> Range<usize> {
420
0
        match self {
421
0
            Self::Format1(item) => item.min_byte_range(),
422
0
            Self::Format2(item) => item.min_byte_range(),
423
0
            Self::Format3(item) => item.min_byte_range(),
424
0
            Self::Format4(item) => item.min_byte_range(),
425
        }
426
0
    }
427
0
    fn min_table_bytes(&self) -> &'a [u8] {
428
0
        match self {
429
0
            Self::Format1(item) => item.min_table_bytes(),
430
0
            Self::Format2(item) => item.min_table_bytes(),
431
0
            Self::Format3(item) => item.min_table_bytes(),
432
0
            Self::Format4(item) => item.min_table_bytes(),
433
        }
434
0
    }
435
}
436
437
impl Format<u16> for AxisValueFormat1<'_> {
438
    const FORMAT: u16 = 1;
439
}
440
441
impl<'a> MinByteRange<'a> for AxisValueFormat1<'a> {
442
0
    fn min_byte_range(&self) -> Range<usize> {
443
0
        0..self.value_byte_range().end
444
0
    }
445
0
    fn min_table_bytes(&self) -> &'a [u8] {
446
0
        let range = self.min_byte_range();
447
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
448
0
    }
449
}
450
451
impl ReadArgs for AxisValueFormat1<'_> {
452
    type Args = ();
453
}
454
455
impl<'a> FontRead<'a> for AxisValueFormat1<'a> {
456
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
457
        #[allow(clippy::absurd_extreme_comparisons)]
458
0
        if data.len() < Self::MIN_SIZE {
459
0
            return Err(ReadError::OutOfBounds);
460
0
        }
461
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
462
0
            return Err(ReadError::OutOfBounds);
463
        };
464
0
        Ok(Self { data })
465
0
    }
466
}
467
468
/// The fields at the start of the table, which are read directly.
469
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
470
#[repr(C, packed)]
471
#[doc(hidden)]
472
pub struct AxisValueFormat1FixedHeader {
473
    pub format: BigEndian<u16>,
474
    pub axis_index: BigEndian<u16>,
475
    pub flags: BigEndian<AxisValueTableFlags>,
476
    pub value_name_id: BigEndian<NameId>,
477
    pub value: BigEndian<Fixed>,
478
}
479
480
#[allow(clippy::absurd_extreme_comparisons)]
481
const _: () =
482
    assert!(std::mem::size_of::<AxisValueFormat1FixedHeader>() <= AxisValueFormat1::MIN_SIZE);
483
484
/// [Axis value table format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-1)
485
#[derive(Clone)]
486
pub struct AxisValueFormat1<'a> {
487
    data: TableDataRef<'a, AxisValueFormat1FixedHeader>,
488
}
489
490
#[allow(clippy::needless_lifetimes)]
491
impl<'a> AxisValueFormat1<'a> {
492
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
493
        + u16::RAW_BYTE_LEN
494
        + AxisValueTableFlags::RAW_BYTE_LEN
495
        + NameId::RAW_BYTE_LEN
496
        + Fixed::RAW_BYTE_LEN);
497
    basic_table_impls!(impl_the_methods);
498
499
    /// Format identifier — set to 1.
500
0
    pub fn format(&self) -> u16 {
501
0
        self.data.header().format.get()
502
0
    }
503
504
    /// Zero-base index into the axis record array identifying the axis
505
    /// of design variation to which the axis value table applies. Must
506
    /// be less than designAxisCount.
507
0
    pub fn axis_index(&self) -> u16 {
508
0
        self.data.header().axis_index.get()
509
0
    }
510
511
    /// Flags — see below for details.
512
0
    pub fn flags(&self) -> AxisValueTableFlags {
513
0
        self.data.header().flags.get()
514
0
    }
515
516
    /// The name ID for entries in the 'name' table that provide a
517
    /// display string for this attribute value.
518
0
    pub fn value_name_id(&self) -> NameId {
519
0
        self.data.header().value_name_id.get()
520
0
    }
521
522
    /// A numeric value for this attribute value.
523
0
    pub fn value(&self) -> Fixed {
524
0
        self.data.header().value.get()
525
0
    }
526
527
0
    pub fn format_byte_range(&self) -> Range<usize> {
528
0
        let start = 0usize;
529
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
530
0
        start..end
531
0
    }
532
533
0
    pub fn axis_index_byte_range(&self) -> Range<usize> {
534
0
        let start = self.format_byte_range().end;
535
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
536
0
        start..end
537
0
    }
538
539
0
    pub fn flags_byte_range(&self) -> Range<usize> {
540
0
        let start = self.axis_index_byte_range().end;
541
0
        let end = start.saturating_add(AxisValueTableFlags::RAW_BYTE_LEN);
542
0
        start..end
543
0
    }
544
545
0
    pub fn value_name_id_byte_range(&self) -> Range<usize> {
546
0
        let start = self.flags_byte_range().end;
547
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
548
0
        start..end
549
0
    }
550
551
0
    pub fn value_byte_range(&self) -> Range<usize> {
552
0
        let start = self.value_name_id_byte_range().end;
553
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
554
0
        start..end
555
0
    }
556
}
557
558
const _: () = assert!(FontData::default_data_long_enough(
559
    AxisValueFormat1::MIN_SIZE
560
));
561
562
impl Default for AxisValueFormat1<'_> {
563
0
    fn default() -> Self {
564
        Self {
565
0
            data: TableDataRef::new(FontData::default_format_1_u16_table_data().as_bytes())
566
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
567
        }
568
0
    }
569
}
570
571
impl Format<u16> for AxisValueFormat2<'_> {
572
    const FORMAT: u16 = 2;
573
}
574
575
impl<'a> MinByteRange<'a> for AxisValueFormat2<'a> {
576
0
    fn min_byte_range(&self) -> Range<usize> {
577
0
        0..self.range_max_value_byte_range().end
578
0
    }
579
0
    fn min_table_bytes(&self) -> &'a [u8] {
580
0
        let range = self.min_byte_range();
581
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
582
0
    }
583
}
584
585
impl ReadArgs for AxisValueFormat2<'_> {
586
    type Args = ();
587
}
588
589
impl<'a> FontRead<'a> for AxisValueFormat2<'a> {
590
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
591
        #[allow(clippy::absurd_extreme_comparisons)]
592
0
        if data.len() < Self::MIN_SIZE {
593
0
            return Err(ReadError::OutOfBounds);
594
0
        }
595
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
596
0
            return Err(ReadError::OutOfBounds);
597
        };
598
0
        Ok(Self { data })
599
0
    }
600
}
601
602
/// The fields at the start of the table, which are read directly.
603
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
604
#[repr(C, packed)]
605
#[doc(hidden)]
606
pub struct AxisValueFormat2FixedHeader {
607
    pub format: BigEndian<u16>,
608
    pub axis_index: BigEndian<u16>,
609
    pub flags: BigEndian<AxisValueTableFlags>,
610
    pub value_name_id: BigEndian<NameId>,
611
    pub nominal_value: BigEndian<Fixed>,
612
    pub range_min_value: BigEndian<Fixed>,
613
    pub range_max_value: BigEndian<Fixed>,
614
}
615
616
#[allow(clippy::absurd_extreme_comparisons)]
617
const _: () =
618
    assert!(std::mem::size_of::<AxisValueFormat2FixedHeader>() <= AxisValueFormat2::MIN_SIZE);
619
620
/// [Axis value table format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-2)
621
#[derive(Clone)]
622
pub struct AxisValueFormat2<'a> {
623
    data: TableDataRef<'a, AxisValueFormat2FixedHeader>,
624
}
625
626
#[allow(clippy::needless_lifetimes)]
627
impl<'a> AxisValueFormat2<'a> {
628
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
629
        + u16::RAW_BYTE_LEN
630
        + AxisValueTableFlags::RAW_BYTE_LEN
631
        + NameId::RAW_BYTE_LEN
632
        + Fixed::RAW_BYTE_LEN
633
        + Fixed::RAW_BYTE_LEN
634
        + Fixed::RAW_BYTE_LEN);
635
    basic_table_impls!(impl_the_methods);
636
637
    /// Format identifier — set to 2.
638
0
    pub fn format(&self) -> u16 {
639
0
        self.data.header().format.get()
640
0
    }
641
642
    /// Zero-base index into the axis record array identifying the axis
643
    /// of design variation to which the axis value table applies. Must
644
    /// be less than designAxisCount.
645
0
    pub fn axis_index(&self) -> u16 {
646
0
        self.data.header().axis_index.get()
647
0
    }
648
649
    /// Flags — see below for details.
650
0
    pub fn flags(&self) -> AxisValueTableFlags {
651
0
        self.data.header().flags.get()
652
0
    }
653
654
    /// The name ID for entries in the 'name' table that provide a
655
    /// display string for this attribute value.
656
0
    pub fn value_name_id(&self) -> NameId {
657
0
        self.data.header().value_name_id.get()
658
0
    }
659
660
    /// A nominal numeric value for this attribute value.
661
0
    pub fn nominal_value(&self) -> Fixed {
662
0
        self.data.header().nominal_value.get()
663
0
    }
664
665
    /// The minimum value for a range associated with the specified
666
    /// name ID.
667
0
    pub fn range_min_value(&self) -> Fixed {
668
0
        self.data.header().range_min_value.get()
669
0
    }
670
671
    /// The maximum value for a range associated with the specified
672
    /// name ID.
673
0
    pub fn range_max_value(&self) -> Fixed {
674
0
        self.data.header().range_max_value.get()
675
0
    }
676
677
0
    pub fn format_byte_range(&self) -> Range<usize> {
678
0
        let start = 0usize;
679
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
680
0
        start..end
681
0
    }
682
683
0
    pub fn axis_index_byte_range(&self) -> Range<usize> {
684
0
        let start = self.format_byte_range().end;
685
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
686
0
        start..end
687
0
    }
688
689
0
    pub fn flags_byte_range(&self) -> Range<usize> {
690
0
        let start = self.axis_index_byte_range().end;
691
0
        let end = start.saturating_add(AxisValueTableFlags::RAW_BYTE_LEN);
692
0
        start..end
693
0
    }
694
695
0
    pub fn value_name_id_byte_range(&self) -> Range<usize> {
696
0
        let start = self.flags_byte_range().end;
697
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
698
0
        start..end
699
0
    }
700
701
0
    pub fn nominal_value_byte_range(&self) -> Range<usize> {
702
0
        let start = self.value_name_id_byte_range().end;
703
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
704
0
        start..end
705
0
    }
706
707
0
    pub fn range_min_value_byte_range(&self) -> Range<usize> {
708
0
        let start = self.nominal_value_byte_range().end;
709
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
710
0
        start..end
711
0
    }
712
713
0
    pub fn range_max_value_byte_range(&self) -> Range<usize> {
714
0
        let start = self.range_min_value_byte_range().end;
715
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
716
0
        start..end
717
0
    }
718
}
719
720
impl Format<u16> for AxisValueFormat3<'_> {
721
    const FORMAT: u16 = 3;
722
}
723
724
impl<'a> MinByteRange<'a> for AxisValueFormat3<'a> {
725
0
    fn min_byte_range(&self) -> Range<usize> {
726
0
        0..self.linked_value_byte_range().end
727
0
    }
728
0
    fn min_table_bytes(&self) -> &'a [u8] {
729
0
        let range = self.min_byte_range();
730
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
731
0
    }
732
}
733
734
impl ReadArgs for AxisValueFormat3<'_> {
735
    type Args = ();
736
}
737
738
impl<'a> FontRead<'a> for AxisValueFormat3<'a> {
739
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
740
        #[allow(clippy::absurd_extreme_comparisons)]
741
0
        if data.len() < Self::MIN_SIZE {
742
0
            return Err(ReadError::OutOfBounds);
743
0
        }
744
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
745
0
            return Err(ReadError::OutOfBounds);
746
        };
747
0
        Ok(Self { data })
748
0
    }
749
}
750
751
/// The fields at the start of the table, which are read directly.
752
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
753
#[repr(C, packed)]
754
#[doc(hidden)]
755
pub struct AxisValueFormat3FixedHeader {
756
    pub format: BigEndian<u16>,
757
    pub axis_index: BigEndian<u16>,
758
    pub flags: BigEndian<AxisValueTableFlags>,
759
    pub value_name_id: BigEndian<NameId>,
760
    pub value: BigEndian<Fixed>,
761
    pub linked_value: BigEndian<Fixed>,
762
}
763
764
#[allow(clippy::absurd_extreme_comparisons)]
765
const _: () =
766
    assert!(std::mem::size_of::<AxisValueFormat3FixedHeader>() <= AxisValueFormat3::MIN_SIZE);
767
768
/// [Axis value table format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-3)
769
#[derive(Clone)]
770
pub struct AxisValueFormat3<'a> {
771
    data: TableDataRef<'a, AxisValueFormat3FixedHeader>,
772
}
773
774
#[allow(clippy::needless_lifetimes)]
775
impl<'a> AxisValueFormat3<'a> {
776
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
777
        + u16::RAW_BYTE_LEN
778
        + AxisValueTableFlags::RAW_BYTE_LEN
779
        + NameId::RAW_BYTE_LEN
780
        + Fixed::RAW_BYTE_LEN
781
        + Fixed::RAW_BYTE_LEN);
782
    basic_table_impls!(impl_the_methods);
783
784
    /// Format identifier — set to 3.
785
0
    pub fn format(&self) -> u16 {
786
0
        self.data.header().format.get()
787
0
    }
788
789
    /// Zero-base index into the axis record array identifying the axis
790
    /// of design variation to which the axis value table applies. Must
791
    /// be less than designAxisCount.
792
0
    pub fn axis_index(&self) -> u16 {
793
0
        self.data.header().axis_index.get()
794
0
    }
795
796
    /// Flags — see below for details.
797
0
    pub fn flags(&self) -> AxisValueTableFlags {
798
0
        self.data.header().flags.get()
799
0
    }
800
801
    /// The name ID for entries in the 'name' table that provide a
802
    /// display string for this attribute value.
803
0
    pub fn value_name_id(&self) -> NameId {
804
0
        self.data.header().value_name_id.get()
805
0
    }
806
807
    /// A numeric value for this attribute value.
808
0
    pub fn value(&self) -> Fixed {
809
0
        self.data.header().value.get()
810
0
    }
811
812
    /// The numeric value for a style-linked mapping from this value.
813
0
    pub fn linked_value(&self) -> Fixed {
814
0
        self.data.header().linked_value.get()
815
0
    }
816
817
0
    pub fn format_byte_range(&self) -> Range<usize> {
818
0
        let start = 0usize;
819
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
820
0
        start..end
821
0
    }
822
823
0
    pub fn axis_index_byte_range(&self) -> Range<usize> {
824
0
        let start = self.format_byte_range().end;
825
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
826
0
        start..end
827
0
    }
828
829
0
    pub fn flags_byte_range(&self) -> Range<usize> {
830
0
        let start = self.axis_index_byte_range().end;
831
0
        let end = start.saturating_add(AxisValueTableFlags::RAW_BYTE_LEN);
832
0
        start..end
833
0
    }
834
835
0
    pub fn value_name_id_byte_range(&self) -> Range<usize> {
836
0
        let start = self.flags_byte_range().end;
837
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
838
0
        start..end
839
0
    }
840
841
0
    pub fn value_byte_range(&self) -> Range<usize> {
842
0
        let start = self.value_name_id_byte_range().end;
843
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
844
0
        start..end
845
0
    }
846
847
0
    pub fn linked_value_byte_range(&self) -> Range<usize> {
848
0
        let start = self.value_byte_range().end;
849
0
        let end = start.saturating_add(Fixed::RAW_BYTE_LEN);
850
0
        start..end
851
0
    }
852
}
853
854
impl Format<u16> for AxisValueFormat4<'_> {
855
    const FORMAT: u16 = 4;
856
}
857
858
impl<'a> MinByteRange<'a> for AxisValueFormat4<'a> {
859
0
    fn min_byte_range(&self) -> Range<usize> {
860
0
        0..self.axis_values_byte_range().end
861
0
    }
862
0
    fn min_table_bytes(&self) -> &'a [u8] {
863
0
        let range = self.min_byte_range();
864
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
865
0
    }
866
}
867
868
impl ReadArgs for AxisValueFormat4<'_> {
869
    type Args = ();
870
}
871
872
impl<'a> FontRead<'a> for AxisValueFormat4<'a> {
873
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
874
        #[allow(clippy::absurd_extreme_comparisons)]
875
0
        if data.len() < Self::MIN_SIZE {
876
0
            return Err(ReadError::OutOfBounds);
877
0
        }
878
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
879
0
            return Err(ReadError::OutOfBounds);
880
        };
881
0
        Ok(Self { data })
882
0
    }
883
}
884
885
/// The fields at the start of the table, which are read directly.
886
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
887
#[repr(C, packed)]
888
#[doc(hidden)]
889
pub struct AxisValueFormat4FixedHeader {
890
    pub format: BigEndian<u16>,
891
    pub axis_count: BigEndian<u16>,
892
    pub flags: BigEndian<AxisValueTableFlags>,
893
    pub value_name_id: BigEndian<NameId>,
894
}
895
896
#[allow(clippy::absurd_extreme_comparisons)]
897
const _: () =
898
    assert!(std::mem::size_of::<AxisValueFormat4FixedHeader>() <= AxisValueFormat4::MIN_SIZE);
899
900
/// [Axis value table format 4](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-4)
901
#[derive(Clone)]
902
pub struct AxisValueFormat4<'a> {
903
    data: TableDataRef<'a, AxisValueFormat4FixedHeader>,
904
}
905
906
#[allow(clippy::needless_lifetimes)]
907
impl<'a> AxisValueFormat4<'a> {
908
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN
909
        + u16::RAW_BYTE_LEN
910
        + AxisValueTableFlags::RAW_BYTE_LEN
911
        + NameId::RAW_BYTE_LEN);
912
    basic_table_impls!(impl_the_methods);
913
914
    /// Format identifier — set to 4.
915
0
    pub fn format(&self) -> u16 {
916
0
        self.data.header().format.get()
917
0
    }
918
919
    /// The total number of axes contributing to this axis-values
920
    /// combination.
921
0
    pub fn axis_count(&self) -> u16 {
922
0
        self.data.header().axis_count.get()
923
0
    }
924
925
    /// Flags — see below for details.
926
0
    pub fn flags(&self) -> AxisValueTableFlags {
927
0
        self.data.header().flags.get()
928
0
    }
929
930
    /// The name ID for entries in the 'name' table that provide a
931
    /// display string for this combination of axis values.
932
0
    pub fn value_name_id(&self) -> NameId {
933
0
        self.data.header().value_name_id.get()
934
0
    }
935
936
    /// Array of AxisValue records that provide the combination of axis
937
    /// values, one for each contributing axis.
938
0
    pub fn axis_values(&self) -> &'a [AxisValueRecord] {
939
0
        let range = self.axis_values_byte_range();
940
0
        self.offset_data()
941
0
            .read_array(range)
942
0
            .ok()
943
0
            .unwrap_or_default()
944
0
    }
945
946
0
    pub fn format_byte_range(&self) -> Range<usize> {
947
0
        let start = 0usize;
948
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
949
0
        start..end
950
0
    }
951
952
0
    pub fn axis_count_byte_range(&self) -> Range<usize> {
953
0
        let start = self.format_byte_range().end;
954
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
955
0
        start..end
956
0
    }
957
958
0
    pub fn flags_byte_range(&self) -> Range<usize> {
959
0
        let start = self.axis_count_byte_range().end;
960
0
        let end = start.saturating_add(AxisValueTableFlags::RAW_BYTE_LEN);
961
0
        start..end
962
0
    }
963
964
0
    pub fn value_name_id_byte_range(&self) -> Range<usize> {
965
0
        let start = self.flags_byte_range().end;
966
0
        let end = start.saturating_add(NameId::RAW_BYTE_LEN);
967
0
        start..end
968
0
    }
969
970
0
    pub fn axis_values_byte_range(&self) -> Range<usize> {
971
0
        let axis_count = self.axis_count();
972
0
        let start = self.value_name_id_byte_range().end;
973
0
        let end = start.saturating_add(
974
0
            (transforms::to_usize(axis_count)).saturating_mul(AxisValueRecord::RAW_BYTE_LEN),
975
        );
976
0
        start..end
977
0
    }
978
}
979
980
/// Part of [AxisValueFormat4]
981
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
982
#[repr(C)]
983
#[repr(packed)]
984
pub struct AxisValueRecord {
985
    /// Zero-base index into the axis record array identifying the axis
986
    /// to which this value applies. Must be less than designAxisCount.
987
    pub axis_index: BigEndian<u16>,
988
    /// A numeric value for this attribute value.
989
    pub value: BigEndian<Fixed>,
990
}
991
992
impl AxisValueRecord {
993
    /// Zero-base index into the axis record array identifying the axis
994
    /// to which this value applies. Must be less than designAxisCount.
995
0
    pub fn axis_index(&self) -> u16 {
996
0
        self.axis_index.get()
997
0
    }
998
999
    /// A numeric value for this attribute value.
1000
0
    pub fn value(&self) -> Fixed {
1001
0
        self.value.get()
1002
0
    }
1003
}
1004
1005
impl FixedSize for AxisValueRecord {
1006
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + Fixed::RAW_BYTE_LEN;
1007
}
1008
1009
/// [Axis value table flags](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#flags).
1010
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck :: AnyBitPattern)]
1011
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1012
#[repr(transparent)]
1013
pub struct AxisValueTableFlags {
1014
    bits: u16,
1015
}
1016
1017
impl AxisValueTableFlags {
1018
    /// If set, this axis value table provides axis value information
1019
    /// that is applicable to other fonts within the same font family.
1020
    /// This is used if the other fonts were released earlier and did
1021
    /// not include information about values for some axis. If newer
1022
    /// versions of the other fonts include the information themselves
1023
    /// and are present, then this table is ignored.
1024
    pub const OLDER_SIBLING_FONT_ATTRIBUTE: Self = Self { bits: 0x0001 };
1025
1026
    /// If set, it indicates that the axis value represents the
1027
    /// “normal” value for the axis and may be omitted when
1028
    /// composing name strings.
1029
    pub const ELIDABLE_AXIS_VALUE_NAME: Self = Self { bits: 0x0002 };
1030
}
1031
1032
impl AxisValueTableFlags {
1033
    ///  Returns an empty set of flags.
1034
    #[inline]
1035
0
    pub const fn empty() -> Self {
1036
0
        Self { bits: 0 }
1037
0
    }
1038
1039
    /// Returns the set containing all flags.
1040
    #[inline]
1041
0
    pub const fn all() -> Self {
1042
0
        Self {
1043
0
            bits: Self::OLDER_SIBLING_FONT_ATTRIBUTE.bits | Self::ELIDABLE_AXIS_VALUE_NAME.bits,
1044
0
        }
1045
0
    }
1046
1047
    /// Returns the raw value of the flags currently stored.
1048
    #[inline]
1049
0
    pub const fn bits(&self) -> u16 {
1050
0
        self.bits
1051
0
    }
1052
1053
    /// Convert from underlying bit representation, unless that
1054
    /// representation contains bits that do not correspond to a flag.
1055
    #[inline]
1056
0
    pub const fn from_bits(bits: u16) -> Option<Self> {
1057
0
        if (bits & !Self::all().bits()) == 0 {
1058
0
            Some(Self { bits })
1059
        } else {
1060
0
            None
1061
        }
1062
0
    }
1063
1064
    /// Convert from underlying bit representation, dropping any bits
1065
    /// that do not correspond to flags.
1066
    #[inline]
1067
0
    pub const fn from_bits_truncate(bits: u16) -> Self {
1068
0
        Self {
1069
0
            bits: bits & Self::all().bits,
1070
0
        }
1071
0
    }
1072
1073
    /// Returns `true` if no flags are currently stored.
1074
    #[inline]
1075
0
    pub const fn is_empty(&self) -> bool {
1076
0
        self.bits() == Self::empty().bits()
1077
0
    }
1078
1079
    /// Returns `true` if there are flags common to both `self` and `other`.
1080
    #[inline]
1081
0
    pub const fn intersects(&self, other: Self) -> bool {
1082
0
        !(Self {
1083
0
            bits: self.bits & other.bits,
1084
0
        })
1085
0
        .is_empty()
1086
0
    }
1087
1088
    /// Returns `true` if all of the flags in `other` are contained within `self`.
1089
    #[inline]
1090
0
    pub const fn contains(&self, other: Self) -> bool {
1091
0
        (self.bits & other.bits) == other.bits
1092
0
    }
1093
1094
    /// Inserts the specified flags in-place.
1095
    #[inline]
1096
0
    pub fn insert(&mut self, other: Self) {
1097
0
        self.bits |= other.bits;
1098
0
    }
1099
1100
    /// Removes the specified flags in-place.
1101
    #[inline]
1102
0
    pub fn remove(&mut self, other: Self) {
1103
0
        self.bits &= !other.bits;
1104
0
    }
1105
1106
    /// Toggles the specified flags in-place.
1107
    #[inline]
1108
0
    pub fn toggle(&mut self, other: Self) {
1109
0
        self.bits ^= other.bits;
1110
0
    }
1111
1112
    /// Returns the intersection between the flags in `self` and
1113
    /// `other`.
1114
    ///
1115
    /// Specifically, the returned set contains only the flags which are
1116
    /// present in *both* `self` *and* `other`.
1117
    ///
1118
    /// This is equivalent to using the `&` operator (e.g.
1119
    /// [`ops::BitAnd`]), as in `flags & other`.
1120
    ///
1121
    /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
1122
    #[inline]
1123
    #[must_use]
1124
0
    pub const fn intersection(self, other: Self) -> Self {
1125
0
        Self {
1126
0
            bits: self.bits & other.bits,
1127
0
        }
1128
0
    }
1129
1130
    /// Returns the union of between the flags in `self` and `other`.
1131
    ///
1132
    /// Specifically, the returned set contains all flags which are
1133
    /// present in *either* `self` *or* `other`, including any which are
1134
    /// present in both.
1135
    ///
1136
    /// This is equivalent to using the `|` operator (e.g.
1137
    /// [`ops::BitOr`]), as in `flags | other`.
1138
    ///
1139
    /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
1140
    #[inline]
1141
    #[must_use]
1142
0
    pub const fn union(self, other: Self) -> Self {
1143
0
        Self {
1144
0
            bits: self.bits | other.bits,
1145
0
        }
1146
0
    }
1147
1148
    /// Returns the difference between the flags in `self` and `other`.
1149
    ///
1150
    /// Specifically, the returned set contains all flags present in
1151
    /// `self`, except for the ones present in `other`.
1152
    ///
1153
    /// It is also conceptually equivalent to the "bit-clear" operation:
1154
    /// `flags & !other` (and this syntax is also supported).
1155
    ///
1156
    /// This is equivalent to using the `-` operator (e.g.
1157
    /// [`ops::Sub`]), as in `flags - other`.
1158
    ///
1159
    /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
1160
    #[inline]
1161
    #[must_use]
1162
0
    pub const fn difference(self, other: Self) -> Self {
1163
0
        Self {
1164
0
            bits: self.bits & !other.bits,
1165
0
        }
1166
0
    }
1167
}
1168
1169
impl std::ops::BitOr for AxisValueTableFlags {
1170
    type Output = Self;
1171
1172
    /// Returns the union of the two sets of flags.
1173
    #[inline]
1174
0
    fn bitor(self, other: AxisValueTableFlags) -> Self {
1175
0
        Self {
1176
0
            bits: self.bits | other.bits,
1177
0
        }
1178
0
    }
1179
}
1180
1181
impl std::ops::BitOrAssign for AxisValueTableFlags {
1182
    /// Adds the set of flags.
1183
    #[inline]
1184
0
    fn bitor_assign(&mut self, other: Self) {
1185
0
        self.bits |= other.bits;
1186
0
    }
1187
}
1188
1189
impl std::ops::BitXor for AxisValueTableFlags {
1190
    type Output = Self;
1191
1192
    /// Returns the left flags, but with all the right flags toggled.
1193
    #[inline]
1194
0
    fn bitxor(self, other: Self) -> Self {
1195
0
        Self {
1196
0
            bits: self.bits ^ other.bits,
1197
0
        }
1198
0
    }
1199
}
1200
1201
impl std::ops::BitXorAssign for AxisValueTableFlags {
1202
    /// Toggles the set of flags.
1203
    #[inline]
1204
0
    fn bitxor_assign(&mut self, other: Self) {
1205
0
        self.bits ^= other.bits;
1206
0
    }
1207
}
1208
1209
impl std::ops::BitAnd for AxisValueTableFlags {
1210
    type Output = Self;
1211
1212
    /// Returns the intersection between the two sets of flags.
1213
    #[inline]
1214
0
    fn bitand(self, other: Self) -> Self {
1215
0
        Self {
1216
0
            bits: self.bits & other.bits,
1217
0
        }
1218
0
    }
1219
}
1220
1221
impl std::ops::BitAndAssign for AxisValueTableFlags {
1222
    /// Disables all flags disabled in the set.
1223
    #[inline]
1224
0
    fn bitand_assign(&mut self, other: Self) {
1225
0
        self.bits &= other.bits;
1226
0
    }
1227
}
1228
1229
impl std::ops::Sub for AxisValueTableFlags {
1230
    type Output = Self;
1231
1232
    /// Returns the set difference of the two sets of flags.
1233
    #[inline]
1234
0
    fn sub(self, other: Self) -> Self {
1235
0
        Self {
1236
0
            bits: self.bits & !other.bits,
1237
0
        }
1238
0
    }
1239
}
1240
1241
impl std::ops::SubAssign for AxisValueTableFlags {
1242
    /// Disables all flags enabled in the set.
1243
    #[inline]
1244
0
    fn sub_assign(&mut self, other: Self) {
1245
0
        self.bits &= !other.bits;
1246
0
    }
1247
}
1248
1249
impl std::ops::Not for AxisValueTableFlags {
1250
    type Output = Self;
1251
1252
    /// Returns the complement of this set of flags.
1253
    #[inline]
1254
0
    fn not(self) -> Self {
1255
0
        Self { bits: !self.bits } & Self::all()
1256
0
    }
1257
}
1258
1259
impl std::fmt::Debug for AxisValueTableFlags {
1260
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1261
0
        let members: &[(&str, Self)] = &[
1262
0
            (
1263
0
                "OLDER_SIBLING_FONT_ATTRIBUTE",
1264
0
                Self::OLDER_SIBLING_FONT_ATTRIBUTE,
1265
0
            ),
1266
0
            ("ELIDABLE_AXIS_VALUE_NAME", Self::ELIDABLE_AXIS_VALUE_NAME),
1267
0
        ];
1268
0
        let mut first = true;
1269
0
        for (name, value) in members {
1270
0
            if self.contains(*value) {
1271
0
                if !first {
1272
0
                    f.write_str(" | ")?;
1273
0
                }
1274
0
                first = false;
1275
0
                f.write_str(name)?;
1276
0
            }
1277
        }
1278
0
        if first {
1279
0
            f.write_str("(empty)")?;
1280
0
        }
1281
0
        Ok(())
1282
0
    }
1283
}
1284
1285
impl std::fmt::Binary for AxisValueTableFlags {
1286
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1287
0
        std::fmt::Binary::fmt(&self.bits, f)
1288
0
    }
1289
}
1290
1291
impl std::fmt::Octal for AxisValueTableFlags {
1292
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1293
0
        std::fmt::Octal::fmt(&self.bits, f)
1294
0
    }
1295
}
1296
1297
impl std::fmt::LowerHex for AxisValueTableFlags {
1298
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1299
0
        std::fmt::LowerHex::fmt(&self.bits, f)
1300
0
    }
1301
}
1302
1303
impl std::fmt::UpperHex for AxisValueTableFlags {
1304
0
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1305
0
        std::fmt::UpperHex::fmt(&self.bits, f)
1306
0
    }
1307
}
1308
1309
impl font_types::Scalar for AxisValueTableFlags {
1310
    type Raw = <u16 as font_types::Scalar>::Raw;
1311
0
    fn to_raw(self) -> Self::Raw {
1312
0
        self.bits().to_raw()
1313
0
    }
1314
0
    fn from_raw(raw: Self::Raw) -> Self {
1315
0
        let t = <u16>::from_raw(raw);
1316
0
        Self::from_bits_truncate(t)
1317
0
    }
1318
}