ttf_parser/tables/
maxp.rs

1//! A [Maximum Profile Table](
2//! https://docs.microsoft.com/en-us/typography/opentype/spec/maxp) implementation.
3
4use core::num::NonZeroU16;
5
6use crate::parser::Stream;
7
8/// A [Maximum Profile Table](https://docs.microsoft.com/en-us/typography/opentype/spec/maxp).
9#[derive(Clone, Copy, Debug)]
10pub struct Table {
11    /// The total number of glyphs in the face.
12    pub number_of_glyphs: NonZeroU16,
13}
14
15impl Table {
16    /// Parses a table from raw data.
17    pub fn parse(data: &[u8]) -> Option<Self> {
18        let mut s = Stream::new(data);
19        let version = s.read::<u32>()?;
20        if !(version == 0x00005000 || version == 0x00010000) {
21            return None;
22        }
23
24        let n = s.read::<u16>()?;
25        let number_of_glyphs = NonZeroU16::new(n)?;
26        Some(Table { number_of_glyphs })
27    }
28}