Skip to content

CommonType Containers

Simon Cozens edited this page Sep 5, 2020 · 2 revisions

CommonType Containers

SFNT-based font formats

Currently, SFNT-based fonts are “described”, “documented”, “specified” or “standardized” in several places:

OpenType

The OpenType® format, documented with a “specification”.

The **Script development specs are separate documents that are not part of the OpenType spec. The text for the script development specs is © Microsoft.

TrueType

The TrueType® format, documented with a “reference manual”.

OFF

The Open Font Format standard, or OFF, documented with a “standard”.

  • The Open Font Format standard is an international standard published as ISO/IEC 14496-22:2019 “Information technology — Coding of audio-visual objects — Part 22: Open Font Format” by ISO® (International Organization for Standardization) and IEC (International Electrotechnical Commission).
  • The Open Font Format standard is available at no charge on the ISO website.
  • The text of the standard is © ISO.

The OFF standard closely follows the OpenType specification, but does not include the Script development specs.

Real world

Implementations typically follow an amalgamation of these documents. Some apps or OSes (most notably Microsoft’s) follow OpenType, some apps (most notably Apple’s as well as HarfBuzz) follow a mixture of OpenType and TrueType.

Analogy: audiovisual formats

Font formats (including desktop and web font formats) can be explained using an analogy with digital audiovisual formats. In audiovisual applications, there is a distinction between container formats and coding formats.

For example, AVI, MKV, OGG and MP4 are all container formats that can hold various metadata and data for various streams of audiovisual data. This is different from the coding format which specifies in which way the multimedia contents of each stream is encoded (e.g. AAC, MP3, MPEG-2, H.264 etc.).

Container formats

Following this analogy, there are several fundamentally different groups of container formats for digital font files:

  1. SFNT-based container formats that derive from the structure of TrueType and OpenType files. They include WOFF, EOT, OTF, TTF, TTC, DFONT, FFIL, and can store monochrome outline font data. Some of them are highly relevant for CSS webfont use. SFNT-based containers can also contain bitmap data, but this is irrelevant for CSS webfont use.

  2. PostScript-based container formats that derive from the structure of PostScript files, and can store monochrome and color outline font data. They are outside of the scope of discussion, apart from CFF, which is a PostScript-based container format embedded in the SFNT-based containers.

  3. bitmap container formats, outside the scope of CSS webfont discussion.

  4. special web-only container formats including Flash, Silverlight, SVG and JavaScript (e.g. Cufon)

Coding formats

Within SFNT-based container formats, several coding formats can be used.

Similar to the audio and video streams in audiovisual files, we can identify several kinds of streams that can be stored in SFNT-based container formats.

Principally, an SFNT-based container format can contain one or more SFNT streams and potentially additional non-SFNT streams. A TTF and OTF file contains just one SFNT stream. A TTC or DFONT file contains one or more SFNT stream (DFONT also contains a Mac-related non-SFNT stream). An EOT or WOFF file contains one SFNT stream and an additional non-SFNT stream (metadata).

SFNT stream

An SFNT stream is made up of several “substreams” of different purpose.

Selection substream

The font selection substream contains central information about the font’s identity (naming, family linking, digital signature), and has info that is exposed to end-user in user interfaces. This includes the SFNT tables head, hhea, name, OS/2, DSIG, fvar, STAT and some others.

Encoding substream

The encoding substream provides mapping from character codes to glyphs. This includes the SFNT tables cmap, post. The info in the encoding substream also affects selection: if a font does not cover some characters, systems will fall back to another font, using the selection substream as guidance.

Layout substream

The layout substream instructs the layout engine how to rearrange and position the glyphs in a line, and perform “shaping”. This includes the SFNT tables kern, BASE, GDEF, GSUB, GPOS, JSTF, morx, kerx, trak and others.

Several coding formats exist. An SFNT font can contain one or more layout substreams. For example, a font may have a TrueType layout substream (the kern table), an OpenType layout substream, and an AAT substream. The TrueType layout substream is the most primitive, the latter ones offer more sophistication. This is analogous to audio streams, where one audiovisual file can have audio in both mono (~TrueType) and Dolby 5.1 (~OpenType) versions. The layout engine needs to choose one — just like you wouldn’t want to listen to two parallel audio tracks at the same time.

  • “TrueType layout”: legacy, table: kern

  • “OpenType layout” or “OTL”: suitable for all rendering substreams, tables: BASE, GDEF, GSUB, GPOS, JSTF

  • “AAT” or “Apple Advanced Typography” or “AAT layout”: suitable for static monochrome outline and color substreams, tables: morx, kerx, trak and others

  • “Graphite” or “SIL Graphite”: alternative layout substream coding format developed by SIL, designed to support complex writing systems where the needed shaping behaviors either aren't implemented or aren't possible using OpenType layout

Rendering substream

The rendering substream instructs the font rasterizer how to draw the glyph shapes. This includes the SFNT tables CFF2, CFF , SVG , glyf, gvar, cvt , fpgm, loca, prep, VORG, EBDT, EBLC, EBSC, CBDT, CBLC, sbix.

The rendering substream exists in several coding formats, which differ as to whether they contain outline- or bitmap-based data, whether they’re static or variable, and whether they contain monochromatic/grayscale or color content.

A font can only contain one monochrome outline rendering substream (either TrueType or CFF). The coding format of the monochrome outline rendering substream is identified by the SFNT version field at the beginning of the SFNT stream.

  • In TrueType coding format, the SFNT version field is \00\01\00\00.
  • In CFF coding format, the SFNT version field is OTTO.

This makes the glyph imaging substream analogous to the video stream in an audiovisual file (you rather not have two parallel video streams in a file).

TODO: Clarify CFF2

TODO: Clarify interaction between the monochrome outline substream and the other substreams

Legacy bitmap

  • “SBIT”: monochrome or grayscale bitmaps, PPM-specific, legacy, tables: EBDT, EBLC, EBSC, bdat, bloc

Monochrome outline

  • “TrueType”: monochrome static outline, quadratic splines, tables: cvt, fpgm, glyf, loca, prep, hdmx, LTSH, VDMX, vhea, vmtx
  • “TrueType Variations” or “variable TrueType”: monochrome variable outline, quadratic splines, all of TrueType plus gvar
  • “CFF” or “PostScript”: monochrome static outline, cubic splines, tables: CFF , VORG
  • “CFF2 Variations” or “variable PostScript”: monochrome variable or static outline, cubic splines, tables: CFF2

Color

  • “COLR” or “layered color”: overlays glyphs from any of the color variable or static outline substreams and colorizes each layer, tables: COLR, CPAL
  • “SVG”: color static outline and bitmap, cubic and quadratic splines, must also include a monochrome outline substream, tables: SVG
  • “sbix”: color bitmaps based on PNG, may contain multiple PPM masters, must (?) also include a monochrome outline substream, tables: sbix
  • “CBDT”: color bitmaps based on PNG, may contain PPM masters at up to 127 PPM, PPM-specific when combined with a monochrome outline substream, scalable if no monochrome outline substream present, semi-legacy, tables: CBDT, CBLC

Other substreams

Additional and private SFNT substreams (for example private VOLT or VTT tables).

Non-SFNT stream

While “desktop font formats” (TTF, OTF) just contain an SFNT stream, the “native web font formats” (WOFF) may also contain a non-SFNT stream with metadata.

Container and coding formats overview

Numerous combinations of line layout and glyph imaging substreams can be found in shipping fonts (the three most common combinations are indicated in bold). The table also indicates which containers support which substreams. + indicates that the container supports a given combination of substreams, ++ indicates that the container is preferred to store that combination, or that the container is most likely to include such combination. * indicates the container most relevant to CSS webfont use.

TODO: WOFF2

Format name Coding format Container format
Line Glyph TTF* OTF TTC DFONT FFIL EOT* WOFF*
TrueType TrueType TrueType ++ + ++ ++ ++ ++ ++
OpenType-TrueType OpenType TrueType ++ + ++ + + ++ ++
OpenType-CFF OpenType CFF ++ + + ++
AAT-TrueType AAT TrueType + + + ++ ++ + +
AAT-CFF, AAT CFF + ++ ++ +
Graphite-TrueType Graphite TrueType + + + + + + +
Graphite-CFF Graphite CFF + + + +

Modern containers

  • TTF is a container format for desktop and web fonts that contains just one SFNT stream with the glyph imaging substream in TrueType coding format

  • OTF is a container format for desktop and web fonts that that contains just one SFNT stream with the glyph imaging substream in TrueType or CFF coding format

  • WOFF is a container format for web fonts that contains one SFNT stream with the glyph imaging stream in compressed TrueType or CFF coding format, plus a metadata stream (the WOFF metadata)

  • WOFF2 is a newer container format (TODO)

  • TTC is a container format for desktop fonts that contains one or more SFNT streams with glyph imaging substreams in TrueType coding format (TODO: also CFF)

Legacy containers

  • DFONT is a container format for desktop fonts that contains one or more SFNT streams with glyph imaging substreams in TrueType (or possibly CFF) coding format, plus a metadata stream (i.e. other Mac resources)

  • FFIL is a container format for desktop fonts that contains one or more SFNT streams with glyph imaging substreams in TrueType coding format, plus a metadata stream (i.e. other Mac resources) — unlike the other container formats, it is stored as a Mac "resource fork", which makes it work only on Mac OS

  • EOT is a container format for web fonts that contains one SFNT stream with the glyph imaging substream in (potentially compressed) TrueType coding format, plus a metadata stream (the EOT metadata)