write_fonts/generated/
generated_gvar.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
8pub use read_fonts::tables::gvar::GvarFlags;
9
10/// The ['gvar' header](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar#gvar-header)
11#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct Gvar {
14    /// The number of variation axes for this font. This must be the
15    /// same number as axisCount in the 'fvar' table.
16    pub axis_count: u16,
17    /// Offset from the start of this table to the shared tuple records.
18    pub shared_tuples: OffsetMarker<SharedTuples, WIDTH_32>,
19    /// Offsets from the start of the GlyphVariationData array to each
20    /// GlyphVariationData table.
21    pub glyph_variation_data_offsets: Vec<GlyphVariationData>,
22}
23
24impl FontWrite for Gvar {
25    #[allow(clippy::unnecessary_cast)]
26    fn write_into(&self, writer: &mut TableWriter) {
27        (MajorMinor::VERSION_1_0 as MajorMinor).write_into(writer);
28        self.axis_count.write_into(writer);
29        (u16::try_from(array_len(&self.shared_tuples)).unwrap()).write_into(writer);
30        (self.compute_shared_tuples_offset()).write_into(writer);
31        (self.compute_glyph_count() as u16).write_into(writer);
32        (self.compute_flags() as GvarFlags).write_into(writer);
33        (self.compute_data_array_offset() as u32).write_into(writer);
34        (self.compile_variation_data()).write_into(writer);
35    }
36    fn table_type(&self) -> TableType {
37        TableType::TopLevel(Gvar::TAG)
38    }
39}
40
41impl Validate for Gvar {
42    fn validate_impl(&self, ctx: &mut ValidationCtx) {
43        ctx.in_table("Gvar", |ctx| {
44            ctx.in_field("shared_tuples", |ctx| {
45                self.shared_tuples.validate_impl(ctx);
46            });
47            ctx.in_field("glyph_variation_data_offsets", |ctx| {
48                self.glyph_variation_data_offsets.validate_impl(ctx);
49            });
50        })
51    }
52}
53
54impl TopLevelTable for Gvar {
55    const TAG: Tag = Tag::new(b"gvar");
56}
57
58impl FontWrite for GvarFlags {
59    fn write_into(&self, writer: &mut TableWriter) {
60        writer.write_slice(&self.bits().to_be_bytes())
61    }
62}
63
64/// Array of tuple records shared across all glyph variation data tables.
65#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
66#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67pub struct SharedTuples {
68    pub tuples: Vec<Tuple>,
69}
70
71impl SharedTuples {
72    /// Construct a new `SharedTuples`
73    pub fn new(tuples: Vec<Tuple>) -> Self {
74        Self { tuples }
75    }
76}
77
78impl FontWrite for SharedTuples {
79    fn write_into(&self, writer: &mut TableWriter) {
80        self.tuples.write_into(writer);
81    }
82    fn table_type(&self) -> TableType {
83        TableType::Named("SharedTuples")
84    }
85}
86
87impl Validate for SharedTuples {
88    fn validate_impl(&self, ctx: &mut ValidationCtx) {
89        ctx.in_table("SharedTuples", |ctx| {
90            ctx.in_field("tuples", |ctx| {
91                if self.tuples.len() > (u16::MAX as usize) {
92                    ctx.report("array exceeds max length");
93                }
94                self.tuples.validate_impl(ctx);
95            });
96        })
97    }
98}
99
100impl<'a> FromObjRef<read_fonts::tables::gvar::SharedTuples<'a>> for SharedTuples {
101    fn from_obj_ref(obj: &read_fonts::tables::gvar::SharedTuples<'a>, _: FontData) -> Self {
102        let offset_data = obj.offset_data();
103        SharedTuples {
104            tuples: obj
105                .tuples()
106                .iter()
107                .filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
108                .collect(),
109        }
110    }
111}
112
113#[allow(clippy::needless_lifetimes)]
114impl<'a> FromTableRef<read_fonts::tables::gvar::SharedTuples<'a>> for SharedTuples {}
115
116/// The [GlyphVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar#the-glyphvariationdata-table-array) table
117#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
118#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
119pub struct GlyphVariationDataHeader {
120    /// A packed field. The high 4 bits are flags, and the low 12 bits
121    /// are the number of tuple variation tables for this glyph. The
122    /// number of tuple variation tables can be any number between 1
123    /// and 4095.
124    pub tuple_variation_count: TupleVariationCount,
125    /// Array of tuple variation headers.
126    pub tuple_variation_headers: Vec<TupleVariationHeader>,
127}
128
129impl Validate for GlyphVariationDataHeader {
130    fn validate_impl(&self, ctx: &mut ValidationCtx) {
131        ctx.in_table("GlyphVariationDataHeader", |ctx| {
132            ctx.in_field("tuple_variation_headers", |ctx| {
133                self.tuple_variation_headers.validate_impl(ctx);
134            });
135        })
136    }
137}