write_fonts/generated/
generated_vvar.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 [VVAR (Vertical Metrics Variations)](https://docs.microsoft.com/en-us/typography/opentype/spec/vvar) table
9#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Vvar {
12    /// Offset in bytes from the start of this table to the item variation store table.
13    pub item_variation_store: OffsetMarker<ItemVariationStore, WIDTH_32>,
14    /// Offset in bytes from the start of this table to the delta-set index mapping for advance heights (may be NULL).
15    pub advance_height_mapping: NullableOffsetMarker<DeltaSetIndexMap, WIDTH_32>,
16    /// Offset in bytes from the start of this table to the delta-set index mapping for top side bearings (may be NULL).
17    pub tsb_mapping: NullableOffsetMarker<DeltaSetIndexMap, WIDTH_32>,
18    /// Offset in bytes from the start of this table to the delta-set index mapping for bottom side bearings (may be NULL).
19    pub bsb_mapping: NullableOffsetMarker<DeltaSetIndexMap, WIDTH_32>,
20    /// Offset in bytes from the start of this table to the delta-set index mapping for Y coordinates of vertical origins (may be NULL).
21    pub v_org_mapping: NullableOffsetMarker<DeltaSetIndexMap, WIDTH_32>,
22}
23
24impl Vvar {
25    /// Construct a new `Vvar`
26    pub fn new(
27        item_variation_store: ItemVariationStore,
28        advance_height_mapping: Option<DeltaSetIndexMap>,
29        tsb_mapping: Option<DeltaSetIndexMap>,
30        bsb_mapping: Option<DeltaSetIndexMap>,
31        v_org_mapping: Option<DeltaSetIndexMap>,
32    ) -> Self {
33        Self {
34            item_variation_store: item_variation_store.into(),
35            advance_height_mapping: advance_height_mapping.into(),
36            tsb_mapping: tsb_mapping.into(),
37            bsb_mapping: bsb_mapping.into(),
38            v_org_mapping: v_org_mapping.into(),
39        }
40    }
41}
42
43impl FontWrite for Vvar {
44    #[allow(clippy::unnecessary_cast)]
45    fn write_into(&self, writer: &mut TableWriter) {
46        (MajorMinor::VERSION_1_0 as MajorMinor).write_into(writer);
47        self.item_variation_store.write_into(writer);
48        self.advance_height_mapping.write_into(writer);
49        self.tsb_mapping.write_into(writer);
50        self.bsb_mapping.write_into(writer);
51        self.v_org_mapping.write_into(writer);
52    }
53    fn table_type(&self) -> TableType {
54        TableType::TopLevel(Vvar::TAG)
55    }
56}
57
58impl Validate for Vvar {
59    fn validate_impl(&self, ctx: &mut ValidationCtx) {
60        ctx.in_table("Vvar", |ctx| {
61            ctx.in_field("item_variation_store", |ctx| {
62                self.item_variation_store.validate_impl(ctx);
63            });
64            ctx.in_field("advance_height_mapping", |ctx| {
65                self.advance_height_mapping.validate_impl(ctx);
66            });
67            ctx.in_field("tsb_mapping", |ctx| {
68                self.tsb_mapping.validate_impl(ctx);
69            });
70            ctx.in_field("bsb_mapping", |ctx| {
71                self.bsb_mapping.validate_impl(ctx);
72            });
73            ctx.in_field("v_org_mapping", |ctx| {
74                self.v_org_mapping.validate_impl(ctx);
75            });
76        })
77    }
78}
79
80impl TopLevelTable for Vvar {
81    const TAG: Tag = Tag::new(b"VVAR");
82}
83
84impl<'a> FromObjRef<read_fonts::tables::vvar::Vvar<'a>> for Vvar {
85    fn from_obj_ref(obj: &read_fonts::tables::vvar::Vvar<'a>, _: FontData) -> Self {
86        Vvar {
87            item_variation_store: obj.item_variation_store().to_owned_table(),
88            advance_height_mapping: obj.advance_height_mapping().to_owned_table(),
89            tsb_mapping: obj.tsb_mapping().to_owned_table(),
90            bsb_mapping: obj.bsb_mapping().to_owned_table(),
91            v_org_mapping: obj.v_org_mapping().to_owned_table(),
92        }
93    }
94}
95
96#[allow(clippy::needless_lifetimes)]
97impl<'a> FromTableRef<read_fonts::tables::vvar::Vvar<'a>> for Vvar {}
98
99impl<'a> FontRead<'a> for Vvar {
100    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
101        <read_fonts::tables::vvar::Vvar as FontRead>::read(data).map(|x| x.to_owned_table())
102    }
103}