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_mvar.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 Mvar<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.value_records_byte_range().end
11
0
    }
12
0
    fn min_table_bytes(&self) -> &'a [u8] {
13
0
        let range = self.min_byte_range();
14
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
15
0
    }
16
}
17
18
impl TopLevelTable for Mvar<'_> {
19
    /// `MVAR`
20
    const TAG: Tag = Tag::new(b"MVAR");
21
}
22
23
impl ReadArgs for Mvar<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Mvar<'a> {
28
679
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
679
        if data.len() < Self::MIN_SIZE {
31
33
            return Err(ReadError::OutOfBounds);
32
646
        }
33
646
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
646
        Ok(Self { data })
37
679
    }
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 MvarFixedHeader {
45
    pub version: BigEndian<MajorMinor>,
46
    pub _reserved: BigEndian<u16>,
47
    pub value_record_size: BigEndian<u16>,
48
    pub value_record_count: BigEndian<u16>,
49
    pub item_variation_store_offset: BigEndian<Nullable<Offset16>>,
50
}
51
52
#[allow(clippy::absurd_extreme_comparisons)]
53
const _: () = assert!(std::mem::size_of::<MvarFixedHeader>() <= Mvar::MIN_SIZE);
54
55
/// The [MVAR (Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/mvar) table
56
#[derive(Clone)]
57
pub struct Mvar<'a> {
58
    data: TableDataRef<'a, MvarFixedHeader>,
59
}
60
61
#[allow(clippy::needless_lifetimes)]
62
impl<'a> Mvar<'a> {
63
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
64
        + u16::RAW_BYTE_LEN
65
        + u16::RAW_BYTE_LEN
66
        + u16::RAW_BYTE_LEN
67
        + Offset16::RAW_BYTE_LEN);
68
    basic_table_impls!(impl_the_methods);
69
70
    /// Major version number of the horizontal metrics variations table — set to 1.
71
    /// Minor version number of the horizontal metrics variations table — set to 0.
72
0
    pub fn version(&self) -> MajorMinor {
73
0
        self.data.header().version.get()
74
0
    }
75
76
    /// The size in bytes of each value record — must be greater than zero.
77
1.29k
    pub fn value_record_size(&self) -> u16 {
78
1.29k
        self.data.header().value_record_size.get()
79
1.29k
    }
80
81
    /// The number of value records — may be zero.
82
646
    pub fn value_record_count(&self) -> u16 {
83
646
        self.data.header().value_record_count.get()
84
646
    }
85
86
    /// Offset in bytes from the start of this table to the item variation store table. If valueRecordCount is zero, set to zero; if valueRecordCount is greater than zero, must be greater than zero.
87
646
    pub fn item_variation_store_offset(&self) -> Nullable<Offset16> {
88
646
        self.data.header().item_variation_store_offset.get()
89
646
    }
90
91
    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
92
646
    pub fn item_variation_store(&self) -> Option<Result<ItemVariationStore<'a>, ReadError>> {
93
646
        let data = self.offset_data();
94
646
        self.item_variation_store_offset().resolve(data)
95
646
    }
96
97
    /// Array of value records that identify target items and the associated delta-set index for each. The valueTag records must be in binary order of their valueTag field.
98
646
    pub fn value_records(&self) -> ComputedArray<'a, ValueRecord> {
99
646
        let range = self.value_records_byte_range();
100
646
        ComputedArray::new(self.offset_data(), range, self.value_record_size()).unwrap_or_default()
101
646
    }
102
103
646
    pub fn version_byte_range(&self) -> Range<usize> {
104
646
        let start = 0usize;
105
646
        let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
106
646
        start..end
107
646
    }
108
109
646
    pub fn _reserved_byte_range(&self) -> Range<usize> {
110
646
        let start = self.version_byte_range().end;
111
646
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
112
646
        start..end
113
646
    }
114
115
646
    pub fn value_record_size_byte_range(&self) -> Range<usize> {
116
646
        let start = self._reserved_byte_range().end;
117
646
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
118
646
        start..end
119
646
    }
120
121
646
    pub fn value_record_count_byte_range(&self) -> Range<usize> {
122
646
        let start = self.value_record_size_byte_range().end;
123
646
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
124
646
        start..end
125
646
    }
126
127
646
    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
128
646
        let start = self.value_record_count_byte_range().end;
129
646
        let end = start.saturating_add(Offset16::RAW_BYTE_LEN);
130
646
        start..end
131
646
    }
132
133
646
    pub fn value_records_byte_range(&self) -> Range<usize> {
134
646
        let value_record_count = self.value_record_count();
135
646
        let start = self.item_variation_store_offset_byte_range().end;
136
646
        let end = start.saturating_add((transforms::to_usize(value_record_count)).saturating_mul(
137
646
            <ValueRecord as ComputeSize>::compute_size(self.value_record_size()).unwrap_or(0),
138
        ));
139
646
        start..end
140
646
    }
141
}
142
143
const _: () = assert!(FontData::default_data_long_enough(Mvar::MIN_SIZE));
144
145
impl Default for Mvar<'_> {
146
0
    fn default() -> Self {
147
        Self {
148
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
149
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
150
        }
151
0
    }
152
}
153
154
/// [ValueRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/mvar#table-formats) metrics variation record
155
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
156
#[repr(C)]
157
#[repr(packed)]
158
pub struct ValueRecord {
159
    /// Four-byte tag identifying a font-wide measure.
160
    pub value_tag: BigEndian<Tag>,
161
    /// A delta-set outer index — used to select an item variation data subtable within the item variation store.
162
    pub delta_set_outer_index: BigEndian<u16>,
163
    /// A delta-set inner index — used to select a delta-set row within an item variation data subtable.
164
    pub delta_set_inner_index: BigEndian<u16>,
165
}
166
167
impl ValueRecord {
168
    /// Four-byte tag identifying a font-wide measure.
169
272
    pub fn value_tag(&self) -> Tag {
170
272
        self.value_tag.get()
171
272
    }
172
173
    /// A delta-set outer index — used to select an item variation data subtable within the item variation store.
174
4
    pub fn delta_set_outer_index(&self) -> u16 {
175
4
        self.delta_set_outer_index.get()
176
4
    }
177
178
    /// A delta-set inner index — used to select a delta-set row within an item variation data subtable.
179
4
    pub fn delta_set_inner_index(&self) -> u16 {
180
4
        self.delta_set_inner_index.get()
181
4
    }
182
}
183
184
impl FixedSize for ValueRecord {
185
    const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
186
}