Skip to main content

read_fonts/generated/
generated_vvar.rs

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)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Vvar<'a> {
9    fn min_byte_range(&self) -> Range<usize> {
10        0..self.v_org_mapping_offset_byte_range().end
11    }
12    fn min_table_bytes(&self) -> &'a [u8] {
13        let range = self.min_byte_range();
14        self.data.as_bytes().get(range).unwrap_or_default()
15    }
16}
17
18impl TopLevelTable for Vvar<'_> {
19    /// `VVAR`
20    const TAG: Tag = Tag::new(b"VVAR");
21}
22
23impl ReadArgs for Vvar<'_> {
24    type Args = ();
25}
26
27impl<'a> FontRead<'a> for Vvar<'a> {
28    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29        #[allow(clippy::absurd_extreme_comparisons)]
30        if data.len() < Self::MIN_SIZE {
31            return Err(ReadError::OutOfBounds);
32        }
33        Ok(Self { data })
34    }
35}
36
37/// The [VVAR (Vertical Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/vvar) table
38#[derive(Clone)]
39pub struct Vvar<'a> {
40    data: FontData<'a>,
41}
42
43#[allow(clippy::needless_lifetimes)]
44impl<'a> Vvar<'a> {
45    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
46        + Offset32::RAW_BYTE_LEN
47        + Offset32::RAW_BYTE_LEN
48        + Offset32::RAW_BYTE_LEN
49        + Offset32::RAW_BYTE_LEN
50        + Offset32::RAW_BYTE_LEN);
51    basic_table_impls!(impl_the_methods);
52
53    /// Major version number of the horizontal metrics variations table — set to 1.
54    /// Minor version number of the horizontal metrics variations table — set to 0.
55    pub fn version(&self) -> MajorMinor {
56        let range = self.version_byte_range();
57        self.data.read_at(range.start).ok().unwrap()
58    }
59
60    /// Offset in bytes from the start of this table to the item variation store table.
61    pub fn item_variation_store_offset(&self) -> Offset32 {
62        let range = self.item_variation_store_offset_byte_range();
63        self.data.read_at(range.start).ok().unwrap()
64    }
65
66    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
67    pub fn item_variation_store(&self) -> Result<ItemVariationStore<'a>, ReadError> {
68        let data = self.data;
69        self.item_variation_store_offset().resolve(data)
70    }
71
72    /// Offset in bytes from the start of this table to the delta-set index mapping for advance heights (may be NULL).
73    pub fn advance_height_mapping_offset(&self) -> Nullable<Offset32> {
74        let range = self.advance_height_mapping_offset_byte_range();
75        self.data.read_at(range.start).ok().unwrap()
76    }
77
78    /// Attempt to resolve [`advance_height_mapping_offset`][Self::advance_height_mapping_offset].
79    pub fn advance_height_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
80        let data = self.data;
81        self.advance_height_mapping_offset().resolve(data)
82    }
83
84    /// Offset in bytes from the start of this table to the delta-set index mapping for top side bearings (may be NULL).
85    pub fn tsb_mapping_offset(&self) -> Nullable<Offset32> {
86        let range = self.tsb_mapping_offset_byte_range();
87        self.data.read_at(range.start).ok().unwrap()
88    }
89
90    /// Attempt to resolve [`tsb_mapping_offset`][Self::tsb_mapping_offset].
91    pub fn tsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
92        let data = self.data;
93        self.tsb_mapping_offset().resolve(data)
94    }
95
96    /// Offset in bytes from the start of this table to the delta-set index mapping for bottom side bearings (may be NULL).
97    pub fn bsb_mapping_offset(&self) -> Nullable<Offset32> {
98        let range = self.bsb_mapping_offset_byte_range();
99        self.data.read_at(range.start).ok().unwrap()
100    }
101
102    /// Attempt to resolve [`bsb_mapping_offset`][Self::bsb_mapping_offset].
103    pub fn bsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
104        let data = self.data;
105        self.bsb_mapping_offset().resolve(data)
106    }
107
108    /// Offset in bytes from the start of this table to the delta-set index mapping for Y coordinates of vertical origins (may be NULL).
109    pub fn v_org_mapping_offset(&self) -> Nullable<Offset32> {
110        let range = self.v_org_mapping_offset_byte_range();
111        self.data.read_at(range.start).ok().unwrap()
112    }
113
114    /// Attempt to resolve [`v_org_mapping_offset`][Self::v_org_mapping_offset].
115    pub fn v_org_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
116        let data = self.data;
117        self.v_org_mapping_offset().resolve(data)
118    }
119
120    pub fn version_byte_range(&self) -> Range<usize> {
121        let start = 0;
122        let end = start + MajorMinor::RAW_BYTE_LEN;
123        start..end
124    }
125
126    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
127        let start = self.version_byte_range().end;
128        let end = start + Offset32::RAW_BYTE_LEN;
129        start..end
130    }
131
132    pub fn advance_height_mapping_offset_byte_range(&self) -> Range<usize> {
133        let start = self.item_variation_store_offset_byte_range().end;
134        let end = start + Offset32::RAW_BYTE_LEN;
135        start..end
136    }
137
138    pub fn tsb_mapping_offset_byte_range(&self) -> Range<usize> {
139        let start = self.advance_height_mapping_offset_byte_range().end;
140        let end = start + Offset32::RAW_BYTE_LEN;
141        start..end
142    }
143
144    pub fn bsb_mapping_offset_byte_range(&self) -> Range<usize> {
145        let start = self.tsb_mapping_offset_byte_range().end;
146        let end = start + Offset32::RAW_BYTE_LEN;
147        start..end
148    }
149
150    pub fn v_org_mapping_offset_byte_range(&self) -> Range<usize> {
151        let start = self.bsb_mapping_offset_byte_range().end;
152        let end = start + Offset32::RAW_BYTE_LEN;
153        start..end
154    }
155}
156
157const _: () = assert!(FontData::default_data_long_enough(Vvar::MIN_SIZE));
158
159impl Default for Vvar<'_> {
160    fn default() -> Self {
161        Self {
162            data: FontData::default_table_data(),
163        }
164    }
165}
166
167#[cfg(feature = "experimental_traverse")]
168impl<'a> SomeTable<'a> for Vvar<'a> {
169    fn type_name(&self) -> &str {
170        "Vvar"
171    }
172    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
173        match idx {
174            0usize => Some(Field::new("version", self.version())),
175            1usize => Some(Field::new(
176                "item_variation_store_offset",
177                FieldType::offset(
178                    self.item_variation_store_offset(),
179                    self.item_variation_store(),
180                ),
181            )),
182            2usize => Some(Field::new(
183                "advance_height_mapping_offset",
184                FieldType::offset(
185                    self.advance_height_mapping_offset(),
186                    self.advance_height_mapping(),
187                ),
188            )),
189            3usize => Some(Field::new(
190                "tsb_mapping_offset",
191                FieldType::offset(self.tsb_mapping_offset(), self.tsb_mapping()),
192            )),
193            4usize => Some(Field::new(
194                "bsb_mapping_offset",
195                FieldType::offset(self.bsb_mapping_offset(), self.bsb_mapping()),
196            )),
197            5usize => Some(Field::new(
198                "v_org_mapping_offset",
199                FieldType::offset(self.v_org_mapping_offset(), self.v_org_mapping()),
200            )),
201            _ => None,
202        }
203    }
204}
205
206#[cfg(feature = "experimental_traverse")]
207#[allow(clippy::needless_lifetimes)]
208impl<'a> std::fmt::Debug for Vvar<'a> {
209    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
210        (self as &dyn SomeTable<'a>).fmt(f)
211    }
212}