Archive for October, 2009

At my day job (http://www.epyc.be), we developed a framework for rendering exercises (drag and drop, select text, multiple choice, fill in,… you name it, we got it). One of the features of this framework is font libraries on exercise level. In this way we can use different fonts and only load them when needed.  If in an application we have for example 100 multiple choice questions that need font A, and only one of those questions needs font B, font B will be loaded when that specific exercise is rendered. Once loaded they are cached in memory, in case another exercise needs the same font library.
When an exercise is loaded, the first thing the base class does is loading the necessary font library  in order to render the exercise. In the exercise logic, whenever we need a font, we can create one like this:

1
2
3
4
var font:Font=FontMananger.getInstance().getFont(
fontName,
fontLibrary
);

In theory, this would also allow the use of foreign character sets…. Only in theory, because when we finally needed this feature, we ran into a “little” problem.
A font library in our system is an empty swf file with some embedded fonts. We normally create these libraries by clicking “new font” in the library:

This workflow worked fine until we had to create a Polish version of one of our projects. The problem is that it is impossible to define which characters you want to embed when embedding fonts in the library. Flash only embeds a basic char set. Strangly enough, when embedding a font for a specific text field, you CAN define the extra character set :

So, it looks like the folks at Adobe simply forgot about this. We tried everything, but no success using the Flash IDE.
Eventually we had to switch to Flexbuilder to create the font libraries. Here’s how we did this:

1
2
3
4
5
6
7
8
9
10
11
12
package {
import flash.display.Sprite;
import flash.text.Font;
public class FontLib extends Sprite
{
[Embed(systemFont = "Arial", fontName = "Arial", mimeType = "application/x-font", unicodeRange = "U+0-U+00FF,U+0100-U+01FF,U+0200-U+02FF" )]
public var DefaultFont:Class;
public function FontLib()
{
}
}
}

As you can see, in Flex we can define the Unicode ranges that need to be embedded. In this way we can create font libraries containing Baltic or Cyrillic character sets, or even Chinese!
There’s also a little problem with this workflow: Since the DefaultFont class is defined inside the FontLib application class, the compiler internally changes the class name to “FontLib_DefaultFont”. After loading this font library, and we want to create an instance of a certain font class, we have to add “FontLib_” before the class name.
Conclusion: Adobe, please add functionality to the Flash IDE so we can define extra character sets to be embedded when embedding fonts in the library!
If anyone knows a way of doing this by using the Flash IDE, please let me know.

I realize I haven’t been writing much blog entries in the past months. One of the reasons for this is my Africa trip. I went to Ghana in September. For those of you who are interested in seeing some photos. You can do so here.

Larabanga mosque

Other then that I’ve been busy with some interesting projects. More on that soon…