Coverage Report

Created: 2025-07-23 06:50

/src/fontations/read-fonts/generated/generated_hvar.rs
Line
Count
Source (jump to first uncovered line)
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
/// The [HVAR (Horizontal Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/hvar) table
9
#[derive(Debug, Clone, Copy)]
10
#[doc(hidden)]
11
pub struct HvarMarker {}
12
13
impl HvarMarker {
14
1.34k
    pub fn version_byte_range(&self) -> Range<usize> {
15
1.34k
        let start = 0;
16
1.34k
        start..start + MajorMinor::RAW_BYTE_LEN
17
1.34k
    }
18
19
1.34k
    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
20
1.34k
        let start = self.version_byte_range().end;
21
1.34k
        start..start + Offset32::RAW_BYTE_LEN
22
1.34k
    }
23
24
672
    pub fn advance_width_mapping_offset_byte_range(&self) -> Range<usize> {
25
672
        let start = self.item_variation_store_offset_byte_range().end;
26
672
        start..start + Offset32::RAW_BYTE_LEN
27
672
    }
28
29
0
    pub fn lsb_mapping_offset_byte_range(&self) -> Range<usize> {
30
0
        let start = self.advance_width_mapping_offset_byte_range().end;
31
0
        start..start + Offset32::RAW_BYTE_LEN
32
0
    }
33
34
0
    pub fn rsb_mapping_offset_byte_range(&self) -> Range<usize> {
35
0
        let start = self.lsb_mapping_offset_byte_range().end;
36
0
        start..start + Offset32::RAW_BYTE_LEN
37
0
    }
38
}
39
40
impl MinByteRange for HvarMarker {
41
0
    fn min_byte_range(&self) -> Range<usize> {
42
0
        0..self.rsb_mapping_offset_byte_range().end
43
0
    }
44
}
45
46
impl TopLevelTable for Hvar<'_> {
47
    /// `HVAR`
48
    const TAG: Tag = Tag::new(b"HVAR");
49
}
50
51
impl<'a> FontRead<'a> for Hvar<'a> {
52
1.06M
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
53
1.06M
        let mut cursor = data.cursor();
54
1.06M
        cursor.advance::<MajorMinor>();
55
1.06M
        cursor.advance::<Offset32>();
56
1.06M
        cursor.advance::<Offset32>();
57
1.06M
        cursor.advance::<Offset32>();
58
1.06M
        cursor.advance::<Offset32>();
59
1.06M
        cursor.finish(HvarMarker {})
60
1.06M
    }
61
}
62
63
/// The [HVAR (Horizontal Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/hvar) table
64
pub type Hvar<'a> = TableRef<'a, HvarMarker>;
65
66
#[allow(clippy::needless_lifetimes)]
67
impl<'a> Hvar<'a> {
68
    /// Major version number of the horizontal metrics variations table — set to 1.
69
    /// Minor version number of the horizontal metrics variations table — set to 0.
70
0
    pub fn version(&self) -> MajorMinor {
71
0
        let range = self.shape.version_byte_range();
72
0
        self.data.read_at(range.start).unwrap()
73
0
    }
74
75
    /// Offset in bytes from the start of this table to the item variation store table.
76
672
    pub fn item_variation_store_offset(&self) -> Offset32 {
77
672
        let range = self.shape.item_variation_store_offset_byte_range();
78
672
        self.data.read_at(range.start).unwrap()
79
672
    }
80
81
    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
82
672
    pub fn item_variation_store(&self) -> Result<ItemVariationStore<'a>, ReadError> {
83
672
        let data = self.data;
84
672
        self.item_variation_store_offset().resolve(data)
85
672
    }
86
87
    /// Offset in bytes from the start of this table to the delta-set index mapping for advance widths (may be NULL).
88
672
    pub fn advance_width_mapping_offset(&self) -> Nullable<Offset32> {
89
672
        let range = self.shape.advance_width_mapping_offset_byte_range();
90
672
        self.data.read_at(range.start).unwrap()
91
672
    }
92
93
    /// Attempt to resolve [`advance_width_mapping_offset`][Self::advance_width_mapping_offset].
94
672
    pub fn advance_width_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
95
672
        let data = self.data;
96
672
        self.advance_width_mapping_offset().resolve(data)
97
672
    }
98
99
    /// Offset in bytes from the start of this table to the delta-set index mapping for left side bearings (may be NULL).
100
0
    pub fn lsb_mapping_offset(&self) -> Nullable<Offset32> {
101
0
        let range = self.shape.lsb_mapping_offset_byte_range();
102
0
        self.data.read_at(range.start).unwrap()
103
0
    }
104
105
    /// Attempt to resolve [`lsb_mapping_offset`][Self::lsb_mapping_offset].
106
0
    pub fn lsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
107
0
        let data = self.data;
108
0
        self.lsb_mapping_offset().resolve(data)
109
0
    }
110
111
    /// Offset in bytes from the start of this table to the delta-set index mapping for right side bearings (may be NULL).
112
0
    pub fn rsb_mapping_offset(&self) -> Nullable<Offset32> {
113
0
        let range = self.shape.rsb_mapping_offset_byte_range();
114
0
        self.data.read_at(range.start).unwrap()
115
0
    }
116
117
    /// Attempt to resolve [`rsb_mapping_offset`][Self::rsb_mapping_offset].
118
0
    pub fn rsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
119
0
        let data = self.data;
120
0
        self.rsb_mapping_offset().resolve(data)
121
0
    }
122
}
123
124
#[cfg(feature = "experimental_traverse")]
125
impl<'a> SomeTable<'a> for Hvar<'a> {
126
    fn type_name(&self) -> &str {
127
        "Hvar"
128
    }
129
    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
130
        match idx {
131
            0usize => Some(Field::new("version", self.version())),
132
            1usize => Some(Field::new(
133
                "item_variation_store_offset",
134
                FieldType::offset(
135
                    self.item_variation_store_offset(),
136
                    self.item_variation_store(),
137
                ),
138
            )),
139
            2usize => Some(Field::new(
140
                "advance_width_mapping_offset",
141
                FieldType::offset(
142
                    self.advance_width_mapping_offset(),
143
                    self.advance_width_mapping(),
144
                ),
145
            )),
146
            3usize => Some(Field::new(
147
                "lsb_mapping_offset",
148
                FieldType::offset(self.lsb_mapping_offset(), self.lsb_mapping()),
149
            )),
150
            4usize => Some(Field::new(
151
                "rsb_mapping_offset",
152
                FieldType::offset(self.rsb_mapping_offset(), self.rsb_mapping()),
153
            )),
154
            _ => None,
155
        }
156
    }
157
}
158
159
#[cfg(feature = "experimental_traverse")]
160
#[allow(clippy::needless_lifetimes)]
161
impl<'a> std::fmt::Debug for Hvar<'a> {
162
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
163
        (self as &dyn SomeTable<'a>).fmt(f)
164
    }
165
}