fonttools-rs
This is an attempt to write an Rust library to read, manipulate and write TTF/OTF files. It is in the early stages of development. Contributions are welcome.
Example usage
use fonttools::font::{self, Font, Table};
use fonttools::name::{name, NameRecord, NameRecordID};
// Load a font (tables are lazy-loaded)
let fontfile = File::open("Test.otf").unwrap();
use std::fs::File;
let mut myfont = font::load(fontfile).expect("Could not load font");
// Access an existing table
if let Table::Name(name_table) = myfont.get_table(b"name")
.expect("Error reading name table")
.expect("There was no name table") {
// Manipulate the table (table-specific)
name_table.records.push(NameRecord::windows_unicode(
NameRecordID::LicenseURL,
"http://opensource.org/licenses/OFL-1.1"
));
}
let mut outfile = File::create("Test-with-OFL.otf").expect("Could not create file");
myfont.save(&mut outfile);
See the documentation for more details, and the fonttools-cli utilities (installable via cargo install fonttools_cli
) for code examples.