Coverage Report

Created: 2026-07-25 07:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/read-fonts/generated/generated_vvar.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 Vvar<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.v_org_mapping_offset_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.data.as_bytes().get(range).unwrap_or_default()
15
0
    }
16
}
17
18
impl TopLevelTable for Vvar<'_> {
19
    /// `VVAR`
20
    const TAG: Tag = Tag::new(b"VVAR");
21
}
22
23
impl ReadArgs for Vvar<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Vvar<'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
        Ok(Self { data })
34
0
    }
35
}
36
37
/// The [VVAR (Vertical Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/vvar) table
38
#[derive(Clone)]
39
pub struct Vvar<'a> {
40
    data: FontData<'a>,
41
}
42
43
#[allow(clippy::needless_lifetimes)]
44
impl<'a> Vvar<'a> {
45
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
46
        + Offset32::RAW_BYTE_LEN
47
        + Offset32::RAW_BYTE_LEN
48
        + Offset32::RAW_BYTE_LEN
49
        + Offset32::RAW_BYTE_LEN
50
        + Offset32::RAW_BYTE_LEN);
51
    basic_table_impls!(impl_the_methods);
52
53
    /// Major version number of the horizontal metrics variations table — set to 1.
54
    /// Minor version number of the horizontal metrics variations table — set to 0.
55
0
    pub fn version(&self) -> MajorMinor {
56
0
        let range = self.version_byte_range();
57
0
        self.data.read_at(range.start).ok().unwrap()
58
0
    }
59
60
    /// Offset in bytes from the start of this table to the item variation store table.
61
0
    pub fn item_variation_store_offset(&self) -> Offset32 {
62
0
        let range = self.item_variation_store_offset_byte_range();
63
0
        self.data.read_at(range.start).ok().unwrap()
64
0
    }
65
66
    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
67
0
    pub fn item_variation_store(&self) -> Result<ItemVariationStore<'a>, ReadError> {
68
0
        let data = self.data;
69
0
        self.item_variation_store_offset().resolve(data)
70
0
    }
71
72
    /// Offset in bytes from the start of this table to the delta-set index mapping for advance heights (may be NULL).
73
0
    pub fn advance_height_mapping_offset(&self) -> Nullable<Offset32> {
74
0
        let range = self.advance_height_mapping_offset_byte_range();
75
0
        self.data.read_at(range.start).ok().unwrap()
76
0
    }
77
78
    /// Attempt to resolve [`advance_height_mapping_offset`][Self::advance_height_mapping_offset].
79
0
    pub fn advance_height_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
80
0
        let data = self.data;
81
0
        self.advance_height_mapping_offset().resolve(data)
82
0
    }
83
84
    /// Offset in bytes from the start of this table to the delta-set index mapping for top side bearings (may be NULL).
85
0
    pub fn tsb_mapping_offset(&self) -> Nullable<Offset32> {
86
0
        let range = self.tsb_mapping_offset_byte_range();
87
0
        self.data.read_at(range.start).ok().unwrap()
88
0
    }
89
90
    /// Attempt to resolve [`tsb_mapping_offset`][Self::tsb_mapping_offset].
91
0
    pub fn tsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
92
0
        let data = self.data;
93
0
        self.tsb_mapping_offset().resolve(data)
94
0
    }
95
96
    /// Offset in bytes from the start of this table to the delta-set index mapping for bottom side bearings (may be NULL).
97
0
    pub fn bsb_mapping_offset(&self) -> Nullable<Offset32> {
98
0
        let range = self.bsb_mapping_offset_byte_range();
99
0
        self.data.read_at(range.start).ok().unwrap()
100
0
    }
101
102
    /// Attempt to resolve [`bsb_mapping_offset`][Self::bsb_mapping_offset].
103
0
    pub fn bsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
104
0
        let data = self.data;
105
0
        self.bsb_mapping_offset().resolve(data)
106
0
    }
107
108
    /// Offset in bytes from the start of this table to the delta-set index mapping for Y coordinates of vertical origins (may be NULL).
109
0
    pub fn v_org_mapping_offset(&self) -> Nullable<Offset32> {
110
0
        let range = self.v_org_mapping_offset_byte_range();
111
0
        self.data.read_at(range.start).ok().unwrap()
112
0
    }
113
114
    /// Attempt to resolve [`v_org_mapping_offset`][Self::v_org_mapping_offset].
115
0
    pub fn v_org_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
116
0
        let data = self.data;
117
0
        self.v_org_mapping_offset().resolve(data)
118
0
    }
119
120
0
    pub fn version_byte_range(&self) -> Range<usize> {
121
0
        let start = 0;
122
0
        let end = start + MajorMinor::RAW_BYTE_LEN;
123
0
        start..end
124
0
    }
125
126
0
    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
127
0
        let start = self.version_byte_range().end;
128
0
        let end = start + Offset32::RAW_BYTE_LEN;
129
0
        start..end
130
0
    }
131
132
0
    pub fn advance_height_mapping_offset_byte_range(&self) -> Range<usize> {
133
0
        let start = self.item_variation_store_offset_byte_range().end;
134
0
        let end = start + Offset32::RAW_BYTE_LEN;
135
0
        start..end
136
0
    }
137
138
0
    pub fn tsb_mapping_offset_byte_range(&self) -> Range<usize> {
139
0
        let start = self.advance_height_mapping_offset_byte_range().end;
140
0
        let end = start + Offset32::RAW_BYTE_LEN;
141
0
        start..end
142
0
    }
143
144
0
    pub fn bsb_mapping_offset_byte_range(&self) -> Range<usize> {
145
0
        let start = self.tsb_mapping_offset_byte_range().end;
146
0
        let end = start + Offset32::RAW_BYTE_LEN;
147
0
        start..end
148
0
    }
149
150
0
    pub fn v_org_mapping_offset_byte_range(&self) -> Range<usize> {
151
0
        let start = self.bsb_mapping_offset_byte_range().end;
152
0
        let end = start + Offset32::RAW_BYTE_LEN;
153
0
        start..end
154
0
    }
155
}
156
157
const _: () = assert!(FontData::default_data_long_enough(Vvar::MIN_SIZE));
158
159
impl Default for Vvar<'_> {
160
0
    fn default() -> Self {
161
0
        Self {
162
0
            data: FontData::default_table_data(),
163
0
        }
164
0
    }
165
}
166
167
#[cfg(feature = "experimental_traverse")]
168
impl<'a> SomeTable<'a> for Vvar<'a> {
169
    fn type_name(&self) -> &str {
170
        "Vvar"
171
    }
172
    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
173
        match idx {
174
            0usize => Some(Field::new("version", self.version())),
175
            1usize => Some(Field::new(
176
                "item_variation_store_offset",
177
                FieldType::offset(
178
                    self.item_variation_store_offset(),
179
                    self.item_variation_store(),
180
                ),
181
            )),
182
            2usize => Some(Field::new(
183
                "advance_height_mapping_offset",
184
                FieldType::offset(
185
                    self.advance_height_mapping_offset(),
186
                    self.advance_height_mapping(),
187
                ),
188
            )),
189
            3usize => Some(Field::new(
190
                "tsb_mapping_offset",
191
                FieldType::offset(self.tsb_mapping_offset(), self.tsb_mapping()),
192
            )),
193
            4usize => Some(Field::new(
194
                "bsb_mapping_offset",
195
                FieldType::offset(self.bsb_mapping_offset(), self.bsb_mapping()),
196
            )),
197
            5usize => Some(Field::new(
198
                "v_org_mapping_offset",
199
                FieldType::offset(self.v_org_mapping_offset(), self.v_org_mapping()),
200
            )),
201
            _ => None,
202
        }
203
    }
204
}
205
206
#[cfg(feature = "experimental_traverse")]
207
#[allow(clippy::needless_lifetimes)]
208
impl<'a> std::fmt::Debug for Vvar<'a> {
209
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
210
        (self as &dyn SomeTable<'a>).fmt(f)
211
    }
212
}