Allsorts now supports shaping Myanmar script, Apple Advanced Typography
morx&kerntables, and COLRv0 & COLRv1 colour fonts.
Allsorts is a Rust crate (library) that can parse OpenType, WOFF, and WOFF2 fonts, shape text, and subset fonts1. We use it in Prince for all font parsing, shaping, and subsetting.
Allsorts 0.16 is another big release containing new features and improvements built over the last 18 months.
Shaping Myanmar
Allsorts can now shape text that uses Myanmar script, such as Burmese.
Kerning with kern
The kern table, inherited from TrueType is an alternative to GPOS for kerning adjustments. It's
most commonly encountered in older fonts, or fonts designed specifically for macOS, but some modern
fonts like previous versions of OpenSans also use it. Allsorts 0.16 will now make use of a kern
table if there is no kerning feature in the GPOS table. In addition to the kern format specified
by OpenType, Allsorts also supports Apple's extensions for more sophisticated
kern-based kerning.
Shaping with morx
The extended glyph metamorphosis table (morx) allows specifying a set of transformations
that can apply to the glyphs of a font. This is how shaping is achieved in Apple Advanced
Typography. It uses a state machine to implement the transformations. Where shaping with GSUB
typically requires the shaping engine to have some knowledge of the scripts it can shape, morx
allows a single implementation to implement almost any script. The drawback is that all the logic
must be encoded in every font instead of once in the shaping engine.
Allsorts now implements shaping with morx when the GSUB table is absent. Being an Apple
technology, morx is most commonly encountered in fonts shipped on Apple platforms. For example
Hoefler Text, and Zapfino.
COLR Fonts
One of the many mechanisms to achieve colour fonts is through the COLR table, and its companion
CPAL. This format is commonly encountered in recent versions of Noto Color Emoji, and Segoe UI
Emoji (the Windows emoji font). It uses regular glyph outlines (as opposed to bitmaps or SVG) and
colours them by applying paint operators such as fills, clips, and gradients. There are two COLR
formats: COLRv0, which allows basic colouring and layering of outlines, and the more
sophisticated COLRv1 that adds many more operators as well as support for multiple types of
gradients.
Allsorts supports both formats and provides a generic mechanism for traversing the paint tree. The emitted calls translate well into 2D graphics library APIs that have a PostScript-inspired model, such as Cairo, or Quartz.
Other Improvements & Fixes
There were a number of other smaller fixes and improvements in this release, including:
- Respecting the flip flag in
sbixlookup.- This enables the right facing emoji in Apple Color Emoji to work properly.
- Applying a maximum limit to GPOS substitutions.
- This mitigates fonts using a 'billion laughs' attack to exhaust resources.
- Applying
GPOSlookups in global order.- This improves compatibility with Segoe UI Emoji.
- Implementing support for mark filtering sets.
- This was required for some Myanmar script fonts.
- Updating Unicode data to Unicode 16.
- Providing access to bounding box of glyphs.
- Glyphs can be traversed to calculate their bounding box.
- Applying variations when visiting the outlines of
glyfbased fonts.
With all of these improvements Allsorts went from passing 432 of the Unicode text-rendering-tests to 540, leaving 212 failing tests (mostly scripts that are not yet supported).
Project Showcase
Before wrapping up I thought it would be nice to mention some of the other projects that are using Allsorts:
- Azul desktop GUI framework.
- printpdf Rust library for creating, reading, writing and rendering PDF documents.
- flo_draw 2D rendering libraries for Rust.
- next.js React JS full-stack web framework.
Font shaping is the process of taking text in the form of Unicode codepoints and a font, and laying out glyphs according to the text. This involves applying kerning, ligatures, and substitutions specified by the font and performing glyph reordering according to the OpenType rules specific to each complex script.