1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#[allow(unused_imports)]
use crate::codegen_prelude::*;
pub use read_fonts::tables::gvar::GvarFlags;
#[derive(Clone, Debug, Default)]
pub struct Gvar {
pub axis_count: u16,
pub shared_tuples: OffsetMarker<SharedTuples, WIDTH_32>,
pub glyph_variation_data_offsets: Vec<GlyphVariationData>,
}
impl FontWrite for Gvar {
#[allow(clippy::unnecessary_cast)]
fn write_into(&self, writer: &mut TableWriter) {
(MajorMinor::VERSION_1_0 as MajorMinor).write_into(writer);
self.axis_count.write_into(writer);
(array_len(&self.shared_tuples).unwrap() as u16).write_into(writer);
self.shared_tuples.write_into(writer);
(self.compute_glyph_count() as u16).write_into(writer);
(self.compute_flags() as GvarFlags).write_into(writer);
(self.compute_data_array_offset() as u32).write_into(writer);
(self.compile_variation_data()).write_into(writer);
}
}
impl Validate for Gvar {
fn validate_impl(&self, ctx: &mut ValidationCtx) {
ctx.in_table("Gvar", |ctx| {
ctx.in_field("shared_tuples", |ctx| {
self.shared_tuples.validate_impl(ctx);
});
ctx.in_field("glyph_variation_data_offsets", |ctx| {
self.glyph_variation_data_offsets.validate_impl(ctx);
});
})
}
}
impl TopLevelTable for Gvar {
const TAG: Tag = Tag::new(b"gvar");
}
impl FontWrite for GvarFlags {
fn write_into(&self, writer: &mut TableWriter) {
writer.write_slice(&self.bits().to_be_bytes())
}
}
#[derive(Clone, Debug, Default)]
pub struct SharedTuples {
pub tuples: Vec<Tuple>,
}
impl SharedTuples {
pub fn new(tuples: Vec<Tuple>) -> Self {
Self { tuples }
}
}
impl FontWrite for SharedTuples {
fn write_into(&self, writer: &mut TableWriter) {
self.tuples.write_into(writer);
}
}
impl Validate for SharedTuples {
fn validate_impl(&self, ctx: &mut ValidationCtx) {
ctx.in_table("SharedTuples", |ctx| {
ctx.in_field("tuples", |ctx| {
if self.tuples.len() > (u16::MAX as usize) {
ctx.report("array exceeds max length");
}
self.tuples.validate_impl(ctx);
});
})
}
}
impl<'a> FromObjRef<read_fonts::tables::gvar::SharedTuples<'a>> for SharedTuples {
fn from_obj_ref(obj: &read_fonts::tables::gvar::SharedTuples<'a>, _: FontData) -> Self {
let offset_data = obj.offset_data();
SharedTuples {
tuples: obj
.tuples()
.iter()
.filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
.collect(),
}
}
}
impl<'a> FromTableRef<read_fonts::tables::gvar::SharedTuples<'a>> for SharedTuples {}
#[derive(Clone, Debug, Default)]
pub struct GlyphVariationDataHeader {
pub tuple_variation_count: TupleVariationCount,
pub tuple_variation_headers: Vec<TupleVariationHeader>,
}
impl Validate for GlyphVariationDataHeader {
fn validate_impl(&self, ctx: &mut ValidationCtx) {
ctx.in_table("GlyphVariationDataHeader", |ctx| {
ctx.in_field("tuple_variation_headers", |ctx| {
self.tuple_variation_headers.validate_impl(ctx);
});
})
}
}