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