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_hvar.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 Hvar<'a> {
9
0
    fn min_byte_range(&self) -> Range<usize> {
10
0
        0..self.rsb_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.offset_data().as_bytes().get(range).unwrap_or_default()
15
0
    }
16
}
17
18
impl TopLevelTable for Hvar<'_> {
19
    /// `HVAR`
20
    const TAG: Tag = Tag::new(b"HVAR");
21
}
22
23
impl ReadArgs for Hvar<'_> {
24
    type Args = ();
25
}
26
27
impl<'a> FontRead<'a> for Hvar<'a> {
28
868
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29
        #[allow(clippy::absurd_extreme_comparisons)]
30
868
        if data.len() < Self::MIN_SIZE {
31
12
            return Err(ReadError::OutOfBounds);
32
856
        }
33
856
        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34
0
            return Err(ReadError::OutOfBounds);
35
        };
36
856
        Ok(Self { data })
37
868
    }
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 HvarFixedHeader {
45
    pub version: BigEndian<MajorMinor>,
46
    pub item_variation_store_offset: BigEndian<Offset32>,
47
    pub advance_width_mapping_offset: BigEndian<Nullable<Offset32>>,
48
    pub lsb_mapping_offset: BigEndian<Nullable<Offset32>>,
49
    pub rsb_mapping_offset: BigEndian<Nullable<Offset32>>,
50
}
51
52
#[allow(clippy::absurd_extreme_comparisons)]
53
const _: () = assert!(std::mem::size_of::<HvarFixedHeader>() <= Hvar::MIN_SIZE);
54
55
/// The [HVAR (Horizontal Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/hvar) table
56
#[derive(Clone)]
57
pub struct Hvar<'a> {
58
    data: TableDataRef<'a, HvarFixedHeader>,
59
}
60
61
#[allow(clippy::needless_lifetimes)]
62
impl<'a> Hvar<'a> {
63
    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
64
        + Offset32::RAW_BYTE_LEN
65
        + Offset32::RAW_BYTE_LEN
66
        + Offset32::RAW_BYTE_LEN
67
        + Offset32::RAW_BYTE_LEN);
68
    basic_table_impls!(impl_the_methods);
69
70
    /// Major version number of the horizontal metrics variations table — set to 1.
71
    /// Minor version number of the horizontal metrics variations table — set to 0.
72
0
    pub fn version(&self) -> MajorMinor {
73
0
        self.data.header().version.get()
74
0
    }
75
76
    /// Offset in bytes from the start of this table to the item variation store table.
77
3.18k
    pub fn item_variation_store_offset(&self) -> Offset32 {
78
3.18k
        self.data.header().item_variation_store_offset.get()
79
3.18k
    }
80
81
    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
82
3.18k
    pub fn item_variation_store(&self) -> Result<ItemVariationStore<'a>, ReadError> {
83
3.18k
        let data = self.offset_data();
84
3.18k
        self.item_variation_store_offset().resolve(data)
85
3.18k
    }
86
87
    /// Offset in bytes from the start of this table to the delta-set index mapping for advance widths (may be NULL).
88
3.03k
    pub fn advance_width_mapping_offset(&self) -> Nullable<Offset32> {
89
3.03k
        self.data.header().advance_width_mapping_offset.get()
90
3.03k
    }
91
92
    /// Attempt to resolve [`advance_width_mapping_offset`][Self::advance_width_mapping_offset].
93
3.03k
    pub fn advance_width_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
94
3.03k
        let data = self.offset_data();
95
3.03k
        self.advance_width_mapping_offset().resolve(data)
96
3.03k
    }
97
98
    /// Offset in bytes from the start of this table to the delta-set index mapping for left side bearings (may be NULL).
99
0
    pub fn lsb_mapping_offset(&self) -> Nullable<Offset32> {
100
0
        self.data.header().lsb_mapping_offset.get()
101
0
    }
102
103
    /// Attempt to resolve [`lsb_mapping_offset`][Self::lsb_mapping_offset].
104
0
    pub fn lsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
105
0
        let data = self.offset_data();
106
0
        self.lsb_mapping_offset().resolve(data)
107
0
    }
108
109
    /// Offset in bytes from the start of this table to the delta-set index mapping for right side bearings (may be NULL).
110
0
    pub fn rsb_mapping_offset(&self) -> Nullable<Offset32> {
111
0
        self.data.header().rsb_mapping_offset.get()
112
0
    }
113
114
    /// Attempt to resolve [`rsb_mapping_offset`][Self::rsb_mapping_offset].
115
0
    pub fn rsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
116
0
        let data = self.offset_data();
117
0
        self.rsb_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_width_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 lsb_mapping_offset_byte_range(&self) -> Range<usize> {
139
0
        let start = self.advance_width_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 rsb_mapping_offset_byte_range(&self) -> Range<usize> {
145
0
        let start = self.lsb_mapping_offset_byte_range().end;
146
0
        let end = start + Offset32::RAW_BYTE_LEN;
147
0
        start..end
148
0
    }
149
}
150
151
const _: () = assert!(FontData::default_data_long_enough(Hvar::MIN_SIZE));
152
153
impl Default for Hvar<'_> {
154
0
    fn default() -> Self {
155
        Self {
156
0
            data: TableDataRef::new(FontData::default_table_data().as_bytes())
157
0
                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
158
        }
159
0
    }
160
}