Export to GitHub

splinkresource - Fonts.wiki


The goal is to compile each font we wish to use in our application into a seperate swf. So we can reference and change each font seperately in the configuration xml. A font requires to live inside a class which extends Sprite. A font is bound to a public member of that class with the embed tag. If a font supports various styles the styles should go into the same class. Here is an example:

``` public class ArialFont extends Sprite { [Embed(source = 'arial.ttf', fontName = 'Arial')] public var arial : Class;

[Embed(source = 'arialbd.ttf', fontName = 'Arial', fontWeight='bold')]
public var arialBold : Class;

[Embed(source = 'ariali.ttf', fontName = 'Arial', fontStyle='italic')]
public var arialItalic : Class;

[Embed(source = 'arialbi.ttf', fontName = 'Arial', fontWeight='bold', fontStyle='italic')]
public var arialBoldItalic : Class;

} ```

If you dont't want to embed to whole font, you can specify the characters to embed using the unicodeRange property. Often different locales require to embed different unicode ranges. [Embed(source = 'arial.ttf', fontName = 'Arial' unicodeRange='U+0041-U+005A,U+0061-U+007A')]

Note that if you compile the font with the Flex 4 SDK you must add a new argument called embedAsCFF which defines whether the font can be used with the classic TextField (embedAsCFF=false) or the new Text Layout Framework (embedAsCFF=true).

Here is an ant task which compiles the font: <target name="font_compile"> <exec executable="${flex.mxmlc}"> <arg line="-default-size 1 1" /> <arg line="-source-path ${source}" /> <arg line="-compiler.fonts.advanced-anti-aliasing=false" /> <arg line="-output ${deploy}/arial.swf" /> <arg line="${source}/ArialFont.as" /> </exec> </target>

If strange exceptions occur when you compile a font, you might try and change the font manager in the mxmlc arguments: For more information on the subject check out the Adobe livedocs <arg line="-managers flash.fonts.JREFontManager flash.fonts.BatikFontManager flash.fonts.AFEFontManager" />

Finally this is the code for the resourcebundles configuration xml: <fonts path="fonts/"> <font id="Arial" type="normal" src="arial.swf" filesize="0" /> </fonts>

and the code to access the font in your actionscript application: ResourceProvider.instance().getFontDataByType("normal");