/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.46.0/generated/generated_vvar.rs
Line | Count | Source |
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)] |
6 | | use crate::codegen_prelude::*; |
7 | | |
8 | | impl<'a> MinByteRange<'a> for Vvar<'a> { |
9 | 0 | fn min_byte_range(&self) -> Range<usize> { |
10 | 0 | 0..self.v_org_mapping_offset_byte_range().end |
11 | 0 | } |
12 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
13 | 0 | let range = self.min_byte_range(); |
14 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
15 | 0 | } |
16 | | } |
17 | | |
18 | | impl TopLevelTable for Vvar<'_> { |
19 | | /// `VVAR` |
20 | | const TAG: Tag = Tag::new(b"VVAR"); |
21 | | } |
22 | | |
23 | | impl ReadArgs for Vvar<'_> { |
24 | | type Args = (); |
25 | | } |
26 | | |
27 | | impl<'a> FontRead<'a> for Vvar<'a> { |
28 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
29 | | #[allow(clippy::absurd_extreme_comparisons)] |
30 | 0 | if data.len() < Self::MIN_SIZE { |
31 | 0 | return Err(ReadError::OutOfBounds); |
32 | 0 | } |
33 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
34 | 0 | return Err(ReadError::OutOfBounds); |
35 | | }; |
36 | 0 | Ok(Self { data }) |
37 | 0 | } |
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)] |
44 | | pub 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)] |
54 | | const _: () = 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)] |
58 | | pub struct Vvar<'a> { |
59 | | data: TableDataRef<'a, VvarFixedHeader>, |
60 | | } |
61 | | |
62 | | #[allow(clippy::needless_lifetimes)] |
63 | | impl<'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 | 0 | pub fn version(&self) -> MajorMinor { |
75 | 0 | self.data.header().version.get() |
76 | 0 | } |
77 | | |
78 | | /// Offset in bytes from the start of this table to the item variation store table. |
79 | 0 | pub fn item_variation_store_offset(&self) -> Offset32 { |
80 | 0 | self.data.header().item_variation_store_offset.get() |
81 | 0 | } |
82 | | |
83 | | /// Attempt to resolve [`item_variation_store_offset`][Self::item_variation_store_offset]. |
84 | 0 | pub fn item_variation_store(&self) -> Result<ItemVariationStore<'a>, ReadError> { |
85 | 0 | let data = self.offset_data(); |
86 | 0 | self.item_variation_store_offset().resolve(data) |
87 | 0 | } |
88 | | |
89 | | /// Offset in bytes from the start of this table to the delta-set index mapping for advance heights (may be NULL). |
90 | 0 | pub fn advance_height_mapping_offset(&self) -> Nullable<Offset32> { |
91 | 0 | self.data.header().advance_height_mapping_offset.get() |
92 | 0 | } |
93 | | |
94 | | /// Attempt to resolve [`advance_height_mapping_offset`][Self::advance_height_mapping_offset]. |
95 | 0 | pub fn advance_height_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> { |
96 | 0 | let data = self.offset_data(); |
97 | 0 | self.advance_height_mapping_offset().resolve(data) |
98 | 0 | } |
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 | 0 | pub fn tsb_mapping_offset(&self) -> Nullable<Offset32> { |
102 | 0 | self.data.header().tsb_mapping_offset.get() |
103 | 0 | } |
104 | | |
105 | | /// Attempt to resolve [`tsb_mapping_offset`][Self::tsb_mapping_offset]. |
106 | 0 | pub fn tsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> { |
107 | 0 | let data = self.offset_data(); |
108 | 0 | self.tsb_mapping_offset().resolve(data) |
109 | 0 | } |
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 | 0 | pub fn bsb_mapping_offset(&self) -> Nullable<Offset32> { |
113 | 0 | self.data.header().bsb_mapping_offset.get() |
114 | 0 | } |
115 | | |
116 | | /// Attempt to resolve [`bsb_mapping_offset`][Self::bsb_mapping_offset]. |
117 | 0 | pub fn bsb_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> { |
118 | 0 | let data = self.offset_data(); |
119 | 0 | self.bsb_mapping_offset().resolve(data) |
120 | 0 | } |
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 | 0 | pub fn v_org_mapping_offset(&self) -> Nullable<Offset32> { |
124 | 0 | self.data.header().v_org_mapping_offset.get() |
125 | 0 | } |
126 | | |
127 | | /// Attempt to resolve [`v_org_mapping_offset`][Self::v_org_mapping_offset]. |
128 | 0 | pub fn v_org_mapping(&self) -> Option<Result<DeltaSetIndexMap<'a>, ReadError>> { |
129 | 0 | let data = self.offset_data(); |
130 | 0 | self.v_org_mapping_offset().resolve(data) |
131 | 0 | } |
132 | | |
133 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
134 | 0 | let start = 0; |
135 | 0 | let end = start + MajorMinor::RAW_BYTE_LEN; |
136 | 0 | start..end |
137 | 0 | } |
138 | | |
139 | 0 | pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> { |
140 | 0 | let start = self.version_byte_range().end; |
141 | 0 | let end = start + Offset32::RAW_BYTE_LEN; |
142 | 0 | start..end |
143 | 0 | } |
144 | | |
145 | 0 | pub fn advance_height_mapping_offset_byte_range(&self) -> Range<usize> { |
146 | 0 | let start = self.item_variation_store_offset_byte_range().end; |
147 | 0 | let end = start + Offset32::RAW_BYTE_LEN; |
148 | 0 | start..end |
149 | 0 | } |
150 | | |
151 | 0 | pub fn tsb_mapping_offset_byte_range(&self) -> Range<usize> { |
152 | 0 | let start = self.advance_height_mapping_offset_byte_range().end; |
153 | 0 | let end = start + Offset32::RAW_BYTE_LEN; |
154 | 0 | start..end |
155 | 0 | } |
156 | | |
157 | 0 | pub fn bsb_mapping_offset_byte_range(&self) -> Range<usize> { |
158 | 0 | let start = self.tsb_mapping_offset_byte_range().end; |
159 | 0 | let end = start + Offset32::RAW_BYTE_LEN; |
160 | 0 | start..end |
161 | 0 | } |
162 | | |
163 | 0 | pub fn v_org_mapping_offset_byte_range(&self) -> Range<usize> { |
164 | 0 | let start = self.bsb_mapping_offset_byte_range().end; |
165 | 0 | let end = start + Offset32::RAW_BYTE_LEN; |
166 | 0 | start..end |
167 | 0 | } |
168 | | } |
169 | | |
170 | | const _: () = assert!(FontData::default_data_long_enough(Vvar::MIN_SIZE)); |
171 | | |
172 | | impl Default for Vvar<'_> { |
173 | 0 | fn default() -> Self { |
174 | | Self { |
175 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
176 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
177 | | } |
178 | 0 | } |
179 | | } |