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 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 Ok(Self { data })
34 }
35}
36
37#[derive(Clone)]
39pub struct Mvar<'a> {
40 data: FontData<'a>,
41}
42
43#[allow(clippy::needless_lifetimes)]
44impl<'a> Mvar<'a> {
45 pub const MIN_SIZE: usize = (MajorMinor::RAW_BYTE_LEN
46 + u16::RAW_BYTE_LEN
47 + u16::RAW_BYTE_LEN
48 + u16::RAW_BYTE_LEN
49 + Offset16::RAW_BYTE_LEN);
50 basic_table_impls!(impl_the_methods);
51
52 pub fn version(&self) -> MajorMinor {
55 let range = self.version_byte_range();
56 self.data.read_at(range.start).ok().unwrap()
57 }
58
59 pub fn value_record_size(&self) -> u16 {
61 let range = self.value_record_size_byte_range();
62 self.data.read_at(range.start).ok().unwrap()
63 }
64
65 pub fn value_record_count(&self) -> u16 {
67 let range = self.value_record_count_byte_range();
68 self.data.read_at(range.start).ok().unwrap()
69 }
70
71 pub fn item_variation_store_offset(&self) -> Nullable<Offset16> {
73 let range = self.item_variation_store_offset_byte_range();
74 self.data.read_at(range.start).ok().unwrap()
75 }
76
77 pub fn item_variation_store(&self) -> Option<Result<ItemVariationStore<'a>, ReadError>> {
79 let data = self.data;
80 self.item_variation_store_offset().resolve(data)
81 }
82
83 pub fn value_records(&self) -> &'a [ValueRecord] {
85 let range = self.value_records_byte_range();
86 self.data.read_array(range).ok().unwrap_or_default()
87 }
88
89 pub fn version_byte_range(&self) -> Range<usize> {
90 let start = 0;
91 let end = start + MajorMinor::RAW_BYTE_LEN;
92 start..end
93 }
94
95 pub fn _reserved_byte_range(&self) -> Range<usize> {
96 let start = self.version_byte_range().end;
97 let end = start + u16::RAW_BYTE_LEN;
98 start..end
99 }
100
101 pub fn value_record_size_byte_range(&self) -> Range<usize> {
102 let start = self._reserved_byte_range().end;
103 let end = start + u16::RAW_BYTE_LEN;
104 start..end
105 }
106
107 pub fn value_record_count_byte_range(&self) -> Range<usize> {
108 let start = self.value_record_size_byte_range().end;
109 let end = start + u16::RAW_BYTE_LEN;
110 start..end
111 }
112
113 pub fn item_variation_store_offset_byte_range(&self) -> Range<usize> {
114 let start = self.value_record_count_byte_range().end;
115 let end = start + Offset16::RAW_BYTE_LEN;
116 start..end
117 }
118
119 pub fn value_records_byte_range(&self) -> Range<usize> {
120 let value_record_count = self.value_record_count();
121 let start = self.item_variation_store_offset_byte_range().end;
122 let end = start
123 + (transforms::to_usize(value_record_count)).saturating_mul(ValueRecord::RAW_BYTE_LEN);
124 start..end
125 }
126}
127
128const _: () = assert!(FontData::default_data_long_enough(Mvar::MIN_SIZE));
129
130impl Default for Mvar<'_> {
131 fn default() -> Self {
132 Self {
133 data: FontData::default_table_data(),
134 }
135 }
136}
137
138#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, bytemuck :: AnyBitPattern)]
140#[repr(C)]
141#[repr(packed)]
142pub struct ValueRecord {
143 pub value_tag: BigEndian<Tag>,
145 pub delta_set_outer_index: BigEndian<u16>,
147 pub delta_set_inner_index: BigEndian<u16>,
149}
150
151impl ValueRecord {
152 pub fn value_tag(&self) -> Tag {
154 self.value_tag.get()
155 }
156
157 pub fn delta_set_outer_index(&self) -> u16 {
159 self.delta_set_outer_index.get()
160 }
161
162 pub fn delta_set_inner_index(&self) -> u16 {
164 self.delta_set_inner_index.get()
165 }
166}
167
168impl FixedSize for ValueRecord {
169 const RAW_BYTE_LEN: usize = Tag::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN;
170}