This class defines flash font.
Flash text has been designed to be completely device independent.
Text is guaranteed to look exactly the same on every device, regardless
of which fonts are installed on the client machine.
The SWF format achieves this by including the exact shape of every letter,
number (or other text character) used in the movie. These character shape
definitions are called glyphs.
Defining each and every glyph increases the size of a SWF file,
particularly if the font is complex. However, it is a necessary tradeoff.
At design time, Flash knows nothing about the capabilities of the client device,
therefore glyphs must always be included in the SWF file, even if the desired font
is already on the client machine.
To guarantee text is reproduced correctly, SWF also includes the exact position
of every character in a text block. Again, this adds to the file size, but allows
sophisticated text layout effects (like kerning and text wrapping) without requiring
a complex layout engine built into the Flash player.
Glyph Definitions
Glyphs are defined once in a standard coordinate
space called the EM square. The same set of glyphs are
used for every point size of a given font. To render a glyph
at different point sizes, the Flash player scales the glyph
from EM coordinates to point-size coordinates.
Flash fonts do not include any hinting information for improving
the quality of small font sizes. However, antialiasing dramatically
improves the legibility of down-scaled text. Flash text remains
legible down to about 12-points (viewed at 100%). Below that, text
may appear fuzzy and blurred. In any case, it is rare for Flash movies
to be used for large bodies of text with small point sizes.
TrueType fonts can be readily converted to SWF glyphs. A simple
algorithm can replace the Quadratic B-splines (used by TrueType) with
Quadratic Bezier curves (used by SWF).
The EM Square
The EM square is an imaginary square that
is used to size and align glyphs. The EM square is
generally large enough to completely contain all glyphs,
including accented glyphs. It includes the font's ascent,
descent, and some extra spacing to prevent lines of text from
colliding.
SWF glyphs are always defined on an EM square of 1024 by 1024
units. Glyphs from other sources (such as TrueType fonts) may
be defined on a different EM square. To use these glyphs in SWF,
they should be scaled to fit an EM square of 1024.
Kerning and Advance Values
Kerning defines the horizontal distance between two glyphs.
This distance may be smaller or larger than the width of the
left-hand glyph. Some kerning pairs are more aesthetically
pleasing if they are moved closer together.
SWF stores kerning information as an advance value.
That is, the horizontal advance from one glyph to another.
SWF stores an advance value for every character in a text block.
The DefineFont Tag
The DefineFont tag defines the shape outlines of
each glyph used in a particular font. Only the glyphs that are
used by subsequent DefineText tags are actually defined.
The FontId uniquely identifies the font. It can be used by subsequent
DefineText tags to select the font.
The offset table and shape table are used together. These tables
have the same number of entries, and there is a one-to-one ordering match
between the order of the offsets, and the order of the shapes.
The offset table points to locations in the shape table. Each offset entry
stores the difference (in bytes) between the start of the offset table and
the location of the corresponding shape:
Location of ShapeRecord[n] = StartOfOffsetTable + OffsetTable[n]
Because the ShapeTable immediately follows the OffsetTable ,
the number of entries in both tables can be inferred by dividing
the first offset by two:
Shape count = OffsetTable[0] / 2
Mapping to Native Fonts
SWF also supports the use of native fonts. Rather than using the
glyph outlines in the DefineFont tag, fonts can be rendered using
the client machine's font engine. Since most native font engines
include hinting techniques, they may produce better results at very
small point sizes.
The DefineFontInfo tag defines the mapping of a Flash font to a native font.
It includes the font name, font style - bold, italic, or plain, and the
encoding scheme used - ANSI, Unicode or ShiftJIS. It also defines a mapping
of glyph indices to character codes. Thus if 'a' were the first character in
your DefineFont tag, the DefineFontInfo tag would map index zero to the character
code for 'a'.
DefineFont2
The DefineFont2 tag extends the functionality of DefineFont.
Enhancements include:
- 32-bit entries in the OffsetTable, for fonts with more than 64K glyphs.
- Mapping to native fonts, by incorporating all the functionality of DefineFontInfo.
- Ascent, descent and leading information.
- An advance table that defines the advance for each glyph (in EM square coordinates).
- A bounds table that defines the bounding-box of each glyph (in EM square coordinates).
- A table of kerning pairs that defines the distance between pairs of glyphs
Kerning Record
A Kerning Record defines the distance between two glyphs in EM
square coordinates. Certain pairs of glyphs appear more aesthetically
pleasing if they are moved closer together, or farther apart.
The FontKerningCode1 and FontKerningCode2 fields are the character codes
for the left and right characters. The FontKerningAdjustment field is a
signed integer that defines the offset from the advance value of the
left-hand character. The distance between two characters can be calculated
like this:
Distance = FontAdvanceTable[ord(FontKerningCode1)] + FontKerningAdjustment
author: Dmitry Skavish |