Skip to content

Commit

Permalink
Initial support for parsing the PANOSE number.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Zepeda committed Sep 7, 2024
1 parent daa00fc commit b2641a7
Show file tree
Hide file tree
Showing 5 changed files with 1,343 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/font-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ fn main() {
}
}

println!("{:?}", face.tables().os2.unwrap().panose());

println!("Elapsed: {}us", now.elapsed().as_micros());
}

Expand Down
11 changes: 11 additions & 0 deletions src/tables/os2.rs → src/tables/os2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! A [OS/2 and Windows Metrics Table](https://docs.microsoft.com/en-us/typography/opentype/spec/os2)
//! implementation.
pub mod panose;

use panose::Panose;

use crate::parser::Stream;
use crate::LineMetrics;

Expand All @@ -11,6 +15,7 @@ const Y_SUBSCRIPT_X_SIZE_OFFSET: usize = 10;
const Y_SUPERSCRIPT_X_SIZE_OFFSET: usize = 18;
const Y_STRIKEOUT_SIZE_OFFSET: usize = 26;
const Y_STRIKEOUT_POSITION_OFFSET: usize = 28;
const PANOSE_OFFSET: usize = 32;
const UNICODE_RANGES_OFFSET: usize = 42;
const SELECTION_OFFSET: usize = 62;
const TYPO_ASCENDER_OFFSET: usize = 68;
Expand Down Expand Up @@ -522,6 +527,12 @@ impl<'a> Table<'a> {
UnicodeRanges(n4 << 96 | n3 << 64 | n2 << 32 | n1)
}

/// Returns the [PANOSE classification](https://monotype.github.io/panose/pan1.htm) information.
pub fn panose(&self) -> Option<Panose> {
let mut s = Stream::new_at(self.data, PANOSE_OFFSET).unwrap();
s.read::<Panose>()
}

#[inline]
fn fs_selection(&self) -> u16 {
Stream::read_at::<u16>(self.data, SELECTION_OFFSET).unwrap_or(0)
Expand Down
Loading

0 comments on commit b2641a7

Please sign in to comment.