truetype/tables/
maximum_profile.rs

1//! The [maximum profile][1].
2//!
3//! [1]: https://learn.microsoft.com/en-us/typography/opentype/spec/maxp
4
5use crate::{q32, Result};
6
7/// A maximum profile.
8#[derive(Clone, Debug)]
9pub enum MaximumProfile {
10    /// Version 0.5.
11    Version0(MaximumProfile0),
12    /// Version 1.
13    Version1(MaximumProfile1),
14}
15
16table! {
17    /// A maximum profile of version 0.5.
18    #[derive(Copy)]
19    pub MaximumProfile0 {
20        version     (q32), // version
21        glyph_count (u16), // numGlyphs
22    }
23}
24
25table! {
26    /// A maximum profile of version 1.
27    #[derive(Copy)]
28    pub MaximumProfile1 {
29        version                     (q32), // version
30        glyph_count                 (u16), // numGlyphs
31        max_points                  (u16), // maxPoints
32        max_contours                (u16), // maxContours
33        max_composite_points        (u16), // maxCompositePoints
34        max_composite_contours      (u16), // maxCompositeContours
35        max_zones                   (u16), // maxZones
36        max_twilight_points         (u16), // maxTwilightPoints
37        max_storage                 (u16), // maxStorage
38        max_function_definitions    (u16), // maxFunctionDefs
39        max_instruction_definitions (u16), // maxInstructionDefs
40        max_stack_elements          (u16), // maxStackElements
41        max_size_of_instructions    (u16), // maxSizeOfInstructions
42        max_component_elements      (u16), // maxComponentElements
43        max_component_depth         (u16), // maxComponentDepth
44    }
45}
46
47impl MaximumProfile {
48    /// Return the number of glyphs.
49    pub fn glyph_count(&self) -> usize {
50        match self {
51            MaximumProfile::Version0(ref profile) => profile.glyph_count as usize,
52            MaximumProfile::Version1(ref profile) => profile.glyph_count as usize,
53        }
54    }
55}
56
57impl crate::value::Read for MaximumProfile {
58    fn read<T: crate::tape::Read>(tape: &mut T) -> Result<Self> {
59        Ok(match tape.peek::<q32>()? {
60            q32(0x00005000) => MaximumProfile::Version0(tape.take()?),
61            q32(0x00010000) => MaximumProfile::Version1(tape.take()?),
62            _ => raise!("found an unknown version of the maximum profile"),
63        })
64    }
65}