fontoxide
A Rust port of fontTools.
fontoxide is a complete, behavior-compatible port of fontTools: the same tables, the
same operations (subsetting, instancing, merging, feature compilation, variable font
building, …) and the same command lines, producing byte-for-byte the same fonts and TTX
as fontTools. It is pure safe Rust, has no C dependencies, and compiles to
wasm32-unknown-unknown.
Status
- Version 0.2.0, tracking fontTools 4.69.1.
- Every fontTools subpackage is ported, except drawing and rendering (plotting, cairo, FreeType, …); for those, fontoxide provides the data to draw with.
- All ported upstream tests pass: 3,608 of fontTools' 3,784 tests are ported, the other 176 don't apply to Rust (see COMPATIBILITY.md), none are pending.
Quick start
[]
= "0.1"
use BTreeMap;
use ;
use ;
use ;
Names follow Rust conventions (TTFont → Font, instantiateVariableFont →
instantiate_variable_font), and the documentation of each item names its fontTools
counterpart. fontTools refers to glyphs by name; fontoxide's tables use glyph IDs.
Command line
This installs fontoxide, which runs fontTools' command lines: fontoxide <module> is
fonttools <module>.
To also install fontTools' own command names (fonttools, ttx, pyftsubset and
pyftmerge, with fontTools' usage and help texts), enable the fonttools-names feature:
Crates
Each crate corresponds to a fontTools subpackage. The umbrella crate fontoxide
re-exports all of them, each behind a feature of the same name:
| Crate | fontoxide:: |
fontTools |
|---|---|---|
fontoxide-ttlib |
ttlib |
fontTools.ttLib (including cffLib, ttGlyphPen, t2CharStringPen) |
fontoxide-misc |
misc, agl, afmlib, tfmlib |
fontTools.misc, agl, afmLib, tfmLib |
fontoxide-pens |
pens |
fontTools.pens |
fontoxide-unicodedata |
unicodedata |
fontTools.unicodedata |
fontoxide-encodings |
(used by ttlib) |
fontTools.encodings |
fontoxide-subset |
subset |
fontTools.subset |
fontoxide-varlib |
varlib |
fontTools.varLib |
fontoxide-merge |
merge |
fontTools.merge |
fontoxide-fealib |
fealib |
fontTools.feaLib |
fontoxide-otllib |
otllib |
fontTools.otlLib |
fontoxide-colorlib |
colorlib |
fontTools.colorLib |
fontoxide-designspacelib |
designspacelib |
fontTools.designspaceLib |
fontoxide-ufolib |
ufolib |
fontTools.ufoLib |
fontoxide-cu2qu |
cu2qu |
fontTools.cu2qu |
fontoxide-qu2cu |
qu2cu |
fontTools.qu2cu |
fontoxide-svglib |
svglib |
fontTools.svgLib |
fontoxide-t1lib |
t1lib |
fontTools.t1Lib |
fontoxide-voltlib |
voltlib |
fontTools.voltLib |
fontoxide-mtilib |
mtilib |
fontTools.mtiLib |
fontoxide-diff |
diff |
fontTools.diff |
fontoxide-repack |
repack |
the HarfBuzz repacker (uharfbuzz's serialize_with_tag) |
fontoxide |
font_builder |
fontTools.fontBuilder |
fontoxide-cli |
fontTools.ttx, fontTools.__main__ (the fontoxide executable) |
Features
By default, the fontoxide crate has everything, like pip install fonttools[all].
With default-features = false, it has only ttlib, misc, pens and unicodedata;
each other subpackage is a feature of the same name (subset, varlib, fealib, …).
fontTools' optional dependencies are features named after its extras:
| Feature | fontTools extra | Without it |
|---|---|---|
woff |
woff (brotli, zopfli) |
WOFF 2.0, and WOFF 1.0 with --with-zopfli, fail with an ImportError |
graphite |
graphite (lz4) |
compressed Silf and Glat tables are kept compressed, with a warning |
pathops |
pathops (skia-pathops) |
removing overlaps fails with an ImportError |
repacker |
repacker (uharfbuzz) |
GSUB and GPOS are packed with fontTools' own serializer |
Without an extra, fontoxide behaves as fontTools does without that Python package. The
individual crates don't turn the extras on; enable them with the features of
fontoxide-ttlib.
Compatibility
For the same input and options, fontoxide produces the same output as fontTools 4.68.0
with fonttools[all], byte for byte. This is checked by the ported upstream tests and by
differential testing against fontTools on a font corpus (cargo xtask parity).
The exceptions are documented in COMPATIBILITY.md. In short:
compressed data (WOFF 2.0, zopfli, LZ4, .ufoz) matches after decompression only;
overlap removal uses linesweeper instead of Skia
and is geometrically equivalent; invalid input can fail earlier, or be handled where
fontTools crashes; output that depends on Python's hash order is made deterministic.
fontTools bugs that affect output are reproduced on purpose, and listed there too.
Versioning
fontoxide is 0.x. Each update to a new fontTools release bumps the minor version, since
the output may change with it. The fontTools version is in the badge above and in
fontoxide::FONTTOOLS_VERSION; fontoxide --version prints both.
Only the latest stable Rust is supported while fontoxide is pre-1.0.
Performance
Some measurements against Python fontTools (fontoxide in a release build). They are single measurements on one machine, so take them as an indication only:
- merge: 4–13× faster; for example, merging Segoe UI, Trebuchet and Corbel Bold takes 2.2 s with fontTools and 0.17 s with fontoxide.
- varLib.interpolatable: 25–36× faster; Segoe UI Variable takes 50 s with fontTools and 1.5 s with fontoxide.
- varLib.avar.plan: 20–30× faster.
- feaLib: 7× faster; a feature file for 6,000 glyphs compiles in 420 ms with fontTools and 60 ms with fontoxide.
- Building CFF2 variable fonts: about 25× faster.
Development
Requirements: the latest stable Rust, uv (for the fontTools reference environment), and git submodules:
upstream/fonttools is the fontTools release being tracked. tools/reference runs that
exact checkout to produce reference data.
| Command | Purpose |
|---|---|
cargo test --workspace |
Run the tests |
cargo clippy --workspace --all-targets |
Lint (no warnings allowed) |
cargo fmt --all --check |
Check formatting |
cargo xtask reference |
Show the fontTools reference environment |
cargo xtask parity [PATHS…] |
Compare against fontTools on a font corpus (see corpus.md) |
cargo xtask test-manifest [--check] |
Sync upstream/tests.toml with the upstream test suite |
cargo xtask codegen |
Export table definitions from fontTools and regenerate code |
cargo xtask coverage |
Measure code coverage (cargo-llvm-cov) |
cargo xtask upstream-report FROM TO |
List upstream changes between two tags, grouped by crate |
cargo xtask sweep |
Remove stale test binaries and caches from target/ |
Fuzz targets for cargo-fuzz are in fuzz/.
See CONTRIBUTING.md for the conventions.
Updating to a new fontTools release
- Check out the new tag in
upstream/fonttools. cargo xtask upstream-report <old> <new>for the to-do list.cargo xtask codegenandcargo xtask test-manifest.- Port the changes, and update
syncedinupstream/map.toml,FONTTOOLS_VERSIONand the badge above; bump the minor version. cargo xtask parityto re-check against the new release.
Relationship to fontations and fontc
fontations is a Rust font stack modeled on HarfBuzz (fast zero-copy reading, shaping, subsetting with skera), and fontc is a font compiler that replaces fontmake. Neither is a port of fontTools: they make their own choices, and their output is not meant to match fontTools'. fontoxide is for when you want fontTools itself, in Rust: its API, its command lines, TTX, and its exact output.
License
MIT, like fontTools. See LICENSE, which includes fontTools' notice.
Some crates include third-party code or data under their own licenses:
fontoxide-repackis a port of the HarfBuzz repacker (LICENSE-HARFBUZZ).fontoxide-miscincludes the Adobe Glyph List data, copyright Adobe, under the BSD-3-Clause license (LICENSE-AGL).fontoxide-unicodedataincludes data from the Unicode Character Database, under the Unicode License v3 (LICENSE-UNICODE).fontoxide-encodingsincludes character mapping tables taken from CPython's codecs, under the Python Software Foundation License (LICENSE-PYTHON).