Introduction
OpenType is a font format developed by Microsoft and Adobe in the late 1990s and standardised as the Open Font Format, ISO/IEC 14496-22. It extends the TrueType container with Adobe’s PostScript outlines, in a table called CFF, and with layout tables that hold typographic features such as ligatures, small capitals, kerning and the shaping rules complex scripts need. Variable fonts, which hold a whole range of weights or widths in one file, are also OpenType.
A font with PostScript outlines usually has the extension .otf; an
OpenType font with TrueType outlines usually keeps .ttf.
Structure
An OpenType font uses the same table
directory as TrueType: a 12-byte header, a 16-byte record per table sorted by tag,
then the tables, all big-endian. A font with PostScript outlines starts with the
version tag OTTO and stores its glyphs in a
CFF table of
Type 2 charstrings, or a
CFF2 table, instead of
glyf and loca. The tables every font needs
(cmap, head, hhea, hmtx,
maxp, name, OS/2, post) are the
same as in TrueType and are described on the TTF
pages; an OpenType font with TrueType outlines is a TrueType font in every respect.
0Table directoryOTTOor00 01 00 00, number of tables, search values12 bytes12Table records tag, checksum, offset, length16 bytes each…Tables each at its recorded offsetvaries…head, hhea, maxp, hmtx, cmap, name, OS/2, post required tablesvaries…CFF or CFF2 PostScript outlines (or glyf and loca)varies…vhea, vmtx, VORG vertical metricsoptional…GDEF, GSUB, GPOS, BASE, JSTF, MATH layout, built on the common tablesoptional…fvar, avar, STAT and gvar, cvar, HVAR, VVAR, MVAR, in variable fontsoptional…COLR, CPAL, SVG and EBLC, EBDT, CBLC, CBDT, sbix colour and bitmap glyphsoptional…DSIG, PCLT, meta, MERG signature and other dataoptional
In the explorer
Dropping a .otf file on the explorer shows its table directory and the
tables it decodes, with the same decoders as for TrueType
fonts: head, hhea, maxp (version 0.5 for CFF outlines, 1.0 for TrueType outlines),
hmtx, name, cmap (formats 0, 2, 4, 6, 8, 10, 12, 13 and 14), OS/2, post, loca and glyf,
vhea and vmtx, gasp, cvt, fpgm, prep, kern, and DSIG
(its structure only: the signature is not verified).
The CFF and CFF2 tables are decoded: the header, the Name, Top DICT, String and Global Subr INDEXes, the Top DICT operators with their meanings, the CharStrings INDEX, the Private DICTs and their local subroutines, the charset, the encoding, the FDArray and FDSelect of a CID-keyed font, and the CFF2 VariationStore. A Type 2 charstring interpreter (subroutines, hints counted, flex, the accented-character form of endchar) runs every glyph: it gives the glyph sheet of the Outlines tab, the width and contour count of each glyph, and a problem for a stack overflow, subroutines nested too deep, a missing subroutine or a bad operator. Expanding a glyph in the structure shows its charstring operator by operator. VORG is decoded too. The layout tables GSUB, GPOS, GDEF, BASE and JSTF and MATH are decoded with their scripts, language systems, features, lookups and subtables (GSUB lookup types 1 to 8, GPOS types 1 to 9, every Coverage and ClassDef table, anchors, value records, device and VariationIndex tables and FeatureVariations), and the Tables tab lists what each subtable maps, a page at a time. The variation tables (fvar, avar 1 and 2, STAT, cvar, gvar, HVAR, VVAR, MVAR) are decoded too, with an option for a named instance and for each axis that redraws the glyf and CFF2 outlines; so are the colour tables (CPAL, COLR versions 0 and 1, SVG: each document opens as an entry, unpacked when gzip-compressed), the bitmap tables (EBLC, EBDT, EBSC, CBLC, CBDT, sbix: one picture for each strike, each sbix image an entry of its own type) and hdmx, LTSH, VDMX, PCLT, meta and MERG. The Apple Advanced Typography tables (feat, morx, mort, kerx, just, trak, ankr, opbd, prop, lcar, bsln, fdsc, fmtx, gcid, xref, Zapf, ltag) are decoded with the same code, and a font with TrueType outlines gets an Instructions tab that disassembles its programs. At an instance, the Outlines tab lists the advance widths with HVAR applied. Every other table is shown as bytes, labelled “not yet decoded”, and a list of every registered table tag says which are decoded.
Each table’s checksum is worked out and shown beside the recorded one in the table directory. A difference is shown and is not counted as a problem: real system fonts have wrong checksums and nothing that opens a font checks them. The problems listed are rules of the specification that make a table unreadable or inconsistent; rules that real fonts break and no program enforces are listed as notes.
Not described
Known, not yet covered
- Reference: version 2 of the
avartable, which comes from a later revision of the specification than the 1.9.1 text the pages follow. - Reference: the parts shared with TrueType that the TTF pages leave open (full language identifiers, PANOSE values, the Apple Font Feature Registry, the Apple tables acnt, bdat, bhed and bloc, and the semantics of each instruction).
- Reference: the COLR, CPAL, SVG and CBDT pages rest on the
specification’s own examples or hand-made ones, because no such font was at hand to
check them against (the CFF2 tables of the variable fonts in Apple’s
SFIndia.ttcare read by the viewer without a problem, and their outlines at instances agree with HarfBuzz’s). - Viewer: CFF outlines are drawn from their charstrings without hinting
(the stem hints and hint masks are read and counted, not applied), a CFF2 font is drawn
at an instance of the variation axes by evaluating its blend operators, and the Type 1
charstring format (
CharstringType1) is not read. - Viewer: the layout tables GSUB,
GPOS, GDEF,
BASE and JSTF and
MATH are read and checked against the structure
(offsets, counts, glyphs, nested lookup indexes), not against whether the font shapes a
script correctly. A typed string is run through every GSUB lookup type (1 to 8) and every GPOS
type (1 to 9), or Apple’s morx, mort, kerx and trak, or the kern table (the “Text to shape”
option, compared with
hb-shapeon every font and collection member under/System/Library/Fontsand/Library/Fonts: 787 fonts and 62,173 strings in nineteen scripts, 62,160 the same, 13 different only where HarfBuzz runs a shaper the viewer does not run, for Mongolian and N’Ko (the Universal Shaping Engine) and Arabic in one font without form features, none different for another reason). The Indic shaper (Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, with the old and new script tags), Khmer, Myanmar, Hangul, and the Arabic, Hebrew, Thai and Lao shapers (from Microsoft’s script pages and, where those say nothing, from HarfBuzz) and right-to-left runs with every mirrored character are run. Not run: the Universal Shaping Engine, the Arabic fallback from presentation forms, the stch feature, device tables and variation indexes (the default instance and no pixel size, ashb-shapeuses), and the result lists what was left out. The TTF page has the details. - Viewer: the Apple tables acnt, bdat, bhed and bloc are decoded, and the
other Apple tables too; the state machines of morx, mort, kerx
and kern are run on the shaped string (the justification table
justis read, not run). TrueType instructions are fully disassembled and explained but not executed, as a stated choice: what a hint does to the points is not shown. - Viewer: variable-font outlines are redrawn at an instance for
glyf(gvar) and CFF2 (blend), and the advance widths at an instance are listed with HVAR (VVAR for heights, the gvar phantom points for a glyf font without HVAR) applied, and the control values with the cvar deltas added; the variation indexes of GPOS, GDEF and BASE are decoded and checked, not applied. avar version 2 follows HarfBuzz’s source and the Boring Expansion specification, because the specification page read for the viewer describes version 1 only. - Viewer: the colour glyphs of COLR
(version 0 layers, version 1 paints with every paint format, each base glyph clipped to its
ClipList box) are drawn with the foreground colour of the “Foreground colour” option; SVG
glyph documents are drawn by the viewer’s own renderer (fills and strokes, linear and radial
gradients, clip paths, masks, group opacity, transforms and
use; filters, text, images, patterns, markers and style sheets are listed as not drawn); Apple’sflipsbix type, which no specification defines, is drawn as the glyph it names mirrored (inferred from Apple Color Emoji’s glyph names); EBDT/CBDT image format 3 has no layout at all. - Viewer: the SVG documents are checked against the content rules of the
OpenType SVG page (problems for its “must” rules: UTF-8 and well-formed XML, the SVG and xlink
namespaces, the restricted elements,
rgba(), em and ex units, colour profiles, CSS2 system colours, and an element with the idglyphNfor every glyph of each record’s range; notes for the “should” and optional items such as style, filters, masks, animation and other namespaces). Open: the check reads attributes and CSS declarations, not selectors or the cascade, and does not test thatvar()is the first item of a value. Every problem the decoders find is listed under its true count; the caps of 40, 60 and 100 messages thatkern,name,glyfand CFF charstring problems had are gone.
Unknown
- Reference: the layout of EBDT/CBDT image format 4 (Apple’s compressed bitmaps): the OpenType EBDT page says it is Apple’s and “not supported in OpenType”, Apple’s bdat page gives only its three offsets and calls it a modified Huffman encoding, and FreeType has no loader for it, so no source read for the viewer gives the layout of the trees or the bit stream: the viewer shows the three offsets and the data as bytes. This is a fact of the format’s published description, not a gap in the viewer.
Links
Software
Developers
- fontTools – library that reads, edits and writes OpenType fonts (Python)
- FreeType – library that renders glyphs from OpenType and TrueType fonts (C)
- HarfBuzz – text shaping library that applies OpenType layout features (C++)
- opentype.js – library that parses and writes OpenType fonts (JavaScript)
Reference
- OpenType specification – Microsoft’s full specification of the format and its tables
- The Compact Font Format Specification – Adobe Technical Note #5176, the format of the CFF table (PDF)
- The Type 2 Charstring Format – Adobe Technical Note #5177, the glyph programs inside CFF (PDF)