A font is a set of glyph outlines, each a SHAPE, with the character code of each glyph and, optionally, layout and kerning. Static text refers to glyphs by index and places them one by one; a text field holds real text and lays it out at run time, with an embedded font or one of the computer’s own. In this format names and text are UTF-8 and character codes are 16-bit.
Glyph shapes
A glyph is a SHAPE with no style lists: fill style 1 is implied and there are no lines. The glyphs of DefineFont and DefineFont2 are drawn in an EM square of 1,024 units, which at 1 twip a unit is 51.2 pixels; DefineFont3’s EM square is 20,480 units, 20 times finer. An empty glyph, such as a space, can have no records at all: its offset equals the next one.
DefineFont (10)
| Type | Name | Meaning |
|---|---|---|
| UI16 | FontID | The character ID |
| UI16 × nGlyphs | OffsetTable | Offsets of the glyphs, from the start of this table; nGlyphs = the first offset ÷ 2 |
| SHAPE × nGlyphs | GlyphShapeTable | The glyphs |
It has no character codes: a DefineFontInfo or DefineFontInfo2 with the same ID gives them.
DefineFontInfo (13)
| Type | Name | Meaning |
|---|---|---|
| UI16 | FontID | The DefineFont it describes |
| UI8 | FontNameLen | The length of the name |
| UI8 × FontNameLen | FontName | The font’s name |
| UB[2] | FontFlagsReserved | 0 |
| UB[1] | FontFlagsSmallText | Drawn for small sizes (SWF 7) |
| UB[1] | FontFlagsShiftJIS | Shift-JIS codes |
| UB[1] | FontFlagsANSI | ANSI codes |
| UB[1] | FontFlagsItalic | Italic |
| UB[1] | FontFlagsBold | Bold |
| UB[1] | FontFlagsWideCodes | The codes are UI16 |
| UI8 or UI16 × nGlyphs | CodeTable | The character code of each glyph, in order |
DefineFontInfo2 (62, SWF 6)
DefineFontInfo with a UI8 LanguageCode after the flags byte, and
FontFlagsWideCodes always 1, so the code table is UI16 Unicode values.
| LanguageCode | Language |
|---|---|
| 0 | None |
| 1 | Latin |
| 2 | Japanese |
| 3 | Korean |
| 4 | Simplified Chinese |
| 5 | Traditional Chinese |
DefineFont2 (48, SWF 3)
| Type | Name | Meaning |
|---|---|---|
| UI16 | FontID | The character ID |
| UB[1] | FontFlagsHasLayout | Layout fields follow the code table |
| UB[1] | FontFlagsShiftJIS | Shift-JIS |
| UB[1] | FontFlagsSmallText | Drawn for small sizes (SWF 7) |
| UB[1] | FontFlagsANSI | ANSI |
| UB[1] | FontFlagsWideOffsets | The offsets are UI32 |
| UB[1] | FontFlagsWideCodes | The codes are UI16; always 1 in this format |
| UB[1] | FontFlagsItalic | Italic |
| UB[1] | FontFlagsBold | Bold |
| UI8 | LanguageCode | As in DefineFontInfo2 |
| UI8 | FontNameLen | The length of the name |
| UI8 × FontNameLen | FontName | The font’s name |
| UI16 | NumGlyphs | The number of glyphs; may be 0 |
| UI16 or UI32 × NumGlyphs | OffsetTable | Glyph offsets from the start of this table |
| UI16 or UI32 | CodeTableOffset | The code table’s offset, from the same start |
| SHAPE × NumGlyphs | GlyphShapeTable | The glyphs |
| UI16 × NumGlyphs | CodeTable | The character code of each glyph |
| SI16 | FontAscent | If HasLayout |
| SI16 | FontDescent | If HasLayout |
| SI16 | FontLeading | If HasLayout |
| SI16 × NumGlyphs | FontAdvanceTable | If HasLayout: each glyph’s advance |
| RECT × NumGlyphs | FontBoundsTable | If HasLayout: each glyph’s bounds |
| UI16 | KerningCount | If HasLayout |
| KERNINGRECORD × KerningCount | FontKerningTable | If HasLayout: UI16 FontKerningCode1, UI16 FontKerningCode2, SI16 FontKerningAdjustment |
A real DefineFont2 with no glyphs, from a SWF 6 movie: 01 00 font 1,
flags 05 (wide codes, bold), language 0, name length 5,
Arial, then 0 glyphs and a 2-byte code table offset: a font that
only names a typeface.
DefineFont3 (75, SWF 8)
The same fields as DefineFont2, with glyphs at 20 times the resolution, in an EM square of 20,480 units. The code table is always UI16.
DefineFont4 (91, SWF 10)
| Type | Name | Meaning |
|---|---|---|
| UI16 | FontID | The character ID |
| UB[5] | FontFlagsReserved | 0 |
| UB[1] | FontFlagsHasFontData | FontData follows |
| UB[1] | FontFlagsItalic | Italic |
| UB[1] | FontFlagsBold | Bold |
| STRING | FontName | The font’s name |
| bytes | FontData | An OpenType font with CFF outlines, to the end of the tag |
Used by the Text Layout Framework through flash.text.engine, not by
ordinary text fields.
DefineFontAlignZones (73, SWF 8)
| Type | Name | Meaning |
|---|---|---|
| UI16 | FontID | A DefineFont3 |
| UB[2] | CSMTableHint | 0 thin, 1 medium, 2 thick |
| UB[6] | Reserved | 0 |
| ZONERECORD × glyphs | ZoneTable | One per glyph |
A ZONERECORD is UI8 NumZoneData (2), then NumZoneData × ZONEDATA (FLOAT16 AlignmentCoordinate, FLOAT16 Range), then UB[6] Reserved, UB[1] ZoneMaskY and UB[1] ZoneMaskX. The zones help the FlashType renderer snap glyph stems to pixels.
CSMTextSettings (74, SWF 8)
| Type | Name | Meaning |
|---|---|---|
| UI16 | TextID | A DefineText, DefineText2 or DefineEditText |
| UB[2] | UseFlashType | 0 normal, 1 advanced anti-aliasing |
| UB[3] | GridFit | 0 none, 1 pixel, 2 sub-pixel |
| UB[3] | Reserved | 0 |
| FLOAT | Thickness | Stroke thickness adjustment |
| FLOAT | Sharpness | Sharpness adjustment |
| UI8 | Reserved | 0 |
DefineFontName (88, SWF 9)
| Type | Name | Meaning |
|---|---|---|
| UI16 | FontID | The font |
| STRING | FontName | Its full name |
| STRING | FontCopyright | Its copyright notice |
DefineText (11)
| Type | Name | Meaning |
|---|---|---|
| UI16 | CharacterID | The character ID |
| RECT | TextBounds | The bounds |
| MATRIX | TextMatrix | Transforms the text |
| UI8 | GlyphBits | Bits in each glyph index |
| UI8 | AdvanceBits | Bits in each advance |
| TEXTRECORD[] | TextRecords | The text |
| UI8 | EndOfRecordsFlag | 0 |
Colours in its records are RGB.
DefineText2 (33, SWF 3)
The same fields as DefineText, with RGBA colours in the records.
TEXTRECORD
| Type | Name | Meaning |
|---|---|---|
| UB[1] | TextRecordType | 1 |
| UB[3] | StyleFlagsReserved | 0 |
| UB[1] | StyleFlagsHasFont | FontID and TextHeight follow |
| UB[1] | StyleFlagsHasColor | TextColor follows |
| UB[1] | StyleFlagsHasYOffset | YOffset follows |
| UB[1] | StyleFlagsHasXOffset | XOffset follows |
| UI16 | FontID | If HasFont |
| RGB or RGBA | TextColor | If HasColor: RGB in DefineText, RGBA in DefineText2 |
| SI16 | XOffset | If HasXOffset: the x position, in twips |
| SI16 | YOffset | If HasYOffset: the baseline’s y position |
| UI16 | TextHeight | If HasFont: the size, in twips |
| UI8 | GlyphCount | The glyphs in this record |
| GLYPHENTRY × GlyphCount | GlyphEntries | UB[GlyphBits] GlyphIndex, SB[AdvanceBits] GlyphAdvance; padded to a byte at the end |
Glyph indexes point into the font’s glyph table; they are not character codes, so static text does not hold its characters, and a reader gets them from the font’s code table. To draw a record: start at XOffset and YOffset, draw glyph i scaled by TextHeight ÷ 1,024, then move x by its advance.
DefineEditText (37, SWF 4)
| Type | Name | Meaning |
|---|---|---|
| UI16 | CharacterID | The character ID |
| RECT | Bounds | The field’s rectangle |
| UB[1] × 8 | first flags byte | HasText, WordWrap, Multiline, Password, ReadOnly, HasTextColor, HasMaxLength, HasFont |
| UB[1] × 8 | second flags byte | HasFontClass (SWF 9), AutoSize (SWF 6), HasLayout, NoSelect, Border, WasStatic (SWF 8), HTML, UseOutlines |
| UI16 | FontID | If HasFont |
| STRING | FontClass | If HasFontClass: an ActionScript 3 font class |
| UI16 | FontHeight | If HasFont: in twips |
| RGBA | TextColor | If HasTextColor |
| UI16 | MaxLength | If HasMaxLength |
| UI8 | Align | If HasLayout: 0 left, 1 right, 2 centre, 3 justify |
| UI16 | LeftMargin | If HasLayout |
| UI16 | RightMargin | If HasLayout |
| UI16 | Indent | If HasLayout |
| SI16 | Leading | If HasLayout |
| STRING | VariableName | The ActionScript variable the field shows |
| STRING | InitialText | If HasText: the text, in Flash’s HTML subset if HTML is set |
UseOutlines draws the text with the font’s embedded glyphs; without it the player uses a font on the computer. AutoSize resizes the field to fit its text.