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        let end = start + MajorMinor::RAW_BYTE_LEN;
119        start..end
120    }
121
122    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
123        let start = self.version_byte_range().end;
124        let end = start + Offset32::RAW_BYTE_LEN;
125        start..end
126    }
127
128    pub fn advance_height_mapping_offset_byte_range(&self) -> Range<usize> {
129        let start = self.item_variation_store_offset_byte_range().end;
130        let end = start + Offset32::RAW_BYTE_LEN;
131        start..end
132    }
133
134    pub fn tsb_mapping_offset_byte_range(&self) -> Range<usize> {
135        let start = self.advance_height_mapping_offset_byte_range().end;
136        let end = start + Offset32::RAW_BYTE_LEN;
137        start..end
138    }
139
140    pub fn bsb_mapping_offset_byte_range(&self) -> Range<usize> {
141        let start = self.tsb_mapping_offset_byte_range().end;
142        let end = start + Offset32::RAW_BYTE_LEN;
143        start..end
144    }
145
146    pub fn v_org_mapping_offset_byte_range(&self) -> Range<usize> {
147        let start = self.bsb_mapping_offset_byte_range().end;
148        let end = start + Offset32::RAW_BYTE_LEN;
149        start..end
150    }
151}
152
153const _: () = assert!(FontData::default_data_long_enough(Vvar::MIN_SIZE));
154
155impl Default for Vvar<'_> {
156    fn default() -> Self {
157        Self {
158            data: FontData::default_table_data(),
159        }
160    }
161}
162
163#[cfg(feature = "experimental_traverse")]
164impl<'a> SomeTable<'a> for Vvar<'a> {
165    fn type_name(&self) -> &str {
166        "Vvar"
167    }
168    fn get_field(&self, idx: usize) -> Option<Field<'a>> {
169        match idx {
170            0usize => Some(Field::new("version", self.version())),
171            1usize => Some(Field::new(
172                "item_variation_store_offset",
173                FieldType::offset(
174                    self.item_variation_store_offset(),
175                    self.item_variation_store(),
176                ),
177            )),
178            2usize => Some(Field::new(
179                "advance_height_mapping_offset",
180                FieldType::offset(
181                    self.advance_height_mapping_offset(),
182                    self.advance_height_mapping(),
183                ),
184            )),
185            3usize => Some(Field::new(
186                "tsb_mapping_offset",
187                FieldType::offset(self.tsb_mapping_offset(), self.tsb_mapping()),
188            )),
189            4usize => Some(Field::new(
190                "bsb_mapping_offset",
191                FieldType::offset(self.bsb_mapping_offset(), self.bsb_mapping()),
192            )),
193            5usize => Some(Field::new(
194                "v_org_mapping_offset",
195                FieldType::offset(self.v_org_mapping_offset(), self.v_org_mapping()),
196            )),
197            _ => None,
198        }
199    }
200}
201
202#[cfg(feature = "experimental_traverse")]
203#[allow(clippy::needless_lifetimes)]
204impl<'a> std::fmt::Debug for Vvar<'a> {
205    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
206        (self as &dyn SomeTable<'a>).fmt(f)
207    }
208}