read_fonts/generated/
generated_mvar.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8impl<'a> MinByteRange<'a> for Mvar<'a> {
9 fn min_byte_range(&self) -> Range<usize> {
10 0..self.value_records_byte_range().end
11 }
12 fn min_table_bytes(&self) -> &'a [u8] {
13 let range = self.min_byte_range();
14 self.data.as_bytes().get(range).unwrap_or_default()
15 }
16}
17
18impl TopLevelTable for Mvar<'_> {
19 const TAG: Tag = Tag::new(b"MVAR");
21}
22
23impl<'a> FontRead<'a> for Mvar<'a> {
24 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
25 #[allow(clippy::absurd_extreme_comparisons)]
26 if data.len() < Self::MIN_SIZE {
27 return Err(ReadError::OutOfBounds);
28 }
29 Ok(Self { data })
30 }
31}
32
33#[derive(Clone)]
35pub struct Mvar<'a> {
36 data: FontData<'a>,
37}
38
39#[allow(clippy::needless_lifetimes)]
40impl<'a> Mvar<'a> {
41 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
42 + u16::RAW_BYTE_LEN
43 + u16::RAW_BYTE_LEN
44 + u16::RAW_BYTE_LEN
45 + Offset16::RAW_BYTE_LEN);
46 basic_table_impls!(impl_the_methods);
47
48 pub fn version(&self) -> MajorMinor {
51 let range = self.version_byte_range();
52 self.data.read_at(range.start).ok().unwrap()
53 }
54
55 pub fn value_record_size(&self) -> u16 {
57 let range = self.value_record_size_byte_range();
58 self.data.read_at(range.start).ok().unwrap()
59 }
60
61 pub fn value_record_count(&self) -> u16 {
63 let range = self.value_record_count_byte_range();
64 self.data.read_at(range.start).ok().unwrap()
65 }
66
67 pub fn item_variation_store_offset(&self) -> Nullable<Offset16> {
69 let range = self.item_variation_store_offset_byte_range();
70 self.data.read_at(range.start).ok().unwrap()
71 }
72
73 pub fn item_variation_store(&self) -> Option<Result<ItemVariationStore<'a>, ReadError>> {
75 let data = self.data;
76 self.item_variation_store_offset().resolve(data)
77 }
78
79 pub fn value_records(&self) -> &'a [ValueRecord] {
81 let range = self.value_records_byte_range();
82 self.data.read_array(range).ok().unwrap_or_default()
83 }
84
85 pub fn version_byte_range(&self) -> Range<usize> {
86 let start = 0;
87 start..start + MajorMinor::RAW_BYTE_LEN
88 }
89
90 pub fn _reserved_byte_range(&self) -> Range<usize> {
91 let start = self.version_byte_range().end;
92 start..start + u16::RAW_BYTE_LEN
93 }
94
95 pub fn value_record_size_byte_range(&self) -> Range<usize> {
96 let start = self._reserved_byte_range().end;
97 start..start + u16::RAW_BYTE_LEN
98 }
99
100 pub fn value_record_count_byte_range(&self) -> Range<usize> {
101 let start = self.value_record_size_byte_range().end;
102 start..start + u16::RAW_BYTE_LEN
103 }
104
105 pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
106 let start = self.value_record_count_byte_range().end;
107 start..start + Offset16::RAW_BYTE_LEN
108 }
109
110 pub fn value_records_byte_range(&self) -> Range<usize> {
111 let value_record_count = self.value_record_count();
112 let start = self.item_variation_store_offset_byte_range().end;
113 start..start + (value_record_count as usize).saturating_mul(ValueRecord::RAW_BYTE_LEN)
114 }
115}
116
117const _: () = assert!(FontData::default_data_long_enough(Mvar::MIN_SIZE));
118
119impl Default for Mvar<'_> {
120 fn default() -> Self {
121 Self {
122 data: FontData::default_table_data(),
123 }
124 }
125}
126
127#[cfg(feature = "experimental_traverse")]
128impl<'a> SomeTable<'a> for Mvar<'a> {
129 fn type_name(&self) -> &str {
130 "Mvar"
131 }
132 fn get_field(&self, idx: usize) -> Option<Field<'a>> {
133 match idx {
134 0usize => Some(Field::new("version", self.version())),
135 1usize => Some(Field::new("value_record_size", self.value_record_size())),
136 2usize => Some(Field::new("value_record_count", self.value_record_count())),
137 3usize => Some(Field::new(
138 "item_variation_store_offset",
139 FieldType::offset(
140 self.item_variation_store_offset(),
141 self.item_variation_store(),
142 ),
143 )),
144 4usize => Some(Field::new(
145 "value_records",
146 traversal::FieldType::array_of_records(
147 stringify!(ValueRecord),
148 self.value_records(),
149 self.offset_data(),
150 ),
151 )),
152 _ => None,
153 }
154 }
155}
156
157#[cfg(feature = "experimental_traverse")]
158#[allow(clippy::needless_lifetimes)]
159impl<'a> std::fmt::Debug for Mvar<'a> {
160 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
161 (self as &dyn SomeTable<'a>).fmt(f)
162 }
163}
164
165#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
167#[repr(C)]
168#[repr(packed)]
169pub struct ValueRecord {
170 pub value_tag: BigEndian<Tag>,
172 pub delta_set_outer_index: BigEndian<u16>,
174 pub delta_set_inner_index: BigEndian<u16>,
176}
177
178impl ValueRecord {
179 pub fn value_tag(&self) -> Tag {
181 self.value_tag.get()
182 }
183
184 pub fn delta_set_outer_index(&self) -> u16 {
186 self.delta_set_outer_index.get()
187 }
188
189 pub fn delta_set_inner_index(&self) -> u16 {
191 self.delta_set_inner_index.get()
192 }
193}
194
195impl FixedSize for ValueRecord {
196 const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
197}
198
199#[cfg(feature = "experimental_traverse")]
200impl<'a> SomeRecord<'a> for ValueRecord {
201 fn traverse(self, data: FontData<'a>) -> RecordResolver<'a> {
202 RecordResolver {
203 name: "ValueRecord",
204 get_field: Box::new(move |idx, _data| match idx {
205 0usize => Some(Field::new("value_tag", self.value_tag())),
206 1usize => Some(Field::new(
207 "delta_set_outer_index",
208 self.delta_set_outer_index(),
209 )),
210 2usize => Some(Field::new(
211 "delta_set_inner_index",
212 self.delta_set_inner_index(),
213 )),
214 _ => None,
215 }),
216 data,
217 }
218 }
219}