/src/fontations/write-fonts/generated/generated_mvar.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 | | /// The [MVAR (Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/mvar) table |
9 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
10 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
11 | | pub struct Mvar { |
12 | | /// Major version number of the horizontal metrics variations table — set to 1. |
13 | | /// Minor version number of the horizontal metrics variations table — set to 0. |
14 | | pub version: MajorMinor, |
15 | | /// The size in bytes of each value record — must be greater than zero. |
16 | | pub value_record_size: u16, |
17 | | /// The number of value records — may be zero. |
18 | | pub value_record_count: u16, |
19 | | /// Offset in bytes from the start of this table to the item variation store table. If valueRecordCount is zero, set to zero; if valueRecordCount is greater than zero, must be greater than zero. |
20 | | pub item_variation_store: NullableOffsetMarker<ItemVariationStore>, |
21 | | /// Array of value records that identify target items and the associated delta-set index for each. The valueTag records must be in binary order of their valueTag field. |
22 | | pub value_records: Vec<ValueRecord>, |
23 | | } |
24 | | |
25 | | impl FontWrite for Mvar { |
26 | | #[allow(clippy::unnecessary_cast)] |
27 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
28 | 0 | self.version.write_into(writer); |
29 | 0 | (0 as u16).write_into(writer); |
30 | 0 | self.value_record_size.write_into(writer); |
31 | 0 | self.value_record_count.write_into(writer); |
32 | 0 | self.item_variation_store.write_into(writer); |
33 | 0 | self.value_records.write_into(writer); |
34 | 0 | } |
35 | 0 | fn table_type(&self) -> TableType { |
36 | 0 | TableType::TopLevel(Mvar::TAG) |
37 | 0 | } |
38 | | } |
39 | | |
40 | | impl Validate for Mvar { |
41 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
42 | 0 | ctx.in_table("Mvar", |ctx| { |
43 | 0 | ctx.in_field("item_variation_store", |ctx| { |
44 | 0 | self.item_variation_store.validate_impl(ctx); |
45 | 0 | }); |
46 | 0 | ctx.in_field("value_records", |ctx| { |
47 | 0 | if self.value_records.len() > (u16::MAX as usize) { |
48 | 0 | ctx.report("array exceeds max length"); |
49 | 0 | } |
50 | 0 | self.value_records.validate_impl(ctx); |
51 | 0 | }); |
52 | 0 | }) |
53 | 0 | } |
54 | | } |
55 | | |
56 | | impl TopLevelTable for Mvar { |
57 | | const TAG: Tag = Tag::new(b"MVAR"); |
58 | | } |
59 | | |
60 | | impl<'a> FromObjRef<read_fonts::tables::mvar::Mvar<'a>> for Mvar { |
61 | 0 | fn from_obj_ref(obj: &read_fonts::tables::mvar::Mvar<'a>, _: FontData) -> Self { |
62 | 0 | let offset_data = obj.offset_data(); |
63 | 0 | Mvar { |
64 | 0 | version: obj.version(), |
65 | 0 | value_record_size: obj.value_record_size(), |
66 | 0 | value_record_count: obj.value_record_count(), |
67 | 0 | item_variation_store: obj.item_variation_store().to_owned_table(), |
68 | 0 | value_records: obj.value_records().to_owned_obj(offset_data), |
69 | 0 | } |
70 | 0 | } |
71 | | } |
72 | | |
73 | | #[allow(clippy::needless_lifetimes)] |
74 | | impl<'a> FromTableRef<read_fonts::tables::mvar::Mvar<'a>> for Mvar {} |
75 | | |
76 | | impl<'a> FontRead<'a> for Mvar { |
77 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
78 | 0 | <read_fonts::tables::mvar::Mvar as FontRead>::read(data).map(|x| x.to_owned_table()) |
79 | 0 | } |
80 | | } |
81 | | |
82 | | /// [ValueRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/mvar#table-formats) metrics variation record |
83 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
84 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
85 | | pub struct ValueRecord { |
86 | | /// Four-byte tag identifying a font-wide measure. |
87 | | pub value_tag: Tag, |
88 | | /// A delta-set outer index — used to select an item variation data subtable within the item variation store. |
89 | | pub delta_set_outer_index: u16, |
90 | | /// A delta-set inner index — used to select a delta-set row within an item variation data subtable. |
91 | | pub delta_set_inner_index: u16, |
92 | | } |
93 | | |
94 | | impl ValueRecord { |
95 | | /// Construct a new `ValueRecord` |
96 | 0 | pub fn new(value_tag: Tag, delta_set_outer_index: u16, delta_set_inner_index: u16) -> Self { |
97 | 0 | Self { |
98 | 0 | value_tag, |
99 | 0 | delta_set_outer_index, |
100 | 0 | delta_set_inner_index, |
101 | 0 | } |
102 | 0 | } |
103 | | } |
104 | | |
105 | | impl FontWrite for ValueRecord { |
106 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
107 | 0 | self.value_tag.write_into(writer); |
108 | 0 | self.delta_set_outer_index.write_into(writer); |
109 | 0 | self.delta_set_inner_index.write_into(writer); |
110 | 0 | } |
111 | 0 | fn table_type(&self) -> TableType { |
112 | 0 | TableType::Named("ValueRecord") |
113 | 0 | } |
114 | | } |
115 | | |
116 | | impl Validate for ValueRecord { |
117 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
118 | | } |
119 | | |
120 | | impl FromObjRef<read_fonts::tables::mvar::ValueRecord> for ValueRecord { |
121 | 0 | fn from_obj_ref(obj: &read_fonts::tables::mvar::ValueRecord, _: FontData) -> Self { |
122 | 0 | ValueRecord { |
123 | 0 | value_tag: obj.value_tag(), |
124 | 0 | delta_set_outer_index: obj.delta_set_outer_index(), |
125 | 0 | delta_set_inner_index: obj.delta_set_inner_index(), |
126 | 0 | } |
127 | 0 | } |
128 | | } |