/src/fontations/write-fonts/generated/generated_stat.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 | | pub use read_fonts::tables::stat::AxisValueTableFlags; |
9 | | |
10 | | /// [STAT](https://docs.microsoft.com/en-us/typography/opentype/spec/stat) (Style Attributes Table) |
11 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
12 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
13 | | pub struct Stat { |
14 | | /// Offset in bytes from the beginning of the STAT table to the |
15 | | /// start of the design axes array. If designAxisCount is zero, set |
16 | | /// to zero; if designAxisCount is greater than zero, must be |
17 | | /// greater than zero. |
18 | | pub design_axes: OffsetMarker<Vec<AxisRecord>, WIDTH_32>, |
19 | | /// Offset in bytes from the beginning of the STAT table to the |
20 | | /// start of the design axes value offsets array. If axisValueCount |
21 | | /// is zero, set to zero; if axisValueCount is greater than zero, |
22 | | /// must be greater than zero. |
23 | | pub offset_to_axis_values: NullableOffsetMarker<Vec<OffsetMarker<AxisValue>>, WIDTH_32>, |
24 | | /// Name ID used as fallback when projection of names into a |
25 | | /// particular font model produces a subfamily name containing only |
26 | | /// elidable elements. |
27 | | pub elided_fallback_name_id: Option<NameId>, |
28 | | } |
29 | | |
30 | | impl FontWrite for Stat { |
31 | | #[allow(clippy::unnecessary_cast)] |
32 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
33 | 0 | let version = MajorMinor::VERSION_1_2 as MajorMinor; |
34 | 0 | version.write_into(writer); |
35 | 0 | (8 as u16).write_into(writer); |
36 | 0 | (u16::try_from(array_len(&self.design_axes)).unwrap()).write_into(writer); |
37 | 0 | self.design_axes.write_into(writer); |
38 | 0 | (u16::try_from(array_len(&self.offset_to_axis_values)).unwrap()).write_into(writer); |
39 | 0 | self.offset_to_axis_values.write_into(writer); |
40 | 0 | version.compatible((1u16, 1u16)).then(|| { |
41 | 0 | self.elided_fallback_name_id |
42 | 0 | .as_ref() |
43 | 0 | .expect("missing conditional field should have failed validation") |
44 | 0 | .write_into(writer) |
45 | 0 | }); |
46 | 0 | } |
47 | 0 | fn table_type(&self) -> TableType { |
48 | 0 | TableType::TopLevel(Stat::TAG) |
49 | 0 | } |
50 | | } |
51 | | |
52 | | impl Validate for Stat { |
53 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
54 | 0 | ctx.in_table("Stat", |ctx| { |
55 | 0 | let version: MajorMinor = MajorMinor::VERSION_1_2; |
56 | 0 | ctx.in_field("design_axes", |ctx| { |
57 | 0 | self.design_axes.validate_impl(ctx); |
58 | 0 | }); |
59 | 0 | ctx.in_field("offset_to_axis_values", |ctx| { |
60 | 0 | self.offset_to_axis_values.validate_impl(ctx); |
61 | 0 | }); |
62 | 0 | ctx.in_field("elided_fallback_name_id", |ctx| { |
63 | 0 | if version.compatible((1u16, 1u16)) && self.elided_fallback_name_id.is_none() { |
64 | 0 | ctx.report(format!("field must be present for version {version}")); |
65 | 0 | } |
66 | 0 | }); |
67 | 0 | }) |
68 | 0 | } |
69 | | } |
70 | | |
71 | | impl TopLevelTable for Stat { |
72 | | const TAG: Tag = Tag::new(b"STAT"); |
73 | | } |
74 | | |
75 | | impl<'a> FromObjRef<read_fonts::tables::stat::Stat<'a>> for Stat { |
76 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::Stat<'a>, _: FontData) -> Self { |
77 | 0 | let offset_data = obj.offset_data(); |
78 | 0 | Stat { |
79 | 0 | design_axes: obj.design_axes().to_owned_obj(offset_data), |
80 | 0 | offset_to_axis_values: convert_axis_value_offsets(obj.offset_to_axis_values()), |
81 | 0 | elided_fallback_name_id: obj.elided_fallback_name_id(), |
82 | 0 | } |
83 | 0 | } |
84 | | } |
85 | | |
86 | | #[allow(clippy::needless_lifetimes)] |
87 | | impl<'a> FromTableRef<read_fonts::tables::stat::Stat<'a>> for Stat {} |
88 | | |
89 | | impl ReadArgs for Stat { |
90 | | type Args = (); |
91 | | } |
92 | | |
93 | | impl<'a> FontRead<'a> for Stat { |
94 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
95 | 0 | <read_fonts::tables::stat::Stat as FontRead>::read(data).map(|x| x.to_owned_table()) |
96 | 0 | } |
97 | | } |
98 | | |
99 | | /// [Axis Records](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-records) |
100 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
101 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
102 | | pub struct AxisRecord { |
103 | | /// A tag identifying the axis of design variation. |
104 | | pub axis_tag: Tag, |
105 | | /// The name ID for entries in the 'name' table that provide a |
106 | | /// display string for this axis. |
107 | | pub axis_name_id: NameId, |
108 | | /// A value that applications can use to determine primary sorting |
109 | | /// of face names, or for ordering of labels when composing family |
110 | | /// or face names. |
111 | | pub axis_ordering: u16, |
112 | | } |
113 | | |
114 | | impl AxisRecord { |
115 | | /// Construct a new `AxisRecord` |
116 | 0 | pub fn new(axis_tag: Tag, axis_name_id: NameId, axis_ordering: u16) -> Self { |
117 | 0 | Self { |
118 | 0 | axis_tag, |
119 | 0 | axis_name_id, |
120 | 0 | axis_ordering, |
121 | 0 | } |
122 | 0 | } |
123 | | } |
124 | | |
125 | | impl FontWrite for AxisRecord { |
126 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
127 | 0 | self.axis_tag.write_into(writer); |
128 | 0 | self.axis_name_id.write_into(writer); |
129 | 0 | self.axis_ordering.write_into(writer); |
130 | 0 | } |
131 | 0 | fn table_type(&self) -> TableType { |
132 | 0 | TableType::Named("AxisRecord") |
133 | 0 | } |
134 | | } |
135 | | |
136 | | impl Validate for AxisRecord { |
137 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
138 | | } |
139 | | |
140 | | impl FromObjRef<read_fonts::tables::stat::AxisRecord> for AxisRecord { |
141 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::AxisRecord, _: FontData) -> Self { |
142 | 0 | AxisRecord { |
143 | 0 | axis_tag: obj.axis_tag(), |
144 | 0 | axis_name_id: obj.axis_name_id(), |
145 | 0 | axis_ordering: obj.axis_ordering(), |
146 | 0 | } |
147 | 0 | } |
148 | | } |
149 | | |
150 | | /// An array of [AxisValue] tables. |
151 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
152 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
153 | | pub struct AxisValueArray { |
154 | | /// Array of offsets to axis value tables, in bytes from the start |
155 | | /// of the axis value offsets array. |
156 | | pub axis_values: Vec<OffsetMarker<AxisValue>>, |
157 | | } |
158 | | |
159 | | impl AxisValueArray { |
160 | | /// Construct a new `AxisValueArray` |
161 | 0 | pub fn new(axis_values: Vec<AxisValue>) -> Self { |
162 | 0 | Self { |
163 | 0 | axis_values: axis_values.into_iter().map(Into::into).collect(), |
164 | 0 | } |
165 | 0 | } |
166 | | } |
167 | | |
168 | | impl FontWrite for AxisValueArray { |
169 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
170 | 0 | self.axis_values.write_into(writer); |
171 | 0 | } |
172 | 0 | fn table_type(&self) -> TableType { |
173 | 0 | TableType::Named("AxisValueArray") |
174 | 0 | } |
175 | | } |
176 | | |
177 | | impl Validate for AxisValueArray { |
178 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
179 | 0 | ctx.in_table("AxisValueArray", |ctx| { |
180 | 0 | ctx.in_field("axis_values", |ctx| { |
181 | 0 | if self.axis_values.len() > to_usize(u16::MAX) { |
182 | 0 | ctx.report("array exceeds max length"); |
183 | 0 | } |
184 | 0 | self.axis_values.validate_impl(ctx); |
185 | 0 | }); |
186 | 0 | }) |
187 | 0 | } |
188 | | } |
189 | | |
190 | | impl<'a> FromObjRef<read_fonts::tables::stat::AxisValueArray<'a>> for AxisValueArray { |
191 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::AxisValueArray<'a>, _: FontData) -> Self { |
192 | 0 | AxisValueArray { |
193 | 0 | axis_values: obj.axis_values().to_owned_table(), |
194 | 0 | } |
195 | 0 | } |
196 | | } |
197 | | |
198 | | #[allow(clippy::needless_lifetimes)] |
199 | | impl<'a> FromTableRef<read_fonts::tables::stat::AxisValueArray<'a>> for AxisValueArray {} |
200 | | |
201 | | /// [Axis Value Tables](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-tables) |
202 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
203 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
204 | | pub enum AxisValue { |
205 | | Format1(AxisValueFormat1), |
206 | | Format2(AxisValueFormat2), |
207 | | Format3(AxisValueFormat3), |
208 | | Format4(AxisValueFormat4), |
209 | | } |
210 | | |
211 | | impl AxisValue { |
212 | | /// Construct a new `AxisValueFormat1` subtable |
213 | 0 | pub fn format_1( |
214 | 0 | axis_index: u16, |
215 | 0 | flags: AxisValueTableFlags, |
216 | 0 | value_name_id: NameId, |
217 | 0 | value: Fixed, |
218 | 0 | ) -> Self { |
219 | 0 | Self::Format1(AxisValueFormat1::new( |
220 | 0 | axis_index, |
221 | 0 | flags, |
222 | 0 | value_name_id, |
223 | 0 | value, |
224 | 0 | )) |
225 | 0 | } |
226 | | |
227 | | /// Construct a new `AxisValueFormat2` subtable |
228 | 0 | pub fn format_2( |
229 | 0 | axis_index: u16, |
230 | 0 | flags: AxisValueTableFlags, |
231 | 0 | value_name_id: NameId, |
232 | 0 | nominal_value: Fixed, |
233 | 0 | range_min_value: Fixed, |
234 | 0 | range_max_value: Fixed, |
235 | 0 | ) -> Self { |
236 | 0 | Self::Format2(AxisValueFormat2::new( |
237 | 0 | axis_index, |
238 | 0 | flags, |
239 | 0 | value_name_id, |
240 | 0 | nominal_value, |
241 | 0 | range_min_value, |
242 | 0 | range_max_value, |
243 | 0 | )) |
244 | 0 | } |
245 | | |
246 | | /// Construct a new `AxisValueFormat3` subtable |
247 | 0 | pub fn format_3( |
248 | 0 | axis_index: u16, |
249 | 0 | flags: AxisValueTableFlags, |
250 | 0 | value_name_id: NameId, |
251 | 0 | value: Fixed, |
252 | 0 | linked_value: Fixed, |
253 | 0 | ) -> Self { |
254 | 0 | Self::Format3(AxisValueFormat3::new( |
255 | 0 | axis_index, |
256 | 0 | flags, |
257 | 0 | value_name_id, |
258 | 0 | value, |
259 | 0 | linked_value, |
260 | 0 | )) |
261 | 0 | } |
262 | | |
263 | | /// Construct a new `AxisValueFormat4` subtable |
264 | 0 | pub fn format_4( |
265 | 0 | flags: AxisValueTableFlags, |
266 | 0 | value_name_id: NameId, |
267 | 0 | axis_values: Vec<AxisValueRecord>, |
268 | 0 | ) -> Self { |
269 | 0 | Self::Format4(AxisValueFormat4::new(flags, value_name_id, axis_values)) |
270 | 0 | } |
271 | | } |
272 | | |
273 | | impl Default for AxisValue { |
274 | 0 | fn default() -> Self { |
275 | 0 | Self::Format1(Default::default()) |
276 | 0 | } |
277 | | } |
278 | | |
279 | | impl FontWrite for AxisValue { |
280 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
281 | 0 | match self { |
282 | 0 | Self::Format1(item) => item.write_into(writer), |
283 | 0 | Self::Format2(item) => item.write_into(writer), |
284 | 0 | Self::Format3(item) => item.write_into(writer), |
285 | 0 | Self::Format4(item) => item.write_into(writer), |
286 | | } |
287 | 0 | } |
288 | 0 | fn table_type(&self) -> TableType { |
289 | 0 | match self { |
290 | 0 | Self::Format1(item) => item.table_type(), |
291 | 0 | Self::Format2(item) => item.table_type(), |
292 | 0 | Self::Format3(item) => item.table_type(), |
293 | 0 | Self::Format4(item) => item.table_type(), |
294 | | } |
295 | 0 | } |
296 | | } |
297 | | |
298 | | impl Validate for AxisValue { |
299 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
300 | 0 | match self { |
301 | 0 | Self::Format1(item) => item.validate_impl(ctx), |
302 | 0 | Self::Format2(item) => item.validate_impl(ctx), |
303 | 0 | Self::Format3(item) => item.validate_impl(ctx), |
304 | 0 | Self::Format4(item) => item.validate_impl(ctx), |
305 | | } |
306 | 0 | } |
307 | | } |
308 | | |
309 | | impl FromObjRef<read_fonts::tables::stat::AxisValue<'_>> for AxisValue { |
310 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::AxisValue, _: FontData) -> Self { |
311 | | use read_fonts::tables::stat::AxisValue as ObjRefType; |
312 | 0 | match obj { |
313 | 0 | ObjRefType::Format1(item) => AxisValue::Format1(item.to_owned_table()), |
314 | 0 | ObjRefType::Format2(item) => AxisValue::Format2(item.to_owned_table()), |
315 | 0 | ObjRefType::Format3(item) => AxisValue::Format3(item.to_owned_table()), |
316 | 0 | ObjRefType::Format4(item) => AxisValue::Format4(item.to_owned_table()), |
317 | | } |
318 | 0 | } |
319 | | } |
320 | | |
321 | | impl FromTableRef<read_fonts::tables::stat::AxisValue<'_>> for AxisValue {} |
322 | | |
323 | | impl ReadArgs for AxisValue { |
324 | | type Args = (); |
325 | | } |
326 | | |
327 | | impl<'a> FontRead<'a> for AxisValue { |
328 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
329 | 0 | <read_fonts::tables::stat::AxisValue as FontRead>::read(data).map(|x| x.to_owned_table()) |
330 | 0 | } |
331 | | } |
332 | | |
333 | | impl From<AxisValueFormat1> for AxisValue { |
334 | 0 | fn from(src: AxisValueFormat1) -> AxisValue { |
335 | 0 | AxisValue::Format1(src) |
336 | 0 | } |
337 | | } |
338 | | |
339 | | impl From<AxisValueFormat2> for AxisValue { |
340 | 0 | fn from(src: AxisValueFormat2) -> AxisValue { |
341 | 0 | AxisValue::Format2(src) |
342 | 0 | } |
343 | | } |
344 | | |
345 | | impl From<AxisValueFormat3> for AxisValue { |
346 | 0 | fn from(src: AxisValueFormat3) -> AxisValue { |
347 | 0 | AxisValue::Format3(src) |
348 | 0 | } |
349 | | } |
350 | | |
351 | | impl From<AxisValueFormat4> for AxisValue { |
352 | 0 | fn from(src: AxisValueFormat4) -> AxisValue { |
353 | 0 | AxisValue::Format4(src) |
354 | 0 | } |
355 | | } |
356 | | |
357 | | /// [Axis value table format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-1) |
358 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
359 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
360 | | pub struct AxisValueFormat1 { |
361 | | /// Zero-base index into the axis record array identifying the axis |
362 | | /// of design variation to which the axis value table applies. Must |
363 | | /// be less than designAxisCount. |
364 | | pub axis_index: u16, |
365 | | /// Flags — see below for details. |
366 | | pub flags: AxisValueTableFlags, |
367 | | /// The name ID for entries in the 'name' table that provide a |
368 | | /// display string for this attribute value. |
369 | | pub value_name_id: NameId, |
370 | | /// A numeric value for this attribute value. |
371 | | pub value: Fixed, |
372 | | } |
373 | | |
374 | | impl AxisValueFormat1 { |
375 | | /// Construct a new `AxisValueFormat1` |
376 | 0 | pub fn new( |
377 | 0 | axis_index: u16, |
378 | 0 | flags: AxisValueTableFlags, |
379 | 0 | value_name_id: NameId, |
380 | 0 | value: Fixed, |
381 | 0 | ) -> Self { |
382 | 0 | Self { |
383 | 0 | axis_index, |
384 | 0 | flags, |
385 | 0 | value_name_id, |
386 | 0 | value, |
387 | 0 | } |
388 | 0 | } |
389 | | } |
390 | | |
391 | | impl FontWrite for AxisValueFormat1 { |
392 | | #[allow(clippy::unnecessary_cast)] |
393 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
394 | 0 | (1 as u16).write_into(writer); |
395 | 0 | self.axis_index.write_into(writer); |
396 | 0 | self.flags.write_into(writer); |
397 | 0 | self.value_name_id.write_into(writer); |
398 | 0 | self.value.write_into(writer); |
399 | 0 | } |
400 | 0 | fn table_type(&self) -> TableType { |
401 | 0 | TableType::Named("AxisValueFormat1") |
402 | 0 | } |
403 | | } |
404 | | |
405 | | impl Validate for AxisValueFormat1 { |
406 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
407 | | } |
408 | | |
409 | | impl<'a> FromObjRef<read_fonts::tables::stat::AxisValueFormat1<'a>> for AxisValueFormat1 { |
410 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::AxisValueFormat1<'a>, _: FontData) -> Self { |
411 | 0 | AxisValueFormat1 { |
412 | 0 | axis_index: obj.axis_index(), |
413 | 0 | flags: obj.flags(), |
414 | 0 | value_name_id: obj.value_name_id(), |
415 | 0 | value: obj.value(), |
416 | 0 | } |
417 | 0 | } |
418 | | } |
419 | | |
420 | | #[allow(clippy::needless_lifetimes)] |
421 | | impl<'a> FromTableRef<read_fonts::tables::stat::AxisValueFormat1<'a>> for AxisValueFormat1 {} |
422 | | |
423 | | impl ReadArgs for AxisValueFormat1 { |
424 | | type Args = (); |
425 | | } |
426 | | |
427 | | impl<'a> FontRead<'a> for AxisValueFormat1 { |
428 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
429 | 0 | <read_fonts::tables::stat::AxisValueFormat1 as FontRead>::read(data) |
430 | 0 | .map(|x| x.to_owned_table()) |
431 | 0 | } |
432 | | } |
433 | | |
434 | | /// [Axis value table format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-2) |
435 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
436 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
437 | | pub struct AxisValueFormat2 { |
438 | | /// Zero-base index into the axis record array identifying the axis |
439 | | /// of design variation to which the axis value table applies. Must |
440 | | /// be less than designAxisCount. |
441 | | pub axis_index: u16, |
442 | | /// Flags — see below for details. |
443 | | pub flags: AxisValueTableFlags, |
444 | | /// The name ID for entries in the 'name' table that provide a |
445 | | /// display string for this attribute value. |
446 | | pub value_name_id: NameId, |
447 | | /// A nominal numeric value for this attribute value. |
448 | | pub nominal_value: Fixed, |
449 | | /// The minimum value for a range associated with the specified |
450 | | /// name ID. |
451 | | pub range_min_value: Fixed, |
452 | | /// The maximum value for a range associated with the specified |
453 | | /// name ID. |
454 | | pub range_max_value: Fixed, |
455 | | } |
456 | | |
457 | | impl AxisValueFormat2 { |
458 | | /// Construct a new `AxisValueFormat2` |
459 | 0 | pub fn new( |
460 | 0 | axis_index: u16, |
461 | 0 | flags: AxisValueTableFlags, |
462 | 0 | value_name_id: NameId, |
463 | 0 | nominal_value: Fixed, |
464 | 0 | range_min_value: Fixed, |
465 | 0 | range_max_value: Fixed, |
466 | 0 | ) -> Self { |
467 | 0 | Self { |
468 | 0 | axis_index, |
469 | 0 | flags, |
470 | 0 | value_name_id, |
471 | 0 | nominal_value, |
472 | 0 | range_min_value, |
473 | 0 | range_max_value, |
474 | 0 | } |
475 | 0 | } |
476 | | } |
477 | | |
478 | | impl FontWrite for AxisValueFormat2 { |
479 | | #[allow(clippy::unnecessary_cast)] |
480 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
481 | 0 | (2 as u16).write_into(writer); |
482 | 0 | self.axis_index.write_into(writer); |
483 | 0 | self.flags.write_into(writer); |
484 | 0 | self.value_name_id.write_into(writer); |
485 | 0 | self.nominal_value.write_into(writer); |
486 | 0 | self.range_min_value.write_into(writer); |
487 | 0 | self.range_max_value.write_into(writer); |
488 | 0 | } |
489 | 0 | fn table_type(&self) -> TableType { |
490 | 0 | TableType::Named("AxisValueFormat2") |
491 | 0 | } |
492 | | } |
493 | | |
494 | | impl Validate for AxisValueFormat2 { |
495 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
496 | | } |
497 | | |
498 | | impl<'a> FromObjRef<read_fonts::tables::stat::AxisValueFormat2<'a>> for AxisValueFormat2 { |
499 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::AxisValueFormat2<'a>, _: FontData) -> Self { |
500 | 0 | AxisValueFormat2 { |
501 | 0 | axis_index: obj.axis_index(), |
502 | 0 | flags: obj.flags(), |
503 | 0 | value_name_id: obj.value_name_id(), |
504 | 0 | nominal_value: obj.nominal_value(), |
505 | 0 | range_min_value: obj.range_min_value(), |
506 | 0 | range_max_value: obj.range_max_value(), |
507 | 0 | } |
508 | 0 | } |
509 | | } |
510 | | |
511 | | #[allow(clippy::needless_lifetimes)] |
512 | | impl<'a> FromTableRef<read_fonts::tables::stat::AxisValueFormat2<'a>> for AxisValueFormat2 {} |
513 | | |
514 | | impl ReadArgs for AxisValueFormat2 { |
515 | | type Args = (); |
516 | | } |
517 | | |
518 | | impl<'a> FontRead<'a> for AxisValueFormat2 { |
519 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
520 | 0 | <read_fonts::tables::stat::AxisValueFormat2 as FontRead>::read(data) |
521 | 0 | .map(|x| x.to_owned_table()) |
522 | 0 | } |
523 | | } |
524 | | |
525 | | /// [Axis value table format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-3) |
526 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
527 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
528 | | pub struct AxisValueFormat3 { |
529 | | /// Zero-base index into the axis record array identifying the axis |
530 | | /// of design variation to which the axis value table applies. Must |
531 | | /// be less than designAxisCount. |
532 | | pub axis_index: u16, |
533 | | /// Flags — see below for details. |
534 | | pub flags: AxisValueTableFlags, |
535 | | /// The name ID for entries in the 'name' table that provide a |
536 | | /// display string for this attribute value. |
537 | | pub value_name_id: NameId, |
538 | | /// A numeric value for this attribute value. |
539 | | pub value: Fixed, |
540 | | /// The numeric value for a style-linked mapping from this value. |
541 | | pub linked_value: Fixed, |
542 | | } |
543 | | |
544 | | impl AxisValueFormat3 { |
545 | | /// Construct a new `AxisValueFormat3` |
546 | 0 | pub fn new( |
547 | 0 | axis_index: u16, |
548 | 0 | flags: AxisValueTableFlags, |
549 | 0 | value_name_id: NameId, |
550 | 0 | value: Fixed, |
551 | 0 | linked_value: Fixed, |
552 | 0 | ) -> Self { |
553 | 0 | Self { |
554 | 0 | axis_index, |
555 | 0 | flags, |
556 | 0 | value_name_id, |
557 | 0 | value, |
558 | 0 | linked_value, |
559 | 0 | } |
560 | 0 | } |
561 | | } |
562 | | |
563 | | impl FontWrite for AxisValueFormat3 { |
564 | | #[allow(clippy::unnecessary_cast)] |
565 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
566 | 0 | (3 as u16).write_into(writer); |
567 | 0 | self.axis_index.write_into(writer); |
568 | 0 | self.flags.write_into(writer); |
569 | 0 | self.value_name_id.write_into(writer); |
570 | 0 | self.value.write_into(writer); |
571 | 0 | self.linked_value.write_into(writer); |
572 | 0 | } |
573 | 0 | fn table_type(&self) -> TableType { |
574 | 0 | TableType::Named("AxisValueFormat3") |
575 | 0 | } |
576 | | } |
577 | | |
578 | | impl Validate for AxisValueFormat3 { |
579 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
580 | | } |
581 | | |
582 | | impl<'a> FromObjRef<read_fonts::tables::stat::AxisValueFormat3<'a>> for AxisValueFormat3 { |
583 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::AxisValueFormat3<'a>, _: FontData) -> Self { |
584 | 0 | AxisValueFormat3 { |
585 | 0 | axis_index: obj.axis_index(), |
586 | 0 | flags: obj.flags(), |
587 | 0 | value_name_id: obj.value_name_id(), |
588 | 0 | value: obj.value(), |
589 | 0 | linked_value: obj.linked_value(), |
590 | 0 | } |
591 | 0 | } |
592 | | } |
593 | | |
594 | | #[allow(clippy::needless_lifetimes)] |
595 | | impl<'a> FromTableRef<read_fonts::tables::stat::AxisValueFormat3<'a>> for AxisValueFormat3 {} |
596 | | |
597 | | impl ReadArgs for AxisValueFormat3 { |
598 | | type Args = (); |
599 | | } |
600 | | |
601 | | impl<'a> FontRead<'a> for AxisValueFormat3 { |
602 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
603 | 0 | <read_fonts::tables::stat::AxisValueFormat3 as FontRead>::read(data) |
604 | 0 | .map(|x| x.to_owned_table()) |
605 | 0 | } |
606 | | } |
607 | | |
608 | | /// [Axis value table format 4](https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-4) |
609 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
610 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
611 | | pub struct AxisValueFormat4 { |
612 | | /// Flags — see below for details. |
613 | | pub flags: AxisValueTableFlags, |
614 | | /// The name ID for entries in the 'name' table that provide a |
615 | | /// display string for this combination of axis values. |
616 | | pub value_name_id: NameId, |
617 | | /// Array of AxisValue records that provide the combination of axis |
618 | | /// values, one for each contributing axis. |
619 | | pub axis_values: Vec<AxisValueRecord>, |
620 | | } |
621 | | |
622 | | impl AxisValueFormat4 { |
623 | | /// Construct a new `AxisValueFormat4` |
624 | 0 | pub fn new( |
625 | 0 | flags: AxisValueTableFlags, |
626 | 0 | value_name_id: NameId, |
627 | 0 | axis_values: Vec<AxisValueRecord>, |
628 | 0 | ) -> Self { |
629 | 0 | Self { |
630 | 0 | flags, |
631 | 0 | value_name_id, |
632 | 0 | axis_values, |
633 | 0 | } |
634 | 0 | } |
635 | | } |
636 | | |
637 | | impl FontWrite for AxisValueFormat4 { |
638 | | #[allow(clippy::unnecessary_cast)] |
639 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
640 | 0 | (4 as u16).write_into(writer); |
641 | 0 | (u16::try_from(array_len(&self.axis_values)).unwrap()).write_into(writer); |
642 | 0 | self.flags.write_into(writer); |
643 | 0 | self.value_name_id.write_into(writer); |
644 | 0 | self.axis_values.write_into(writer); |
645 | 0 | } |
646 | 0 | fn table_type(&self) -> TableType { |
647 | 0 | TableType::Named("AxisValueFormat4") |
648 | 0 | } |
649 | | } |
650 | | |
651 | | impl Validate for AxisValueFormat4 { |
652 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
653 | 0 | ctx.in_table("AxisValueFormat4", |ctx| { |
654 | 0 | ctx.in_field("axis_values", |ctx| { |
655 | 0 | if self.axis_values.len() > to_usize(u16::MAX) { |
656 | 0 | ctx.report("array exceeds max length"); |
657 | 0 | } |
658 | 0 | self.axis_values.validate_impl(ctx); |
659 | 0 | }); |
660 | 0 | }) |
661 | 0 | } |
662 | | } |
663 | | |
664 | | impl<'a> FromObjRef<read_fonts::tables::stat::AxisValueFormat4<'a>> for AxisValueFormat4 { |
665 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::AxisValueFormat4<'a>, _: FontData) -> Self { |
666 | 0 | let offset_data = obj.offset_data(); |
667 | 0 | AxisValueFormat4 { |
668 | 0 | flags: obj.flags(), |
669 | 0 | value_name_id: obj.value_name_id(), |
670 | 0 | axis_values: obj.axis_values().to_owned_obj(offset_data), |
671 | 0 | } |
672 | 0 | } |
673 | | } |
674 | | |
675 | | #[allow(clippy::needless_lifetimes)] |
676 | | impl<'a> FromTableRef<read_fonts::tables::stat::AxisValueFormat4<'a>> for AxisValueFormat4 {} |
677 | | |
678 | | impl ReadArgs for AxisValueFormat4 { |
679 | | type Args = (); |
680 | | } |
681 | | |
682 | | impl<'a> FontRead<'a> for AxisValueFormat4 { |
683 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
684 | 0 | <read_fonts::tables::stat::AxisValueFormat4 as FontRead>::read(data) |
685 | 0 | .map(|x| x.to_owned_table()) |
686 | 0 | } |
687 | | } |
688 | | |
689 | | /// Part of [AxisValueFormat4] |
690 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
691 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
692 | | pub struct AxisValueRecord { |
693 | | /// Zero-base index into the axis record array identifying the axis |
694 | | /// to which this value applies. Must be less than designAxisCount. |
695 | | pub axis_index: u16, |
696 | | /// A numeric value for this attribute value. |
697 | | pub value: Fixed, |
698 | | } |
699 | | |
700 | | impl AxisValueRecord { |
701 | | /// Construct a new `AxisValueRecord` |
702 | 0 | pub fn new(axis_index: u16, value: Fixed) -> Self { |
703 | 0 | Self { axis_index, value } |
704 | 0 | } |
705 | | } |
706 | | |
707 | | impl FontWrite for AxisValueRecord { |
708 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
709 | 0 | self.axis_index.write_into(writer); |
710 | 0 | self.value.write_into(writer); |
711 | 0 | } |
712 | 0 | fn table_type(&self) -> TableType { |
713 | 0 | TableType::Named("AxisValueRecord") |
714 | 0 | } |
715 | | } |
716 | | |
717 | | impl Validate for AxisValueRecord { |
718 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
719 | | } |
720 | | |
721 | | impl FromObjRef<read_fonts::tables::stat::AxisValueRecord> for AxisValueRecord { |
722 | 0 | fn from_obj_ref(obj: &read_fonts::tables::stat::AxisValueRecord, _: FontData) -> Self { |
723 | 0 | AxisValueRecord { |
724 | 0 | axis_index: obj.axis_index(), |
725 | 0 | value: obj.value(), |
726 | 0 | } |
727 | 0 | } |
728 | | } |
729 | | |
730 | | impl FontWrite for AxisValueTableFlags { |
731 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
732 | 0 | writer.write_slice(&self.bits().to_be_bytes()) |
733 | 0 | } |
734 | | } |