use std::{fs::File, io::{BufReader, Read, Seek, SeekFrom}}; use bincode::{de::read, Result}; use log::debug; use serde::Deserialize; use super::{deserialize, table_directory::{FontTable, TableDirectoryRecord}}; #[derive(Debug, Deserialize)] pub struct MaximumProfileV05 { pub num_glyphs: u16 } #[derive(Debug, Deserialize)] pub struct MaximumProfileV10 { pub num_glyphs: u16, pub max_points: u16, pub max_countours: u16, pub max_composite_points: u16, pub max_composite_countours: u16, pub max_zones: u16, pub max_twilight_points: u16, pub max_storage: u16, pub max_function_defs: u16, pub max_instruction_defs: u16, pub max_stack_elements: u16, pub max_size_of_instructions: u16, pub max_component_elements: u16, pub max_component_depth: u16 } #[derive(Debug)] pub enum MaximumProfile { V0_5(MaximumProfileV05), V1_0(MaximumProfileV10) } impl MaximumProfile { pub fn num_glyphs(&self) -> u16 { match self { Self::V0_5(profile) => profile.num_glyphs, Self::V1_0(profile) => profile.num_glyphs } } } impl FontTable for MaximumProfile { const TAG: &'static str = "maxp"; type InitData = (); fn decode(mut reader: BufReader, _: &TableDirectoryRecord, _: Option) -> Result where Self: Sized { let version: u32 = deserialize(reader.by_ref())?; debug!("maxp table version: {:#08x}", version); match version { 0x00005000 => todo!(), 0x00010000 => Ok(MaximumProfile::V1_0(deserialize(reader.by_ref())?)), _ => { return Err(bincode::ErrorKind::Custom("Invalid maxp table version".into()).into()); } } } }