Format:WOFF2
| Developer | W3C Web Fonts Working Group (Google's woff2 reference code) |
|---|---|
| Versions | WOFF File Format 2.0 (W3C Recommendation 2018) |
| Magic | 77 4F 46 32 ('wOF2') at 0 |
| Extensions | .woff2 |
| Endianness | big |
| License | reference code MIT (google/woff2) |
| On this wiki | Facts · Code · Notes · Topics |
W3C web font container (.woff2, signature 'wOF2'): a 48-byte big-endian header, a compact table directory (flag byte with a known-tag index and transform version, UIntBase128 lengths) and all font tables, glyf/loca and hmtx optionally transformed, compressed together as one Brotli stream; decompressing and reversing the transforms gives back a TrueType/OpenType font.
Overview
WOFF2 packs a Format:OpenType font file (or a collection) for the web. Unlike WOFF 1, which compresses every table separately with zlib, WOFF2 concatenates the (optionally transformed) table data and compresses it as one Format:Brotli stream that starts right after the table directory (and, for collections, the collection directory). Google's reference encoder calls BrotliEncoderCompress with window 22 and BROTLI_MODE_FONT, so the stream usually starts with 1B or 5B.
Header
48 bytes, big endian: signature 'wOF2', flavor (the sfnt version: 00 01 00 00, 'OTTO', or 'ttcf' for a collection), length (whole file; the reference decoder rejects a mismatch), numTables (u16), reserved (u16), totalSfntSize, totalCompressedSize (length of the Brotli stream), majorVersion, minorVersion (u16 each), metaOffset, metaLength, metaOrigLength (optional Brotli-compressed XML metadata), privOffset, privLength. See Fact:WOFF2/struct/WOFF2Header.
Table directory
One variable-length entry per table, in the order of the compressed data:
flags(u8): bits 0-5 index into a fixed list of 63 known tags (0 cmap, 1 head, 2 hhea, 3 hmtx, 4 maxp, 5 name, 6 OS/2, 7 post, 8 cvt, 9 fpgm, 10 glyf, 11 loca, 12 prep, 13 CFF, ...); 63 means a 4-byte tag follows. Bits 6-7 are the transform version.origLength: UIntBase128 (1-5 bytes, 7 bits each, high bit = more, a leading 0x80 is invalid).transformLength: UIntBase128, present only when the table is transformed: for glyf and loca transform version 0 means transformed (any other version: stored as is), for every other table any version other than 0 means transformed (hmtx version 1). A transformed loca has transformLength 0 (it is rebuilt from glyf).
The decompressed Brotli stream is exactly the sum of each table's transformLength (if transformed) or origLength.
Checked
Six WOFF2 fonts shipped with Blender 5.2 (DejaVuSansMono, Inter, Noto Sans Hebrew, Javanese, Armenian, Gujarati; 18 KB to 351 KB) were parsed with the layout above: in each the length field equals the file size, the Brotli stream starts at the end of the directory (offsets 0x59-0x7A), its first byte is 1B or 5B (WBITS 22) and the pure-Python decoder of Code:Brotli/Brotli decoder and library scanner (Python) decodes it to exactly the expected total (36,087 to 850,618 bytes). The glyf/loca/hmtx transforms themselves were not reversed here.
Code & repositories
- https://github.com/google/woff2 @
fb9c3379f2605b10f3e8f1d9636664ab5576775c· license: MIT
Google's WOFF2 reference encoder/decoder (C++, MIT; uses libbrotli): woff2_compress, woff2_decompress and woff2_info, with the header and table-directory reader in src/woff2_dec.cc, the 63 known tags in src/table_tags.cc and the glyf/loca/hmtx transforms in src/transform.cc and src/woff2_dec.cc.
Tested on: Read at this commit (header, directory, UIntBase128, Brotli calls); the layout was checked on six WOFF2 fonts shipped with Blender 5.2 with a Python parser and the wiki's Brotli decoder. Not built. · checked 2026-10-17; last activity 2026-06-29
Pitfalls
- The table data is one stream: to get any table you must decompress everything before it.
- The decoded glyf table is in the transformed layout (separate streams of contour counts, points, flags, glyphs, composites, bboxes, instructions), not a usable glyf; reverse it with google/woff2's woff2_decompress or a WOFF2-aware library before parsing.
- Collections (
flavor'ttcf') have a collection directory after the table directory; the compressed stream starts after it. - The transformed glyf header (36 bytes, seven substreams) is in Fact:WOFF2/struct/Transformed glyf table header; the hmtx transform flags are in Fact:WOFF2/behavior/Transformed hmtx flags. Both were read in google/woff2 src/woff2_dec.cc at fb9c3379f2.
Evidence & references
- https://github.com/google/woff2 at commit fb9c3379f2605b10f3e8f1d9636664ab5576775c (MIT): header in src/woff2_dec.cc lines 1073-1135 (ReadWOFF2Header), table directory lines 810-865 (ReadTableDirectory), known tags in src/table_tags.cc lines 16-80, UIntBase128 in src/variable_length.cc lines 86-109, Brotli call in src/woff2_enc.cc lines 40-52 and src/woff2_dec.cc line 801.
- W3C WOFF File Format 2.0.