ttf_parser/tables/
vorg.rs1use crate::GlyphId;
5use crate::parser::{Stream, FromData, LazyArray16};
6
7#[derive(Clone, Copy, Debug)]
10pub struct VerticalOriginMetrics {
11 pub glyph_id: GlyphId,
13 pub y: i16,
15}
16
17impl FromData for VerticalOriginMetrics {
18 const SIZE: usize = 4;
19
20 #[inline]
21 fn parse(data: &[u8]) -> Option<Self> {
22 let mut s = Stream::new(data);
23 Some(VerticalOriginMetrics {
24 glyph_id: s.read::<GlyphId>()?,
25 y: s.read::<i16>()?,
26 })
27 }
28}
29
30
31#[derive(Clone, Copy, Debug)]
33pub struct Table<'a> {
34 pub default_y: i16,
36 pub metrics: LazyArray16<'a, VerticalOriginMetrics>,
40}
41
42impl<'a> Table<'a> {
43 pub fn parse(data: &'a [u8]) -> Option<Self> {
45 let mut s = Stream::new(data);
46
47 let version = s.read::<u32>()?;
48 if version != 0x00010000 {
49 return None;
50 }
51
52 let default_y = s.read::<i16>()?;
53 let count = s.read::<u16>()?;
54 let metrics = s.read_array16::<VerticalOriginMetrics>(count)?;
55
56 Some(Table {
57 default_y,
58 metrics,
59 })
60 }
61
62 pub fn glyph_y_origin(&self, glyph_id: GlyphId) -> i16 {
64 self.metrics.binary_search_by(|m| m.glyph_id.cmp(&glyph_id))
65 .map(|(_, m)| m.y)
66 .unwrap_or(self.default_y)
67 }
68}