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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use font_types::Tag;
use crate::font_data::FontData;
pub trait FontRead<'a>: Sized {
fn read(data: FontData<'a>) -> Result<Self, ReadError>;
}
pub trait ReadArgs {
type Args: Copy;
}
pub trait FontReadWithArgs<'a>: Sized + ReadArgs {
fn read_with_args(data: FontData<'a>, args: &Self::Args) -> Result<Self, ReadError>;
}
pub trait Format<T> {
const FORMAT: T;
}
pub trait ComputeSize: ReadArgs {
fn compute_size(args: &Self::Args) -> usize;
}
#[derive(Debug, Clone)]
pub enum ReadError {
OutOfBounds,
InvalidFormat(i64),
InvalidSfnt(u32),
InvalidArrayLen,
ValidationError,
NullOffset,
TableIsMissing(Tag),
MalformedData(&'static str),
}
impl std::fmt::Display for ReadError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ReadError::OutOfBounds => write!(f, "An offset was out of bounds"),
ReadError::InvalidFormat(x) => write!(f, "Invalid format '{x}'"),
ReadError::InvalidSfnt(ver) => write!(f, "Invalid sfnt version 0x{ver:08X}"),
ReadError::InvalidArrayLen => {
write!(f, "Specified array length not a multiple of item size")
}
ReadError::ValidationError => write!(f, "A validation error occured"),
ReadError::NullOffset => write!(f, "An offset was unexpectedly null"),
ReadError::TableIsMissing(tag) => write!(f, "the {tag} table is missing"),
ReadError::MalformedData(msg) => write!(f, "Malformed data: '{msg}'"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ReadError {}