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