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_feat.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 Feat<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.names_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 Feat<'_> {
19
    /// `feat`
20
    const TAG: Tag = Tag::new(b"feat");
21
}
22
23
impl ReadArgs for Feat<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Feat<'a> {
28
3
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
3
        if data.len() < Self::MIN_SIZE {
31
1
            return Err(ReadError::OutOfBounds);
32
2
        }
33
2
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
2
        Ok(Self { data })
37
3
    }
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 FeatFixedHeader {
45
    pub version: BigEndian<MajorMinor>,
46
    pub feature_name_count: BigEndian<u16>,
47
    pub _reserved1: BigEndian<u16>,
48
    pub _reserved2: BigEndian<u32>,
49
}
50
51
#[allow(clippy::absurd_extreme_comparisons)]
52
const _: () = assert!(std::mem::size_of::<FeatFixedHeader>() <= Feat::MIN_SIZE);
53
54
/// The [feature name](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6feat.html) table.
55
#[derive(Clone)]
56
pub struct Feat<'a> {
57
    data: TableDataRef<'a, FeatFixedHeader>,
58
}
59
60
#[allow(clippy::needless_lifetimes)]
61
impl<'a> Feat<'a> {
62
    pub const MIN_SIZE: usize =
63
        (MajorMinor::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
64
    basic_table_impls!(impl_the_methods);
65
66
    /// Version number of the feature name table (0x00010000 for the current
67
    /// version).
68
0
    pub fn version(&self) -> MajorMinor {
69
0
        self.data.header().version.get()
70
0
    }
71
72
    /// The number of entries in the feature name array.
73
0
    pub fn feature_name_count(&self) -> u16 {
74
0
        self.data.header().feature_name_count.get()
75
0
    }
76
77
    /// The feature name array, sorted by feature type.
78
0
    pub fn names(&self) -> &'a [FeatureName] {
79
0
        let range = self.names_byte_range();
80
0
        self.offset_data()
81
0
            .read_array(range)
82
0
            .ok()
83
0
            .unwrap_or_default()
84
0
    }
85
86
0
    pub fn version_byte_range(&self) -> Range<usize> {
87
0
        let start = 0usize;
88
0
        let end = start.saturating_add(MajorMinor::RAW_BYTE_LEN);
89
0
        start..end
90
0
    }
91
92
0
    pub fn feature_name_count_byte_range(&self) -> Range<usize> {
93
0
        let start = self.version_byte_range().end;
94
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
95
0
        start..end
96
0
    }
97
98
0
    pub fn _reserved1_byte_range(&self) -> Range<usize> {
99
0
        let start = self.feature_name_count_byte_range().end;
100
0
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
101
0
        start..end
102
0
    }
103
104
0
    pub fn _reserved2_byte_range(&self) -> Range<usize> {
105
0
        let start = self._reserved1_byte_range().end;
106
0
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
107
0
        start..end
108
0
    }
109
110
0
    pub fn names_byte_range(&self) -> Range<usize> {
111
0
        let feature_name_count = self.feature_name_count();
112
0
        let start = self._reserved2_byte_range().end;
113
0
        let end = start.saturating_add(
114
0
            (transforms::to_usize(feature_name_count)).saturating_mul(FeatureName::RAW_BYTE_LEN),
115
        );
116
0
        start..end
117
0
    }
118
}
119
120
const _: () = assert!(FontData::default_data_long_enough(Feat::MIN_SIZE));
121
122
impl Default for Feat<'_> {
123
0
    fn default() -> Self {
124
        Self {
125
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
126
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
127
        }
128
0
    }
129
}
130
131
/// Type, flags and names for a feature.
132
#[derive(Clone, Debug, Copy, bytemuck :: AnyBitPattern)]
133
#[repr(C)]
134
#[repr(packed)]
135
pub struct FeatureName {
136
    /// Feature type.
137
    pub feature: BigEndian<u16>,
138
    /// The number of records in the setting name array.
139
    pub n_settings: BigEndian<u16>,
140
    /// Offset in bytes from the beginning of this table to this feature's
141
    /// setting name array. The actual type of record this offset refers
142
    /// to will depend on the exclusivity value, as described below.
143
    pub setting_table_offset: BigEndian<Offset32>,
144
    /// Flags associated with the feature type.
145
    pub feature_flags: BigEndian<u16>,
146
    /// The name table index for the feature's name.
147
    pub name_index: BigEndian<NameId>,
148
}
149
150
impl FeatureName {
151
    /// Feature type.
152
0
    pub fn feature(&self) -> u16 {
153
0
        self.feature.get()
154
0
    }
155
156
    /// The number of records in the setting name array.
157
0
    pub fn n_settings(&self) -> u16 {
158
0
        self.n_settings.get()
159
0
    }
160
161
    /// Offset in bytes from the beginning of this table to this feature's
162
    /// setting name array. The actual type of record this offset refers
163
    /// to will depend on the exclusivity value, as described below.
164
0
    pub fn setting_table_offset(&self) -> Offset32 {
165
0
        self.setting_table_offset.get()
166
0
    }
167
168
    /// Offset in bytes from the beginning of this table to this feature's
169
    /// setting name array. The actual type of record this offset refers
170
    /// to will depend on the exclusivity value, as described below.
171
    ///
172
    /// The `data` argument should be retrieved from the parent table
173
    /// By calling its `offset_data` method.
174
0
    pub fn setting_table<'a>(&self, data: FontData<'a>) -> Result<SettingNameArray<'a>, ReadError> {
175
0
        let args = self.n_settings();
176
0
        self.setting_table_offset().resolve_with_args(data, args)
177
0
    }
178
179
    /// Flags associated with the feature type.
180
0
    pub fn feature_flags(&self) -> u16 {
181
0
        self.feature_flags.get()
182
0
    }
183
184
    /// The name table index for the feature's name.
185
0
    pub fn name_index(&self) -> NameId {
186
0
        self.name_index.get()
187
0
    }
188
}
189
190
impl FixedSize for FeatureName {
191
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN
192
        + u16::RAW_BYTE_LEN
193
        + Offset32::RAW_BYTE_LEN
194
        + u16::RAW_BYTE_LEN
195
        + NameId::RAW_BYTE_LEN;
196
}
197
198
impl<'a> MinByteRange<'a> for SettingNameArray<'a> {
199
0
    fn min_byte_range(&self) -> Range<usize> {
200
0
        0..self.settings_byte_range().end
201
0
    }
202
0
    fn min_table_bytes(&self) -> &'a [u8] {
203
0
        let range = self.min_byte_range();
204
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
205
0
    }
206
}
207
208
impl ReadArgs for SettingNameArray<'_> {
209
    type Args = u16;
210
}
211
212
impl<'a> FontRead<'a> for SettingNameArray<'a> {
213
0
    fn read_with_args(data: FontData<'a>, args: u16) -> Result<Self, ReadError> {
214
0
        let n_settings = args;
215
216
        #[allow(clippy::absurd_extreme_comparisons)]
217
0
        if data.len() < Self::MIN_SIZE {
218
0
            return Err(ReadError::OutOfBounds);
219
0
        }
220
0
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
221
0
            return Err(ReadError::OutOfBounds);
222
        };
223
0
        Ok(Self { data, n_settings })
224
0
    }
225
}
226
227
impl<'a> SettingNameArray<'a> {
228
    /// A constructor that requires additional arguments.
229
    ///
230
    /// This type requires some external state in order to be
231
    /// parsed.
232
0
    pub fn read(data: FontData<'a>, n_settings: u16) -> Result<Self, ReadError> {
233
0
        let args = n_settings;
234
0
        Self::read_with_args(data, args)
235
0
    }
236
}
237
238
/// The fields at the start of the table, which are read directly.
239
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
240
#[repr(C, packed)]
241
#[doc(hidden)]
242
pub struct SettingNameArrayFixedHeader {}
243
244
#[allow(clippy::absurd_extreme_comparisons)]
245
const _: () =
246
    assert!(std::mem::size_of::<SettingNameArrayFixedHeader>() <= SettingNameArray::MIN_SIZE);
247
248
#[derive(Clone)]
249
pub struct SettingNameArray<'a> {
250
    data: TableDataRef<'a, SettingNameArrayFixedHeader>,
251
    n_settings: u16,
252
}
253
254
#[allow(clippy::needless_lifetimes)]
255
impl<'a> SettingNameArray<'a> {
256
    pub const MIN_SIZE: usize = 0;
257
    basic_table_impls!(impl_the_methods);
258
259
    /// List of setting names for a feature.
260
0
    pub fn settings(&self) -> &'a [SettingName] {
261
0
        let range = self.settings_byte_range();
262
0
        self.offset_data()
263
0
            .read_array(range)
264
0
            .ok()
265
0
            .unwrap_or_default()
266
0
    }
267
268
0
    pub(crate) fn n_settings(&self) -> u16 {
269
0
        self.n_settings
270
0
    }
271
272
0
    pub fn settings_byte_range(&self) -> Range<usize> {
273
0
        let n_settings = self.n_settings();
274
0
        let start = 0usize;
275
0
        let end = start.saturating_add(
276
0
            (transforms::to_usize(n_settings)).saturating_mul(SettingName::RAW_BYTE_LEN),
277
        );
278
0
        start..end
279
0
    }
280
}
281
282
#[allow(clippy::absurd_extreme_comparisons)]
283
const _: () = assert!(FontData::default_data_long_enough(
284
    SettingNameArray::MIN_SIZE
285
));
286
287
impl Default for SettingNameArray<'_> {
288
0
    fn default() -> Self {
289
        Self {
290
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
291
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
292
0
            n_settings: Default::default(),
293
        }
294
0
    }
295
}
296
297
/// Associates a setting with a name identifier.
298
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
299
#[repr(C)]
300
#[repr(packed)]
301
pub struct SettingName {
302
    /// The setting.
303
    pub setting: BigEndian<u16>,
304
    /// The name table index for the setting's name.
305
    pub name_index: BigEndian<NameId>,
306
}
307
308
impl SettingName {
309
    /// The setting.
310
0
    pub fn setting(&self) -> u16 {
311
0
        self.setting.get()
312
0
    }
313
314
    /// The name table index for the setting's name.
315
0
    pub fn name_index(&self) -> NameId {
316
0
        self.name_index.get()
317
0
    }
318
}
319
320
impl FixedSize for SettingName {
321
    const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + NameId::RAW_BYTE_LEN;
322
}