ttf_parser/tables/hhea.rs
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
//! A [Horizontal Header Table](
//! https://docs.microsoft.com/en-us/typography/opentype/spec/hhea) implementation.
use crate::parser::Stream;
/// A [Horizontal Header Table](https://docs.microsoft.com/en-us/typography/opentype/spec/hhea).
#[derive(Clone, Copy, Debug)]
pub struct Table {
/// Face ascender.
pub ascender: i16,
/// Face descender.
pub descender: i16,
/// Face line gap.
pub line_gap: i16,
/// Number of metrics in the `hmtx` table.
pub number_of_metrics: u16,
}
impl Table {
/// Parses a table from raw data.
pub fn parse(data: &[u8]) -> Option<Self> {
// Do not check the exact length, because some fonts include
// padding in table's length in table records, which is incorrect.
if data.len() < 36 {
return None;
}
let mut s = Stream::new(data);
s.skip::<u32>(); // version
let ascender = s.read::<i16>()?;
let descender = s.read::<i16>()?;
let line_gap = s.read::<i16>()?;
s.advance(24);
let number_of_metrics = s.read::<u16>()?;
Some(Table {
ascender,
descender,
line_gap,
number_of_metrics,
})
}
}