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, from SWF 4, holds real text and lays it out at run time. In this format character codes are 8-bit ANSI or Shift-JIS, or 16-bit when a font’s WideCodes flag is set, and names and text are in the player’s code page.
Glyph shapes
A glyph is a SHAPE with no style lists: fill style 1 is implied and there are no lines. Glyphs are drawn in an EM square of 1,024 units, which at 1 twip a unit is 51.2 pixels. 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 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[3] | FontFlagsReserved | 0 (later formats use the third bit for SmallText) |
| 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 |
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] | FontFlagsReserved | 0 (later formats use it for SmallText) |
| UB[1] | FontFlagsANSI | ANSI |
| UB[1] | FontFlagsWideOffsets | The offsets are UI32 |
| UB[1] | FontFlagsWideCodes | The codes are UI16 |
| UB[1] | FontFlagsItalic | Italic |
| UB[1] | FontFlagsBold | Bold |
| UI8 | LanguageCode | A language code; the codes belong to SWF 6 and later, and the explorer shows the byte’s value |
| 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 |
| UI8 or UI16 × NumGlyphs | CodeTable | The character code of each glyph; UI16 if WideCodes |
| 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: FontKerningCode1 and FontKerningCode2 (UI8, or UI16 if WideCodes), SI16 FontKerningAdjustment |
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 | two reserved bits (later formats use them for HasFontClass and AutoSize), HasLayout, NoSelect, Border, a reserved bit (later WasStatic), HTML, UseOutlines |
| UI16 | FontID | If HasFont |
| 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 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. In Flash 4 and 5 a text field is tied to a variable by VariableName: setting the variable changes the text.
Font tags from later versions
These came with SWF 6 and later and have no place in a SWF 1 to 5 movie. Where one turns up, the explorer reads it with the fields below.
| Tag | SWF | Fields |
|---|---|---|
| DefineFontInfo2 (62) | 6 | DefineFontInfo with a UI8 LanguageCode after the flags, and 16-bit codes always |
| DefineFont3 (75) | 8 | DefineFont2’s fields, with glyphs in an EM square of 20,480 units |
| DefineFontAlignZones (73) | 8 | UI16 FontID, UB[2] CSMTableHint, UB[6] Reserved, then a zone record for each glyph |
| CSMTextSettings (74) | 8 | UI16 TextID, UB[2] UseFlashType, UB[3] GridFit, UB[3] Reserved, FLOAT Thickness, FLOAT Sharpness, UI8 Reserved |
| DefineFontName (88) | 9 | UI16 FontID, STRING FontName, STRING FontCopyright |
| DefineFont4 (91) | 10 | UI16 FontID, a flags byte, STRING FontName, then an OpenType font with CFF outlines |