1 //! Hinting error definitions.
2 
3 /// Errors that may occur when interpreting TrueType bytecode.
4 #[derive(Clone, Debug)]
5 pub enum HintErrorKind {
6     UnexpectedEndOfBytecode,
7     InvalidOpcode(u8),
8     DefinitionInGlyphProgram,
9     NestedDefinition,
10     InvalidDefintionIndex(usize),
11     ValueStackOverflow,
12     ValueStackUnderflow,
13     CallStackOverflow,
14     CallStackUnderflow,
15     InvalidStackValue(i32),
16     InvalidPointIndex(usize),
17     InvalidPointRange(usize, usize),
18     InvalidContourIndex(usize),
19     InvalidCvtIndex(usize),
20     InvalidStorageIndex(usize),
21     DivideByZero,
22     InvalidZoneIndex(i32),
23     NegativeLoopCounter,
24     InvalidJump,
25 }
26 
27 impl core::fmt::Display for HintErrorKind {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result28     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29         match self {
30             Self::UnexpectedEndOfBytecode => write!(f, "unexpected end of bytecode"),
31             Self::InvalidOpcode(opcode) => write!(f, "invalid instruction opcode {opcode}"),
32             Self::DefinitionInGlyphProgram => {
33                 write!(f, "FDEF or IDEF instruction present in glyph program")
34             }
35             Self::NestedDefinition => write!(
36                 f,
37                 "FDEF or IDEF instruction present in another FDEF or IDEF block"
38             ),
39             Self::InvalidDefintionIndex(index) => write!(
40                 f,
41                 "invalid function or instruction definition index {index}"
42             ),
43             Self::ValueStackOverflow => write!(f, "value stack overflow"),
44             Self::ValueStackUnderflow => write!(f, "value stack underflow"),
45             Self::CallStackOverflow => write!(f, "call stack overflow"),
46             Self::CallStackUnderflow => write!(f, "call stack underflow"),
47             Self::InvalidStackValue(value) => write!(
48                 f,
49                 "stack value {value} was invalid for the current operation"
50             ),
51             Self::InvalidPointIndex(index) => write!(f, "point index {index} was out of bounds"),
52             Self::InvalidPointRange(start, end) => {
53                 write!(f, "point range {start}..{end} was out of bounds")
54             }
55             Self::InvalidContourIndex(index) => {
56                 write!(f, "contour index {index} was out of bounds")
57             }
58             Self::InvalidCvtIndex(index) => write!(f, "cvt index {index} was out of bounds"),
59             Self::InvalidStorageIndex(index) => {
60                 write!(f, "storage area index {index} was out of bounds")
61             }
62             Self::DivideByZero => write!(f, "attempt to divide by 0"),
63             Self::InvalidZoneIndex(index) => write!(
64                 f,
65                 "zone index {index} was invalid (only 0 or 1 are permitted)"
66             ),
67             Self::NegativeLoopCounter => {
68                 write!(f, "attempt to set the loop counter to a negative value")
69             }
70             Self::InvalidJump => write!(f, "the target of a jump instruction was invalid"),
71         }
72     }
73 }
74