we (web engine): Experimental web browser project to understand the limits of Claude
1//! `maxp` — Maximum Profile table.
2//!
3//! Contains the number of glyphs in the font plus (for TrueType) various
4//! maximum values used for memory allocation.
5//! Reference: <https://learn.microsoft.com/en-us/typography/opentype/spec/maxp>
6
7use crate::font::parse::Reader;
8use crate::font::FontError;
9
10/// Parsed `maxp` table.
11#[derive(Debug)]
12pub struct MaxpTable {
13 /// Version (0x00005000 for CFF, 0x00010000 for TrueType).
14 pub version: u32,
15 /// Total number of glyphs in the font.
16 pub num_glyphs: u16,
17}
18
19impl MaxpTable {
20 /// Parse the `maxp` table from raw bytes.
21 pub fn parse(data: &[u8]) -> Result<MaxpTable, FontError> {
22 let r = Reader::new(data);
23 if r.len() < 6 {
24 return Err(FontError::MalformedTable("maxp"));
25 }
26
27 let version = r.u32(0)?;
28 let num_glyphs = r.u16(4)?;
29
30 Ok(MaxpTable {
31 version,
32 num_glyphs,
33 })
34 }
35}