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.offset_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 ReadArgs for Mvar<'_> {
24 type Args = ();
25}
26
27impl<'a> FontRead<'a> for Mvar<'a> {
28 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
29 #[allow(clippy::absurd_extreme_comparisons)]
30 if data.len() < Self::MIN_SIZE {
31 return Err(ReadError::OutOfBounds);
32 }
33 let Some(data) = TableDataRef::new(data.as_bytes()) else {
34 return Err(ReadError::OutOfBounds);
35 };
36 Ok(Self { data })
37 }
38}
39
40#[derive(Clone, Copy, bytemuck :: AnyBitPattern)]
42#[repr(C, packed)]
43#[doc(hidden)]
44pub struct MvarFixedHeader {
45 pub version: BigEndian<MajorMinor>,
46 pub _reserved: BigEndian<u16>,
47 pub value_record_size: BigEndian<u16>,
48 pub value_record_count: BigEndian<u16>,
49 pub item_variation_store_offset: BigEndian<Nullable<Offset16>>,
50}
51
52#[allow(clippy::absurd_extreme_comparisons)]
53const _: () = assert!(std::mem::size_of::<MvarFixedHeader>() <= Mvar::MIN_SIZE);
54
55#[derive(Clone)]
57pub struct Mvar<'a> {
58 data: TableDataRef<'a, MvarFixedHeader>,
59}
60
61#[allow(clippy::needless_lifetimes)]
62impl<'a> Mvar<'a> {
63 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
64 + u16::RAW_BYTE_LEN
65 + u16::RAW_BYTE_LEN
66 + u16::RAW_BYTE_LEN
67 + Offset16::RAW_BYTE_LEN);
68 basic_table_impls!(impl_the_methods);
69
70 pub fn version(&self) -> MajorMinor {
73 self.data.header().version.get()
74 }
75
76 pub fn value_record_size(&self) -> u16 {
78 self.data.header().value_record_size.get()
79 }
80
81 pub fn value_record_count(&self) -> u16 {
83 self.data.header().value_record_count.get()
84 }
85
86 pub fn item_variation_store_offset(&self) -> Nullable<Offset16> {
88 self.data.header().item_variation_store_offset.get()
89 }
90
91 pub fn item_variation_store(&self) -> Option<Result<ItemVariationStore<'a>, ReadError>> {
93 let data = self.offset_data();
94 self.item_variation_store_offset().resolve(data)
95 }
96
97 pub fn value_records(&self) -> &'a [ValueRecord] {
99 let range = self.value_records_byte_range();
100 self.offset_data()
101 .read_array(range)
102 .ok()
103 .unwrap_or_default()
104 }
105
106 pub fn version_byte_range(&self) -> Range<usize> {
107 let start = 0;
108 let end = start + MajorMinor::RAW_BYTE_LEN;
109 start..end
110 }
111
112 pub fn _reserved_byte_range(&self) -> Range<usize> {
113 let start = self.version_byte_range().end;
114 let end = start + u16::RAW_BYTE_LEN;
115 start..end
116 }
117
118 pub fn value_record_size_byte_range(&self) -> Range<usize> {
119 let start = self._reserved_byte_range().end;
120 let end = start + u16::RAW_BYTE_LEN;
121 start..end
122 }
123
124 pub fn value_record_count_byte_range(&self) -> Range<usize> {
125 let start = self.value_record_size_byte_range().end;
126 let end = start + u16::RAW_BYTE_LEN;
127 start..end
128 }
129
130 pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
131 let start = self.value_record_count_byte_range().end;
132 let end = start + Offset16::RAW_BYTE_LEN;
133 start..end
134 }
135
136 pub fn value_records_byte_range(&self) -> Range<usize> {
137 let value_record_count = self.value_record_count();
138 let start = self.item_variation_store_offset_byte_range().end;
139 let end = start
140 + (transforms::to_usize(value_record_count)).saturating_mul(ValueRecord::RAW_BYTE_LEN);
141 start..end
142 }
143}
144
145const _: () = assert!(FontData::default_data_long_enough(Mvar::MIN_SIZE));
146
147impl Default for Mvar<'_> {
148 fn default() -> Self {
149 Self {
150 data: TableDataRef::new(FontData::default_table_data().as_bytes())
151 .unwrap_or_else(|| unreachable!("the default data covers MIN_SIZE")),
152 }
153 }
154}
155
156#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
158#[repr(C)]
159#[repr(packed)]
160pub struct ValueRecord {
161 pub value_tag: BigEndian<Tag>,
163 pub delta_set_outer_index: BigEndian<u16>,
165 pub delta_set_inner_index: BigEndian<u16>,
167}
168
169impl ValueRecord {
170 pub fn value_tag(&self) -> Tag {
172 self.value_tag.get()
173 }
174
175 pub fn delta_set_outer_index(&self) -> u16 {
177 self.delta_set_outer_index.get()
178 }
179
180 pub fn delta_set_inner_index(&self) -> u16 {
182 self.delta_set_inner_index.get()
183 }
184}
185
186impl FixedSize for ValueRecord {
187 const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
188}