diff --git a/src/main.rs b/src/main.rs index 07eb17a..3445213 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,11 +153,15 @@ struct Index { splitters: Vec, } -fn do_inspect>(path: P) { +fn do_inspect>(path: P, show_glyhs: bool) { let read_file = std::fs::read(path).unwrap(); let fd = sff::decode(&read_file); - for i in 32..128 { - fd.print_symbol(fd.find_codepoint(i).unwrap()); + fd.print_header(); + fd.print_table_descs(); + if show_glyhs { + for off in fd.valid_glyph_offsets() { + fd.print_symbol(off); + } } } @@ -251,6 +255,8 @@ struct Cli { enum Command { Inspect { path: String, + #[arg(long)] + show_glyphs: bool, }, Create { #[arg(long)] @@ -289,7 +295,7 @@ fn str_to_encoding(s: &str) -> sff::Encoding { fn main() { let cli = Cli::parse(); match cli.cmd { - Command::Inspect { path } => do_inspect(path), + Command::Inspect { path, show_glyphs } => do_inspect(path, show_glyphs), Command::Create { font_dir, encoding, diff --git a/src/sff.rs b/src/sff.rs index 3f154e5..8651208 100644 --- a/src/sff.rs +++ b/src/sff.rs @@ -1,5 +1,5 @@ #[derive(Debug)] -struct Table { +pub struct TableDesc { first_codepoint: u32, num_codepoints: u32, offset: u32, @@ -103,7 +103,7 @@ pub struct FileDesc<'a> { char_width: usize, char_height: usize, encoding: Encoding, - tables: Vec, + tables: Vec, } #[derive(Debug, Copy, Clone)] @@ -176,6 +176,35 @@ impl<'a> FileDesc<'a> { println!(); } } + + pub fn print_header(&self) { + println!("sff {{"); + println!(" char_width: {}", self.char_width); + println!(" char_height: {}", self.char_height); + println!(" encoding: {:?}", self.encoding); + println!(" number of tables: {}", self.tables.len()); + println!("}}"); + } + + pub fn print_table_descs(&self) { + for table in &self.tables { + println!("table {{"); + println!( + " first: {} ({:0>4x})", + table.first_codepoint, table.first_codepoint + ); + println!(" number: {}", table.num_codepoints); + println!(" file offset: {:0>8x}", table.offset); + println!("}}"); + } + } + + pub fn valid_glyph_offsets(&self) -> impl Iterator + '_ { + self.tables.iter().flat_map(|tab| { + (tab.first_codepoint..tab.first_codepoint + tab.num_codepoints) + .map(|c| self.find_codepoint(c).unwrap()) + }) + } } pub fn decode(input: &[u8]) -> FileDesc<'_> { @@ -198,7 +227,7 @@ pub fn decode(input: &[u8]) -> FileDesc<'_> { let mut tables = Vec::new(); let mut coff = 0x10; for _ in 0..num_tables { - let tab = Table { + let tab = TableDesc { first_codepoint: get_u32(input, coff), num_codepoints: get_u32(input, coff + 4), offset: get_u32(input, coff + 8),