#table #font #opentype #manipulating #version #reading #layout

fonttools

A library for reading, manipulating and writing OpenType font files

1 unstable release

0.1.0 Jun 10, 2021

#36 in #opentype


Used in 3 crates

Apache-2.0

380KB
9K SLoC

fonttools-rs

This is an attempt to write an Rust library to read, manipulate and write TTF/OTF files. It is in the extremely early stages of experimental development. Contributions are welcome.


lib.rs:

A library for parsing, manipulating and writing OpenType fonts

This is a prerelease version; it is not feature complete. Notably, variable fonts are supported, but GPOS/GSUB (OpenType Layout) is not.

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);

For information about creating and manipulating structures for each specific OpenType table, see the modules below. See the [font] module as the entry point to creating, parsing and saving an OpenType font.

Dependencies

~11–21MB
~272K SLoC