Skip to main content

write_fonts/generated/
generated_mvar.rs

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)]
6use 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))]
11pub 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
25impl FontWrite for Mvar {
26    #[allow(clippy::unnecessary_cast)]
27    fn write_into(&self, writer: &mut TableWriter) {
28        self.version.write_into(writer);
29        (0 as u16).write_into(writer);
30        self.value_record_size.write_into(writer);
31        self.value_record_count.write_into(writer);
32        self.item_variation_store.write_into(writer);
33        self.value_records.write_into(writer);
34    }
35    fn table_type(&self) -> TableType {
36        TableType::TopLevel(Mvar::TAG)
37    }
38}
39
40impl Validate for Mvar {
41    fn validate_impl(&self, ctx: &mut ValidationCtx) {
42        ctx.in_table("Mvar", |ctx| {
43            ctx.in_field("item_variation_store", |ctx| {
44                self.item_variation_store.validate_impl(ctx);
45            });
46            ctx.in_field("value_records", |ctx| {
47                if self.value_records.len() > to_usize(u16::MAX) {
48                    ctx.report("array exceeds max length");
49                }
50                self.value_records.validate_impl(ctx);
51            });
52        })
53    }
54}
55
56impl TopLevelTable for Mvar {
57    const TAG: Tag = Tag::new(b"MVAR");
58}
59
60impl<'a> FromObjRef<read_fonts::tables::mvar::Mvar<'a>> for Mvar {
61    fn from_obj_ref(obj: &read_fonts::tables::mvar::Mvar<'a>, _: FontData) -> Self {
62        let offset_data = obj.offset_data();
63        Mvar {
64            version: obj.version(),
65            value_record_size: obj.value_record_size(),
66            value_record_count: obj.value_record_count(),
67            item_variation_store: obj.item_variation_store().to_owned_table(),
68            value_records: obj.value_records().to_owned_obj(offset_data),
69        }
70    }
71}
72
73#[allow(clippy::needless_lifetimes)]
74impl<'a> FromTableRef<read_fonts::tables::mvar::Mvar<'a>> for Mvar {}
75
76impl ReadArgs for Mvar {
77    type Args = ();
78}
79
80impl<'a> FontRead<'a> for Mvar {
81    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
82        <read_fonts::tables::mvar::Mvar as FontRead>::read(data).map(|x| x.to_owned_table())
83    }
84}
85
86/// [ValueRecord](https://learn.microsoft.com/en-us/typography/opentype/spec/mvar#table-formats) metrics variation record
87#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
88#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89pub struct ValueRecord {
90    /// Four-byte tag identifying a font-wide measure.
91    pub value_tag: Tag,
92    /// A delta-set outer index — used to select an item variation data subtable within the item variation store.
93    pub delta_set_outer_index: u16,
94    /// A delta-set inner index — used to select a delta-set row within an item variation data subtable.
95    pub delta_set_inner_index: u16,
96}
97
98impl ValueRecord {
99    /// Construct a new `ValueRecord`
100    pub fn new(value_tag: Tag, delta_set_outer_index: u16, delta_set_inner_index: u16) -> Self {
101        Self {
102            value_tag,
103            delta_set_outer_index,
104            delta_set_inner_index,
105        }
106    }
107}
108
109impl FontWrite for ValueRecord {
110    fn write_into(&self, writer: &mut TableWriter) {
111        self.value_tag.write_into(writer);
112        self.delta_set_outer_index.write_into(writer);
113        self.delta_set_inner_index.write_into(writer);
114    }
115    fn table_type(&self) -> TableType {
116        TableType::Named("ValueRecord")
117    }
118}
119
120impl Validate for ValueRecord {
121    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
122}
123
124impl FromObjRef<read_fonts::tables::mvar::ValueRecord> for ValueRecord {
125    fn from_obj_ref(obj: &read_fonts::tables::mvar::ValueRecord, _: FontData) -> Self {
126        ValueRecord {
127            value_tag: obj.value_tag(),
128            delta_set_outer_index: obj.delta_set_outer_index(),
129            delta_set_inner_index: obj.delta_set_inner_index(),
130        }
131    }
132}