sr-aef 0.1.2

Uncompile OpenType fonts back into Adobe feature file (fea) source code
Documentation

sr-aef

crates.io docs.rs

sr-aef "uncompiles" an OpenType/TrueType font back into Adobe Feature File (fea) source code. It reads the OpenType layout tables (GSUB, GPOS and, optionally, GDEF) out of a compiled binary font and reconstructs an equivalent feature file using the fea-rs-ast AST.

Because binary fonts lose the original structure of their layout code (lookup splitting, class naming, comments, ...), the output is a faithful functional reconstruction rather than a byte-for-byte copy of the original source.

sr-aef is used by babelfont when compiling a font back to TrueType, and can also be used directly as a "TTF to fea" tool.

Library usage

The main entry points are uncompile, uncompile_bytes, and uncompile_context.

use sr_aef::{fea_rs_ast::AsFea, uncompile_bytes};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let data = std::fs::read("MyFont.ttf")?;
    let feature_file = uncompile_bytes(&data, true)?; // `true` also uncompiles GDEF
    println!("{}", feature_file.as_fea(""));
    Ok(())
}

The returned value is a fea_rs_ast::FeatureFile; call .as_fea() (via the AsFea trait) to render it as feature file text.

For tools that want the component parts rather than a finished feature file, uncompile_context returns an UncompileContext with the reconstructed lookups, classes, mark classes, anchors and language systems, ready to be placed wherever you need them.

Version pinning

sr-aef re-exports the exact versions of fea-rs-ast and skrifa that it is built against (sr_aef::fea_rs_ast and sr_aef::skrifa). If you are already using those crates, prefer the re-exports so that the AST and font-reading types line up with what sr-aef produces.

Command-line usage

A small CLI is available behind the cli feature:

cargo install sr-aef --features cli

or from PyPI:

pip install sr-aef

Print the reconstructed feature file for a font:

sr-aef MyFont.ttf

Dump the intermediate, partially-uncompiled context as JSON (useful for debugging):

sr-aef --debug MyFont.ttf

Status

sr-aef is in early development and its API may change between releases.

License

sr-aef is available under the MIT or Apache-2.0 licenses, at your option. See LICENSE-MIT and LICENSE-APACHE.