Font.hx

Font import module for importing TrueType fonts.

Summary
Font.hxFont import module for importing TrueType fonts.
ttfImports 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.

ttf

Imports specified glyphs (character drawings) from a TrueType font file as DefineFont2 swf tag.

Mandatory attributes

importPath to the file to be imported.
nameFont name.  You can access the imported font with this name from AS3 for example.

Optional attributes

language(none, latin, japanese, korean, simpleChinese, traditionalChinese) Language code to include in font definition.
classClass 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)

Child nodes

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.

Summary
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.

include (child of <characters>)

Specifies a character set or character range to include.

Optional attributes

rangeRange of characters in the form: firstCharacter..lastCharacter
charactersIndividual characters in arbitrary order

exclude (child of <characters>)

Specifies a character set or character range to exclude.

Optional attributes

rangeRange of characters in the form: firstCharacter..lastCharacter
charactersIndividual characters in arbitrary order

Example 1

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>

Example 2

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);
Imports specified glyphs (character drawings) from a TrueType font file as DefineFont2 swf tag.
Close