write_fonts/generated/
generated_gvar.rs1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8pub use read_fonts::tables::gvar::GvarFlags;
9
10#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct Gvar {
14 pub axis_count: u16,
17 pub shared_tuples: OffsetMarker<SharedTuples, WIDTH_32>,
19 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#[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 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#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
118#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
119pub struct GlyphVariationDataHeader {
120 pub tuple_variation_count: TupleVariationCount,
125 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}