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