ttf_parser/tables/
head.rs1use crate::Rect;
5use crate::parser::{Stream, Fixed};
6
7#[allow(missing_docs)]
10#[derive(Clone, Copy, PartialEq, Debug)]
11pub enum IndexToLocationFormat {
12 Short,
13 Long,
14}
15
16
17#[derive(Clone, Copy, Debug)]
19pub struct Table {
20 pub units_per_em: u16,
24 pub global_bbox: Rect,
26 pub index_to_location_format: IndexToLocationFormat,
29}
30
31impl Table {
32 pub fn parse(data: &[u8]) -> Option<Self> {
34 if data.len() != 54 {
35 return None
36 }
37
38 let mut s = Stream::new(data);
39 s.skip::<u32>(); s.skip::<Fixed>(); s.skip::<u32>(); s.skip::<u32>(); s.skip::<u16>(); let units_per_em = s.read::<u16>()?;
45 s.skip::<u64>(); s.skip::<u64>(); let x_min = s.read::<i16>()?;
48 let y_min = s.read::<i16>()?;
49 let x_max = s.read::<i16>()?;
50 let y_max = s.read::<i16>()?;
51 s.skip::<u16>(); s.skip::<u16>(); s.skip::<i16>(); let index_to_location_format = s.read::<u16>()?;
55
56 if !(units_per_em >= 16 && units_per_em <= 16384) {
57 return None;
58 }
59
60 let index_to_location_format = match index_to_location_format {
61 0 => IndexToLocationFormat::Short,
62 1 => IndexToLocationFormat::Long,
63 _ => return None,
64 };
65
66 Some(Table {
67 units_per_em,
68 global_bbox: Rect { x_min, y_min, x_max, y_max },
69 index_to_location_format,
70 })
71 }
72}