more output on inspect; optionally print all symbols

This commit is contained in:
uosfz 2025-08-05 20:07:16 +02:00
parent 7147a92741
commit 069f89a809
Signed by: uosfz
SSH key fingerprint: SHA256:FlktuluyhTQg3jHZNLKwxOOC5hbfrUXM0tz3IA3lGJo
2 changed files with 42 additions and 7 deletions

View file

@ -153,11 +153,15 @@ struct Index {
splitters: Vec<Splitter>,
}
fn do_inspect<P: AsRef<Path>>(path: P) {
fn do_inspect<P: AsRef<Path>>(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,

View file

@ -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<Table>,
tables: Vec<TableDesc>,
}
#[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<Item = GlyphOffset> + '_ {
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),