Font parser, shaping engine, and subsetter
Allsorts is a font parser, shaping engine, and subsetter for OpenType, WOFF, and WOFF2 written entirely in Rust. It was extracted from Prince, a tool that typesets and lays out HTML and CSS documents into PDF.
The Allsorts shaping engine was developed in conjunction with a specification for OpenType shaping, which aims to specify OpenType font shaping behaviour.
- Parse TrueType (
ttf), OpenType (
otf), WOFF, and WOFF2 files.
- Shape Arabic, Cyrillic, Greek, Hebrew, Indic scripts (Bengali, Devanagari, Gujarati, Gurmukhi, Kannada, Malayalam, Oriya, Sinhala, Tamil, Telugu), Khmer, Lao, Latin, Syriac, Thai, and other scripts.
- Subset from TrueType, OpenType, WOFF, and WOFF2 files into OpenType.
What is font shaping?
Font shaping is the process of taking text in the form of Unicode codepoints and a font, and laying out glyphs from the font according to the text. This involves honouring kerning, ligatures, and substitutions specified by the font. For some languages this is relatively straightforward. For others, such as Indic scripts it is quite complex. After shaping, another library such as Pathfinder or FreeType is responsible for rendering the glyphs. To learn more about text rendering, Andrea Cognolato has a good overview of modern font rending on Linux. The concepts remain similar on other platforms.
Refer to the Allsorts Tools repository for a set of tools that exercise Allsorts font parsing, shaping, and subsetting.
Unimplemented Features / Known Issues
We don’t currently support:
- Shaping Mongolian, and Tibetan.
- Apple’s morx table.
- Unicode normalisation.
- The crate is not extensively documented yet (#5).
- Allsorts does not do font lookup/matching. For this something like font-kit is recommended.
Allsorts is still under active development but reached its first release milestone with its inclusion in Prince 13. In Prince it is responsible for all font loading, and font shaping.
Currently, the font parsing code is handwritten. It is planned for this to eventually be replaced by machine generated code via our declarative data definition language project.
Allsorts CI runs tests on Linux, macOS, and Windows. Via Prince it is also built for FreeBSD.
Building and Testing
Minimum Supported Rust Version: 1.51.0
To build the crate ensure you have Rust 1.51.0 or newer installed.
cargo build and run the tests with
|Feature||Description||Default Enabled||Extra Dependencies|
|Enable code for accessing glyph outlines||✅|
|Use the zlib backend to flate2||✅|
|Use the Rust backend to flate2||❌|
|Enable Prince specific tests and code||❌|
Note: In our testing the
flate2 backend was faster but you may
prefer the Rust backend for a pure Rust solution when compiling to WASM or
Contributions are welcome, please refer to the contributing document for more details.
Code of Conduct
We aim to uphold the Rust community standards:
We are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, disability, ethnicity, religion, or similar personal characteristic.
We follow the Rust code of conduct.
- OpenType shaping documents forms the specification from which the shaping engine is implemented.
- HarfBuzz the widely used open source font shaping engine was used as reference for test output.
- The Adobe Annotated OpenType Specification test suite is used as part of the Allsorts test suite.
- ttf-parser for CFF CharString parsing code.
Allsorts is distributed under the terms of the Apache License (Version 2.0).
See LICENSE for details.
pub use font::Font;
pub use pathfinder_geometry;
pub use tinyvec;
Reading and writing of binary data.
Bitmap font handling.
CFF font handling.
Checksum calculation routines.
Utilities for performing contextual lookup in gpos and gsub.
Central font handling support.
Top-level font file representation.
gdef font table utilities.
Utilities for obtaining a name from a fonts
Utilities for accessing glyph information such as advance.
Calculate glyph positions.
Glyph positioning (
Glyph substitution (
GDEF font table parsing and glyph lookup and layout properties.
Utilities for handling the Mac OS Roman character set.
Access glyphs outlines. Requires the
outline cargo feature (enabled by default).
post table parsing and writing.
Definitions of the sizes of binary types.
OpenType font table parsing and writing.
Utilities and constants for OpenType tags.
Unicode utilities and character properties.
Reading of the WOFF font format.
Reading of the WOFF2 font format.
Generate a 4-byte OpenType tag from byte string