Skip to main content
Known Participant
May 12, 2015
Answered

Embed fonts at runtime

  • May 12, 2015
  • 1 reply
  • 1107 views

Hi,

I am embedding around 100 fonts(ttf, otf, ttc etc.) in my Adobe Air desktop application using css stylesheet.

I am using Flash Builder 4.7 for the development.

The issue I am facing is the compiler gets much slow when compiling the fonts and sometimes I can't make a release build.

Hence i am thinking is there any way I can skip the fonts embedding at compile time and put the fonts in some application directory and load the fonts at run time when necessary.

Please advice.

Thanks in advance.

Jameel

This topic has been closed for replies.
Correct answer

I know you are using FB, so please bear with me while I explain. I have successfully created font libraries using Flash Pro by creating one FLA that has a bunch of Font objects in the Library labeled as to which font family and member it represents (Avenir-Roman for example), has all the character ranges I need checked off, and that Font object has "Export for ActionScript" enabled and given a class name of, using my previous example, "AvenirRoman".

A SWF is published from that FLA will all the fonts I need for X project and then I load that SWF into my main project using a Loader object which needs to utilize those fonts. After the SWF font library is loaded, I use the following line of code:

Font.registerFont(loader.contentLoaderInfo.applicationDomain.getDefinition("AvenirRoman") as Class);

I do that line of code for each font I included in the library and from that point I am able to use the fonts included in the SWF font library in my TextField's as long as "embedFonts = true" is set on my TextField's. An Array with all the font names could be setup to perform a loop on, but I have never needed more than 4 fonts so I just did the callouts individually.

Now since you said you are using Flash Builder, I assume you are using the [Embed] method to include fonts. I would think that you could create a separate project for the sole purpose of building a font library and then load the SWC or SWF that project would create and do the same thing, just in Flash Builder. My example above assumes the usage of a Loader object with a variable name "loader". I know the Flash Builder has more options at including files in projects than Flash Pro, so some tweaking may have to be done if the font library SWC/SWF is included in the files that build your exported project.

1 reply

Colin Holgate
Inspiring
May 12, 2015

I wonder if you could put the fonts into a SWC, and include that in the FLA? That trick can dramatic speed up publishing, but I'm not sure if the fonts would be seen by the rest of the app.

Known Participant
May 13, 2015

This might be possible in Flash Professional, but I am using Flash Builder and not using fla.

Correct answer
May 13, 2015

I know you are using FB, so please bear with me while I explain. I have successfully created font libraries using Flash Pro by creating one FLA that has a bunch of Font objects in the Library labeled as to which font family and member it represents (Avenir-Roman for example), has all the character ranges I need checked off, and that Font object has "Export for ActionScript" enabled and given a class name of, using my previous example, "AvenirRoman".

A SWF is published from that FLA will all the fonts I need for X project and then I load that SWF into my main project using a Loader object which needs to utilize those fonts. After the SWF font library is loaded, I use the following line of code:

Font.registerFont(loader.contentLoaderInfo.applicationDomain.getDefinition("AvenirRoman") as Class);

I do that line of code for each font I included in the library and from that point I am able to use the fonts included in the SWF font library in my TextField's as long as "embedFonts = true" is set on my TextField's. An Array with all the font names could be setup to perform a loop on, but I have never needed more than 4 fonts so I just did the callouts individually.

Now since you said you are using Flash Builder, I assume you are using the [Embed] method to include fonts. I would think that you could create a separate project for the sole purpose of building a font library and then load the SWC or SWF that project would create and do the same thing, just in Flash Builder. My example above assumes the usage of a Loader object with a variable name "loader". I know the Flash Builder has more options at including files in projects than Flash Pro, so some tweaking may have to be done if the font library SWC/SWF is included in the files that build your exported project.