Skip to main content

Crate fontoxide_ttlib

Crate fontoxide_ttlib 

Source
Expand description

Port of fontTools.ttLib: the Font object (TTFont), sfnt/TTC/WOFF/WOFF2 containers, table implementations, and TTX serialization.

use fontoxide_ttlib::{Font, ReadOptions, TtxOptions, tables::Head};

let data = std::fs::read("font.ttf")?;
let mut font = Font::read(data, ReadOptions::default())?;
let head: &mut Head = font.require::<Head>()?;
println!("{}", head.units_per_em);
let ttx = font.to_ttx(&TtxOptions::default())?;

§Features

The features are fontTools’ extras, all on by default. Without one, fontoxide behaves as fontTools does without that Python package:

FeaturefontTools extra (package)Without it
woffwoff (brotli, zopfli)reading and writing WOFF 2.0, and WOFF 1.0 with WriteOptions::use_zopfli, fail with Error::Import
graphitegraphite (lz4)LZ4-compressed Silf and Glat tables are kept compressed, with a warning
pathopspathops (skia-pathops)remove_overlaps and the command line remove_overlaps::main fail with Error::Import
repackerrepacker (uharfbuzz)GSUB and GPOS are packed with fontTools’ serializer; Font::use_harfbuzz_repacker Some(true) fails with Error::Import

Re-exports§

pub use collection::TtCollection;
pub use font::Font;
pub use font::Progress;
pub use font::ReadOptions;
pub use font::TableKey;
pub use font::TtxOptions;
pub use font::WriteOptions;
pub use glyph_order::GlyphOrder;
pub use glyph_set::GlyphSet;
pub use sfnt::Flavor;
pub use sfnt::FlavorData;
pub use table::DefaultTable;
pub use table::Table;
pub use table::TableType;
pub use table::TableXml;
pub use ttx::TtxFile;
pub use ttx::TtxImportOptions;

Modules§

beyond64k
Converts between Open Font Format beyond-64k companion tables (a port of fontTools.ttLib.beyond64k).
binary
Big-endian binary reading and writing, the equivalent of struct.unpack / struct.pack with > formats.
cff
Port of fontTools.cffLib: CFF and CFF2 font data, and Type 2 charstrings (fontTools.misc.psCharStrings), with Type 1 charstrings in t1_charstring.
cli
The command line (fontTools.ttLib.__main__): opens fonts and collections, and saves them as one font or a collection.
collection
Port of fontTools.ttLib.ttCollection: TrueType / OpenType collections.
font
Port of fontTools.ttLib.ttFont: the Font object (TTFont).
fonttools_tables
Facts about fontTools’ table classes, generated from upstream.
glyph_order
The glyph order: glyph names by glyph ID (TTFont.getGlyphOrder and friends).
glyph_set
Drawing the glyphs of a font (fontTools.ttLib.ttGlyphSet).
iup
fontTools.varLib.iup: interpolation of untouched points (IUP) and the optimizer that leaves out the deltas IUP can infer.
mac_utils
Port of fontTools.ttLib.macUtils: fonts in the sfnt resources of Mac resource forks (.dfont files and font suitcases), and the res_name_or_index argument of TTFont (Font::open).
ot
The machinery behind OpenType Layout and related tables (fontTools.ttLib.tables.otBase and otConverters).
pens
Pens that build glyphs: fontTools.pens.ttGlyphPen and fontTools.pens.t2CharStringPen. They live here rather than in fontoxide-pens because they make glyf glyphs and CFF charstrings.
remove_overlaps
Simplifies glyphs by merging overlapping contours and components (a port of fontTools.ttLib.removeOverlaps).
reorder_glyphs
Reorder the glyphs of a font (fontTools.ttLib.reorderGlyphs).
scale_upem
Change the units-per-EM of a font (fontTools.ttLib.scaleUpem).
sfnt
Port of fontTools.ttLib.sfnt: reading and writing the sfnt container (plain sfnt, TrueType collections and WOFF 1.0). WOFF 2.0 lives in crate::woff2.
sstruct
Fixed-layout binary structures, the equivalent of fontTools.misc.sstruct.
table
The table interface (DefaultTable) and the registry that maps tags to table implementations (getTableClass).
tables
Table implementations (fontTools.ttLib.tables).
ttx
Reading TTX documents (fontTools.misc.xmlReader.XMLReader, the TTX-specific part), and the file names of TTX dumps split into several files (saveXML(splitTables=True, splitGlyphs=True)).
var
The parts of fontTools.varLib that ttLib relies on to evaluate variations at a location: models.supportScalar, iup.iup_delta, and the instancers of varStore and multiVarStore.
woff2
WOFF 2.0 (fontTools.ttLib.woff2).
woff2_cli
The command line of fontTools.ttLib.woff2 (main, compress and decompress): compresses fonts to WOFF 2.0 and decompresses them.

Structs§

Tag
A four-byte OpenType tag (Tag).

Enums§

Error
Errors from reading, writing or converting fonts.

Constants§

FONTTOOLS_VERSION
The fontTools release whose behavior this version matches.

Functions§

set_clock
Sets the clock of timestamp_now, a function returning the seconds since the Unix epoch, in place of the system clock.

Type Aliases§

Result
Shorthand for Result<T, fontoxide_ttlib::Error>.