write_fonts/generated/
generated_avar.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Avar {
12 pub axis_segment_maps: Vec<SegmentMaps>,
14 pub axis_index_map: NullableOffsetMarker<DeltaSetIndexMap, WIDTH_32>,
16 pub var_store: NullableOffsetMarker<ItemVariationStore, WIDTH_32>,
18}
19
20impl Avar {
21 pub fn new(axis_segment_maps: Vec<SegmentMaps>) -> Self {
23 Self {
24 axis_segment_maps,
25 ..Default::default()
26 }
27 }
28}
29
30impl FontWrite for Avar {
31 #[allow(clippy::unnecessary_cast)]
32 fn write_into(&self, writer: &mut TableWriter) {
33 let version = self.compute_version() as MajorMinor;
34 version.write_into(writer);
35 (0 as u16).write_into(writer);
36 (u16::try_from(array_len(&self.axis_segment_maps)).unwrap()).write_into(writer);
37 self.axis_segment_maps.write_into(writer);
38 version
39 .compatible((2u16, 0u16))
40 .then(|| self.axis_index_map.write_into(writer));
41 version
42 .compatible((2u16, 0u16))
43 .then(|| self.var_store.write_into(writer));
44 }
45 fn table_type(&self) -> TableType {
46 TableType::TopLevel(Avar::TAG)
47 }
48}
49
50impl Validate for Avar {
51 fn validate_impl(&self, ctx: &mut ValidationCtx) {
52 ctx.in_table("Avar", |ctx| {
53 ctx.in_field("axis_segment_maps", |ctx| {
54 if self.axis_segment_maps.len() > (u16::MAX as usize) {
55 ctx.report("array exceeds max length");
56 }
57 self.axis_segment_maps.validate_impl(ctx);
58 });
59 ctx.in_field("axis_index_map", |ctx| {
60 self.axis_index_map.validate_impl(ctx);
61 });
62 ctx.in_field("var_store", |ctx| {
63 self.var_store.validate_impl(ctx);
64 });
65 })
66 }
67}
68
69impl TopLevelTable for Avar {
70 const TAG: Tag = Tag::new(b"avar");
71}
72
73impl<'a> FromObjRef<read_fonts::tables::avar::Avar<'a>> for Avar {
74 fn from_obj_ref(obj: &read_fonts::tables::avar::Avar<'a>, _: FontData) -> Self {
75 let offset_data = obj.offset_data();
76 Avar {
77 axis_segment_maps: obj
78 .axis_segment_maps()
79 .iter()
80 .filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
81 .collect(),
82 axis_index_map: obj.axis_index_map().to_owned_table(),
83 var_store: obj.var_store().to_owned_table(),
84 }
85 }
86}
87
88#[allow(clippy::needless_lifetimes)]
89impl<'a> FromTableRef<read_fonts::tables::avar::Avar<'a>> for Avar {}
90
91impl<'a> FontRead<'a> for Avar {
92 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
93 <read_fonts::tables::avar::Avar as FontRead>::read(data).map(|x| x.to_owned_table())
94 }
95}
96
97#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
99#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
100pub struct SegmentMaps {
101 pub axis_value_maps: Vec<AxisValueMap>,
103}
104
105impl SegmentMaps {
106 pub fn new(axis_value_maps: Vec<AxisValueMap>) -> Self {
108 Self { axis_value_maps }
109 }
110}
111
112impl FontWrite for SegmentMaps {
113 #[allow(clippy::unnecessary_cast)]
114 fn write_into(&self, writer: &mut TableWriter) {
115 (u16::try_from(array_len(&self.axis_value_maps)).unwrap()).write_into(writer);
116 self.axis_value_maps.write_into(writer);
117 }
118 fn table_type(&self) -> TableType {
119 TableType::Named("SegmentMaps")
120 }
121}
122
123impl Validate for SegmentMaps {
124 fn validate_impl(&self, ctx: &mut ValidationCtx) {
125 ctx.in_table("SegmentMaps", |ctx| {
126 ctx.in_field("axis_value_maps", |ctx| {
127 if self.axis_value_maps.len() > (u16::MAX as usize) {
128 ctx.report("array exceeds max length");
129 }
130 self.axis_value_maps.validate_impl(ctx);
131 });
132 })
133 }
134}
135
136impl FromObjRef<read_fonts::tables::avar::SegmentMaps<'_>> for SegmentMaps {
137 fn from_obj_ref(obj: &read_fonts::tables::avar::SegmentMaps, offset_data: FontData) -> Self {
138 SegmentMaps {
139 axis_value_maps: obj.axis_value_maps().to_owned_obj(offset_data),
140 }
141 }
142}
143
144#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
146#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
147pub struct AxisValueMap {
148 pub from_coordinate: F2Dot14,
150 pub to_coordinate: F2Dot14,
152}
153
154impl AxisValueMap {
155 pub fn new(from_coordinate: F2Dot14, to_coordinate: F2Dot14) -> Self {
157 Self {
158 from_coordinate,
159 to_coordinate,
160 }
161 }
162}
163
164impl FontWrite for AxisValueMap {
165 fn write_into(&self, writer: &mut TableWriter) {
166 self.from_coordinate.write_into(writer);
167 self.to_coordinate.write_into(writer);
168 }
169 fn table_type(&self) -> TableType {
170 TableType::Named("AxisValueMap")
171 }
172}
173
174impl Validate for AxisValueMap {
175 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
176}
177
178impl FromObjRef<read_fonts::tables::avar::AxisValueMap> for AxisValueMap {
179 fn from_obj_ref(obj: &read_fonts::tables::avar::AxisValueMap, _: FontData) -> Self {
180 AxisValueMap {
181 from_coordinate: obj.from_coordinate(),
182 to_coordinate: obj.to_coordinate(),
183 }
184 }
185}