Babelfont
Babelfont is a Rust library for working with font source files from different font editing software. It provides a unified interface to load, examine, manipulate, and convert fonts between various formats, abstracting over the differences between font editors' native representations.
Features
- Multi-format Support: Load and save fonts in UFO, DesignSpace, Glyphs, FontLab VFJ, and Babelfont's own JSON format
- Format Conversion: Convert fonts between different editor formats seamlessly
- Font Manipulation: Apply filters to subset, scale, or otherwise transform fonts
- JSON Serialization: Full serialization/deserialization of Babelfont's internal representation
- Variable Font Support: Full support for variable/multiple master fonts with axes, masters, and instances
- Feature-based Compilation: Optional dependencies for specific format support
Status
Babelfont is currently in early development. While the core architecture and many features are implemented, some format support and filters are still works in progress.
- Glyphs file format: Mostly complete for reading and writing Glyphs 2 and Glyphs 3 files.
- UFO/DesignSpace: Reading support is implemented; writing support is in progress.
- FontLab VFJ: Very basic reading support is implemented; writing support is planned.
- Fontra: Basic reading and writing support is implemented.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Feature Flags
By default, all major format support is enabled. You can customize which formats are supported:
[]
= { = "0.1", = false, = ["glyphs", "ufo"] }
Available features:
glyphs- Support for Glyphs 2 and Glyphs 3 files (.glyphsand.glyphspackage)ufo- Support for UFO and DesignSpace formatsfontlab- Support for FontLab VFJ (JSON) formatfontra- Support for Fontra formatfontir- Enable compilation to binary font formats (.ttf)cli- Command-line interface supporttypescript- TypeScript type definition generation
Quick Start
Loading and Converting Fonts
use ;
Subsetting with Filters
use ;
use ;
Inspecting Font Metadata
use load;
Supported Formats
Input/Output Formats
| Format | Extension | Read | Write | Feature Flag |
|---|---|---|---|---|
| UFO | .ufo |
✓ | ✗ | ufo |
| DesignSpace | .designspace |
✓ | ✓ | ufo |
| Glyphs 2/3 | .glyphs |
✓ | ✓ | glyphs |
| Glyphs Package | .glyphspackage |
✓ | ✗ | glyphs |
| FontLab VFJ | .vfj |
✓ | ✗ | fontlab |
| Babelfont JSON | .babelfont |
✓ | ✓ | (always) |
| TrueType | .ttf |
✗ | ✓ | fontir |
JSON Serialization
One of Babelfont's unique features is its ability to serialize and deserialize its internal representation to and from JSON. This provides a format-agnostic way to store and exchange font data.
The JSON format is complete and lossless, meaning you can:
- Convert any supported format to JSON and back without data loss
- Use JSON as an intermediate format when converting between editor formats
- Inspect the complete font structure in a human-readable format
- Create programmatic workflows using standard JSON tools
Example:
use load;
To generate TypeScript type definitions for the JSON format, run:
$ cargo run --example dump-typescript --features=typescript
Font Filters
Babelfont includes several built-in filters for font manipulation:
RetainGlyphs- Keep only specified glyphs, removing all others. Components referencing removed glyphs are automatically decomposed.DropAxis- Remove a variable font axisDropInstances- Remove named instancesDropKerning- Remove all kerning dataDropFeatures- Remove OpenType feature codeDropGuides- Remove all guidelinesDropSparseMasters- Convert sparse masters to associated layersResolveIncludes- Resolve feature file include statementsScaleUpem- Scale the units-per-em value
Filters can be chained together:
use ;
Core Types
Font- The main font structure containing all font dataGlyph- A single glyph with its layers and metadataLayer- A glyph's outline in a particular masterMaster- A design master in a variable/multiple master fontAxis- A variation axis definitionInstance- A named instance (static font variant)Features- OpenType feature code representationShape- A path or component in a glyph layer
Command-Line Interface
With the cli feature enabled, Babelfont also provides a command-line tool:
# Convert between formats
# Apply filters
# Compile to TTF
Compile the CLI with:
$ cargo build --release --bin babelfont --features=cli
Related Projects
Babelfont is based on the Python babelfont library. Additional development is now happening here, rather than in the original Python version.
License
Babelfont is available under the MIT or Apache-2.0 licenses, at your option.
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues on GitHub.