Coverage Report

Created: 2026-09-14 08:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/write-fonts/generated/generated_maxp.rs
Line
Count
Source
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)]
6
use crate::codegen_prelude::*;
7
8
/// [`maxp`](https://docs.microsoft.com/en-us/typography/opentype/spec/maxp)
9
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11
pub struct Maxp {
12
    /// The number of glyphs in the font.
13
    pub num_glyphs: u16,
14
    /// Maximum points in a non-composite glyph.
15
    pub max_points: Option<u16>,
16
    /// Maximum contours in a non-composite glyph.
17
    pub max_contours: Option<u16>,
18
    /// Maximum points in a composite glyph.
19
    pub max_composite_points: Option<u16>,
20
    /// Maximum contours in a composite glyph.
21
    pub max_composite_contours: Option<u16>,
22
    /// 1 if instructions do not use the twilight zone (Z0), or 2 if
23
    /// instructions do use Z0; should be set to 2 in most cases.
24
    pub max_zones: Option<u16>,
25
    /// Maximum points used in Z0.
26
    pub max_twilight_points: Option<u16>,
27
    /// Number of Storage Area locations.
28
    pub max_storage: Option<u16>,
29
    /// Number of FDEFs, equal to the highest function number + 1.
30
    pub max_function_defs: Option<u16>,
31
    /// Number of IDEFs.
32
    pub max_instruction_defs: Option<u16>,
33
    /// Maximum stack depth across Font Program ('fpgm' table), CVT
34
    /// Program ('prep' table) and all glyph instructions (in the
35
    /// 'glyf' table).
36
    pub max_stack_elements: Option<u16>,
37
    /// Maximum byte count for glyph instructions.
38
    pub max_size_of_instructions: Option<u16>,
39
    /// Maximum number of components referenced at “top level” for
40
    /// any composite glyph.
41
    pub max_component_elements: Option<u16>,
42
    /// Maximum levels of recursion; 1 for simple components.
43
    pub max_component_depth: Option<u16>,
44
}
45
46
impl Maxp {
47
    /// Construct a new `Maxp`
48
0
    pub fn new(num_glyphs: u16) -> Self {
49
0
        Self {
50
0
            num_glyphs,
51
0
            ..Default::default()
52
0
        }
53
0
    }
54
}
55
56
impl FontWrite for Maxp {
57
    #[allow(clippy::unnecessary_cast)]
58
0
    fn write_into(&self, writer: &mut TableWriter) {
59
0
        let version = self.compute_version() as Version16Dot16;
60
0
        version.write_into(writer);
61
0
        self.num_glyphs.write_into(writer);
62
0
        version.compatible((1u16, 0u16)).then(|| {
63
0
            self.max_points
64
0
                .as_ref()
65
0
                .expect("missing conditional field should have failed validation")
66
0
                .write_into(writer)
67
0
        });
68
0
        version.compatible((1u16, 0u16)).then(|| {
69
0
            self.max_contours
70
0
                .as_ref()
71
0
                .expect("missing conditional field should have failed validation")
72
0
                .write_into(writer)
73
0
        });
74
0
        version.compatible((1u16, 0u16)).then(|| {
75
0
            self.max_composite_points
76
0
                .as_ref()
77
0
                .expect("missing conditional field should have failed validation")
78
0
                .write_into(writer)
79
0
        });
80
0
        version.compatible((1u16, 0u16)).then(|| {
81
0
            self.max_composite_contours
82
0
                .as_ref()
83
0
                .expect("missing conditional field should have failed validation")
84
0
                .write_into(writer)
85
0
        });
86
0
        version.compatible((1u16, 0u16)).then(|| {
87
0
            self.max_zones
88
0
                .as_ref()
89
0
                .expect("missing conditional field should have failed validation")
90
0
                .write_into(writer)
91
0
        });
92
0
        version.compatible((1u16, 0u16)).then(|| {
93
0
            self.max_twilight_points
94
0
                .as_ref()
95
0
                .expect("missing conditional field should have failed validation")
96
0
                .write_into(writer)
97
0
        });
98
0
        version.compatible((1u16, 0u16)).then(|| {
99
0
            self.max_storage
100
0
                .as_ref()
101
0
                .expect("missing conditional field should have failed validation")
102
0
                .write_into(writer)
103
0
        });
104
0
        version.compatible((1u16, 0u16)).then(|| {
105
0
            self.max_function_defs
106
0
                .as_ref()
107
0
                .expect("missing conditional field should have failed validation")
108
0
                .write_into(writer)
109
0
        });
110
0
        version.compatible((1u16, 0u16)).then(|| {
111
0
            self.max_instruction_defs
112
0
                .as_ref()
113
0
                .expect("missing conditional field should have failed validation")
114
0
                .write_into(writer)
115
0
        });
116
0
        version.compatible((1u16, 0u16)).then(|| {
117
0
            self.max_stack_elements
118
0
                .as_ref()
119
0
                .expect("missing conditional field should have failed validation")
120
0
                .write_into(writer)
121
0
        });
122
0
        version.compatible((1u16, 0u16)).then(|| {
123
0
            self.max_size_of_instructions
124
0
                .as_ref()
125
0
                .expect("missing conditional field should have failed validation")
126
0
                .write_into(writer)
127
0
        });
128
0
        version.compatible((1u16, 0u16)).then(|| {
129
0
            self.max_component_elements
130
0
                .as_ref()
131
0
                .expect("missing conditional field should have failed validation")
132
0
                .write_into(writer)
133
0
        });
134
0
        version.compatible((1u16, 0u16)).then(|| {
135
0
            self.max_component_depth
136
0
                .as_ref()
137
0
                .expect("missing conditional field should have failed validation")
138
0
                .write_into(writer)
139
0
        });
140
0
    }
141
0
    fn table_type(&self) -> TableType {
142
0
        TableType::TopLevel(Maxp::TAG)
143
0
    }
144
}
145
146
impl Validate for Maxp {
147
0
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
148
0
        ctx.in_table("Maxp", |ctx| {
149
0
            let version: Version16Dot16 = self.compute_version();
150
0
            ctx.in_field("max_points", |ctx| {
151
0
                if version.compatible((1u16, 0u16)) && self.max_points.is_none() {
152
0
                    ctx.report(format!("field must be present for version {version}"));
153
0
                }
154
0
            });
155
0
            ctx.in_field("max_contours", |ctx| {
156
0
                if version.compatible((1u16, 0u16)) && self.max_contours.is_none() {
157
0
                    ctx.report(format!("field must be present for version {version}"));
158
0
                }
159
0
            });
160
0
            ctx.in_field("max_composite_points", |ctx| {
161
0
                if version.compatible((1u16, 0u16)) && self.max_composite_points.is_none() {
162
0
                    ctx.report(format!("field must be present for version {version}"));
163
0
                }
164
0
            });
165
0
            ctx.in_field("max_composite_contours", |ctx| {
166
0
                if version.compatible((1u16, 0u16)) && self.max_composite_contours.is_none() {
167
0
                    ctx.report(format!("field must be present for version {version}"));
168
0
                }
169
0
            });
170
0
            ctx.in_field("max_zones", |ctx| {
171
0
                if version.compatible((1u16, 0u16)) && self.max_zones.is_none() {
172
0
                    ctx.report(format!("field must be present for version {version}"));
173
0
                }
174
0
            });
175
0
            ctx.in_field("max_twilight_points", |ctx| {
176
0
                if version.compatible((1u16, 0u16)) && self.max_twilight_points.is_none() {
177
0
                    ctx.report(format!("field must be present for version {version}"));
178
0
                }
179
0
            });
180
0
            ctx.in_field("max_storage", |ctx| {
181
0
                if version.compatible((1u16, 0u16)) && self.max_storage.is_none() {
182
0
                    ctx.report(format!("field must be present for version {version}"));
183
0
                }
184
0
            });
185
0
            ctx.in_field("max_function_defs", |ctx| {
186
0
                if version.compatible((1u16, 0u16)) && self.max_function_defs.is_none() {
187
0
                    ctx.report(format!("field must be present for version {version}"));
188
0
                }
189
0
            });
190
0
            ctx.in_field("max_instruction_defs", |ctx| {
191
0
                if version.compatible((1u16, 0u16)) && self.max_instruction_defs.is_none() {
192
0
                    ctx.report(format!("field must be present for version {version}"));
193
0
                }
194
0
            });
195
0
            ctx.in_field("max_stack_elements", |ctx| {
196
0
                if version.compatible((1u16, 0u16)) && self.max_stack_elements.is_none() {
197
0
                    ctx.report(format!("field must be present for version {version}"));
198
0
                }
199
0
            });
200
0
            ctx.in_field("max_size_of_instructions", |ctx| {
201
0
                if version.compatible((1u16, 0u16)) && self.max_size_of_instructions.is_none() {
202
0
                    ctx.report(format!("field must be present for version {version}"));
203
0
                }
204
0
            });
205
0
            ctx.in_field("max_component_elements", |ctx| {
206
0
                if version.compatible((1u16, 0u16)) && self.max_component_elements.is_none() {
207
0
                    ctx.report(format!("field must be present for version {version}"));
208
0
                }
209
0
            });
210
0
            ctx.in_field("max_component_depth", |ctx| {
211
0
                if version.compatible((1u16, 0u16)) && self.max_component_depth.is_none() {
212
0
                    ctx.report(format!("field must be present for version {version}"));
213
0
                }
214
0
            });
215
0
        })
216
0
    }
217
}
218
219
impl TopLevelTable for Maxp {
220
    const TAG: Tag = Tag::new(b"maxp");
221
}
222
223
impl<'a> FromObjRef<read_fonts::tables::maxp::Maxp<'a>> for Maxp {
224
0
    fn from_obj_ref(obj: &read_fonts::tables::maxp::Maxp<'a>, _: FontData) -> Self {
225
0
        Maxp {
226
0
            num_glyphs: obj.num_glyphs(),
227
0
            max_points: obj.max_points(),
228
0
            max_contours: obj.max_contours(),
229
0
            max_composite_points: obj.max_composite_points(),
230
0
            max_composite_contours: obj.max_composite_contours(),
231
0
            max_zones: obj.max_zones(),
232
0
            max_twilight_points: obj.max_twilight_points(),
233
0
            max_storage: obj.max_storage(),
234
0
            max_function_defs: obj.max_function_defs(),
235
0
            max_instruction_defs: obj.max_instruction_defs(),
236
0
            max_stack_elements: obj.max_stack_elements(),
237
0
            max_size_of_instructions: obj.max_size_of_instructions(),
238
0
            max_component_elements: obj.max_component_elements(),
239
0
            max_component_depth: obj.max_component_depth(),
240
0
        }
241
0
    }
242
}
243
244
#[allow(clippy::needless_lifetimes)]
245
impl<'a> FromTableRef<read_fonts::tables::maxp::Maxp<'a>> for Maxp {}
246
247
impl ReadArgs for Maxp {
248
    type Args = ();
249
}
250
251
impl<'a> FontRead<'a> for Maxp {
252
0
    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
253
0
        <read_fonts::tables::maxp::Maxp as FontRead>::read(data).map(|x| x.to_owned_table())
254
0
    }
255
}