we (web engine): Experimental web browser project to understand the limits of Claude
at float-layout 60 lines 1.9 kB view raw
1//! `hhea` — Horizontal Header table. 2//! 3//! Contains global horizontal layout metrics. 4//! Reference: <https://learn.microsoft.com/en-us/typography/opentype/spec/hhea> 5 6use crate::font::parse::Reader; 7use crate::font::FontError; 8 9/// Parsed `hhea` table. 10#[derive(Debug)] 11pub struct HheaTable { 12 /// Typographic ascent (in font units). 13 pub ascent: i16, 14 /// Typographic descent (typically negative, in font units). 15 pub descent: i16, 16 /// Typographic line gap (in font units). 17 pub line_gap: i16, 18 /// Maximum advance width across all glyphs. 19 pub advance_width_max: u16, 20 /// Minimum left side bearing across all glyphs. 21 pub min_left_side_bearing: i16, 22 /// Minimum right side bearing across all glyphs. 23 pub min_right_side_bearing: i16, 24 /// Maximum x extent (max(lsb + (xMax - xMin))). 25 pub x_max_extent: i16, 26 /// Number of entries in the hmtx table's longHorMetric array. 27 pub num_long_hor_metrics: u16, 28} 29 30impl HheaTable { 31 /// Parse the `hhea` table from raw bytes. 32 pub fn parse(data: &[u8]) -> Result<HheaTable, FontError> { 33 let r = Reader::new(data); 34 if r.len() < 36 { 35 return Err(FontError::MalformedTable("hhea")); 36 } 37 38 // skip version(4) 39 let ascent = r.i16(4)?; 40 let descent = r.i16(6)?; 41 let line_gap = r.i16(8)?; 42 let advance_width_max = r.u16(10)?; 43 let min_left_side_bearing = r.i16(12)?; 44 let min_right_side_bearing = r.i16(14)?; 45 let x_max_extent = r.i16(16)?; 46 // skip caretSlopeRise(2), caretSlopeRun(2), caretOffset(2), reserved(8), metricDataFormat(2) 47 let num_long_hor_metrics = r.u16(34)?; 48 49 Ok(HheaTable { 50 ascent, 51 descent, 52 line_gap, 53 advance_width_max, 54 min_left_side_bearing, 55 min_right_side_bearing, 56 x_max_extent, 57 num_long_hor_metrics, 58 }) 59 } 60}