Paulo Freitas
Paulo Freitas

Reputation: 13649

Flex: Runtime Font Loading

I've tested this snippet with 3 different TTF fonts and I still din't get @font-face working within Flex. Am I missing something here? Tried both absolute and relative paths on url(), no changes. If I use any standard font (Arial, Verdana, Tahoma...), the Hello World! text appears, but when I try to use any external font, nothing shows.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
 <mx:Style>
  @font-face {
      src: url(josefin-sans.ttf);
      fontFamily: JosefinSans;
  }

  .custom {
      fontFamily: JosefinSans;
      fontSize: 36pt;
  }
</mx:Style>
<mx:Text id="text" styleName="custom" text="Hello World!" />

Compiled with:

mxmlc -static-link-runtime-shared-libraries=true flex.mxml

Upvotes: 0

Views: 346

Answers (1)

a.s.t.r.o
a.s.t.r.o

Reputation: 3338

As you are using MX components, you should embed fonts with embedAsCFF: false; flag.

@font-face
{
    src: url("josefin-sans.ttf");
    fontFamily: "JosefinSans";
    fontWeight: normal;
    embedAsCFF: false;
}

If it doesn't work, launch the application in debug mode and watch for errors. Also, be sure that the font you are using can be displayed with bold and italic if needed.

Upvotes: 2

Related Questions