Introduction
WOFF is a wrapper for TrueType and
OpenType fonts, made for loading fonts on web pages. It
was proposed in 2009 and became a W3C Recommendation in 2012. It compresses the font’s
tables and can carry licensing metadata, and browsers load it through CSS
@font-face. WOFF2, which compresses
better, has largely replaced it, but WOFF is still kept as a fallback for older
browsers.
Structure
A WOFF file is big-endian. It starts with a 44-byte
header: the signature wOFF, the
flavour of the original font (00 01 00 00 for TrueType outlines or
OTTO for CFF), the file length, the number of tables, the size of the font
once unpacked, a version number, and the offsets and lengths of the optional metadata
and private data. A table directory
follows, 20 bytes per table, sorted by tag: the tag, the table’s offset in the file,
its compressed and original lengths and its checksum. The tables come next, in the
order the original font had them, each on a four-byte boundary. Each is compressed with
zlib on its own, or stored as it was when compression would not make it smaller.
Optional extended metadata, compressed XML
about the font and its licence, and private data can follow at the end.
To use the font, a decoder uncompresses each table and rebuilds the TrueType or OpenType file around them, computing the font’s own header and table records again; the result should be the original font, byte for byte.
0HeaderwOFF, flavour, lengths, table count, version44 bytes44Table directory tag, offset, compressed and original length, checksum20 bytes each…Font tables each compressed with zlib or stored, padded to 4 bytesvaries…Extended metadata zlib-compressed XMLoptional…Private data anything, to the end of the fileoptional
In the explorer
Dropping a .woff file on the explorer shows the
header field by field, the
table directory with each table’s
offset, stored and original length and recorded and computed checksum, every table
inflated (or marked stored), and the
extended metadata, decompressed, checked
against the schema and shown as XML (it opens as an entry), with the private data as a
block of bytes.
The font is rebuilt as an sfnt (byte for byte the original when the file is well
formed, with the recorded checksums kept) and given to the
TrueType and OpenType viewer: its Font, Tables,
Outlines and Instructions tabs work on the web font, and the rebuilt font opens with an
Open button. Every rule of the Recommendation that the file breaks is listed as a
problem: the signature, length, the reserved field,
totalSfntSize, the order and alignment of the directory and tables, the
padding, compLength against origLength, the zlib streams and
their sizes, the checksums, and the metadata and private data blocks.
Not described
Known, not yet covered
- Reference: section 2 user-agent rules (follow CSS3 Fonts
@font-face; a linked font is available only to the documents that reference it and is not exposed to other documents or applications; a WOFF file is not an installable desktop font). Not on any page. - Reference: section 6 and 7 user-agent rules not on the pages:
removing
GSUBorGPOSdata automatically is strongly discouraged; extra non-table data in the original font is ignored and not preserved; a user agent that shows font information treats the metadata block as the primary source and may fall back to thenametable; severaltextelements should carry distinct language tags; user agents that display metadata should showextension; the RelaxNG schema exists and the prose takes precedence over it. See Metadata and private data. - Reference: section 5 well-formed input font norms for a lossless round trip (every table including the last padded to 4 bytes, no hidden data between tables, correct header search fields, no overlapping tables) are not listed as such; only the checksum rule is. See Table directory and tables.
- Reference: Appendix B security considerations of the media type registration (hidden data in the font, complex hinting code, limits and buffer-size checks when decompressing, no built-in privacy protection, private data must never be executed) are not described.
- 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 rule that the tables keep the order of the input font (section 6: “MUST be stored in the same order as the well-formed input font”) cannot be compared directly, because the input font is not in the file and the directory is sorted by tag, so nothing in the file records the input’s order. What is checked: the viewer lays the rebuilt font out in the file’s order and sums the whole font. That sum includes the directory’s offsets, so it depends on the order: a well-formed input font rebuilt in its own order sums to 0xB1B0AFBA. The WOFF tab’s “Table order” row says whether it does, and a note says when it does not. A mismatch is a note, not a problem, because it has two causes the file cannot tell apart: another order, or an input font that was not well formed (data between its tables dropped, a wrong checksum).
- 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 WOFF through CSS
@font-face - FontForge – free font editor that opens and saves WOFF (Windows, macOS, Linux)
Developers
- fontTools – library that reads and writes WOFF (Python)
- opentype.js – library that parses WOFF fonts (JavaScript)
Reference
- WOFF File Format 1.0 – the W3C Recommendation that defines WOFF (13 December 2012)
- RFC 8081 – registers the
font/woffmedia type, which replacedapplication/font-woff - OpenType font file – the table directory and checksums of the fonts WOFF wraps