Avg. Rating 5.0

Problem

Embedding a font in Flex has been improved in Flex 4 and it can be a powerful tool for customizing your application, however using fonts can quickly increase the size of your swf.

Solution

A great and easy way to reduce this impact is to limit the character set embedded. There are a few places you could do this, but I find it easiest to do in CSS.

Detailed explanation

So I promised Ed I'd get a recipe up by today, and although this is a pretty simple solution, it can save a lot of space when you are embedding fonts.

In your css file use @font-face to embed a font and make it accessible throughout your application.

Note: The font file used in this sample is not included in the attachment since I don't want to get in trouble for distributing it, but you can find it here.

@font-face {
        src: url("assets/fonts/Fertigo_PRO.otf");
        fontFamily: Fertigo;
        fontStyle: normal;
        fontWeight: normal;
        advancedAntiAliasing: true;
        cff:true;
        unicodeRange:
                U+0041-005A, /* Upper-Case [A..Z] */
                U+0061-007A, /* Lower-Case a-z */
                U+0030-0034, /* Numbers [0..4] */
                U+002E-002E; /* Period [.] */
}

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes