Crate fonttools

Source
Expand description

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.

Modules§

avar
The avar (Axis variations) table
cmap
The cmap (Character To Glyph Index Mapping) table
font
The main font object. Start here.
fvar
The fvar (Font variations) table
gasp
The gasp (Grid-fitting and Scan-conversion Procedure) table
glyf
The glyf (Glyf data) table
gvar
The gvar (Glyph variations) table
head
The head (Header) table
hhea
The hhea (Horizontal header) table
hmtx
The hmtx (Horizontal metrics) table
layout
OpenType Layout common tables
maxp
The maxp (Maximum profile) table
name
The name (Naming) table
os2
The OS/2 (OS/2 and Windows Metrics) table
otvar
OpenType Variations common tables
post
The post (PostScript) table
utils
Useful utilities