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.offset_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        let Some(data) = TableDataRef::new(data.as_bytes()) else {
34            return Err(ReadError::OutOfBounds);
35        };
36        Ok(Self { data })
37    }
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)]
44pub struct VvarFixedHeader {
45    pub version: BigEndian<MajorMinor>,
46    pub item_variation_store_offset: BigEndian<Offset32>,
47    pub advance_height_mapping_offset: BigEndian<Nullable<Offset32>>,
48    pub tsb_mapping_offset: BigEndian<Nullable<Offset32>>,
49    pub bsb_mapping_offset: BigEndian<Nullable<Offset32>>,
50    pub v_org_mapping_offset: BigEndian<Nullable<Offset32>>,
51}
52
53#[allow(clippy::absurd_extreme_comparisons)]
54const _: () = assert!(std::mem::size_of::<VvarFixedHeader>() <= Vvar::MIN_SIZE);
55
56/// The [VVAR (Vertical Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/vvar) table
57#[derive(Clone)]
58pub struct Vvar<'a> {
59    data: TableDataRef<'a, VvarFixedHeader>,
60}
61
62#[allow(clippy::needless_lifetimes)]
63impl<'a> Vvar<'a> {
64    pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
65        + Offset32::RAW_BYTE_LEN
66        + Offset32::RAW_BYTE_LEN
67        + Offset32::RAW_BYTE_LEN
68        + Offset32::RAW_BYTE_LEN
69        + Offset32::RAW_BYTE_LEN);
70    basic_table_impls!(impl_the_methods);
71
72    /// Major version number of the horizontal metrics variations table — set to 1.
73    /// Minor version number of the horizontal metrics variations table — set to 0.
74    pub fn version(&self) -> MajorMinor {
75        self.data.header().version.get()
76    }
77
78    /// Offset in bytes from the start of this table to the item variation store table.
79    pub fn item_variation_store_offset(&self) -> Offset32 {
80        self.data.header().item_variation_store_offset.get()
81    }
82
83    /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset].
84    pub fn item_variation_store(&self) -> Result<ItemVariationStore<'a>, ReadError> {
85        let data = self.offset_data();
86        self.item_variation_store_offset().resolve(data)
87    }
88
89    /// Offset in bytes from the start of this table to the delta-set index mapping for advance heights (may be NULL).
90    pub fn advance_height_mapping_offset(&self) -> Nullable<Offset32> {
91        self.data.header().advance_height_mapping_offset.get()
92    }
93
94    /// Attempt to resolve [`advance_height_mapping_offset`][Self::advance_height_mapping_offset].
95    pub fn advance_height_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
96        let data = self.offset_data();
97        self.advance_height_mapping_offset().resolve(data)
98    }
99
100    /// Offset in bytes from the start of this table to the delta-set index mapping for top side bearings (may be NULL).
101    pub fn tsb_mapping_offset(&self) -> Nullable<Offset32> {
102        self.data.header().tsb_mapping_offset.get()
103    }
104
105    /// Attempt to resolve [`tsb_mapping_offset`][Self::tsb_mapping_offset].
106    pub fn tsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
107        let data = self.offset_data();
108        self.tsb_mapping_offset().resolve(data)
109    }
110
111    /// Offset in bytes from the start of this table to the delta-set index mapping for bottom side bearings (may be NULL).
112    pub fn bsb_mapping_offset(&self) -> Nullable<Offset32> {
113        self.data.header().bsb_mapping_offset.get()
114    }
115
116    /// Attempt to resolve [`bsb_mapping_offset`][Self::bsb_mapping_offset].
117    pub fn bsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
118        let data = self.offset_data();
119        self.bsb_mapping_offset().resolve(data)
120    }
121
122    /// Offset in bytes from the start of this table to the delta-set index mapping for Y coordinates of vertical origins (may be NULL).
123    pub fn v_org_mapping_offset(&self) -> Nullable<Offset32> {
124        self.data.header().v_org_mapping_offset.get()
125    }
126
127    /// Attempt to resolve [`v_org_mapping_offset`][Self::v_org_mapping_offset].
128    pub fn v_org_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> {
129        let data = self.offset_data();
130        self.v_org_mapping_offset().resolve(data)
131    }
132
133    pub fn version_byte_range(&self) -> Range<usize> {
134        let start = 0;
135        let end = start + MajorMinor::RAW_BYTE_LEN;
136        start..end
137    }
138
139    pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
140        let start = self.version_byte_range().end;
141        let end = start + Offset32::RAW_BYTE_LEN;
142        start..end
143    }
144
145    pub fn advance_height_mapping_offset_byte_range(&self) -> Range<usize> {
146        let start = self.item_variation_store_offset_byte_range().end;
147        let end = start + Offset32::RAW_BYTE_LEN;
148        start..end
149    }
150
151    pub fn tsb_mapping_offset_byte_range(&self) -> Range<usize> {
152        let start = self.advance_height_mapping_offset_byte_range().end;
153        let end = start + Offset32::RAW_BYTE_LEN;
154        start..end
155    }
156
157    pub fn bsb_mapping_offset_byte_range(&self) -> Range<usize> {
158        let start = self.tsb_mapping_offset_byte_range().end;
159        let end = start + Offset32::RAW_BYTE_LEN;
160        start..end
161    }
162
163    pub fn v_org_mapping_offset_byte_range(&self) -> Range<usize> {
164        let start = self.bsb_mapping_offset_byte_range().end;
165        let end = start + Offset32::RAW_BYTE_LEN;
166        start..end
167    }
168}
169
170const _: () = assert!(FontData::default_data_long_enough(Vvar::MIN_SIZE));
171
172impl Default for Vvar<'_> {
173    fn default() -> Self {
174        Self {
175            data: TableDataRef::new(FontData::default_table_data().as_bytes())
176                .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
177        }
178    }
179}