Various font tools built using Allsorts

Allsorts Tools
Allsorts is a font parser, shaping engine, and subsetter for OpenType, WOFF, and WOFF2 written entirely in Rust. This repository contains tools that were developed to debug and test Allsorts and provide examples of its use.
Note: These tools are for demonstration, reference, and debugging purposes. You should not rely on them for production workflows.
Tools
Available tools:
bitmapsโ dump bitmaps from bitmap fontscmapโ print character to glyph mappingsdumpโ dump font informationhas-tableโ check if a font has a particular tableinstanceโ create a static instance of a font from a variable fontlayout-featuresโ print a list of a font's GSUB and GPOS featuresshapeโ apply shaping to glyphs from a fontspecimenโ generate a HTML font speciment for a fontsubsetโ subset a fontvalidateโ parse the supplied font, reporting any failuresvariationsโ list the variation axes of a variable fontviewโ generate SVGs from glyphs
bitmaps
The bitmaps tool extracts bitmaps from fonts containing glyph bitmaps in either the EBLC/EBDT or CBLC/CBDT tables.
Options
-ois the path to the directory to write the bitmaps to. It will be created
Description
The images are written out as PNGs in a sub-directory for each strike (size). The format is {ppemx}x{ppemy}@{bit_depth}, the files are named {glyph_id}.png:
terminus โโโ 12x12@1 โ โโโ 0.png โ โโโ 1.png โ โโโ 2.png โ โโโ 3.png โ โโโ 4.png โ โโโ 5.png โ โโโ 6.png โ โโโ 7.png โฎ โฎ โโโ 14x14@1 โ โโโ 0.png โฎ โฎ โโโ 32x32@1 โฎ โฎ
Example
allsorts bitmaps -o noto-color-emoji NotoColorEmoji.ttf
cmap
The cmap tool chooses a preferred cmap sub-table and dumps the character to glyph index entries. If the encoding of the table is Unicode then the characters are printed along with the code point, otherwise just the numeric value of the character is printed.
Options
-f,--fontspecifies the path to the font file.-i,--indexis index of the font to dump (for TTC, WOFF2) (default: 0).
Example
$ allsorts cmap --font profontn.otb cmap sub-table encoding: Unicode '' U+0000 -> 0 '' U+0001 -> 1 '' U+0002 -> 2 โฎ '?' U+003F -> 63 '@' U+0040 -> 64 'A' U+0041 -> 65 'B' U+0042 -> 66 โฎ 'ยป' U+00BB -> 187 'ยผ' U+00BC -> 188 'ยฝ' U+00BD -> 189 'ยพ' U+00BE -> 190 'ยฟ' U+00BF -> 191 'ร' U+00C0 -> 192 'ร' U+00C1 -> 193 'ร' U+00C2 -> 194 'ร' U+00C3 -> 195 'ร' U+00C4 -> 196 โฎ
dump
The dump tool prints or extracts information from a font file.
allsorts dump path/to/font prints out information about the font.
Options
--nameincludes the metadata contained in thenametable in the output.-ccan be used to print information about a CFF font or table not
-textracts the named table from the supplied font. The output should be
allsorts dump -t glyf > glyf.bin
-gprints information about a specific glyph in a font.-lprints out all offsets in thelocatable in the font.
Example
$ allsorts dump noto-subset.otd | head TTF - version: 0x4f54544f - num_tables: 9
CFF (checksum: 0x625ba831, offset: 156, length: 166505) OS/2 (checksum: 0x9f6306c8, offset: 166664, length: 96) cmap (checksum: 0x131b2742, offset: 166760, length: 274) head (checksum: 0x09e560e8, offset: 167036, length: 54) hhea (checksum: 0x0c1109cf, offset: 167092, length: 36) hmtx (checksum: 0x1b9b0310, offset: 167128, length: 52) maxp (checksum: 0x000d5000, offset: 167180, length: 6) name (checksum: 0x1f3037ad, offset: 167188, length: 418) post (checksum: 0xff860032, offset: 167608, length: 32)
- CFF: - version: 1.0 - name: NotoSansJP-Regular - num glyphs: 13 - charset: Custom - variant: CID
has-table
The has-table tool checks if the supplied font file contains the table passed via the -t argument. If the font contains the table it exits with status success (0), if the font does not contain the table it exits with status 1.
This tool is handy combined with find, to locate fonts that have the desired table.
Options
-t,--table TABLEtable to check for-i,--index INDEXindex of the font to check (for TTC, WOFF2) (default: 0)-p,--print-fileprint the path to the font if it contains the table.-v,--invert-matchselect fonts that don't have the given table
Example
In this example, we search the current directory for files ending in ttf, otf, or otc and check to see if they contain an EBLC table. If the table is found the path to the font is printed.
find . -regextype posix-extended -type f -iregex '.*\.(ttf|otf|otc)$' -exec allsorts has-table -t EBLC -p {} \;
instance
The instance tool applies a set of values (tuple) to the variation axes of a variable font to produce a static, non-variable font with those settings.
Options
-t,--tupleis a comma separated list of values one for each variation axis
variations tool will list the axes, their order, and limits.
-o,--outputis the path to the output font.
Example
In this example the font has two axes: UNDO and UNDS. We supply a value of 500 for each one and write the output font to UnderlineTest.ttf.
allsorts instance --tuple 500,500 UnderlineTest-VF.ttf -o UnderlineTest.ttf
layout-features
Prints an indented list of a font's GSUB and GPOS features.
Example
$ layout-features fonts/devanagari/AnnapurnaSIL-Regular.ttf Table: GSUB Script: DFLT Language: default Feature: aalt Lookups: 56 Feature: abvs Lookups: 27,28,29,30 Feature: akhn Lookups: 4 Feature: blwf Lookups: 9 # additional output omitted
shape
The shape tool shapes the supplied text according to the supplied font, language, and script. It prints out the glyphs before and after shaping.
Options
-
-f,--font PATHpath to font file -
-i,--index INDEXindex of the font to shape (for TTC, WOFF2) (default: 0) -
-s,--script SCRIPTscript to shape -
-l,--lang LANGlanguage to shape -
--verticalvertical layout, default is horizontal
Example
$ shape -f fonts/devanagari/AnnapurnaSIL-Regular.ttf -s deva -l HIN 'เคถเคฌเฅเคฆเฅเค เคเคฐ เคตเคพเคเฅเคฏเฅเค เคเฅ เคคเคฐเคน' # output omitted
specimen
The specimen tool generates a HTML font specimen sheet containing sample text set in the font as well as information about the font and its supported features.
Options
-i,--index INDEXindex of the font to subset (for TTC, WOFF2) (default: 0)--sample-text TEXTsample text to use in the font specimen
Example
$ allsorts specimen ../allsorts/tests/fonts/bengali/Lohit-Bengali.ttf
subset
The subset tool takes a source font and some text and writes a new version of the source font only containing the glyphs required for the supplied text.
Options
-t,--text TEXTsubset the font to include glyphs from TEXT-a,--allinclude all glyphs in the subset font-i,--index INDEXindex of the font to subset (for TTC, WOFF2) (default: 0)
Example
$ allsorts subset -t 'This a subsetting test' NotoSansJP-Regular.otf noto-subset.otf Number of glyphs in new font: 13
validate
The validate tool attempts to parse all the glyphs (or various DICTs in the case of CFF) in the supplied font. It reports any errors encountered but is otherwise silent. This command was useful for bulk testing Allsorts against a large repertoire of real world fonts.
Example
$ allsorts validate ../allsorts/tests/fonts/bengali/Lohit-Bengali.ttf
Bulk Validation Example
$ fd '\.(ttf|otf|ttc)$' /usr/share/fonts | sort | parallel --bar allsorts validate {}
variations
The variations tool lists information about a variable font. The information includes:
- The variation axes with their tag, minimum, maximum, and default values.
- Any pre-defined instances and their name and axis values.
Example
This example prints variation information for the font at ../text-rendering-tests/fonts/TestHVARTwo.ttf.
$ allsorts variations ../text-rendering-tests/fonts/TestHVARTwo.ttf Axes: (2)
- wght = min: 0, max: 1000, default: 0 - cntr = min: 0, max: 100, default: 0
Instances:
Subfamily: ExtraLight PostScript Name: TestFont-ExtraLight Coordinates: [0.0, 0.0]
Subfamily: Light PostScript Name: TestFont-Light Coordinates: [150.0, 0.0]
Subfamily: Regular PostScript Name: TestFont-Regular Coordinates: [394.0, 0.0]
Subfamily: Semibold PostScript Name: TestFont-Semibold Coordinates: [600.0, 0.0]
Subfamily: Bold PostScript Name: TestFont-Bold Coordinates: [824.0, 0.0]
Subfamily: Black PostScript Name: TestFont-Black Coordinates: [1000.0, 0.0]
Subfamily: Black Medium Contrast PostScript Name: TestFont-BlackMediumContrast Coordinates: [1000.0, 50.0]
Subfamily: Black High Contrast PostScript Name: TestFont-BlackHighContrast Coordinates: [1000.0, 100.0]
view
The view tool shapes the supplied text or list of codepoints according to the supplied font, language, and script. Then, it generates an SVG of the glyphs.
Options
-f,--font PATHpath to font file-s,--script SCRIPTscript to shape-l,--lang LANGlanguage to shape--mark-originmark the origin of each glyph with a cross-hair--margin numortop,right,bottom,leftspecify a margin to be added to the edge of the SVG--fg-colour rrggbbaaset the fill colour of the glyphs--bg-colour rrggbbaaset the background colour of the generated SVG--fg-color rrggbbaaalias for--fg-colour--bg-color rrggbbaaalias for--bg-colour-t,--text TEXTtext to render-c,--codepoints CODEPOINTScomma-separated list of codepoints (as hexadecimal numbers) to render-i,--indices GLYPH_INDICEScomma-separated list of glyph indices to render-F,--features FEATUREScomma-separated list of OpenType features to enable (note: only enables these features)
Example Using Text
$ view -f fonts/devanagari/NotoSerifDevanagari-Regular.ttf -s deva -t 'เคเคฟ' # output omitted
Example Using Codepoints
$ allsorts view -f fonts/devanagari/NotoSerifDevanagari-Regular.ttf -s deva -c '916,93f' # output omitted
Example Using Glyph Indices (and Features)
In this example, the OpenType pres feature is enabled, which allows glyph 30 to be replaced by its special presentation form (glyph 547).
$ view -f fonts/devanagari/NotoSerifDevanagari-Regular.ttf -s deva --features pres -i '30,54' # output omitted
Building and Installing
From Source
Minimum Supported Rust Version: 1.70.0
To build the tools ensure you have Rust installed.
- Build:
cargo build --release - Install:
cargo install --path .
Arch Linux
There is an AUR package for allsorts-tools:
git clone https://aur.archlinux.org/allsorts-tools.git cd allsorts-tools makepkg -si
Contributing
Contributions are welcome, please refer to the Allsorts contributing guide 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.
License
Allsorts and these tools are distributed under the terms of the Apache License (Version 2.0).
See LICENSE for details.