Search code examples
flashactionscript-3actionscriptfontstlf

Trouble loading CFF embedded fonts in an external SWF at runtime


We have a large flash site which is translated into 11 languages. We have a font loading system whereby all the characters required to display the site in each language are embedded in external swfs (so 11 swfs).

A recent update to the site requires us to use the Text Layout Framework (TLF) for one area of text display, which of course only supports fonts embedded in the new CFF format. I've attempted to embed a second instance of the font using the tag embedAsCFF="true", and after loading in the font SWF I can see this font is correctly registered as it shows up in the array returned by Font.enumerateFonts.

The TextFlow instance I am using has the following properties set:

textFlow.fontLookup = FontLookup.EMBEDDED_CFF;
textFlow.renderingMode = RenderingMode.CFF;
textFlow.fontFamily = "HeadingFontCFF";

However the text that is displayed is not finding the embedded font. It is displayed in the Times New Roman device font. I'm pretty sure I have the TLF set up correct, as when I put the [Embed] tag in the same class (i.e. embedding in same SWF) as my TLF code, the font is displayed correctly. So it seems to relate just to fonts loaded in external SWFs.

I think this problem is related to the one listed here: Example of using embedded fonts loaded at runtime Flex 4 runtime loaded modules, although this post refers to a Flex 4 build whereas ours is a pure Flash 10 build.


Solution

  • Okay so after a lot of digging I found the answer. It turns out we were using a compiler argument

    -managers flash.fonts.AFEFontManager
    

    which instructs the compiler to use the AFEFontManager when transcoding the fonts, rather than the default (BatikFontManager/AFEFontManager/JREFontManager). These font managers take font files and turn them into vector outlines to be rendered in Flash. There's more information here: About the font managers.

    It seems that when this argument is included, all fonts are embedded using the old DefineFont3 method, rather than DefineFont4 (CFF), even if you use the tag embedAsCff="true".

    An easy way to see which method was actually used to embed the font is by checking the fontType property of the fonts returned by Font.enumerateFonts(). If the value is "embedded" then DefineFont3 was used, if it's "embeddedCFF" then DefineFont4 was used.

    Hope this helps someone out there!