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