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
use crate::Rect;
use crate::parser::{Stream, Fixed};
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum IndexToLocationFormat {
Short,
Long,
}
#[derive(Clone, Copy, Debug)]
pub struct Table {
pub units_per_em: u16,
pub global_bbox: Rect,
pub index_to_location_format: IndexToLocationFormat,
}
impl Table {
pub fn parse(data: &[u8]) -> Option<Self> {
if data.len() != 54 {
return None
}
let mut s = Stream::new(data);
s.skip::<u32>();
s.skip::<Fixed>();
s.skip::<u32>();
s.skip::<u32>();
s.skip::<u16>();
let units_per_em = s.read::<u16>()?;
s.skip::<u64>();
s.skip::<u64>();
let x_min = s.read::<i16>()?;
let y_min = s.read::<i16>()?;
let x_max = s.read::<i16>()?;
let y_max = s.read::<i16>()?;
s.skip::<u16>();
s.skip::<u16>();
s.skip::<i16>();
let index_to_location_format = s.read::<u16>()?;
if !(units_per_em >= 16 && units_per_em <= 16384) {
return None;
}
let index_to_location_format = match index_to_location_format {
0 => IndexToLocationFormat::Short,
1 => IndexToLocationFormat::Long,
_ => return None,
};
Some(Table {
units_per_em,
global_bbox: Rect { x_min, y_min, x_max, y_max },
index_to_location_format,
})
}
}