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
//! The [maximum profile][1].
//!
//! [1]: https://learn.microsoft.com/en-us/typography/opentype/spec/maxp
use crate::{q32, Result};
/// A maximum profile.
#[derive(Clone, Debug)]
pub enum MaximumProfile {
/// Version 0.5.
Version0(MaximumProfile0),
/// Version 1.
Version1(MaximumProfile1),
}
table! {
/// A maximum profile of version 0.5.
#[derive(Copy)]
pub MaximumProfile0 {
version (q32), // version
glyph_count (u16), // numGlyphs
}
}
table! {
/// A maximum profile of version 1.
#[derive(Copy)]
pub MaximumProfile1 {
version (q32), // version
glyph_count (u16), // numGlyphs
max_points (u16), // maxPoints
max_contours (u16), // maxContours
max_composite_points (u16), // maxCompositePoints
max_composite_contours (u16), // maxCompositeContours
max_zones (u16), // maxZones
max_twilight_points (u16), // maxTwilightPoints
max_storage (u16), // maxStorage
max_function_definitions (u16), // maxFunctionDefs
max_instruction_definitions (u16), // maxInstructionDefs
max_stack_elements (u16), // maxStackElements
max_size_of_instructions (u16), // maxSizeOfInstructions
max_component_elements (u16), // maxComponentElements
max_component_depth (u16), // maxComponentDepth
}
}
impl MaximumProfile {
/// Return the number of glyphs.
pub fn glyph_count(&self) -> usize {
match self {
MaximumProfile::Version0(ref profile) => profile.glyph_count as usize,
MaximumProfile::Version1(ref profile) => profile.glyph_count as usize,
}
}
}
impl crate::value::Read for MaximumProfile {
fn read<T: crate::tape::Read>(tape: &mut T) -> Result<Self> {
Ok(match tape.peek::<q32>()? {
q32(0x00005000) => MaximumProfile::Version0(tape.take()?),
q32(0x00010000) => MaximumProfile::Version1(tape.take()?),
_ => raise!("found an unknown version of the maximum profile"),
})
}
}