/rust/registry/src/index.crates.io-1949cf8c6b5b557f/read-fonts-0.46.0/generated/generated_cvar.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 Cvar<'a> { |
9 | 0 | fn min_byte_range(&self) -> Range<usize> { |
10 | 0 | 0..self.tuple_variation_headers_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 Cvar<'_> { |
19 | | /// `cvar` |
20 | | const TAG: Tag = Tag::new(b"cvar"); |
21 | | } |
22 | | |
23 | | impl ReadArgs for Cvar<'_> { |
24 | | type Args = (); |
25 | | } |
26 | | |
27 | | impl<'a> FontRead<'a> for Cvar<'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 CvarFixedHeader { |
45 | | pub version: BigEndian<MajorMinor>, |
46 | | pub tuple_variation_count: BigEndian<TupleVariationCount>, |
47 | | pub data_offset: BigEndian<Offset16>, |
48 | | } |
49 | | |
50 | | #[allow(clippy::absurd_extreme_comparisons)] |
51 | | const _: () = assert!(std::mem::size_of::<CvarFixedHeader>() <= Cvar::MIN_SIZE); |
52 | | |
53 | | /// The [cvar](https://learn.microsoft.com/en-us/typography/opentype/spec/cvar) table. |
54 | | #[derive(Clone)] |
55 | | pub struct Cvar<'a> { |
56 | | data: TableDataRef<'a, CvarFixedHeader>, |
57 | | } |
58 | | |
59 | | #[allow(clippy::needless_lifetimes)] |
60 | | impl<'a> Cvar<'a> { |
61 | | pub const MIN_SIZE: usize = |
62 | | (MajorMinor::RAW_BYTE_LEN + TupleVariationCount::RAW_BYTE_LEN + Offset16::RAW_BYTE_LEN); |
63 | | basic_table_impls!(impl_the_methods); |
64 | | |
65 | | /// Major/minor version number of the CVT variations table — set to (1,0). |
66 | 0 | pub fn version(&self) -> MajorMinor { |
67 | 0 | self.data.header().version.get() |
68 | 0 | } |
69 | | |
70 | | /// A packed field. The high 4 bits are flags, and the low 12 bits |
71 | | /// are the number of tuple variation tables for this glyph. The |
72 | | /// number of tuple variation tables can be any number between 1 |
73 | | /// and 4095. |
74 | 0 | pub fn tuple_variation_count(&self) -> TupleVariationCount { |
75 | 0 | self.data.header().tuple_variation_count.get() |
76 | 0 | } |
77 | | |
78 | | /// Offset from the start of the 'cvar' table to the serialized data. |
79 | 0 | pub fn data_offset(&self) -> Offset16 { |
80 | 0 | self.data.header().data_offset.get() |
81 | 0 | } |
82 | | |
83 | | /// Attempt to resolve [`data_offset`][Self::data_offset]. |
84 | 0 | pub fn data(&self) -> Result<FontData<'a>, ReadError> { |
85 | 0 | let data = self.offset_data(); |
86 | 0 | self.data_offset().resolve(data) |
87 | 0 | } |
88 | | |
89 | | /// Array of tuple variation headers. |
90 | 0 | pub fn tuple_variation_headers(&self) -> VarLenArray<'a, TupleVariationHeader<'a>> { |
91 | 0 | let range = self.tuple_variation_headers_byte_range(); |
92 | 0 | self.offset_data() |
93 | 0 | .split_off(range.start) |
94 | 0 | .and_then(|d| VarLenArray::read(d).ok()) |
95 | 0 | .unwrap_or_default() |
96 | 0 | } |
97 | | |
98 | 0 | pub fn version_byte_range(&self) -> Range<usize> { |
99 | 0 | let start = 0; |
100 | 0 | let end = start + MajorMinor::RAW_BYTE_LEN; |
101 | 0 | start..end |
102 | 0 | } |
103 | | |
104 | 0 | pub fn tuple_variation_count_byte_range(&self) -> Range<usize> { |
105 | 0 | let start = self.version_byte_range().end; |
106 | 0 | let end = start + TupleVariationCount::RAW_BYTE_LEN; |
107 | 0 | start..end |
108 | 0 | } |
109 | | |
110 | 0 | pub fn data_offset_byte_range(&self) -> Range<usize> { |
111 | 0 | let start = self.tuple_variation_count_byte_range().end; |
112 | 0 | let end = start + Offset16::RAW_BYTE_LEN; |
113 | 0 | start..end |
114 | 0 | } |
115 | | |
116 | 0 | pub fn tuple_variation_headers_byte_range(&self) -> Range<usize> { |
117 | 0 | let start = self.data_offset_byte_range().end; |
118 | 0 | let end = start + self.offset_data().len().saturating_sub(start); |
119 | 0 | start..end |
120 | 0 | } |
121 | | } |
122 | | |
123 | | const _: () = assert!(FontData::default_data_long_enough(Cvar::MIN_SIZE)); |
124 | | |
125 | | impl Default for Cvar<'_> { |
126 | 0 | fn default() -> Self { |
127 | | Self { |
128 | 0 | data: TableDataRef::new(FontData::default_table_data().as_bytes()) |
129 | 0 | .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")), |
130 | | } |
131 | 0 | } |
132 | | } |