1 | //! A [Vertical Header Table]( |
2 | //! https://docs.microsoft.com/en-us/typography/opentype/spec/vhea) implementation. |
3 | |
4 | use crate::parser::Stream; |
5 | |
6 | /// A [Vertical Header Table](https://docs.microsoft.com/en-us/typography/opentype/spec/vhea). |
7 | #[derive (Clone, Copy, Default, Debug)] |
8 | pub struct Table { |
9 | /// Face ascender. |
10 | pub ascender: i16, |
11 | /// Face descender. |
12 | pub descender: i16, |
13 | /// Face line gap. |
14 | pub line_gap: i16, |
15 | /// Number of metrics in the `vmtx` table. |
16 | pub number_of_metrics: u16, |
17 | } |
18 | |
19 | impl Table { |
20 | /// Parses a table from raw data. |
21 | pub fn parse(data: &[u8]) -> Option<Self> { |
22 | // Do not check the exact length, because some fonts include |
23 | // padding in table's length in table records, which is incorrect. |
24 | if data.len() < 36 { |
25 | return None; |
26 | } |
27 | |
28 | let mut s = Stream::new(data); |
29 | s.skip::<u32>(); // version |
30 | let ascender = s.read::<i16>()?; |
31 | let descender = s.read::<i16>()?; |
32 | let line_gap = s.read::<i16>()?; |
33 | s.advance(24); |
34 | let number_of_metrics = s.read::<u16>()?; |
35 | |
36 | Some(Table { |
37 | ascender, |
38 | descender, |
39 | line_gap, |
40 | number_of_metrics, |
41 | }) |
42 | } |
43 | } |
44 | |