Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SWF font parsing: DefineFont3 to TrueType

Implemented in CreationEngineFormats/Swf/, without Skyrim-specific knowledge. References:

The exporter side (which SWFs, which fonts) is in Font export.

SWF container

SwfReader: a 3-byte signature, a version byte and a uint32 file length, then the body.

SignatureBodySupport
FWSUncompressedRead
CWSzlibRead; the only kind in the interface archive
ZWSLZMAThrows NotSupportedException

The body starts with a bit-packed RECT, a frame rate and a frame count, all skipped, then the tags. A tag header is a uint16: code in the top 10 bits, length in the low 6; a length of 0x3F means a uint32 length follows. SwfBitReader reads the MSB-first bit fields.

DefineFont3

DefineFont3Reader (tag 75), the only font tag found in Skyrim SWFs. DefineFontName (tag 88) supplies each font’s name.

FieldNotes
Font iduint16
FlagsHas layout 0x80, wide offsets 0x08, wide codes 0x04, italic 0x02, bold 0x01
Language code, nameSkipped: DefineFontName carries the name
Glyph countuint16
Offset tableuint16 or uint32 per glyph, then the code table offset
Glyph shapesSHAPE records: move, straight and quadratic curve edges
Code tableuint8 or uint16 per glyph
LayoutOnly with the layout flag: ascent, descent, leading, advances, bounds, kerning (not read)

Quadratic curves are the same curve type as TrueType glyf, so no curve fitting is needed. Three properties aren’t stated by SWF19 and were checked on real files, see Spec deviations: the EM square is 20480 units, Y points down, and the per-glyph bounds are always zero.

TrueType writer

SfntBuilder writes the table directory, padding and checksums, including head.checkSumAdjustment. TrueTypeFontWriter builds the tables:

ChoiceWhy
2048 units per EM20480 exceeds the head limit of 16384; dividing by 10 is exact
Synthesized .notdef at glyph 0Required by TrueType; SWF glyphs follow in order
glyf bounds from the contour pointsThe SWF bounds are unusable
cmap format 4, format 12 when format 4’s uint16 length overflowsFirefox rejects format 6; format 12 covers the 17,514-glyph Chinese font
Format 4 through idRangeOffset and glyphIdArrayGlyph order follows the SWF, not character codes
OS/2 version 0Smallest version with usWinAscent and usWinDescent, which set line height
post version 3.0No glyph names needed
One hmtx entry per glyphSimpler; the fonts are small

Generated fonts pass fc-validate and fc-scan (FreeType). FreeType accepts cmap formats browsers don’t: format 6 passed FreeType but Firefox refused it. Any change to the table formats needs a check through @font-face in a browser. Glyph winding hasn’t been checked visually.