Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:OpenType font file

From ReverseEngineering.wiki
Format
Developer Apple (TrueType, 1991); Microsoft and Adobe (OpenType, 1996); ISO/IEC 14496-22 (Open Font Format)
Versions TrueType 1.0; OpenType 1.0 (1997) to 1.9.1
Magic 00 01 00 00, 'OTTO' (4F 54 54 4F), 'true', 'typ1'; collections 'ttcf'; head table magicNumber 5F 0F 3C F5
Extensions .ttf, .otf, .ttc, .otc (also embedded in executables, PDFs, WOFF/WOFF2)
Endianness big
Website https://learn.microsoft.com/en-us/typography/opentype/spec/otff
On this wiki Facts · Code · Notes · Topics

The sfnt font container of TrueType and OpenType fonts (.ttf, .otf, .ttc, .otc): a big-endian table directory (sfnt version 00 01 00 00 or 'OTTO', table count, binary-search fields) followed by 16-byte table records (tag, checksum, offset, length) pointing to 4-byte-aligned tables such as head, cmap, glyf/loca or CFF, hmtx, name and post. Collections start with 'ttcf' and an offset per font.

Overview

An OpenType font file is a set of independent tables found through a directory at the start of the file (the TrueType sfnt wrapper). Each table has a four-character tag: head (font header), hhea/hmtx (horizontal metrics), maxp (glyph count), cmap (character to glyph mapping), name (family and style names), OS/2, post, and the outlines: glyf + loca (TrueType quadratic outlines, with bytecode in fpgm, prep, cvt ) or CFF / CFF2 (PostScript cubic outlines). Optional tables add layout (GSUB, GPOS, GDEF), variations (fvar, gvar, avar, HVAR), color (COLR/CPAL, CBDT/CBLC, sbix, SVG ) and bitmaps (EBDT/EBLC). Everything is big endian. Engines that read it include Library:FreeType (its sfnt, truetype and cff modules), DirectWrite, Core Text, HarfBuzz and stb_truetype.

Structure

  • Table directory at offset 0 (in a collection: at each offset of the TTC header): uint32 sfntVersion, uint16 numTables, searchRange = 16 * 2^floor(log2(numTables)), entrySelector = floor(log2(numTables)), rangeShift = 16 * numTables - searchRange, then numTables table records.
  • Table record (16 bytes): Tag tableTag, uint32 checksum, Offset32 offset (from the start of the file, also in collections), uint32 length (unpadded). Records are sorted by tag in byte order, so upper-case tags (GSUB, OS/2) come before lower-case ones (cmap, head). Tables start on 4-byte boundaries, zero padded.
  • Collection (.ttc/.otc): 'ttcf', uint16 majorVersion (1 or 2), uint16 minorVersion, uint32 numFonts, Offset32 tableDirectoryOffsets[numFonts]; version 2 adds dsigTag, dsigLength, dsigOffset. Fonts in a collection share tables (typically glyf, loca, hmtx) by pointing to the same offsets.
  • head (54 bytes): version 1.0, fontRevision, checksumAdjustment at +8, magicNumber 0x5F0F3CF5 at +12, flags +16, unitsPerEm +18 (1000 for CFF fonts, often 2048 for TrueType), created/modified (seconds since 1904) +20/+28, bounding box +36, macStyle +44, indexToLocFormat +50 (0: loca holds uint16 offsets / 2; 1: uint32 offsets).
  • maxp: version 0.5 (0x00005000, 6 bytes, CFF fonts) or 1.0 (32 bytes, TrueType), numGlyphs at +4.

Identification

Bytes at offset 0 Meaning
00 01 00 00 TrueType outlines (most .ttf)
4F 54 54 4F ('OTTO') CFF or CFF2 outlines (.otf)
74 74 63 66 ('ttcf') collection (.ttc, .otc)
74 72 75 65 ('true'), 74 79 70 31 ('typ1') old Apple fonts (not valid OpenType)
77 4F 46 46 ('wOFF'), 77 4F 46 32 ('wOF2') WOFF / WOFF2 web fonts, flavor field at +4 holds the sfnt version. WOFF compresses each table separately with zlib (Format:Zlib stream); Format:WOFF2 compresses all tables (glyf/loca and hmtx optionally transformed) as a single Format:Brotli stream after the table directory (the C encoder's BROTLI_MODE_FONT)

Inside other files, a font starts with one of the versions followed by a plausible numTables (about 9-30) whose searchRange matches, and a head table whose bytes 12-15 are 5F 0F 3C F5. The wiki's sfntinfo script parses fonts and collections and has a --scan mode for embedded fonts.

Checksums

A table checksum is the sum of its big-endian uint32 words modulo 2^32, the data zero-padded to a multiple of 4. The head checksum is computed with checksumAdjustment read as 0. checksumAdjustment = 0xB1B0AFBA - (sum of the whole file with that field as 0); for a single font the whole-file sum including the field is therefore 0xB1B0AFBA. Collections do not use checksumAdjustment (may be 0). The fact on this page has test vectors.

Code & repositories

  • https://github.com/fonttools/fonttools @ b0fa59394498d146b73e2482ae7c17444ddea50b · license: MIT
    fontTools (MIT): Python sfnt/WOFF/WOFF2 reader and writer; ttLib/sfnt.py has the sfnt, TTC and WOFF header structures and calcChecksum.
    Tested on: source read, not run: source read · checked 2026-10-18; last activity 2026-10-16

Pitfalls

  • Readers do not reject wrong checksums: FreeType never verifies table checksums and only traces a bad head magic. Of 303 fonts in a Windows 11 font directory (265 files, 15 of them collections), 6 table records had a wrong checksum (GPOS, Gloc twice, OS/2, hmtx, loca) although every single-font file had a correct checksumAdjustment; all directories were sorted, all searchRange values correct, all tables 4-byte aligned.
  • Collection table offsets are from the start of the collection file, not from the subfont's table directory.
  • loca with indexToLocFormat 0 stores offset / 2.
  • Fonts are copyrighted works: document structure and checksums, never publish font files you did not make or that are not under a free license (OFL fonts and FreeType's test fonts are).

Evidence & references

  • Microsoft OpenType specification 1.9.1, "OpenType font file" (otff), read 2026-10-17: table directory, table record, checksum procedure with 0xB1B0AFBA, TTC header versions 1.0 and 2.0.
  • FreeType source at VER-2-15-0 (commit 37515cf56ba3349656049edbed89ffc6f6466f2d): src/sfnt/sfobjs.c lines 430-437 (accepted sfnt versions 0x00010000, 'ttcf', 'OTTO', 'true', 'typ1', 0xA5 'kbd', 0xA5 'lst', 0x00020000), src/sfnt/ttload.c lines 255-290 (head at least 0x36 bytes, magic only traced).
  • sfntinfo run on FreeType's free test fonts tests/data/varc-static-gvar.ttf and varc-static-cff2.otf (sample facts) and on all fonts of a Windows 11 font directory (results above; the files are not published).