more output on inspect; optionally print all symbols
This commit is contained in:
parent
7147a92741
commit
069f89a809
2 changed files with 42 additions and 7 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -153,11 +153,15 @@ struct Index {
|
||||||
splitters: Vec<Splitter>,
|
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 read_file = std::fs::read(path).unwrap();
|
||||||
let fd = sff::decode(&read_file);
|
let fd = sff::decode(&read_file);
|
||||||
for i in 32..128 {
|
fd.print_header();
|
||||||
fd.print_symbol(fd.find_codepoint(i).unwrap());
|
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 {
|
enum Command {
|
||||||
Inspect {
|
Inspect {
|
||||||
path: String,
|
path: String,
|
||||||
|
#[arg(long)]
|
||||||
|
show_glyphs: bool,
|
||||||
},
|
},
|
||||||
Create {
|
Create {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
|
@ -289,7 +295,7 @@ fn str_to_encoding(s: &str) -> sff::Encoding {
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
match cli.cmd {
|
match cli.cmd {
|
||||||
Command::Inspect { path } => do_inspect(path),
|
Command::Inspect { path, show_glyphs } => do_inspect(path, show_glyphs),
|
||||||
Command::Create {
|
Command::Create {
|
||||||
font_dir,
|
font_dir,
|
||||||
encoding,
|
encoding,
|
||||||
|
|
|
||||||
35
src/sff.rs
35
src/sff.rs
|
|
@ -1,5 +1,5 @@
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Table {
|
pub struct TableDesc {
|
||||||
first_codepoint: u32,
|
first_codepoint: u32,
|
||||||
num_codepoints: u32,
|
num_codepoints: u32,
|
||||||
offset: u32,
|
offset: u32,
|
||||||
|
|
@ -103,7 +103,7 @@ pub struct FileDesc<'a> {
|
||||||
char_width: usize,
|
char_width: usize,
|
||||||
char_height: usize,
|
char_height: usize,
|
||||||
encoding: Encoding,
|
encoding: Encoding,
|
||||||
tables: Vec<Table>,
|
tables: Vec<TableDesc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
|
@ -176,6 +176,35 @@ impl<'a> FileDesc<'a> {
|
||||||
println!();
|
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<'_> {
|
pub fn decode(input: &[u8]) -> FileDesc<'_> {
|
||||||
|
|
@ -198,7 +227,7 @@ pub fn decode(input: &[u8]) -> FileDesc<'_> {
|
||||||
let mut tables = Vec::new();
|
let mut tables = Vec::new();
|
||||||
let mut coff = 0x10;
|
let mut coff = 0x10;
|
||||||
for _ in 0..num_tables {
|
for _ in 0..num_tables {
|
||||||
let tab = Table {
|
let tab = TableDesc {
|
||||||
first_codepoint: get_u32(input, coff),
|
first_codepoint: get_u32(input, coff),
|
||||||
num_codepoints: get_u32(input, coff + 4),
|
num_codepoints: get_u32(input, coff + 4),
|
||||||
offset: get_u32(input, coff + 8),
|
offset: get_u32(input, coff + 8),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue