Skip to main content

ttf_view/tables/
maxp.rs

1use crate::types::{Tag, Version16Dot16, tags, uint16};
2
3#[repr(C)]
4pub struct MaxpTableRepr {
5    // version ≥ 0.5:
6    pub version: Version16Dot16,
7    pub num_glyphs: uint16,
8    // version ≥ 1.0:
9    v1_fields: MaxpTableReprV1Fields,
10}
11
12#[repr(C)]
13pub struct MaxpTableReprV1Fields {
14    pub max_points: uint16,
15    pub max_contours: uint16,
16    pub max_composite_points: uint16,
17    pub max_composite_contours: uint16,
18    pub max_zones: uint16,
19    pub max_twilight_points: uint16,
20    pub max_storage: uint16,
21    pub max_function_defs: uint16,
22    pub max_instruction_defs: uint16,
23    pub max_stack_elements: uint16,
24    pub max_size_of_instructions: uint16,
25    pub max_component_elements: uint16,
26    pub max_component_depth: uint16,
27}
28
29impl super::Table for MaxpTableRepr {
30    const TAG: Tag = tags::maxp;
31    type Handle<'a> = &'a Self;
32}
33
34impl MaxpTableRepr {
35    pub const fn v1_fields(&self) -> Option<&MaxpTableReprV1Fields> {
36        if self.version >= Version16Dot16::V1_0 { Some(&self.v1_fields) } else { None }
37    }
38}
39
40impl std::fmt::Debug for MaxpTableRepr {
41    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
42        let mut builder = f.debug_struct("MaxpTable");
43        builder.field("version", &self.version).field("num_glyphs", &self.num_glyphs.get());
44
45        if let Some(v1) = self.v1_fields() {
46            builder
47                .field("max_points", &v1.max_points.get())
48                .field("max_contours", &v1.max_contours.get())
49                .field("max_composite_points", &v1.max_composite_points.get())
50                .field("max_composite_contours", &v1.max_composite_contours.get())
51                .field("max_zones", &v1.max_zones.get())
52                .field("max_twilight_points", &v1.max_twilight_points.get())
53                .field("max_storage", &v1.max_storage.get())
54                .field("max_function_defs", &v1.max_function_defs.get())
55                .field("max_instruction_defs", &v1.max_instruction_defs.get())
56                .field("max_stack_elements", &v1.max_stack_elements.get())
57                .field("max_size_of_instructions", &v1.max_size_of_instructions.get())
58                .field("max_component_elements", &v1.max_component_elements.get())
59                .field("max_component_depth", &v1.max_component_depth.get());
60        }
61
62        builder.finish()
63    }
64}