Skip to main content

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.validate_glyph_variation_data(ctx);
49            });
50        })
51    }
52}
53
54impl TopLevelTable for Gvar {
55    const TAG: Tag = Tag::new(b"gvar");
56}
57
58/// GVAR glyph variations table (ISO/IEC 14496-22:2026, 7.3.9).
59#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
60#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
61pub struct GvarExtended {
62    pub axis_count: u16,
63    pub shared_tuples: OffsetMarker<SharedTuples, WIDTH_32>,
64    pub glyph_variation_data_offsets: Vec<GlyphVariationData>,
65}
66
67impl FontWrite for GvarExtended {
68    #[allow(clippy::unnecessary_cast)]
69    fn write_into(&self, writer: &mut TableWriter) {
70        (MajorMinor::VERSION_1_0 as MajorMinor).write_into(writer);
71        self.axis_count.write_into(writer);
72        (u16::try_from(array_len(&self.shared_tuples)).unwrap()).write_into(writer);
73        (self.compute_shared_tuples_offset()).write_into(writer);
74        (self.compute_glyph_count() as Uint24).write_into(writer);
75        (self.compute_flags() as GvarFlags).write_into(writer);
76        (self.compute_data_array_offset() as u32).write_into(writer);
77        (self.compile_variation_data()).write_into(writer);
78    }
79    fn table_type(&self) -> TableType {
80        TableType::TopLevel(GvarExtended::TAG)
81    }
82}
83
84impl Validate for GvarExtended {
85    fn validate_impl(&self, ctx: &mut ValidationCtx) {
86        ctx.in_table("GvarExtended", |ctx| {
87            ctx.in_field("shared_tuples", |ctx| {
88                self.shared_tuples.validate_impl(ctx);
89            });
90            ctx.in_field("glyph_variation_data_offsets", |ctx| {
91                self.validate_glyph_variation_data(ctx);
92            });
93        })
94    }
95}
96
97impl TopLevelTable for GvarExtended {
98    const TAG: Tag = Tag::new(b"GVAR");
99}
100
101impl FontWrite for GvarFlags {
102    fn write_into(&self, writer: &mut TableWriter) {
103        writer.write_slice(&self.bits().to_be_bytes())
104    }
105}
106
107/// Array of tuple records shared across all glyph variation data tables.
108#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
109#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
110pub struct SharedTuples {
111    pub tuples: Vec<Tuple>,
112}
113
114impl SharedTuples {
115    /// Construct a new `SharedTuples`
116    pub fn new(tuples: Vec<Tuple>) -> Self {
117        Self { tuples }
118    }
119}
120
121impl FontWrite for SharedTuples {
122    fn write_into(&self, writer: &mut TableWriter) {
123        self.tuples.write_into(writer);
124    }
125    fn table_type(&self) -> TableType {
126        TableType::Named("SharedTuples")
127    }
128}
129
130impl Validate for SharedTuples {
131    fn validate_impl(&self, ctx: &mut ValidationCtx) {
132        ctx.in_table("SharedTuples", |ctx| {
133            ctx.in_field("tuples", |ctx| {
134                if self.tuples.len() > to_usize(u16::MAX) {
135                    ctx.report("array exceeds max length");
136                }
137                self.tuples.validate_impl(ctx);
138            });
139        })
140    }
141}
142
143impl<'a> FromObjRef<read_fonts::tables::gvar::SharedTuples<'a>> for SharedTuples {
144    fn from_obj_ref(obj: &read_fonts::tables::gvar::SharedTuples<'a>, _: FontData) -> Self {
145        let offset_data = obj.offset_data();
146        SharedTuples {
147            tuples: obj
148                .tuples()
149                .iter()
150                .filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
151                .collect(),
152        }
153    }
154}
155
156#[allow(clippy::needless_lifetimes)]
157impl<'a> FromTableRef<read_fonts::tables::gvar::SharedTuples<'a>> for SharedTuples {}
158
159/// The [GlyphVariationData](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar#the-glyphvariationdata-table-array) table
160#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
161#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
162pub struct GlyphVariationDataHeader {
163    /// A packed field. The high 4 bits are flags, and the low 12 bits
164    /// are the number of tuple variation tables for this glyph. The
165    /// number of tuple variation tables can be any number between 1
166    /// and 4095.
167    pub tuple_variation_count: TupleVariationCount,
168    /// Array of tuple variation headers.
169    pub tuple_variation_headers: Vec<TupleVariationHeader>,
170}
171
172impl Validate for GlyphVariationDataHeader {
173    fn validate_impl(&self, ctx: &mut ValidationCtx) {
174        ctx.in_table("GlyphVariationDataHeader", |ctx| {
175            ctx.in_field("tuple_variation_headers", |ctx| {
176                self.tuple_variation_headers.validate_impl(ctx);
177            });
178        })
179    }
180}
181
182/// Per-glyph variation header in GVAR (ISO/IEC 14496-22:2026, 7.3.9.1.3).
183#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
184#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
185pub struct GlyphVariationDataHeaderExtended {
186    pub tuple_variation_count: TupleVariationCount,
187    pub tuple_variation_headers: Vec<TupleVariationHeader>,
188}
189
190impl Validate for GlyphVariationDataHeaderExtended {
191    fn validate_impl(&self, ctx: &mut ValidationCtx) {
192        ctx.in_table("GlyphVariationDataHeaderExtended", |ctx| {
193            ctx.in_field("tuple_variation_headers", |ctx| {
194                self.tuple_variation_headers.validate_impl(ctx);
195            });
196        })
197    }
198}