ttf_parser/tables/
ankr.rs1use core::num::NonZeroU16;
5
6use crate::GlyphId;
7use crate::parser::{Stream, FromData, LazyArray32};
8use crate::aat;
9
10#[allow(missing_docs)]
12#[derive(Clone, Copy, PartialEq, Default, Debug)]
13pub struct Point {
14 pub x: i16,
15 pub y: i16,
16}
17
18impl FromData for Point {
19 const SIZE: usize = 4;
20
21 #[inline]
22 fn parse(data: &[u8]) -> Option<Self> {
23 let mut s = Stream::new(data);
24 Some(Point {
25 x: s.read::<i16>()?,
26 y: s.read::<i16>()?,
27 })
28 }
29}
30
31
32#[derive(Clone)]
35pub struct Table<'a> {
36 lookup: aat::Lookup<'a>,
37 glyphs_data: &'a [u8],
41}
42
43impl core::fmt::Debug for Table<'_> {
44 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
45 write!(f, "Table {{ ... }}")
46 }
47}
48
49impl<'a> Table<'a> {
50 pub fn parse(number_of_glyphs: NonZeroU16, data: &'a [u8]) -> Option<Self> {
54 let mut s = Stream::new(data);
55
56 let version = s.read::<u16>()?;
57 if version != 0 {
58 return None;
59 }
60
61 s.skip::<u16>(); let lookup_table = s.read_at_offset32(data)?;
64 let glyphs_data = s.read_at_offset32(data)?;
65
66 Some(Table {
67 lookup: aat::Lookup::parse(number_of_glyphs, lookup_table)?,
68 glyphs_data,
69 })
70 }
71
72 pub fn points(&self, glyph_id: GlyphId) -> Option<LazyArray32<'a, Point>> {
74 let offset = self.lookup.value(glyph_id)?;
75
76 let mut s = Stream::new_at(self.glyphs_data, usize::from(offset))?;
77 let number_of_points = s.read::<u32>()?;
78 s.read_array32::<Point>(number_of_points)
79 }
80}