A movie can embed fonts as glyph outlines, and holds text in two ways: static text, which is a list of glyphs placed by the authoring tool, and text fields, which hold characters and are laid out by the player. In a CWS movie, as in every SWF 6 and later movie, the strings are UTF-8 and the character codes in font tables are 16 bits wide, not bytes in the system code page.
DefineFont (10)
| Type | Name | Description |
|---|---|---|
| UI16 | FontID | The character ID |
| UI16 × nGlyphs | OffsetTable | The offset of each glyph from the start of this table; nGlyphs is the first offset ÷ 2 |
| SHAPE × nGlyphs | GlyphShapeTable | The outlines |
SWF 1. Only outlines: the character codes, name and style come from a DefineFontInfo for the same FontID.
Glyph outlines
Each glyph is a SHAPE: no style lists, fill style 1 implied, no lines. Glyphs are drawn in an EM square of 1,024 units (DefineFont, DefineFont2), or 20,480 in DefineFont3, which has 20 times the resolution. An empty glyph, such as a space, can have no bytes: its offset equals the next one.
DefineFontInfo (13)
| Type | Name | Description |
|---|---|---|
| UI16 | FontID | The DefineFont this describes |
| UI8 | FontNameLen | The length of the name in bytes |
| UI8 × FontNameLen | FontName | The font’s name |
| UB[2] | FontFlagsReserved | 0 |
| UB[1] | FontFlagsSmallText | SWF 7 (0x20) |
| UB[1] | FontFlagsShiftJIS | (0x10) |
| UB[1] | FontFlagsANSI | (0x08) |
| UB[1] | FontFlagsItalic | (0x04) |
| UB[1] | FontFlagsBold | (0x02) |
| UB[1] | FontFlagsWideCodes | Codes are UI16 (0x01) |
| UI8 or UI16 × nGlyphs | CodeTable | The character code of each glyph, in glyph order |
DefineFontInfo2 (62)
SWF 6. DefineFontInfo with a UI8 LanguageCode after the flags, and WideCodes always 1. Language codes: 0 none, 1 Latin, 2 Japanese, 3 Korean, 4 Simplified Chinese, 5 Traditional Chinese.
DefineFont2 (48)
| Type | Name | Description |
|---|---|---|
| UI16 | FontID | The character ID |
| UB[1] | FontFlagsHasLayout | Layout fields follow (0x80) |
| UB[1] | FontFlagsShiftJIS | (0x40) |
| UB[1] | FontFlagsSmallText | (0x20) |
| UB[1] | FontFlagsANSI | (0x10) |
| UB[1] | FontFlagsWideOffsets | Offsets are UI32 (0x08) |
| UB[1] | FontFlagsWideCodes | Codes are UI16; always 1 from SWF 6 (0x04) |
| UB[1] | FontFlagsItalic | (0x02) |
| UB[1] | FontFlagsBold | (0x01) |
| UI8 | LanguageCode | As in DefineFontInfo2 |
| UI8 | FontNameLen | The length of the name |
| UI8 × FontNameLen | FontName | The name |
| UI16 | NumGlyphs | The number of glyphs |
| UI16 or UI32 × NumGlyphs | OffsetTable | Glyph offsets from the start of this table |
| UI16 or UI32 | CodeTableOffset | The offset of CodeTable, from the same place |
| SHAPE × NumGlyphs | GlyphShapeTable | The outlines |
| UI16 × NumGlyphs | CodeTable | The character code of each glyph |
| UI16 | FontAscent | If HasLayout |
| UI16 | 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 |
SWF 3. Codes in the kerning records are UI8 when WideCodes is 0, which an SWF 6 or later movie does not use.
DefineFont3 (75)
SWF 8. The same layout as DefineFont2, with the glyphs at 20 times the resolution, in an EM square of 20,480 units, and UI16 codes. It goes with DefineFontAlignZones for the FlashType renderer.
DefineFont4 (91)
| Type | Name | Description |
|---|---|---|
| UI16 | FontID | The character ID |
| UB[5] | FontFlagsReserved | 0 |
| UB[1] | FontFlagsHasFontData | FontData follows |
| UB[1] | FontFlagsItalic | |
| UB[1] | FontFlagsBold | |
| STRING | FontName | The name |
| FONTDATA, 0 or 1 | FontData | Only for an embedded font: an OpenType font with CFF outlines, to the end of the tag |
SWF 10. Used only by the Flash Text Engine (flash.text.engine, and the
Text Layout Framework built on it), not by the older text tags. The font must have
the ‘CFF ’, ‘cmap’, ‘head’, ‘maxp’, ‘OS/2’ and ‘post’ tables, and either ‘hhea’ and
‘hmtx’ or ‘vhea’, ‘vmtx’ and ‘VORG’; its ‘cmap’ must hold a Unicode subtable,
platform and encoding (0, 4), (0, 3), (3, 10), (3, 1) or (3, 0). ‘GSUB’, ‘GPOS’,
‘GDEF’ and ‘BASE’ may also be present. The explorer lists the font’s table directory
and opens FontData as a font file of its own.
DefineFontAlignZones (73)
| Type | Name | Description |
|---|---|---|
| UI16 | FontID | A DefineFont3 |
| UB[2] | CSMTableHint | 0 thin, 1 medium, 2 thick |
| UB[6] | Reserved | 0 |
| ZONERECORD × glyphs | ZoneTable | One a glyph: UI8 NumZoneData (2), then NumZoneData × (FLOAT16 AlignmentCoordinate, FLOAT16 Range), then UB[6] Reserved, UB[1] ZoneMaskY, UB[1] ZoneMaskX |
SWF 8. Alignment zones for the FlashType renderer.
CSMTextSettings (74)
| Type | Name | Description |
|---|---|---|
| UI16 | TextID | A DefineText or DefineEditText |
| UB[2] | UseFlashType | 0 normal, 1 advanced anti-aliasing |
| UB[3] | GridFit | 0 none (alignment zones and LCD sub-pixel information unused), 1 pixel (left-aligned dynamic text only), 2 sub-pixel (to the third of a pixel of an LCD) |
| UB[3] | Reserved | 0 |
| FLOAT | Thickness | Stroke thickness adjustment; 0.0 for the default |
| FLOAT | Sharpness | Sharpness adjustment; 0.0 for the default |
| UI8 | Reserved | 0 |
SWF 8. Thickness and Sharpness replace the player’s default anti-aliasing (CSM) settings for the field. At drawing time outsideCutoff = (0.5 × sharpness − thickness) × font size and insideCutoff = (−0.5 × sharpness − thickness) × font size.
DefineFontName (88)
| Type | Name | Description |
|---|---|---|
| UI16 | FontID | The font |
| STRING | FontName | Its full name |
| STRING | FontCopyright | Its copyright notice |
SWF 9.
DefineText (11)
| Type | Name | Description |
|---|---|---|
| UI16 | CharacterID | The character ID |
| RECT | TextBounds | The bounds |
| MATRIX | TextMatrix | Applied to the text |
| UI8 | GlyphBits | Bits in each glyph index |
| UI8 | AdvanceBits | Bits in each advance |
| TEXTRECORD[] | TextRecords | The text |
| UI8 | EndOfRecordsFlag | 0 |
SWF 1. Static text with RGB colours.
DefineText2 (33)
SWF 3. The same as DefineText, with RGBA text colours.
TEXTRECORD
| Type | Name | Description |
|---|---|---|
| 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, in twips |
| SI16 | YOffset | If HasYOffset, in twips |
| UI16 | TextHeight | If HasFont, in twips |
| UI8 | GlyphCount | The glyphs in this record |
| GLYPHENTRY × GlyphCount | GlyphEntries | Each UB[GlyphBits] GlyphIndex, SB[AdvanceBits] GlyphAdvance; padded to a byte after the last |
Glyph indexes point into the font’s glyph table, not to character codes: static text does not hold its characters, which come from the font’s code table. Glyph i is drawn at the current x, scaled by TextHeight ÷ 1,024 (÷ 20,480 for DefineFont3), and x then moves on by its advance.
DefineEditText (37)
| Type | Name | Description |
|---|---|---|
| UI16 | CharacterID | The character ID |
| RECT | Bounds | The field’s rectangle |
| UB[1] × 8 | first flags byte | HasText 0x80, WordWrap 0x40, Multiline 0x20, Password 0x10, ReadOnly 0x08, HasTextColor 0x04, HasMaxLength 0x02, HasFont 0x01 |
| UB[1] × 8 | second flags byte | HasFontClass 0x80 (SWF 9), AutoSize 0x40 (SWF 6), HasLayout 0x20, NoSelect 0x10, Border 0x08, WasStatic 0x04 (SWF 8), HTML 0x02, UseOutlines 0x01 |
| UI16 | FontID | If HasFont |
| STRING | FontClass | If HasFontClass: an ActionScript 3 font class |
| UI16 | FontHeight | If HasFont or HasFontClass, in twips (see below) |
| RGBA | TextColor | If HasTextColor |
| UI16 | MaxLength | If HasMaxLength |
| UI8 | Align | If HasLayout: 0 left, 1 right, 2 centre, 3 justify |
| UI16 | LeftMargin | If HasLayout, in twips |
| UI16 | RightMargin | If HasLayout |
| UI16 | Indent | If HasLayout |
| SI16 | Leading | If HasLayout |
| STRING | VariableName | The variable the text is bound to (ActionScript 1 and 2) |
| STRING | InitialText | If HasText; Flash’s subset of HTML if HTML is set |
SWF 4. A dynamic or input text field. With UseOutlines the player draws it with the font’s embedded glyphs; otherwise with a device font. The font must be a DefineFont2 or later, not a DefineFont. HasFont and HasFontClass are never both set; HasFontClass (Flash Player 9.0.45 and later) names a font class to load from another SWF.
The specification’s table reads FontHeight only “if HasFont”, but its own text for HasFontClass says the class “and Height” are given, and Flash Player reads FontHeight when either flag is set. Ruffle documents this as a SWF 19 erratum. The explorer reads it in both cases; a reader that follows the table misreads everything after FontClass.
HTML text
With the HTML flag set, InitialText is a limited subset of HTML, with a few tags of Flash’s own. Tag names are not case-sensitive. The specification lists these:
| Tag | Meaning | Attributes |
|---|---|---|
<p> | A paragraph | align: left, right or center |
<br> | A line break | None |
<a> | A hyperlink | href, required; target, a window name, optional |
<font> | A span in a given font | face, a font name that must match a DefineFont2’s; size, in twips, or relative with a leading + or −; color, as #RRGGBB |
<b> | Bold | None |
<i> | Italic | None |
<u> | Underlined | None |
<li> | A bulleted paragraph; <ul> is neither needed nor supported, and there are no numbered lists | None |
<textformat> | A span with formatting options | leftmargin, rightmargin, indent, blockindent and leading in twips; tabstops, a comma-separated list in twips |
<tab> | A tab, to the next tab stop set by <textformat> | None |
Later Flash Players also accept <img>, <span>,
a class on <p>, and letterSpacing and
kerning on <font>, which the specification does not
list. The specification gives SIZE in twips, but Flash writes and reads it in
pixels (SIZE="12" is 12-pixel text), as Adobe’s ActionScript reference
for htmlText describes it.
The explorer’s structure view splits the text into tags and text runs and names
each tag. When it draws a frame it follows <p> with its
alignment, <br>, <li> (with a bullet, if the
font has one), <font>’s face, size and colour,
<b> and <i> (the bold or italic font of the
same name, when the movie has one), <u> (a rule under the text),
<textformat>’s margins, indents, leading and tab stops, and
<tab>. It wraps lines when WordWrap is set, applies the field’s own
margins, indent and leading, and shows a Password field as asterisks. Links do not
change the drawing.