1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// https://docs.microsoft.com/en-us/typography/opentype/spec/post use crate::parser::SafeStream; use crate::{Font, LineMetrics}; // We already checked that `post` table has a valid length, // so it's safe to use `SafeStream`. impl<'a> Font<'a> { /// Parses font's underline metrics. /// /// Returns `None` when `post` table is not present. #[inline] pub fn underline_metrics(&self) -> Option<LineMetrics> { const UNDERLINE_POSITION_OFFSET: usize = 8; let mut s = SafeStream::new_at(self.post?, UNDERLINE_POSITION_OFFSET); // Do not change the order. In the `post` table, line position is set before thickness. Some(LineMetrics { position: s.read(), thickness: s.read(), }) } }