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_kerx.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 Kerx<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.subtables_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 Kerx<'_> {
19
    /// `kerx`
20
    const TAG: Tag = Tag::new(b"kerx");
21
}
22
23
impl ReadArgs for Kerx<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Kerx<'a> {
28
1.83k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
1.83k
        if data.len() < Self::MIN_SIZE {
31
5
            return Err(ReadError::OutOfBounds);
32
1.82k
        }
33
1.82k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
1.82k
        Ok(Self { data })
37
1.83k
    }
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 KerxFixedHeader {
45
    pub version: BigEndian<u16>,
46
    pub padding: BigEndian<u16>,
47
    pub n_tables: BigEndian<u32>,
48
}
49
50
#[allow(clippy::absurd_extreme_comparisons)]
51
const _: () = assert!(std::mem::size_of::<KerxFixedHeader>() <= Kerx::MIN_SIZE);
52
53
/// The [kerx (Extended Kerning)](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6morx.html) table.
54
#[derive(Clone)]
55
pub struct Kerx<'a> {
56
    data: TableDataRef<'a, KerxFixedHeader>,
57
}
58
59
#[allow(clippy::needless_lifetimes)]
60
impl<'a> Kerx<'a> {
61
    pub const MIN_SIZE: usize = (u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
62
    basic_table_impls!(impl_the_methods);
63
64
    /// The version number of the extended kerning table (currently 2, 3, or 4)
65
0
    pub fn version(&self) -> u16 {
66
0
        self.data.header().version.get()
67
0
    }
68
69
    /// The number of subtables included in the extended kerning table.
70
5.43k
    pub fn n_tables(&self) -> u32 {
71
5.43k
        self.data.header().n_tables.get()
72
5.43k
    }
73
74
1.80k
    pub fn subtables(&self) -> VarLenArray<'a, Subtable<'a>> {
75
1.80k
        let range = self.subtables_byte_range();
76
1.80k
        self.offset_data()
77
1.80k
            .split_off(range.start)
78
1.80k
            .and_then(|d| VarLenArray::read(d).ok())
79
1.80k
            .unwrap_or_default()
80
1.80k
    }
81
82
1.80k
    pub fn version_byte_range(&self) -> Range<usize> {
83
1.80k
        let start = 0usize;
84
1.80k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
85
1.80k
        start..end
86
1.80k
    }
87
88
1.80k
    pub fn padding_byte_range(&self) -> Range<usize> {
89
1.80k
        let start = self.version_byte_range().end;
90
1.80k
        let end = start.saturating_add(u16::RAW_BYTE_LEN);
91
1.80k
        start..end
92
1.80k
    }
93
94
1.80k
    pub fn n_tables_byte_range(&self) -> Range<usize> {
95
1.80k
        let start = self.padding_byte_range().end;
96
1.80k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
97
1.80k
        start..end
98
1.80k
    }
99
100
1.80k
    pub fn subtables_byte_range(&self) -> Range<usize> {
101
1.80k
        let n_tables = self.n_tables();
102
1.80k
        let start = self.n_tables_byte_range().end;
103
1.80k
        let end = start.saturating_add({
104
1.80k
            let data = self.offset_data().split_off(start).unwrap_or_default();
105
1.80k
            <Subtable as VarSize>::total_len_for_count(data, transforms::to_usize(n_tables))
106
1.80k
                .unwrap_or(0)
107
        });
108
1.80k
        start..end
109
1.80k
    }
110
}
111
112
const _: () = assert!(FontData::default_data_long_enough(Kerx::MIN_SIZE));
113
114
impl Default for Kerx<'_> {
115
0
    fn default() -> Self {
116
        Self {
117
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
118
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
119
        }
120
0
    }
121
}
122
123
impl<'a> MinByteRange<'a> for Subtable<'a> {
124
0
    fn min_byte_range(&self) -> Range<usize> {
125
0
        0..self.data_byte_range().end
126
0
    }
127
0
    fn min_table_bytes(&self) -> &'a [u8] {
128
0
        let range = self.min_byte_range();
129
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
130
0
    }
131
}
132
133
impl ReadArgs for Subtable<'_> {
134
    type Args = ();
135
}
136
137
impl<'a> FontRead<'a> for Subtable<'a> {
138
3.43k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
139
        #[allow(clippy::absurd_extreme_comparisons)]
140
3.43k
        if data.len() < Self::MIN_SIZE {
141
540
            return Err(ReadError::OutOfBounds);
142
2.89k
        }
143
2.89k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
144
0
            return Err(ReadError::OutOfBounds);
145
        };
146
2.89k
        Ok(Self { data })
147
3.43k
    }
148
}
149
150
/// The fields at the start of the table, which are read directly.
151
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
152
#[repr(C, packed)]
153
#[doc(hidden)]
154
pub struct SubtableFixedHeader {
155
    pub length: BigEndian<u32>,
156
    pub coverage: BigEndian<u32>,
157
    pub tuple_count: BigEndian<u32>,
158
}
159
160
#[allow(clippy::absurd_extreme_comparisons)]
161
const _: () = assert!(std::mem::size_of::<SubtableFixedHeader>() <= Subtable::MIN_SIZE);
162
163
/// A subtable in a `kerx` table.
164
#[derive(Clone)]
165
pub struct Subtable<'a> {
166
    data: TableDataRef<'a, SubtableFixedHeader>,
167
}
168
169
#[allow(clippy::needless_lifetimes)]
170
impl<'a> Subtable<'a> {
171
    pub const MIN_SIZE: usize = (u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
172
    basic_table_impls!(impl_the_methods);
173
174
    /// The length of this subtable in bytes, including this header.
175
0
    pub fn length(&self) -> u32 {
176
0
        self.data.header().length.get()
177
0
    }
178
179
    /// Circumstances under which this table is used.
180
141M
    pub fn coverage(&self) -> u32 {
181
141M
        self.data.header().coverage.get()
182
141M
    }
183
184
    /// The tuple count. This value is only used with variation fonts and should be 0 for all other fonts. The subtable's tupleCount will be ignored if the 'kerx' table version is less than 4.
185
141M
    pub fn tuple_count(&self) -> u32 {
186
141M
        self.data.header().tuple_count.get()
187
141M
    }
188
189
    /// Subtable specific data.
190
4.60k
    pub fn data(&self) -> &'a [u8] {
191
4.60k
        let range = self.data_byte_range();
192
4.60k
        self.offset_data()
193
4.60k
            .read_array(range)
194
4.60k
            .ok()
195
4.60k
            .unwrap_or_default()
196
4.60k
    }
197
198
4.60k
    pub fn length_byte_range(&self) -> Range<usize> {
199
4.60k
        let start = 0usize;
200
4.60k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
201
4.60k
        start..end
202
4.60k
    }
203
204
4.60k
    pub fn coverage_byte_range(&self) -> Range<usize> {
205
4.60k
        let start = self.length_byte_range().end;
206
4.60k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
207
4.60k
        start..end
208
4.60k
    }
209
210
4.60k
    pub fn tuple_count_byte_range(&self) -> Range<usize> {
211
4.60k
        let start = self.coverage_byte_range().end;
212
4.60k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
213
4.60k
        start..end
214
4.60k
    }
215
216
4.60k
    pub fn data_byte_range(&self) -> Range<usize> {
217
4.60k
        let start = self.tuple_count_byte_range().end;
218
4.60k
        let end = start.saturating_add(
219
4.60k
            self.offset_data().len().saturating_sub(start) / u8::RAW_BYTE_LEN * u8::RAW_BYTE_LEN,
220
        );
221
4.60k
        start..end
222
4.60k
    }
223
}
224
225
const _: () = assert!(FontData::default_data_long_enough(Subtable::MIN_SIZE));
226
227
impl Default for Subtable<'_> {
228
0
    fn default() -> Self {
229
        Self {
230
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
231
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
232
        }
233
0
    }
234
}
235
236
impl<'a> MinByteRange<'a> for Subtable0<'a> {
237
0
    fn min_byte_range(&self) -> Range<usize> {
238
0
        0..self.pairs_byte_range().end
239
0
    }
240
0
    fn min_table_bytes(&self) -> &'a [u8] {
241
0
        let range = self.min_byte_range();
242
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
243
0
    }
244
}
245
246
impl ReadArgs for Subtable0<'_> {
247
    type Args = ();
248
}
249
250
impl<'a> FontRead<'a> for Subtable0<'a> {
251
159
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
252
        #[allow(clippy::absurd_extreme_comparisons)]
253
159
        if data.len() < Self::MIN_SIZE {
254
12
            return Err(ReadError::OutOfBounds);
255
147
        }
256
147
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
257
0
            return Err(ReadError::OutOfBounds);
258
        };
259
147
        Ok(Self { data })
260
159
    }
261
}
262
263
/// The fields at the start of the table, which are read directly.
264
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
265
#[repr(C, packed)]
266
#[doc(hidden)]
267
pub struct Subtable0FixedHeader {
268
    pub n_pairs: BigEndian<u32>,
269
    pub search_range: BigEndian<u32>,
270
    pub entry_selector: BigEndian<u32>,
271
    pub range_shift: BigEndian<u32>,
272
}
273
274
#[allow(clippy::absurd_extreme_comparisons)]
275
const _: () = assert!(std::mem::size_of::<Subtable0FixedHeader>() <= Subtable0::MIN_SIZE);
276
277
/// The type 0 `kerx` subtable.
278
#[derive(Clone)]
279
pub struct Subtable0<'a> {
280
    data: TableDataRef<'a, Subtable0FixedHeader>,
281
}
282
283
#[allow(clippy::needless_lifetimes)]
284
impl<'a> Subtable0<'a> {
285
    pub const MIN_SIZE: usize =
286
        (u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN + u32::RAW_BYTE_LEN);
287
    basic_table_impls!(impl_the_methods);
288
289
    /// The number of kerning pairs in this subtable.
290
1.22k
    pub fn n_pairs(&self) -> u32 {
291
1.22k
        self.data.header().n_pairs.get()
292
1.22k
    }
293
294
    /// The largest power of two less than or equal to the value of nPairs, multiplied by the size in bytes of an entry in the subtable.
295
0
    pub fn search_range(&self) -> u32 {
296
0
        self.data.header().search_range.get()
297
0
    }
298
299
    /// This is calculated as log2 of the largest power of two less than or equal to the value of nPairs. This value indicates how many iterations of the search loop have to be made. For example, in a list of eight items, there would be three iterations of the loop.
300
0
    pub fn entry_selector(&self) -> u32 {
301
0
        self.data.header().entry_selector.get()
302
0
    }
303
304
    /// The value of nPairs minus the largest power of two less than or equal to nPairs. This is multiplied by the size in bytes of an entry in the table.
305
0
    pub fn range_shift(&self) -> u32 {
306
0
        self.data.header().range_shift.get()
307
0
    }
308
309
    /// Kerning records.
310
1.22k
    pub fn pairs(&self) -> &'a [Subtable0Pair] {
311
1.22k
        let range = self.pairs_byte_range();
312
1.22k
        self.offset_data()
313
1.22k
            .read_array(range)
314
1.22k
            .ok()
315
1.22k
            .unwrap_or_default()
316
1.22k
    }
317
318
1.22k
    pub fn n_pairs_byte_range(&self) -> Range<usize> {
319
1.22k
        let start = 0usize;
320
1.22k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
321
1.22k
        start..end
322
1.22k
    }
323
324
1.22k
    pub fn search_range_byte_range(&self) -> Range<usize> {
325
1.22k
        let start = self.n_pairs_byte_range().end;
326
1.22k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
327
1.22k
        start..end
328
1.22k
    }
329
330
1.22k
    pub fn entry_selector_byte_range(&self) -> Range<usize> {
331
1.22k
        let start = self.search_range_byte_range().end;
332
1.22k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
333
1.22k
        start..end
334
1.22k
    }
335
336
1.22k
    pub fn range_shift_byte_range(&self) -> Range<usize> {
337
1.22k
        let start = self.entry_selector_byte_range().end;
338
1.22k
        let end = start.saturating_add(u32::RAW_BYTE_LEN);
339
1.22k
        start..end
340
1.22k
    }
341
342
1.22k
    pub fn pairs_byte_range(&self) -> Range<usize> {
343
1.22k
        let n_pairs = self.n_pairs();
344
1.22k
        let start = self.range_shift_byte_range().end;
345
1.22k
        let end = start.saturating_add(
346
1.22k
            (transforms::to_usize(n_pairs)).saturating_mul(Subtable0Pair::RAW_BYTE_LEN),
347
        );
348
1.22k
        start..end
349
1.22k
    }
350
}
351
352
const _: () = assert!(FontData::default_data_long_enough(Subtable0::MIN_SIZE));
353
354
impl Default for Subtable0<'_> {
355
0
    fn default() -> Self {
356
        Self {
357
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
358
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
359
        }
360
0
    }
361
}
362
363
/// The type 0 `kerx` subtable kerning record.
364
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
365
#[repr(C)]
366
#[repr(packed)]
367
pub struct Subtable0Pair {
368
    /// The glyph index for the lefthand glyph in the kerning pair.
369
    pub left: BigEndian<GlyphId16>,
370
    /// The glyph index for the righthand glyph in the kerning pair.
371
    pub right: BigEndian<GlyphId16>,
372
    /// Kerning value.
373
    pub value: BigEndian<i16>,
374
}
375
376
impl Subtable0Pair {
377
    /// The glyph index for the lefthand glyph in the kerning pair.
378
4.38M
    pub fn left(&self) -> GlyphId16 {
379
4.38M
        self.left.get()
380
4.38M
    }
381
382
    /// The glyph index for the righthand glyph in the kerning pair.
383
4.38M
    pub fn right(&self) -> GlyphId16 {
384
4.38M
        self.right.get()
385
4.38M
    }
386
387
    /// Kerning value.
388
108k
    pub fn value(&self) -> i16 {
389
108k
        self.value.get()
390
108k
    }
391
}
392
393
impl FixedSize for Subtable0Pair {
394
    const RAW_BYTE_LEN: usize =
395
        GlyphId16::RAW_BYTE_LEN + GlyphId16::RAW_BYTE_LEN + i16::RAW_BYTE_LEN;
396
}