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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#[allow(unused_imports)]
use crate::codegen_prelude::*;
#[derive(Clone, Debug, Default)]
pub struct Maxp {
pub num_glyphs: u16,
pub max_points: Option<u16>,
pub max_contours: Option<u16>,
pub max_composite_points: Option<u16>,
pub max_composite_contours: Option<u16>,
pub max_zones: Option<u16>,
pub max_twilight_points: Option<u16>,
pub max_storage: Option<u16>,
pub max_function_defs: Option<u16>,
pub max_instruction_defs: Option<u16>,
pub max_stack_elements: Option<u16>,
pub max_size_of_instructions: Option<u16>,
pub max_component_elements: Option<u16>,
pub max_component_depth: Option<u16>,
}
impl Maxp {
pub fn new(num_glyphs: u16) -> Self {
Self {
num_glyphs,
..Default::default()
}
}
}
impl FontWrite for Maxp {
#[allow(clippy::unnecessary_cast)]
fn write_into(&self, writer: &mut TableWriter) {
let version = self.compute_version() as Version16Dot16;
version.write_into(writer);
self.num_glyphs.write_into(writer);
version.compatible((1, 0)).then(|| {
self.max_points
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_contours
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_composite_points
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_composite_contours
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_zones
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_twilight_points
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_storage
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_function_defs
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_instruction_defs
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_stack_elements
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_size_of_instructions
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_component_elements
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
version.compatible((1, 0)).then(|| {
self.max_component_depth
.as_ref()
.expect("missing versioned field should have failed validation")
.write_into(writer)
});
}
}
impl Validate for Maxp {
fn validate_impl(&self, ctx: &mut ValidationCtx) {
ctx.in_table("Maxp", |ctx| {
let version: Version16Dot16 = self.compute_version();
ctx.in_field("max_points", |ctx| {
if version.compatible((1, 0)) && self.max_points.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_contours", |ctx| {
if version.compatible((1, 0)) && self.max_contours.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_composite_points", |ctx| {
if version.compatible((1, 0)) && self.max_composite_points.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_composite_contours", |ctx| {
if version.compatible((1, 0)) && self.max_composite_contours.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_zones", |ctx| {
if version.compatible((1, 0)) && self.max_zones.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_twilight_points", |ctx| {
if version.compatible((1, 0)) && self.max_twilight_points.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_storage", |ctx| {
if version.compatible((1, 0)) && self.max_storage.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_function_defs", |ctx| {
if version.compatible((1, 0)) && self.max_function_defs.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_instruction_defs", |ctx| {
if version.compatible((1, 0)) && self.max_instruction_defs.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_stack_elements", |ctx| {
if version.compatible((1, 0)) && self.max_stack_elements.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_size_of_instructions", |ctx| {
if version.compatible((1, 0)) && self.max_size_of_instructions.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_component_elements", |ctx| {
if version.compatible((1, 0)) && self.max_component_elements.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("max_component_depth", |ctx| {
if version.compatible((1, 0)) && self.max_component_depth.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
})
}
}
impl TopLevelTable for Maxp {
const TAG: Tag = Tag::new(b"maxp");
}
impl<'a> FromObjRef<read_fonts::tables::maxp::Maxp<'a>> for Maxp {
fn from_obj_ref(obj: &read_fonts::tables::maxp::Maxp<'a>, _: FontData) -> Self {
Maxp {
num_glyphs: obj.num_glyphs(),
max_points: obj.max_points(),
max_contours: obj.max_contours(),
max_composite_points: obj.max_composite_points(),
max_composite_contours: obj.max_composite_contours(),
max_zones: obj.max_zones(),
max_twilight_points: obj.max_twilight_points(),
max_storage: obj.max_storage(),
max_function_defs: obj.max_function_defs(),
max_instruction_defs: obj.max_instruction_defs(),
max_stack_elements: obj.max_stack_elements(),
max_size_of_instructions: obj.max_size_of_instructions(),
max_component_elements: obj.max_component_elements(),
max_component_depth: obj.max_component_depth(),
}
}
}
impl<'a> FromTableRef<read_fonts::tables::maxp::Maxp<'a>> for Maxp {}
impl<'a> FontRead<'a> for Maxp {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
<read_fonts::tables::maxp::Maxp as FontRead>::read(data).map(|x| x.to_owned_table())
}
}