Using Fonts in Flex

Recently, I came up with a requirement where I had to dynamically load a language set (English/ Dutch/German/ French/ Hindi etc.) based on the locale for which our Flex application was running.

And I found out that solution to this is using localization of languages. Along with that I also successfully embedded a free font for controlling the display over various other operating systems.

But accomplishing this was not that easy as it sounds, I encountered lot of trouble in displaying a consistent font for all languages, especially Hindi, as most of the free fonts can only display western characters well.

So, for various reasons including maintaining consistency of font appearance across various platforms like Windows/Linux etc, you might be interested in downloading a free font that you can embed in your .swf  client. Well,  right here you can get a good free-font that supports western as well as hindi font(hindi font has a couple of bugs :) )   (Download FreeSans Font)

For more such fonts, check out http://www.gnu.org/software/freefont/

Place this true-type font file "FreeSans.ttf " in your preferred project's location.You can embed this font in your actionscript utility class as shown below:

Embed(source='../../resources/font/FreeSans.ttf', fontName="FreeSans", mimeType="application/x-font")]public var FreeSans:Class;

Where a CSS file , might look like :

@font-face
{
src: url("../resources/font/FreeSans.ttf");
font-family: FreeSans;
advancedAntiAliasing: true;
}

.listItems
{
color: "0x000000";
font-family: "FreeSans";
font-size: "13";
}

you can get the following error during compilation :

"unable to transcode font " -> exception during transcoding: Unexpected exception encountered while reading font file

To resolve this , change your project properties (right-click on your project ) ->  go to "Flex Compiler", then under "Additional compiler arguments:" add "-managers flash.fonts.AFEFontManager".

Hope this will solve all your font related trouble ...

Share the bee buzz:
  • Digg
  • del.icio.us
  • Facebook
  • DZone
  • LinkedIn
  • StumbleUpon
  • Technorati
  • Twitter

One Response to “Using Fonts in Flex”

  1. Hope you’ve worked on a GPL application as you’ve embedded a GPL’ed font in your app.

Leave a Reply