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() > (u16::MAX as usize) {
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<'a> FontRead<'a> for Mvar {
77    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
78        <read_fonts::tables::mvar::Mvar as FontRead>::read(data).map(|x| x.to_owned_table())
79    }
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))]
85pub 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
94impl ValueRecord {
95    /// Construct a new `ValueRecord`
96    pub fn new(value_tag: Tag, delta_set_outer_index: u16, delta_set_inner_index: u16) -> Self {
97        Self {
98            value_tag,
99            delta_set_outer_index,
100            delta_set_inner_index,
101        }
102    }
103}
104
105impl FontWrite for ValueRecord {
106    fn write_into(&self, writer: &mut TableWriter) {
107        self.value_tag.write_into(writer);
108        self.delta_set_outer_index.write_into(writer);
109        self.delta_set_inner_index.write_into(writer);
110    }
111    fn table_type(&self) -> TableType {
112        TableType::Named("ValueRecord")
113    }
114}
115
116impl Validate for ValueRecord {
117    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
118}
119
120impl FromObjRef<read_fonts::tables::mvar::ValueRecord> for ValueRecord {
121    fn from_obj_ref(obj: &read_fonts::tables::mvar::ValueRecord, _: FontData) -> Self {
122        ValueRecord {
123            value_tag: obj.value_tag(),
124            delta_set_outer_index: obj.delta_set_outer_index(),
125            delta_set_inner_index: obj.delta_set_inner_index(),
126        }
127    }
128}