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_avar.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 Avar<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.axis_segment_maps_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 Avar<'_> {
19
    /// `avar`
20
    const TAG: Tag = Tag::new(b"avar");
21
}
22
23
impl ReadArgs for Avar<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Avar<'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 AvarFixedHeader {
45
    pub version: BigEndian<MajorMinor>,
46
    pub _reserved: BigEndian<u16>,
47
    pub axis_count: BigEndian<u16>,
48
}
49
50
#[allow(clippy::absurd_extreme_comparisons)]
51
const _: () = assert!(std::mem::size_of::<AvarFixedHeader>() <= Avar::MIN_SIZE);
52
53
/// The [avar (Axis Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/avar) table
54
#[derive(Clone)]
55
pub struct Avar<'a> {
56
    data: TableDataRef<'a, AvarFixedHeader>,
57
}
58
59
#[allow(clippy::needless_lifetimes)]
60
impl<'a> Avar<'a> {
61
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN);
62
    basic_table_impls!(impl_the_methods);
63
64
    /// Major version number of the axis variations table — set to 1 or 2.
65
    /// Minor version number of the axis variations table — set to 0.
66
0
    pub fn version(&self) -> MajorMinor {
67
0
        self.data.header().version.get()
68
0
    }
69
70
    /// The number of variation axes for this font. This must be the same number as axisCount in the 'fvar' table.
71
0
    pub fn axis_count(&self) -> u16 {
72
0
        self.data.header().axis_count.get()
73
0
    }
74
75
    /// The segment maps array — one segment map for each axis, in the order of axes specified in the 'fvar' table.
76
0
    pub fn axis_segment_maps(&self) -> VarLenArray<'a, SegmentMaps<'a>> {
77
0
        let range = self.axis_segment_maps_byte_range();
78
0
        self.offset_data()
79
0
            .split_off(range.start)
80
0
            .and_then(|d| VarLenArray::read(d).ok())
81
0
            .unwrap_or_default()
82
0
    }
83
84
    /// Offset to DeltaSetIndexMap table (may be NULL).
85
0
    pub fn axis_index_map_offset(&self) -> Option<Nullable<Offset32>> {
86
0
        let range = self.axis_index_map_offset_byte_range();
87
0
        (!range.is_empty())
88
0
            .then(|| self.offset_data().read_at(range.start).ok())
89
0
            .flatten()
90
0
    }
91
92
    /// Attempt to resolve [`axis_index_map_offset`][Self::axis_index_map_offset].
93
0
    pub fn axis_index_map(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
94
0
        let data = self.offset_data();
95
0
        self.axis_index_map_offset().map(|x| x.resolve(data))?
96
0
    }
97
98
    /// Offset to ItemVariationStore (may be NULL).
99
0
    pub fn var_store_offset(&self) -> Option<Nullable<Offset32>> {
100
0
        let range = self.var_store_offset_byte_range();
101
0
        (!range.is_empty())
102
0
            .then(|| self.offset_data().read_at(range.start).ok())
103
0
            .flatten()
104
0
    }
105
106
    /// Attempt to resolve [`var_store_offset`][Self::var_store_offset].
107
0
    pub fn var_store(&self) -> Option<Result<ItemVariationStore<'a>, ReadError>> {
108
0
        let data = self.offset_data();
109
0
        self.var_store_offset().map(|x| x.resolve(data))?
110
0
    }
111
112
0
    pub fn version_byte_range(&self) -> Range<usize> {
113
0
        let start = 0;
114
0
        let end = start + MajorMinor::RAW_BYTE_LEN;
115
0
        start..end
116
0
    }
117
118
0
    pub fn _reserved_byte_range(&self) -> Range<usize> {
119
0
        let start = self.version_byte_range().end;
120
0
        let end = start + u16::RAW_BYTE_LEN;
121
0
        start..end
122
0
    }
123
124
0
    pub fn axis_count_byte_range(&self) -> Range<usize> {
125
0
        let start = self._reserved_byte_range().end;
126
0
        let end = start + u16::RAW_BYTE_LEN;
127
0
        start..end
128
0
    }
129
130
0
    pub fn axis_segment_maps_byte_range(&self) -> Range<usize> {
131
0
        let axis_count = self.axis_count();
132
0
        let start = self.axis_count_byte_range().end;
133
0
        let end = start + {
134
0
            let data = self.offset_data().split_off(start).unwrap_or_default();
135
0
            <SegmentMaps as VarSize>::total_len_for_count(data, transforms::to_usize(axis_count))
136
0
                .unwrap_or(0)
137
0
        };
138
0
        start..end
139
0
    }
140
141
0
    pub fn axis_index_map_offset_byte_range(&self) -> Range<usize> {
142
0
        let start = self.axis_segment_maps_byte_range().end;
143
0
        let end = if self.version().compatible((2u16, 0u16)) {
144
0
            start + Offset32::RAW_BYTE_LEN
145
        } else {
146
0
            start
147
        };
148
0
        start..end
149
0
    }
150
151
0
    pub fn var_store_offset_byte_range(&self) -> Range<usize> {
152
0
        let start = self.axis_index_map_offset_byte_range().end;
153
0
        let end = if self.version().compatible((2u16, 0u16)) {
154
0
            start + Offset32::RAW_BYTE_LEN
155
        } else {
156
0
            start
157
        };
158
0
        start..end
159
0
    }
160
}
161
162
const _: () = assert!(FontData::default_data_long_enough(Avar::MIN_SIZE));
163
164
impl Default for Avar<'_> {
165
0
    fn default() -> Self {
166
        Self {
167
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
168
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
169
        }
170
0
    }
171
}
172
173
/// [SegmentMaps](https://learn.microsoft.com/en-us/typography/opentype/spec/avar#table-formats) record
174
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
175
pub struct SegmentMaps<'a> {
176
    /// The number of correspondence pairs for this axis.
177
    pub position_map_count: BigEndian<u16>,
178
    /// The array of axis value map records for this axis.
179
    pub axis_value_maps: &'a [AxisValueMap],
180
}
181
182
impl<'a> SegmentMaps<'a> {
183
    /// The number of correspondence pairs for this axis.
184
0
    pub fn position_map_count(&self) -> u16 {
185
0
        self.position_map_count.get()
186
0
    }
187
188
    /// The array of axis value map records for this axis.
189
0
    pub fn axis_value_maps(&self) -> &'a [AxisValueMap] {
190
0
        self.axis_value_maps
191
0
    }
192
}
193
194
/// [AxisValueMap](https://learn.microsoft.com/en-us/typography/opentype/spec/avar#table-formats) record
195
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
196
#[repr(C)]
197
#[repr(packed)]
198
pub struct AxisValueMap {
199
    /// A normalized coordinate value obtained using default normalization.
200
    pub from_coordinate: BigEndian<F2Dot14>,
201
    /// The modified, normalized coordinate value.
202
    pub to_coordinate: BigEndian<F2Dot14>,
203
}
204
205
impl AxisValueMap {
206
    /// A normalized coordinate value obtained using default normalization.
207
0
    pub fn from_coordinate(&self) -> F2Dot14 {
208
0
        self.from_coordinate.get()
209
0
    }
210
211
    /// The modified, normalized coordinate value.
212
0
    pub fn to_coordinate(&self) -> F2Dot14 {
213
0
        self.to_coordinate.get()
214
0
    }
215
}
216
217
impl FixedSize for AxisValueMap {
218
    const RAW_BYTE_LEN: usize = F2Dot14::RAW_BYTE_LEN + F2Dot14::RAW_BYTE_LEN;
219
}