Skip to main content

cff_probe/
cff_probe.rs

1//! Independent-oracle interchange: one line per original glyph command.
2use fmd_font::{Font, cff::Command};
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let args: Vec<_> = std::env::args().collect();
5    let font = Font::parse(std::fs::read(&args[1])?)?;
6    for gid in 0..font.num_glyphs {
7        let outline = font.cff_outline(gid)?;
8        println!("G {gid} {} {}", outline.advance, outline.lsb);
9        for c in outline.commands {
10            match c {
11                Command::Move(p) => println!("M {} {}", p.x, p.y),
12                Command::Line(p) => println!("L {} {}", p.x, p.y),
13                Command::Curve(a, b, c) => {
14                    println!("C {} {} {} {} {} {}", a.x, a.y, b.x, b.y, c.x, c.y)
15                }
16                Command::Close => println!("Z"),
17            }
18        }
19    }
20    if let Some(path) = args.get(2) {
21        let subset = font.try_subset_glyphs(&[1, 5, 73, 100, 500, 1000, 2000, 3000], &[])?;
22        std::fs::write(path, subset.bytes)?;
23    }
24    Ok(())
25}