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
80
use core::num::NonZeroU16;
use crate::GlyphId;
use crate::parser::{Stream, FromData, LazyArray32};
use crate::aat;
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Default, Debug)]
pub struct Point {
pub x: i16,
pub y: i16,
}
impl FromData for Point {
const SIZE: usize = 4;
#[inline]
fn parse(data: &[u8]) -> Option<Self> {
let mut s = Stream::new(data);
Some(Point {
x: s.read::<i16>()?,
y: s.read::<i16>()?,
})
}
}
#[derive(Clone)]
pub struct Table<'a> {
lookup: aat::Lookup<'a>,
glyphs_data: &'a [u8],
}
impl core::fmt::Debug for Table<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "Table {{ ... }}")
}
}
impl<'a> Table<'a> {
pub fn parse(number_of_glyphs: NonZeroU16, data: &'a [u8]) -> Option<Self> {
let mut s = Stream::new(data);
let version = s.read::<u16>()?;
if version != 0 {
return None;
}
s.skip::<u16>();
let lookup_table = s.read_at_offset32(data)?;
let glyphs_data = s.read_at_offset32(data)?;
Some(Table {
lookup: aat::Lookup::parse(number_of_glyphs, lookup_table)?,
glyphs_data,
})
}
pub fn points(&self, glyph_id: GlyphId) -> Option<LazyArray32<'a, Point>> {
let offset = self.lookup.value(glyph_id)?;
let mut s = Stream::new_at(self.glyphs_data, usize::from(offset))?;
let number_of_points = s.read::<u32>()?;
s.read_array32::<Point>(number_of_points)
}
}