ttf_parser/tables/
vorg.rs
1use crate::GlyphId;
4use crate::parser::{Stream, FromData, LazyArray16};
5
6
7#[derive(Clone, Copy)]
8struct VertOriginYMetrics {
9 glyph_index: GlyphId,
10 vert_origin_y: i16,
11}
12
13impl FromData for VertOriginYMetrics {
14 const SIZE: usize = 4;
15
16 #[inline]
17 fn parse(data: &[u8]) -> Option<Self> {
18 let mut s = Stream::new(data);
19 Some(VertOriginYMetrics {
20 glyph_index: s.read::<GlyphId>()?,
21 vert_origin_y: s.read::<i16>()?,
22 })
23 }
24}
25
26
27#[derive(Clone, Copy)]
28pub struct Table<'a> {
29 default_y: i16,
30 origins: LazyArray16<'a, VertOriginYMetrics>,
31}
32
33impl<'a> Table<'a> {
34 pub fn parse(data: &'a [u8]) -> Option<Self> {
35 let mut s = Stream::new(data);
36
37 let version: u32 = s.read()?;
38 if version != 0x00010000 {
39 return None;
40 }
41
42 let default_y: i16 = s.read()?;
43 let count: u16 = s.read()?;
44 let origins = s.read_array16::<VertOriginYMetrics>(count)?;
45
46 Some(Table {
47 default_y,
48 origins,
49 })
50 }
51
52 pub fn glyph_y_origin(&self, glyph_id: GlyphId) -> i16 {
53 self.origins.binary_search_by(|m| m.glyph_index.cmp(&glyph_id))
54 .map(|(_, m)| m.vert_origin_y)
55 .unwrap_or(self.default_y)
56 }
57}