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_hhea.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 Hhea<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.number_of_h_metrics_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 Hhea<'_> {
19
    /// `hhea`
20
    const TAG: Tag = Tag::new(b"hhea");
21
}
22
23
impl ReadArgs for Hhea<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Hhea<'a> {
28
1.61k
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
1.61k
        if data.len() < Self::MIN_SIZE {
31
6
            return Err(ReadError::OutOfBounds);
32
1.61k
        }
33
1.61k
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
1.61k
        Ok(Self { data })
37
1.61k
    }
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 HheaFixedHeader {
45
    pub version: BigEndian<MajorMinor>,
46
    pub ascender: BigEndian<FWord>,
47
    pub descender: BigEndian<FWord>,
48
    pub line_gap: BigEndian<FWord>,
49
    pub advance_width_max: BigEndian<UfWord>,
50
    pub min_left_side_bearing: BigEndian<FWord>,
51
    pub min_right_side_bearing: BigEndian<FWord>,
52
    pub x_max_extent: BigEndian<FWord>,
53
    pub caret_slope_rise: BigEndian<i16>,
54
    pub caret_slope_run: BigEndian<i16>,
55
    pub caret_offset: BigEndian<i16>,
56
    pub reserved1: BigEndian<i16>,
57
    pub reserved2: BigEndian<i16>,
58
    pub reserved3: BigEndian<i16>,
59
    pub reserved4: BigEndian<i16>,
60
    pub metric_data_format: BigEndian<i16>,
61
    pub number_of_h_metrics: BigEndian<u16>,
62
}
63
64
#[allow(clippy::absurd_extreme_comparisons)]
65
const _: () = assert!(std::mem::size_of::<HheaFixedHeader>() <= Hhea::MIN_SIZE);
66
67
/// [hhea](https://docs.microsoft.com/en-us/typography/opentype/spec/hhea) Horizontal Header Table
68
#[derive(Clone)]
69
pub struct Hhea<'a> {
70
    data: TableDataRef<'a, HheaFixedHeader>,
71
}
72
73
#[allow(clippy::needless_lifetimes)]
74
impl<'a> Hhea<'a> {
75
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
76
        + FWord::RAW_BYTE_LEN
77
        + FWord::RAW_BYTE_LEN
78
        + FWord::RAW_BYTE_LEN
79
        + UfWord::RAW_BYTE_LEN
80
        + FWord::RAW_BYTE_LEN
81
        + FWord::RAW_BYTE_LEN
82
        + FWord::RAW_BYTE_LEN
83
        + i16::RAW_BYTE_LEN
84
        + i16::RAW_BYTE_LEN
85
        + i16::RAW_BYTE_LEN
86
        + i16::RAW_BYTE_LEN
87
        + i16::RAW_BYTE_LEN
88
        + i16::RAW_BYTE_LEN
89
        + i16::RAW_BYTE_LEN
90
        + i16::RAW_BYTE_LEN
91
        + u16::RAW_BYTE_LEN);
92
    basic_table_impls!(impl_the_methods);
93
94
    /// The major/minor version (1, 0)
95
0
    pub fn version(&self) -> MajorMinor {
96
0
        self.data.header().version.get()
97
0
    }
98
99
    /// Typographic ascent.
100
1.04k
    pub fn ascender(&self) -> FWord {
101
1.04k
        self.data.header().ascender.get()
102
1.04k
    }
103
104
    /// Typographic descent.
105
1.04k
    pub fn descender(&self) -> FWord {
106
1.04k
        self.data.header().descender.get()
107
1.04k
    }
108
109
    /// Typographic line gap. Negative LineGap values are treated as
110
    /// zero in some legacy platform implementations.
111
1.04k
    pub fn line_gap(&self) -> FWord {
112
1.04k
        self.data.header().line_gap.get()
113
1.04k
    }
114
115
    /// Maximum advance width value in 'hmtx' table.
116
1.04k
    pub fn advance_width_max(&self) -> UfWord {
117
1.04k
        self.data.header().advance_width_max.get()
118
1.04k
    }
119
120
    /// Minimum left sidebearing value in 'hmtx' table for glyphs with
121
    /// contours (empty glyphs should be ignored).
122
0
    pub fn min_left_side_bearing(&self) -> FWord {
123
0
        self.data.header().min_left_side_bearing.get()
124
0
    }
125
126
    /// Minimum right sidebearing value; calculated as min(aw - (lsb +
127
    /// xMax - xMin)) for glyphs with contours (empty glyphs should be ignored).
128
0
    pub fn min_right_side_bearing(&self) -> FWord {
129
0
        self.data.header().min_right_side_bearing.get()
130
0
    }
131
132
    /// Max(lsb + (xMax-xMin))
133
0
    pub fn x_max_extent(&self) -> FWord {
134
0
        self.data.header().x_max_extent.get()
135
0
    }
136
137
    /// Used to calculate the slope of the cursor (rise/run); 1 for
138
    /// vertical caret, 0 for horizontal.
139
0
    pub fn caret_slope_rise(&self) -> i16 {
140
0
        self.data.header().caret_slope_rise.get()
141
0
    }
142
143
    /// 0 for vertical caret, 1 for horizontal.
144
0
    pub fn caret_slope_run(&self) -> i16 {
145
0
        self.data.header().caret_slope_run.get()
146
0
    }
147
148
    /// The amount by which a slanted highlight on a glyph needs to be
149
    /// shifted to produce the best appearance. Set to 0 for
150
    /// non-slanted fonts
151
0
    pub fn caret_offset(&self) -> i16 {
152
0
        self.data.header().caret_offset.get()
153
0
    }
154
155
    /// 0 for current format.
156
0
    pub fn metric_data_format(&self) -> i16 {
157
0
        self.data.header().metric_data_format.get()
158
0
    }
159
160
    /// Number of hMetric entries in 'hmtx' table
161
569
    pub fn number_of_h_metrics(&self) -> u16 {
162
569
        self.data.header().number_of_h_metrics.get()
163
569
    }
164
165
0
    pub fn version_byte_range(&self) -> Range<usize> {
166
0
        let start = 0;
167
0
        let end = start + MajorMinor::RAW_BYTE_LEN;
168
0
        start..end
169
0
    }
170
171
0
    pub fn ascender_byte_range(&self) -> Range<usize> {
172
0
        let start = self.version_byte_range().end;
173
0
        let end = start + FWord::RAW_BYTE_LEN;
174
0
        start..end
175
0
    }
176
177
0
    pub fn descender_byte_range(&self) -> Range<usize> {
178
0
        let start = self.ascender_byte_range().end;
179
0
        let end = start + FWord::RAW_BYTE_LEN;
180
0
        start..end
181
0
    }
182
183
0
    pub fn line_gap_byte_range(&self) -> Range<usize> {
184
0
        let start = self.descender_byte_range().end;
185
0
        let end = start + FWord::RAW_BYTE_LEN;
186
0
        start..end
187
0
    }
188
189
0
    pub fn advance_width_max_byte_range(&self) -> Range<usize> {
190
0
        let start = self.line_gap_byte_range().end;
191
0
        let end = start + UfWord::RAW_BYTE_LEN;
192
0
        start..end
193
0
    }
194
195
0
    pub fn min_left_side_bearing_byte_range(&self) -> Range<usize> {
196
0
        let start = self.advance_width_max_byte_range().end;
197
0
        let end = start + FWord::RAW_BYTE_LEN;
198
0
        start..end
199
0
    }
200
201
0
    pub fn min_right_side_bearing_byte_range(&self) -> Range<usize> {
202
0
        let start = self.min_left_side_bearing_byte_range().end;
203
0
        let end = start + FWord::RAW_BYTE_LEN;
204
0
        start..end
205
0
    }
206
207
0
    pub fn x_max_extent_byte_range(&self) -> Range<usize> {
208
0
        let start = self.min_right_side_bearing_byte_range().end;
209
0
        let end = start + FWord::RAW_BYTE_LEN;
210
0
        start..end
211
0
    }
212
213
0
    pub fn caret_slope_rise_byte_range(&self) -> Range<usize> {
214
0
        let start = self.x_max_extent_byte_range().end;
215
0
        let end = start + i16::RAW_BYTE_LEN;
216
0
        start..end
217
0
    }
218
219
0
    pub fn caret_slope_run_byte_range(&self) -> Range<usize> {
220
0
        let start = self.caret_slope_rise_byte_range().end;
221
0
        let end = start + i16::RAW_BYTE_LEN;
222
0
        start..end
223
0
    }
224
225
0
    pub fn caret_offset_byte_range(&self) -> Range<usize> {
226
0
        let start = self.caret_slope_run_byte_range().end;
227
0
        let end = start + i16::RAW_BYTE_LEN;
228
0
        start..end
229
0
    }
230
231
0
    pub fn reserved1_byte_range(&self) -> Range<usize> {
232
0
        let start = self.caret_offset_byte_range().end;
233
0
        let end = start + i16::RAW_BYTE_LEN;
234
0
        start..end
235
0
    }
236
237
0
    pub fn reserved2_byte_range(&self) -> Range<usize> {
238
0
        let start = self.reserved1_byte_range().end;
239
0
        let end = start + i16::RAW_BYTE_LEN;
240
0
        start..end
241
0
    }
242
243
0
    pub fn reserved3_byte_range(&self) -> Range<usize> {
244
0
        let start = self.reserved2_byte_range().end;
245
0
        let end = start + i16::RAW_BYTE_LEN;
246
0
        start..end
247
0
    }
248
249
0
    pub fn reserved4_byte_range(&self) -> Range<usize> {
250
0
        let start = self.reserved3_byte_range().end;
251
0
        let end = start + i16::RAW_BYTE_LEN;
252
0
        start..end
253
0
    }
254
255
0
    pub fn metric_data_format_byte_range(&self) -> Range<usize> {
256
0
        let start = self.reserved4_byte_range().end;
257
0
        let end = start + i16::RAW_BYTE_LEN;
258
0
        start..end
259
0
    }
260
261
0
    pub fn number_of_h_metrics_byte_range(&self) -> Range<usize> {
262
0
        let start = self.metric_data_format_byte_range().end;
263
0
        let end = start + u16::RAW_BYTE_LEN;
264
0
        start..end
265
0
    }
266
}
267
268
const _: () = assert!(FontData::default_data_long_enough(Hhea::MIN_SIZE));
269
270
impl Default for Hhea<'_> {
271
0
    fn default() -> Self {
272
        Self {
273
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
274
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
275
        }
276
0
    }
277
}
278
279
impl<'a> MinByteRange<'a> for HheaExtended<'a> {
280
0
    fn min_byte_range(&self) -> Range<usize> {
281
0
        0..self.number_of_h_metrics_byte_range().end
282
0
    }
283
0
    fn min_table_bytes(&self) -> &'a [u8] {
284
0
        let range = self.min_byte_range();
285
0
        self.offset_data().as_bytes().get(range).unwrap_or_default()
286
0
    }
287
}
288
289
impl TopLevelTable for HheaExtended<'_> {
290
    /// `HHEA`
291
    const TAG: Tag = Tag::new(b"HHEA");
292
}
293
294
impl ReadArgs for HheaExtended<'_> {
295
    type Args = ();
296
}
297
298
impl<'a> FontRead<'a> for HheaExtended<'a> {
299
15
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
300
        #[allow(clippy::absurd_extreme_comparisons)]
301
15
        if data.len() < Self::MIN_SIZE {
302
7
            return Err(ReadError::OutOfBounds);
303
8
        }
304
8
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
305
0
            return Err(ReadError::OutOfBounds);
306
        };
307
8
        Ok(Self { data })
308
15
    }
309
}
310
311
/// The fields at the start of the table, which are read directly.
312
#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
313
#[repr(C, packed)]
314
#[doc(hidden)]
315
pub struct HheaExtendedFixedHeader {
316
    pub version: BigEndian<MajorMinor>,
317
    pub ascender: BigEndian<FWord>,
318
    pub descender: BigEndian<FWord>,
319
    pub line_gap: BigEndian<FWord>,
320
    pub advance_width_max: BigEndian<UfWord>,
321
    pub min_left_side_bearing: BigEndian<FWord>,
322
    pub min_right_side_bearing: BigEndian<FWord>,
323
    pub x_max_extent: BigEndian<FWord>,
324
    pub caret_slope_rise: BigEndian<i16>,
325
    pub caret_slope_run: BigEndian<i16>,
326
    pub caret_offset: BigEndian<i16>,
327
    pub reserved1: BigEndian<i16>,
328
    pub reserved2: BigEndian<i16>,
329
    pub reserved3: BigEndian<i16>,
330
    pub reserved4: BigEndian<i16>,
331
    pub metric_data_format: BigEndian<i16>,
332
    pub number_of_h_metrics: BigEndian<u32>,
333
}
334
335
#[allow(clippy::absurd_extreme_comparisons)]
336
const _: () = assert!(std::mem::size_of::<HheaExtendedFixedHeader>() <= HheaExtended::MIN_SIZE);
337
338
/// HHEA header table (ISO/IEC 14496-22:2026, 5.1.10).
339
#[derive(Clone)]
340
pub struct HheaExtended<'a> {
341
    data: TableDataRef<'a, HheaExtendedFixedHeader>,
342
}
343
344
#[allow(clippy::needless_lifetimes)]
345
impl<'a> HheaExtended<'a> {
346
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
347
        + FWord::RAW_BYTE_LEN
348
        + FWord::RAW_BYTE_LEN
349
        + FWord::RAW_BYTE_LEN
350
        + UfWord::RAW_BYTE_LEN
351
        + FWord::RAW_BYTE_LEN
352
        + FWord::RAW_BYTE_LEN
353
        + FWord::RAW_BYTE_LEN
354
        + i16::RAW_BYTE_LEN
355
        + i16::RAW_BYTE_LEN
356
        + i16::RAW_BYTE_LEN
357
        + i16::RAW_BYTE_LEN
358
        + i16::RAW_BYTE_LEN
359
        + i16::RAW_BYTE_LEN
360
        + i16::RAW_BYTE_LEN
361
        + i16::RAW_BYTE_LEN
362
        + u32::RAW_BYTE_LEN);
363
    basic_table_impls!(impl_the_methods);
364
365
0
    pub fn version(&self) -> MajorMinor {
366
0
        self.data.header().version.get()
367
0
    }
368
369
8
    pub fn ascender(&self) -> FWord {
370
8
        self.data.header().ascender.get()
371
8
    }
372
373
8
    pub fn descender(&self) -> FWord {
374
8
        self.data.header().descender.get()
375
8
    }
376
377
8
    pub fn line_gap(&self) -> FWord {
378
8
        self.data.header().line_gap.get()
379
8
    }
380
381
8
    pub fn advance_width_max(&self) -> UfWord {
382
8
        self.data.header().advance_width_max.get()
383
8
    }
384
385
0
    pub fn min_left_side_bearing(&self) -> FWord {
386
0
        self.data.header().min_left_side_bearing.get()
387
0
    }
388
389
0
    pub fn min_right_side_bearing(&self) -> FWord {
390
0
        self.data.header().min_right_side_bearing.get()
391
0
    }
392
393
0
    pub fn x_max_extent(&self) -> FWord {
394
0
        self.data.header().x_max_extent.get()
395
0
    }
396
397
0
    pub fn caret_slope_rise(&self) -> i16 {
398
0
        self.data.header().caret_slope_rise.get()
399
0
    }
400
401
0
    pub fn caret_slope_run(&self) -> i16 {
402
0
        self.data.header().caret_slope_run.get()
403
0
    }
404
405
0
    pub fn caret_offset(&self) -> i16 {
406
0
        self.data.header().caret_offset.get()
407
0
    }
408
409
0
    pub fn metric_data_format(&self) -> i16 {
410
0
        self.data.header().metric_data_format.get()
411
0
    }
412
413
    /// Number of long metric records in HMTX.
414
0
    pub fn number_of_h_metrics(&self) -> u32 {
415
0
        self.data.header().number_of_h_metrics.get()
416
0
    }
417
418
0
    pub fn version_byte_range(&self) -> Range<usize> {
419
0
        let start = 0;
420
0
        let end = start + MajorMinor::RAW_BYTE_LEN;
421
0
        start..end
422
0
    }
423
424
0
    pub fn ascender_byte_range(&self) -> Range<usize> {
425
0
        let start = self.version_byte_range().end;
426
0
        let end = start + FWord::RAW_BYTE_LEN;
427
0
        start..end
428
0
    }
429
430
0
    pub fn descender_byte_range(&self) -> Range<usize> {
431
0
        let start = self.ascender_byte_range().end;
432
0
        let end = start + FWord::RAW_BYTE_LEN;
433
0
        start..end
434
0
    }
435
436
0
    pub fn line_gap_byte_range(&self) -> Range<usize> {
437
0
        let start = self.descender_byte_range().end;
438
0
        let end = start + FWord::RAW_BYTE_LEN;
439
0
        start..end
440
0
    }
441
442
0
    pub fn advance_width_max_byte_range(&self) -> Range<usize> {
443
0
        let start = self.line_gap_byte_range().end;
444
0
        let end = start + UfWord::RAW_BYTE_LEN;
445
0
        start..end
446
0
    }
447
448
0
    pub fn min_left_side_bearing_byte_range(&self) -> Range<usize> {
449
0
        let start = self.advance_width_max_byte_range().end;
450
0
        let end = start + FWord::RAW_BYTE_LEN;
451
0
        start..end
452
0
    }
453
454
0
    pub fn min_right_side_bearing_byte_range(&self) -> Range<usize> {
455
0
        let start = self.min_left_side_bearing_byte_range().end;
456
0
        let end = start + FWord::RAW_BYTE_LEN;
457
0
        start..end
458
0
    }
459
460
0
    pub fn x_max_extent_byte_range(&self) -> Range<usize> {
461
0
        let start = self.min_right_side_bearing_byte_range().end;
462
0
        let end = start + FWord::RAW_BYTE_LEN;
463
0
        start..end
464
0
    }
465
466
0
    pub fn caret_slope_rise_byte_range(&self) -> Range<usize> {
467
0
        let start = self.x_max_extent_byte_range().end;
468
0
        let end = start + i16::RAW_BYTE_LEN;
469
0
        start..end
470
0
    }
471
472
0
    pub fn caret_slope_run_byte_range(&self) -> Range<usize> {
473
0
        let start = self.caret_slope_rise_byte_range().end;
474
0
        let end = start + i16::RAW_BYTE_LEN;
475
0
        start..end
476
0
    }
477
478
0
    pub fn caret_offset_byte_range(&self) -> Range<usize> {
479
0
        let start = self.caret_slope_run_byte_range().end;
480
0
        let end = start + i16::RAW_BYTE_LEN;
481
0
        start..end
482
0
    }
483
484
0
    pub fn reserved1_byte_range(&self) -> Range<usize> {
485
0
        let start = self.caret_offset_byte_range().end;
486
0
        let end = start + i16::RAW_BYTE_LEN;
487
0
        start..end
488
0
    }
489
490
0
    pub fn reserved2_byte_range(&self) -> Range<usize> {
491
0
        let start = self.reserved1_byte_range().end;
492
0
        let end = start + i16::RAW_BYTE_LEN;
493
0
        start..end
494
0
    }
495
496
0
    pub fn reserved3_byte_range(&self) -> Range<usize> {
497
0
        let start = self.reserved2_byte_range().end;
498
0
        let end = start + i16::RAW_BYTE_LEN;
499
0
        start..end
500
0
    }
501
502
0
    pub fn reserved4_byte_range(&self) -> Range<usize> {
503
0
        let start = self.reserved3_byte_range().end;
504
0
        let end = start + i16::RAW_BYTE_LEN;
505
0
        start..end
506
0
    }
507
508
0
    pub fn metric_data_format_byte_range(&self) -> Range<usize> {
509
0
        let start = self.reserved4_byte_range().end;
510
0
        let end = start + i16::RAW_BYTE_LEN;
511
0
        start..end
512
0
    }
513
514
0
    pub fn number_of_h_metrics_byte_range(&self) -> Range<usize> {
515
0
        let start = self.metric_data_format_byte_range().end;
516
0
        let end = start + u32::RAW_BYTE_LEN;
517
0
        start..end
518
0
    }
519
}
520
521
const _: () = assert!(FontData::default_data_long_enough(HheaExtended::MIN_SIZE));
522
523
impl Default for HheaExtended<'_> {
524
0
    fn default() -> Self {
525
        Self {
526
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
527
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
528
        }
529
0
    }
530
}