Decoding WOFF2 Flag Bytes, Known Tag Tables, and UIntBase128 Streams
Inside the Compact WOFF2 Variable-Length Directory
Traditional SFNT and WOFF 1.0 directories spend 16 to 20 fixed bytes per table entry. To shave overhead on micro-subsets, WOFF2 encodes each directory entry starting with a single flags byte: bits 0..5 index into a 63-entry lookup table of standard OpenType tags (such as cmap=0, head=1, glyf=10, loca=11), while bits 6..7 encode a two-bit transformation version.
Immediately following the flags byte, table lengths are encoded as big-endian base-128 variable-length integers (UIntBase128) where bit 7 acts as a continuation flag. Note an important spec inversion in W3C WOFF2 Section 4.2: for glyf and loca tables, transformation version 0 indicates the preprocessed transform is active (requiring an explicit transformLength field, which equals 0 for loca), whereas version 3 indicates a null pass-through.
- Rejects illegal leading 0x80 bytes and 32-bit overflows in UIntBase128 sequences.
- Flags whether glyf, loca, and hmtx streams use null or structural WOFF2 transforms.
- Reports exact byte offset where the shared Brotli compressed data block begins.
- Compares declared totalSfntSize against actual reconstructed SFNT output bytes.