There are now two types of font embedding available to both Flash (CS4) and Flex 3 and 4. These are DefineFont3 (classic), and DefineFont4 (supporting CFF and the new text engine.)

In Flash, Flex 2 and 3 you’d traditionally embed fonts for use in the TextField class, whether that’s a vanilla TextField, or a component that uses the TextField class and has been set to use embedded fonts. This is DefineFont3 embedding. The steps are usually:

  1. Embed fonts in a SWF using the Flash IDE or the [Embed()] tag in Flex.
  2. Set myTextField.embedFonts = true; (or setStyle(“embedFonts”,true) for a component.)
  3. Either set myTextField.defaultTextFormat, use setTextFormat(), or setStyle().
  4. Set the text with .text or .htmlText (using CSS or the font tag).

With the new flash.text.engine.* package (available as part of the Text Layout Framework for Flex 3 or as standard in Flex 4), we have another way to do text that’s a lot more powerful than the old TextField. But it’s no direct replacement just yet (there are performance reasons), and at least for now you’ll probably be using them alongside eachother, particularly if your Flex project is using the Halo (Flex 3) components.

In my case I’m using the Text Layout Framework for advanced stuff, and inside custom controls I’m using the plain old TextField to give me good performance.

The Problem

When you embed a font for the new text engine (and TLF), you need to specify the font to be embedded using CFF (part of the DefineFont4 embedding engine). Usually I embed each font 4 times when I do this, for regular, bold, italic and bold italic variations. The problem is the CFF embedded font is not available to TextFields.

If you run through the Fonts listed in Fonts.enumerateFonts(), you’ll see your Font there, but the .fontType property shows it is CFF. With Flex 4, CFF is set to true by default. Here’s an example of how to specify DefineFont3 embedding using Flex 4:

[Embed(source='ttf/arial.ttf', fontFamily='Arial', unicodeRange='U+2022,U+25A0,U+25C6,    U+0030-U+0039,   U+002E', cff="false")] 
public static var Arial:Class;

Conclusion

This is really just something to be aware of, there’s no much you can do (as far as I’m aware), apart from either embedding the fonts using both CFF and not using CFF, leading to huge SWFs. Or you stick to using non-embedded fonts when using plain TextFields and the TLF everywhere else.

There has been some discussion on this at Adobe and this includes suggestions on how to deal with this transition. It seems the plan is to develop a new TextField class that uses Vellum (the Text Layout Framework).