Crate allsorts_no_std[][src]

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.

Features

  • Parse TrueType (ttf), OpenType (otf), WOFF, and WOFF2 files.
  • Shape Arabic, Latin, Indic scripts (Bengali, Devanagari, Gujarati, Gurmukhi, Kannada, Malayalam, Oriya, Tamil, Telugu).
  • 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.

Examples/Getting Started

Refer to the Allsorts Tools repository for a trio of tools that exercise Allsorts font parsing, shaping, and subsetting.

For shaping text the primary entry points are:

  • Font — utility type that holds parsed font tables, layout caches, etc. (we need to come up with a better name for it)
  • gsub::apply — apply glyph substitution
  • gpos::gpos_apply — apply glyph positioning

Unimplemented Features / Known Issues

We don’t currently support:

  • Shaping Hebrew, Tibetan, and Mongolian.
  • Apple’s morx table.
  • Emoji.
  • Unicode normalisation.

Known limitations:

  • The crate is not well documented yet (#5).
  • Allsorts does not do font lookup/matching. For this something like font-kit is recommended.
  • The subsetting implementation is tailored towards PDF font embedding (mostly the cmap0 argument to the subset function) at the moment.

Development Status

Allsorts is still under active development but has 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, Fathom.

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

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

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

License

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

See LICENSE for details.

Re-exports

pub use font::Font;
pub use tinyvec;

Modules

big5

Big5 encoding.

binary

Reading and writing of binary data.

bitmap

Bitmap font handling.

cff

CFF font handling.

checksum

Checksum calculation routines.

context

Utilities for performing contextual lookup in gpos and gsub.

error

Error types

font
font_data

Top-level font file representation.

gdef

gdef font table utilities.

get_name

Utilities for obtaining a name from a fonts name table.

glyph_info

Utilities for accessing glyph information such as advance.

gpos

Glyph positioning (gpos) implementation.

gsub

Glyph substitution (gsub) implementation.

layout

GDEF font table parsing and glyph lookup and layout properties.

macroman

Utilities for handling the Mac OS Roman character set.

post

post table parsing and writing.

scripts
size

Definitions of the sizes of binary types.

subset

Font subsetting.

tables

OpenType font table parsing and writing.

tag

Utilities and constants for OpenType tags.

unicode
woff

Reading of the WOFF font format.

woff2

Reading of the WOFF2 font format.

Macros

read_table
tag

Generate a 4-byte OpenType tag from byte string

Constants

DOTTED_CIRCLE