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
//! Parser for TrueType fonts.

#[macro_use]
mod macros;

mod number;
mod tag;
mod tape;

pub mod char_mapping;
pub mod font_header;
pub mod glyph_data;
pub mod glyph_mapping;
pub mod horizontal_header;
pub mod horizontal_metrics;
pub mod maximum_profile;
pub mod naming_table;
pub mod offset_table;
pub mod postscript;
pub mod windows_metrics;

pub use char_mapping::CharMapping;
pub use font_header::FontHeader;
pub use glyph_data::GlyphData;
pub use glyph_mapping::GlyphMapping;
pub use horizontal_header::HorizontalHeader;
pub use horizontal_metrics::HorizontalMetrics;
pub use maximum_profile::MaximumProfile;
pub use naming_table::NamingTable;
pub use number::{q16, q32};
pub use offset_table::OffsetTable;
pub use postscript::PostScript;
pub use tag::Tag;
pub use tape::{Tape, Value, Walue};
pub use windows_metrics::WindowsMetrics;

/// An error.
pub type Error = std::io::Error;

/// An error caused by another error.
#[derive(Debug)]
pub struct ErrorWithSource {
    pub description: String,
    pub source: Error,
}

/// A glyph identifier.
pub type GlyphID = u16;

/// A result.
pub type Result<T> = std::io::Result<T>;

impl std::fmt::Display for ErrorWithSource {
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(formatter, "{}, due to {}", self.description, self.source)
    }
}

impl std::error::Error for ErrorWithSource {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        Some(&self.source)
    }
}