Coverage Report

Created: 2026-10-24 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.46.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
1.41k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
1.41k
        if data.len() < Self::MIN_SIZE {
31
16
            return Err(ReadError::OutOfBounds);
32
1.40k
        }
33
1.40k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
1.40k
        Ok(Self { data })
37
1.41k
    }
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
0
    pub fn value_record_size(&self) -> u16 {
78
0
        self.data.header().value_record_size.get()
79
0
    }
80
81
    /// The number of value records — may be zero.
82
1.40k
    pub fn value_record_count(&self) -> u16 {
83
1.40k
        self.data.header().value_record_count.get()
84
1.40k
    }
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
1.40k
    pub fn item_variation_store_offset(&self) -> Nullable<Offset16> {
88
1.40k
        self.data.header().item_variation_store_offset.get()
89
1.40k
    }
90
91
    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
92
1.40k
    pub fn item_variation_store(&self) -> Option<Result<ItemVariationStore<'a>, ReadError>> {
93
1.40k
        let data = self.offset_data();
94
1.40k
        self.item_variation_store_offset().resolve(data)
95
1.40k
    }
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
1.40k
    pub fn value_records(&self) -> &'a [ValueRecord] {
99
1.40k
        let range = self.value_records_byte_range();
100
1.40k
        self.offset_data()
101
1.40k
            .read_array(range)
102
1.40k
            .ok()
103
1.40k
            .unwrap_or_default()
104
1.40k
    }
105
106
1.40k
    pub fn version_byte_range(&self) -> Range<usize> {
107
1.40k
        let start = 0;
108
1.40k
        let end = start + MajorMinor::RAW_BYTE_LEN;
109
1.40k
        start..end
110
1.40k
    }
111
112
1.40k
    pub fn _reserved_byte_range(&self) -> Range<usize> {
113
1.40k
        let start = self.version_byte_range().end;
114
1.40k
        let end = start + u16::RAW_BYTE_LEN;
115
1.40k
        start..end
116
1.40k
    }
117
118
1.40k
    pub fn value_record_size_byte_range(&self) -> Range<usize> {
119
1.40k
        let start = self._reserved_byte_range().end;
120
1.40k
        let end = start + u16::RAW_BYTE_LEN;
121
1.40k
        start..end
122
1.40k
    }
123
124
1.40k
    pub fn value_record_count_byte_range(&self) -> Range<usize> {
125
1.40k
        let start = self.value_record_size_byte_range().end;
126
1.40k
        let end = start + u16::RAW_BYTE_LEN;
127
1.40k
        start..end
128
1.40k
    }
129
130
1.40k
    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
131
1.40k
        let start = self.value_record_count_byte_range().end;
132
1.40k
        let end = start + Offset16::RAW_BYTE_LEN;
133
1.40k
        start..end
134
1.40k
    }
135
136
1.40k
    pub fn value_records_byte_range(&self) -> Range<usize> {
137
1.40k
        let value_record_count = self.value_record_count();
138
1.40k
        let start = self.item_variation_store_offset_byte_range().end;
139
1.40k
        let end = start
140
1.40k
            + (transforms::to_usize(value_record_count)).saturating_mul(ValueRecord::RAW_BYTE_LEN);
141
1.40k
        start..end
142
1.40k
    }
143
}
144
145
const _: () = assert!(FontData::default_data_long_enough(Mvar::MIN_SIZE));
146
147
impl Default for Mvar<'_> {
148
0
    fn default() -> Self {
149
        Self {
150
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
151
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
152
        }
153
0
    }
154
}
155
156
/// [ValueRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/mvar#table-formats) metrics variation record
157
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
158
#[repr(C)]
159
#[repr(packed)]
160
pub struct ValueRecord {
161
    /// Four-byte tag identifying a font-wide measure.
162
    pub value_tag: BigEndian<Tag>,
163
    /// A delta-set outer index — used to select an item variation data subtable within the item variation store.
164
    pub delta_set_outer_index: BigEndian<u16>,
165
    /// A delta-set inner index — used to select a delta-set row within an item variation data subtable.
166
    pub delta_set_inner_index: BigEndian<u16>,
167
}
168
169
impl ValueRecord {
170
    /// Four-byte tag identifying a font-wide measure.
171
735
    pub fn value_tag(&self) -> Tag {
172
735
        self.value_tag.get()
173
735
    }
174
175
    /// A delta-set outer index — used to select an item variation data subtable within the item variation store.
176
22
    pub fn delta_set_outer_index(&self) -> u16 {
177
22
        self.delta_set_outer_index.get()
178
22
    }
179
180
    /// A delta-set inner index — used to select a delta-set row within an item variation data subtable.
181
22
    pub fn delta_set_inner_index(&self) -> u16 {
182
22
        self.delta_set_inner_index.get()
183
22
    }
184
}
185
186
impl FixedSize for ValueRecord {
187
    const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
188
}