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
use std::io::{Read, Seek};
use std::path::Path;
use crate::{Case, File, Number, Result};
pub struct Font {
pub units_per_em: Number,
pub clipping_ascender: Number,
pub ascender: Number,
pub cap_height: Number,
pub x_height: Number,
pub baseline: Number,
pub descender: Number,
pub clipping_descender: Number,
pub line_gap: Number,
pub case: Box<dyn Case>,
}
impl Font {
#[inline]
pub fn open<T: AsRef<Path>>(path: T) -> Result<Self> {
Font::read(&mut ::std::fs::File::open(path)?)
}
pub fn read<T: Read + Seek>(tape: &mut T) -> Result<Self> {
let File { mut fonts, .. } = File::read(tape)?;
match fonts.len() {
0 => raise!("found an empty file"),
1 => return Ok(fonts.remove(0)),
_ => raise!("files with multiple fonts are not supported yet"),
}
}
}
dereference! { Font::case => Box<dyn Case> }