/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.46.0/generated/generated_fvar.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 Fvar<'a> { |
9 | 0 | fn min_byte_range(&self) -> Range<usize> { |
10 | 0 | 0..self.instance_size_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 Fvar<'_> { |
19 | | /// `fvar` |
20 | | const TAG: Tag = Tag::new(b"fvar"); |
21 | | } |
22 | | |
23 | | impl ReadArgs for Fvar<'_> { |
24 | | type Args = (); |
25 | | } |
26 | | |
27 | | impl<'a> FontRead<'a> for Fvar<'a> { |
28 | 4.24k | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
29 | | #[allow(clippy::absurd_extreme_comparisons)] |
30 | 4.24k | if data.len() < Self::MIN_SIZE { |
31 | 6 | return Err(ReadError::OutOfBounds); |
32 | 4.24k | } |
33 | 4.24k | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
34 | 0 | return Err(ReadError::OutOfBounds); |
35 | | }; |
36 | 4.24k | Ok(Self { data }) |
37 | 4.24k | } |
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 FvarFixedHeader { |
45 | | pub version: BigEndian<MajorMinor>, |
46 | | pub axis_instance_arrays_offset: BigEndian<Offset16>, |
47 | | pub _reserved: BigEndian<u16>, |
48 | | pub axis_count: BigEndian<u16>, |
49 | | pub axis_size: BigEndian<u16>, |
50 | | pub instance_count: BigEndian<u16>, |
51 | | pub instance_size: BigEndian<u16>, |
52 | | } |
53 | | |
54 | | #[allow(clippy::absurd_extreme_comparisons)] |
55 | | const _: () = assert!(std::mem::size_of::<FvarFixedHeader>() <= Fvar::MIN_SIZE); |
56 | | |
57 | | /// The [fvar (Font Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/fvar) table |
58 | | #[derive(Clone)] |
59 | | pub struct Fvar<'a> { |
60 | | data: TableDataRef<'a, FvarFixedHeader>, |
61 | | } |
62 | | |
63 | | #[allow(clippy::needless_lifetimes)] |
64 | | impl<'a> Fvar<'a> { |
65 | | pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN |
66 | | + Offset16::RAW_BYTE_LEN |
67 | | + u16::RAW_BYTE_LEN |
68 | | + u16::RAW_BYTE_LEN |
69 | | + u16::RAW_BYTE_LEN |
70 | | + u16::RAW_BYTE_LEN |
71 | | + u16::RAW_BYTE_LEN); |
72 | | basic_table_impls!(impl_the_methods); |
73 | | |
74 | | /// Major version number of the font variations table — set to 1. |
75 | | /// Minor version number of the font variations table — set to 0. |
76 | 0 | pub fn version(&self) -> MajorMinor { |
77 | 0 | self.data.header().version.get() |
78 | 0 | } |
79 | | |
80 | | /// Offset in bytes from the beginning of the table to the start of the VariationAxisRecord array. The |
81 | | /// InstanceRecord array directly follows. |
82 | 0 | pub fn axis_instance_arrays_offset(&self) -> Offset16 { |
83 | 0 | self.data.header().axis_instance_arrays_offset.get() |
84 | 0 | } |
85 | | |
86 | | /// Attempt to resolve [`axis_instance_arrays_offset`][Self::axis_instance_arrays_offset]. |
87 | 0 | pub fn axis_instance_arrays(&self) -> Result<AxisInstanceArrays<'a>, ReadError> { |
88 | 0 | let data = self.offset_data(); |
89 | 0 | let args = ( |
90 | 0 | self.axis_count(), |
91 | 0 | self.instance_count(), |
92 | 0 | self.instance_size(), |
93 | 0 | ); |
94 | 0 | self.axis_instance_arrays_offset() |
95 | 0 | .resolve_with_args(data, args) |
96 | 0 | } |
97 | | |
98 | | /// The number of variation axes in the font (the number of records in the axes array). |
99 | 4.24k | pub fn axis_count(&self) -> u16 { |
100 | 4.24k | self.data.header().axis_count.get() |
101 | 4.24k | } |
102 | | |
103 | | /// The size in bytes of each VariationAxisRecord — set to 20 (0x0014) for this version. |
104 | 0 | pub fn axis_size(&self) -> u16 { |
105 | 0 | self.data.header().axis_size.get() |
106 | 0 | } |
107 | | |
108 | | /// The number of named instances defined in the font (the number of records in the instances array). |
109 | 0 | pub fn instance_count(&self) -> u16 { |
110 | 0 | self.data.header().instance_count.get() |
111 | 0 | } |
112 | | |
113 | | /// The size in bytes of each InstanceRecord — set to either axisCount * sizeof(Fixed) + 4, or to axisCount * sizeof(Fixed) + 6. |
114 | 0 | pub fn instance_size(&self) -> u16 { |
115 | 0 | self.data.header().instance_size.get() |
116 | 0 | } |
117 | | |
118 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
119 | 0 | let start = 0; |
120 | 0 | let end = start + MajorMinor::RAW_BYTE_LEN; |
121 | 0 | start..end |
122 | 0 | } |
123 | | |
124 | 0 | pub fn axis_instance_arrays_offset_byte_range(&self) -> Range<usize> { |
125 | 0 | let start = self.version_byte_range().end; |
126 | 0 | let end = start + Offset16::RAW_BYTE_LEN; |
127 | 0 | start..end |
128 | 0 | } |
129 | | |
130 | 0 | pub fn _reserved_byte_range(&self) -> Range<usize> { |
131 | 0 | let start = self.axis_instance_arrays_offset_byte_range().end; |
132 | 0 | let end = start + u16::RAW_BYTE_LEN; |
133 | 0 | start..end |
134 | 0 | } |
135 | | |
136 | 0 | pub fn axis_count_byte_range(&self) -> Range<usize> { |
137 | 0 | let start = self._reserved_byte_range().end; |
138 | 0 | let end = start + u16::RAW_BYTE_LEN; |
139 | 0 | start..end |
140 | 0 | } |
141 | | |
142 | 0 | pub fn axis_size_byte_range(&self) -> Range<usize> { |
143 | 0 | let start = self.axis_count_byte_range().end; |
144 | 0 | let end = start + u16::RAW_BYTE_LEN; |
145 | 0 | start..end |
146 | 0 | } |
147 | | |
148 | 0 | pub fn instance_count_byte_range(&self) -> Range<usize> { |
149 | 0 | let start = self.axis_size_byte_range().end; |
150 | 0 | let end = start + u16::RAW_BYTE_LEN; |
151 | 0 | start..end |
152 | 0 | } |
153 | | |
154 | 0 | pub fn instance_size_byte_range(&self) -> Range<usize> { |
155 | 0 | let start = self.instance_count_byte_range().end; |
156 | 0 | let end = start + u16::RAW_BYTE_LEN; |
157 | 0 | start..end |
158 | 0 | } |
159 | | } |
160 | | |
161 | | const _: () = assert!(FontData::default_data_long_enough(Fvar::MIN_SIZE)); |
162 | | |
163 | | impl Default for Fvar<'_> { |
164 | 0 | fn default() -> Self { |
165 | | Self { |
166 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
167 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
168 | | } |
169 | 0 | } |
170 | | } |
171 | | |
172 | | impl<'a> MinByteRange<'a> for AxisInstanceArrays<'a> { |
173 | 0 | fn min_byte_range(&self) -> Range<usize> { |
174 | 0 | 0..self.instances_byte_range().end |
175 | 0 | } |
176 | 0 | fn min_table_bytes(&self) -> &'a [u8] { |
177 | 0 | let range = self.min_byte_range(); |
178 | 0 | self.offset_data().as_bytes().get(range).unwrap_or_default() |
179 | 0 | } |
180 | | } |
181 | | |
182 | | impl ReadArgs for AxisInstanceArrays<'_> { |
183 | | type Args = (u16, u16, u16); |
184 | | } |
185 | | |
186 | | impl<'a> FontRead<'a> for AxisInstanceArrays<'a> { |
187 | 0 | fn read_with_args(data: FontData<'a>, args: (u16, u16, u16)) -> Result<Self, ReadError> { |
188 | 0 | let (axis_count, instance_count, instance_size) = args; |
189 | | |
190 | | #[allow(clippy::absurd_extreme_comparisons)] |
191 | 0 | if data.len() < Self::MIN_SIZE { |
192 | 0 | return Err(ReadError::OutOfBounds); |
193 | 0 | } |
194 | 0 | let Some(data) = TableDataRef::new(data.as_bytes()) else { |
195 | 0 | return Err(ReadError::OutOfBounds); |
196 | | }; |
197 | 0 | Ok(Self { |
198 | 0 | data, |
199 | 0 | axis_count, |
200 | 0 | instance_count, |
201 | 0 | instance_size, |
202 | 0 | }) |
203 | 0 | } |
204 | | } |
205 | | |
206 | | impl<'a> AxisInstanceArrays<'a> { |
207 | | /// A constructor that requires additional arguments. |
208 | | /// |
209 | | /// This type requires some external state in order to be |
210 | | /// parsed. |
211 | 0 | pub fn read( |
212 | 0 | data: FontData<'a>, |
213 | 0 | axis_count: u16, |
214 | 0 | instance_count: u16, |
215 | 0 | instance_size: u16, |
216 | 0 | ) -> Result<Self, ReadError> { |
217 | 0 | let args = (axis_count, instance_count, instance_size); |
218 | 0 | Self::read_with_args(data, args) |
219 | 0 | } |
220 | | } |
221 | | |
222 | | /// The fields at the start of the table, which are read directly. |
223 | | #[derive(Clone, Copy, bytemuck :: AnyBitPattern)] |
224 | | #[repr(C, packed)] |
225 | | #[doc(hidden)] |
226 | | pub struct AxisInstanceArraysFixedHeader {} |
227 | | |
228 | | #[allow(clippy::absurd_extreme_comparisons)] |
229 | | const _: () = |
230 | | assert!(std::mem::size_of::<AxisInstanceArraysFixedHeader>() <= AxisInstanceArrays::MIN_SIZE); |
231 | | |
232 | | /// Shim table to handle combined axis and instance arrays. |
233 | | #[derive(Clone)] |
234 | | pub struct AxisInstanceArrays<'a> { |
235 | | data: TableDataRef<'a, AxisInstanceArraysFixedHeader>, |
236 | | axis_count: u16, |
237 | | instance_count: u16, |
238 | | instance_size: u16, |
239 | | } |
240 | | |
241 | | #[allow(clippy::needless_lifetimes)] |
242 | | impl<'a> AxisInstanceArrays<'a> { |
243 | | pub const MIN_SIZE: usize = 0; |
244 | | basic_table_impls!(impl_the_methods); |
245 | | |
246 | | /// Variation axis record array. |
247 | 0 | pub fn axes(&self) -> &'a [VariationAxisRecord] { |
248 | 0 | let range = self.axes_byte_range(); |
249 | 0 | self.offset_data() |
250 | 0 | .read_array(range) |
251 | 0 | .ok() |
252 | 0 | .unwrap_or_default() |
253 | 0 | } |
254 | | |
255 | | /// Instance record array. |
256 | 0 | pub fn instances(&self) -> ComputedArray<'a, InstanceRecord<'a>> { |
257 | 0 | let range = self.instances_byte_range(); |
258 | 0 | ComputedArray::new( |
259 | 0 | self.offset_data(), |
260 | 0 | range, |
261 | 0 | (self.axis_count(), self.instance_size()), |
262 | | ) |
263 | 0 | .unwrap_or_default() |
264 | 0 | } |
265 | | |
266 | 0 | pub(crate) fn axis_count(&self) -> u16 { |
267 | 0 | self.axis_count |
268 | 0 | } |
269 | | |
270 | 0 | pub(crate) fn instance_count(&self) -> u16 { |
271 | 0 | self.instance_count |
272 | 0 | } |
273 | | |
274 | 0 | pub(crate) fn instance_size(&self) -> u16 { |
275 | 0 | self.instance_size |
276 | 0 | } |
277 | | |
278 | 0 | pub fn axes_byte_range(&self) -> Range<usize> { |
279 | 0 | let axis_count = self.axis_count(); |
280 | 0 | let start = 0; |
281 | 0 | let end = start |
282 | 0 | + (transforms::to_usize(axis_count)).saturating_mul(VariationAxisRecord::RAW_BYTE_LEN); |
283 | 0 | start..end |
284 | 0 | } |
285 | | |
286 | 0 | pub fn instances_byte_range(&self) -> Range<usize> { |
287 | 0 | let instance_count = self.instance_count(); |
288 | 0 | let start = self.axes_byte_range().end; |
289 | 0 | let end = start |
290 | 0 | + (transforms::to_usize(instance_count)).saturating_mul( |
291 | 0 | <InstanceRecord as ComputeSize>::compute_size(( |
292 | 0 | self.axis_count(), |
293 | 0 | self.instance_size(), |
294 | 0 | )) |
295 | 0 | .unwrap_or(0), |
296 | 0 | ); |
297 | 0 | start..end |
298 | 0 | } |
299 | | } |
300 | | |
301 | | #[allow(clippy::absurd_extreme_comparisons)] |
302 | | const _: () = assert!(FontData::default_data_long_enough( |
303 | | AxisInstanceArrays::MIN_SIZE |
304 | | )); |
305 | | |
306 | | impl Default for AxisInstanceArrays<'_> { |
307 | 0 | fn default() -> Self { |
308 | | Self { |
309 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
310 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
311 | 0 | axis_count: Default::default(), |
312 | 0 | instance_count: Default::default(), |
313 | 0 | instance_size: Default::default(), |
314 | | } |
315 | 0 | } |
316 | | } |
317 | | |
318 | | /// The [VariationAxisRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/fvar#variationaxisrecord) |
319 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)] |
320 | | #[repr(C)] |
321 | | #[repr(packed)] |
322 | | pub struct VariationAxisRecord { |
323 | | /// Tag identifying the design variation for the axis. |
324 | | pub axis_tag: BigEndian<Tag>, |
325 | | /// The minimum coordinate value for the axis. |
326 | | pub min_value: BigEndian<Fixed>, |
327 | | /// The default coordinate value for the axis. |
328 | | pub default_value: BigEndian<Fixed>, |
329 | | /// The maximum coordinate value for the axis. |
330 | | pub max_value: BigEndian<Fixed>, |
331 | | /// Axis qualifiers — see details below. |
332 | | pub flags: BigEndian<u16>, |
333 | | /// The name ID for entries in the 'name' table that provide a display name for this axis. |
334 | | pub axis_name_id: BigEndian<NameId>, |
335 | | } |
336 | | |
337 | | impl VariationAxisRecord { |
338 | | /// Tag identifying the design variation for the axis. |
339 | 0 | pub fn axis_tag(&self) -> Tag { |
340 | 0 | self.axis_tag.get() |
341 | 0 | } |
342 | | |
343 | | /// The minimum coordinate value for the axis. |
344 | 0 | pub fn min_value(&self) -> Fixed { |
345 | 0 | self.min_value.get() |
346 | 0 | } |
347 | | |
348 | | /// The default coordinate value for the axis. |
349 | 0 | pub fn default_value(&self) -> Fixed { |
350 | 0 | self.default_value.get() |
351 | 0 | } |
352 | | |
353 | | /// The maximum coordinate value for the axis. |
354 | 0 | pub fn max_value(&self) -> Fixed { |
355 | 0 | self.max_value.get() |
356 | 0 | } |
357 | | |
358 | | /// Axis qualifiers — see details below. |
359 | 0 | pub fn flags(&self) -> u16 { |
360 | 0 | self.flags.get() |
361 | 0 | } |
362 | | |
363 | | /// The name ID for entries in the 'name' table that provide a display name for this axis. |
364 | 0 | pub fn axis_name_id(&self) -> NameId { |
365 | 0 | self.axis_name_id.get() |
366 | 0 | } |
367 | | } |
368 | | |
369 | | impl FixedSize for VariationAxisRecord { |
370 | | const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN |
371 | | + Fixed::RAW_BYTE_LEN |
372 | | + Fixed::RAW_BYTE_LEN |
373 | | + Fixed::RAW_BYTE_LEN |
374 | | + u16::RAW_BYTE_LEN |
375 | | + NameId::RAW_BYTE_LEN; |
376 | | } |