Font import module for importing TrueType fonts.
| Font.hx | Font import module for importing TrueType fonts. |
| ttf | Imports specified glyphs (character drawings) from a TrueType font file as DefineFont2 swf tag. |
| include (child of <characters>) | Specifies a character set or character range to include. |
| exclude (child of <characters>) | Specifies a character set or character range to exclude. |
Imports specified glyphs (character drawings) from a TrueType font file as DefineFont2 swf tag.
| import | Path to the file to be imported. |
| name | Font name. You can access the imported font with this name from AS3 for example. |
| language | (none, latin, japanese, korean, simpleChinese, traditionalChinese) Language code to include in font definition. |
| class | Class name assigned to imported data. Useful for runtime font loading (see RuntimeFontLoadingDemo). |
| genclass | (false, symbolOnly, symbolAndClass) Controls the generation of symbols and AS3 class stubs. Available values are: false (don’t generate neither symbol nor AS3 class stub), symbolOnly (generate only symbol), symbolAndClass (generate symbol and AS3 class stub) |
ttf has only one child node so far: <characters> which has two other optional child nodes <include> and <exclude> for specifying indivudal characters or character ranges to import / omit respectively.
If ttf doesn’t have any child nodes then every character which appear in the file are imported.
| include (child of <characters>) | Specifies a character set or character range to include. |
| exclude (child of <characters>) | Specifies a character set or character range to exclude. |
Specifies a character set or character range to exclude.
| range | Range of characters in the form: firstCharacter..lastCharacter |
| characters | Individual characters in arbitrary order |
Assuming that Font import module is assigned to namespace font the following snippet imports the even numbers and the letters abxyz from arial.ttf and names the font Arial.
<font:ttf import="arial.ttf" name="Arial">
<font:characters>
<font:include range="0..9"/>
<font:exclude characters="13579"/>
<font:include characters="abxyz"/>
</font:characters>
</font:ttf>For runtime font loading support, class stub can be generated for the font by specifying a class name.
<font:ttf import="arial.ttf" class="ArialClass" name="Arial">
<font:characters>
<font:include range="0..9"/>
<font:exclude characters="13579"/>
<font:include characters="abxyz"/>
</font:characters>
</font:ttf>After loading an swf containing such a font with flash.display.Loader, you can register the font for usage like this (example in Haxe, but AS3 would be similar):
var fontClass: Class<Font> = loadedMovieClip.applicationDomain.getDefinition("the.package.ArialClass");
Font.registerFont(fontClass);
...
var tf = new flash.text.TextField();
tf.embedFonts = true;
tf.defaultTextFormat = new flash.text.TextFormat("Arial", 14);