Introduction
WOFF2 is a compressed wrapper for TrueType and
OpenType fonts, made for the web and published as a
W3C Recommendation in March 2018; the current edition is from August 2024. It holds the same tables as the original font, compressed
together with Brotli, and stores the glyph outlines in a transformed form that
compresses better. A WOFF2 file is typically much smaller than the font it came from,
and every current browser loads it through CSS @font-face.
The earlier WOFF 1.0, .woff,
compressed each table separately with zlib.
Structure
A WOFF2 file is big-endian. It begins with a 48-byte
header: the signature wOF2, the
flavour of the original font, the total length, the number of tables, the size the
font will have once decoded, the size of the compressed data, a version number, and the
location of optional metadata and private data. A
table directory follows, written
compactly: one flags byte that usually names one of 63 known table tags and says
whether the table is transformed, then lengths stored as variable-length numbers. A
font collection (ttcf) adds a
collection directory saying
which tables belong to each font. Then comes a single
Brotli stream holding every table,
followed by the optional extended metadata, which is Brotli-compressed XML, and private
data.
Two tables are usually stored in a rearranged form that compresses better: the
glyf outlines are split into
separate streams of contour counts, flags and packed coordinates, and
loca is left out and rebuilt from them. The
hmtx table can also drop side
bearings that equal the glyphs’ xMin. The decoder rebuilds a working
TrueType or OpenType font, with new checksums; it need not be byte for byte the
original.
0HeaderwOF2, flavour, lengths, table count, version48 bytes48Table directory a flags byte and lengths for each tablevaries…Collection directory only for a font collectionvaries…Compressed font data every table in one Brotli streamvaries…Extended metadata, private dataoptional
In the explorer
Dropping a .woff2 file on the explorer shows the
header field by field, the
table directory (each entry’s flags,
known-tag index, transformation version, lengths and place in the stream), a
collection directory for a
collection, and the Brotli stream,
which is decompressed with the explorer’s own Brotli decoder (RFC 7932, with its static
dictionary). The glyf transform is
undone with all seven streams, the bounding box bitmap and the overlap bitmap, and
loca is rebuilt from it; the
hmtx transform is undone in its three
flag forms. The extended metadata is decompressed, checked against the schema and shown
as XML (it opens as an entry), and the private data is a block of bytes.
Each font in the file is rebuilt as an sfnt, with new table checksums and a new
checkSumAdjustment, and given to the TrueType
and OpenType viewer: its Font, Tables, Outlines and Instructions tabs work on the
web font, and the rebuilt font (or, for a collection, each member and the whole
.ttc) opens with an Open button. A collection has an option to choose which
font the tabs show. Every rule of the Recommendation that the file breaks is listed as a
problem: the header, the numbers, the directory, the order of glyf and
loca, the Brotli stream and its lengths, each transform, the blocks and their
padding, the metadata schema.
A table whose directory entry names a transformation version the Recommendation does
not define (any combination other than those in the
table directory page: only
glyf, loca and hmtx have a transform besides the
null one) cannot be decoded, because the Recommendation defines nothing to undo: it says
the whole font must be rejected. The explorer lists the problem and shows that table as
the bytes of the stream, since there is nothing else to show. That is a fact of the
format, not a missing feature.
Not described
Known, not yet covered
- Viewer: the Recommendation’s metadata schema is checked from its
text (the RelaxNG schema it also gives is not run). The metadata is shown in every
language it has, and a second table shows the text a user agent would choose for the
languages typed in the “Metadata language” option, by the Recommendation’s rule (the
preferred language, then each acceptable one, a tag also matching the same tag with its
last parts dropped; then an element with no
xml:lang; then the first). The user’s language is the option, not read from a browser setting. - Viewer: the Brotli stream is shown on the WOFF2 tab as its meta-blocks, the header fields and prefix codes of each, and every command (the literals it inserts, the copies and dictionary words), with the .br viewer’s machinery. Every command is reachable: the table pages through all of them, decoding the stream again from its start for each window of 5,000 commands; the bit-level view that links a command to its bytes in the file is the .br viewer’s and is not here.
- Viewer: the tabs for the rebuilt font are the TrueType and OpenType viewer’s, so what is still open there is open here: TrueType hinting is disassembled, not run; text shaping runs all of GSUB and GPOS and Apple’s morx, kerx and trak, with the Arabic, Hebrew and Thai shapers (not HarfBuzz’s Indic, Khmer, Myanmar and Universal Shaping Engine shapers); SVG glyphs are drawn by a small renderer (fills, strokes, gradients, clip paths, masks; no filters or text). Every problem and note those tabs find is listed with its true count (round 6 removed the caps). The full list is the “Not described” section of the .ttf page.
Links
Software
- Web browsers – every current browser loads WOFF2 through CSS
@font-face - FontForge – free font editor that opens and saves WOFF2 (Windows, macOS, Linux)
Developers
Reference
- WOFF File Format 2.0 – the W3C Recommendation that defines WOFF2 (edition of 8 August 2024)
- RFC 7932 – the Brotli compressed data format
- RFC 8081 – registers the
font/woff2media type