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