Allsorts now supports variable fonts, CFF2, and can generate font specimen documents.
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.
A lot has happened since we last wrote about Allsorts all the way back in 2021. There have been 14 releases since then. In that time Allsorts gained support for variable fonts, CFF2 outlines, and creating font specimen documents, as well as a few bug fixes and improvements.
Variable fonts
With a history dating back to QuickDraw GX on classic Mac OS, variable fonts have become popular since their addition to OpenType 1.8 in 2016. A variable font contains one of more axes of variation: these may be dimensions like weight or slant but can also be entirely custom. They provide many benefits, including:
- Continuous variation: instead of fixed instances like Light, Medium, Regular, Bold a variable font allows an axis to support all values between a minimum and maximum.
- More compact font files, only one file is needed instead of one for each style.
Allsorts has gained support for reading variation information as well as applying it to font data to create a specific font instance. The star of the variable-fonts show is the new instance function, which given a variable font and a collection of values for each axis produces a non-variable font instance that can be embedded in a PDF or used as a regular font in other code or applications.
CFF2
As the name implies, CFF2 is a second take on the support for CFF outlines in OpenType. It eliminates many of the redundancies found in CFF in OpenType, in addition to adding support for variable fonts. CFF2 fonts are presently most likely to be encountered in fonts from Adobe but they are also used in other places, for example the Cantarell font used by the GNOME desktop environment.
CFF Subsetting
In earlier versions of Allsorts only a limited amount of subsetting was applied to CFF fonts. Now the CharStrings (glyph outlines) in CFF fonts are also subset to eliminate unused operators, resulting in much smaller output. This feature was based upon the CharString parser from ttf-parser, so thanks to RazrFalcon for that.
Font Specimens
Sometimes you want to see what a font looks like and know some of the technical details about it. To support this we added the ability to generate a HTML font specimen containing sample text and information about the font. This document generated for Cantarell is an example.
This feature is turned off by default. Enable the specimen
Cargo feature
enable it.
Allsorts Tools
Allsorts tools as been enhanced to make use of the new Allsorts features. There are three new sub-commands:
variations
— list variation information about a font.instance
— create an instance of a variable font.specimen
— generate a font specimen for a font.
variations
variations
lists variation axes in a font, their domain and any pre-defined
instances in the font. Example output:
$ allsorts variations /usr/share/fonts/cantarell/Cantarell-VF.otf
Axes: (1)
- wght = min: 100, max: 800, default: 400
Instances:
Subfamily: Thin
Coordinates: [100.0]
Subfamily: Light
Coordinates: [300.0]
Subfamily: Regular
Coordinates: [400.0]
Subfamily: Bold
Coordinates: [700.0]
Subfamily: Extra Bold
Coordinates: [800.0]
Style Attributes:
Thin
Light
Regular
Bold
Extra Bold
instance
instance
is used to produce a non-variable font instance from a variable font.
For example if we wanted an instance of Cantarell with a weight of 555 we'd run:
allsorts instance -t 555 -o Cantarell555.otf /usr/share/fonts/cantarell/Cantarell-VF.otf
specimen
The specimen
command generates a document in HTML format describing features of the
font along with some sample text set in the font. For example,
specimen /usr/share/fonts/cantarell/Cantarell-VF.otf > cantarell.html
View a font specimen for Cantarell.
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.