21 releases (breaking)

0.15.0 Jun 6, 2024
0.14.1 Aug 15, 2023
0.14.0 Mar 2, 2023
0.13.0 Nov 15, 2022
0.1.0 Nov 19, 2019

#228 in Parser implementations

Download history 740/week @ 2024-08-01 722/week @ 2024-08-08 798/week @ 2024-08-15 662/week @ 2024-08-22 921/week @ 2024-08-29 687/week @ 2024-09-05 492/week @ 2024-09-12 508/week @ 2024-09-19 574/week @ 2024-09-26 589/week @ 2024-10-03 595/week @ 2024-10-10 706/week @ 2024-10-17 687/week @ 2024-10-24 1225/week @ 2024-10-31 759/week @ 2024-11-07 895/week @ 2024-11-14

3,683 downloads per month
Used in 6 crates (4 directly)

Apache-2.0

1.5MB
38K SLoC


Allsorts

Font parser, shaping engine, and subsetter for OpenType, WOFF, and WOFF2 implemented in Rust


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.

Features

  • Parse TrueType/OpenType (glyf, CFF, CFF2), 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.
  • Instance variable fonts into non-variable fonts.

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.

Examples

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.

Known limitations:

  • The crate is not extensively documented yet (#5).
  • Allsorts does not do font lookup/matching. For this something like font-kit is recommended.

Development Status

Allsorts is still under active development but reached its first release milestone with its inclusion in Prince 13 in 2019. 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.

Platform Support

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.66.0

To build the crate ensure you have Rust 1.66.0 or newer installed.

Build with cargo build and run the tests with cargo test.

Cargo Features

Feature Description Default Enabled Extra Dependencies
outline Enable code for accessing glyph outlines
flate2_zlib Use the zlib backend to flate2 zlib
flate2_rust Use the Rust backend to flate2 miniz_oxide
prince Enable Prince specific tests and code
specimen Enable module for generating HTML font specimens upon, unicode-blocks

Note: In our testing the zlib flate2 backend was faster but you may prefer the Rust backend for a pure Rust solution when compiling to WASM or similar.

Contributing

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.

Acknowledgements

License

Allsorts is distributed under the terms of the Apache License (Version 2.0).

See LICENSE for details.

Dependencies

~9MB
~234K SLoC