Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I display embedded fonts in AS3?

I have gone through all topics on Embedding fonts in AS3 I could find,a nd tried all solutions. I'm probably missing something obvious, but I don't fully understand what I'm doing so please guide me in the right direction. Many of the answers involve Flash Builder or another tool but I use FlashDevelop. No idea whether that matters.

I have this line in my Main.as:

[Embed(source = "assets/SKA_75_marul_CE_extended.ttf", 
fontName = "SKA_75_marul_CE_extended", 
fontWeight = "bold", 
advancedAntiAliasing = "true", 
mimeType = "application/x-font")] 
public static var SKA_75_marul_CE_extended:String;

And this exists in the constructor of an extended Sprite called Pointer.as:

var format:TextFormat = new TextFormat();
format.font = "SKA_75_marul_CE_extended";
format.color = 0xFFCCCC;
format.size = 20;           

var label:TextField = new TextField();
label.defaultTextFormat = format;
label.text = "test";
label.embedFonts = true;
label.antiAliasType = AntiAliasType.ADVANCED;

//label.setTextFormat(format);    --> I tried this too, didn't work...
label.defaultTextFormat = format;
label.x += img.width + 50;
this.addChild(label);

The only way I've found to get it to display anything is if I turn off embedFonts. I've tried embedding C:/windows/fonts/arial.ttf without success.

It seems that embedding fonts is a dark art like no other and I must concede after 1 hour of struggling. Please send help.

UPDATE:

Here's the working code, turns out it was due to having the correct order of operations...:

[Embed(source="assets/SKA_75_marul_CE_extended.ttf", 
                fontName = "myFont", 
                mimeType = "application/x-font", 
                fontWeight="normal", 
                fontStyle="normal", 
                unicodeRange="U+0020-U+007E", 
                advancedAntiAliasing="true", 
                embedAsCFF="false")]
        private var myEmbeddedFont:Class;

            var tf:TextFormat = new TextFormat( "myFont", 20,0xffffff );

            var t:TextField     = new TextField;
            t.embedFonts        = true; // very important to set
            t.defaultTextFormat = tf;
            t.text              = text;
            t.x += img.width + 50;
            t.width = 700;
            this.addChild( t );
like image 839
joon Avatar asked Apr 11 '12 00:04

joon


People also ask

How do I make fonts embedded?

Embed fonts in a document or presentation Open the file you want to embed fonts in. On the application (PowerPoint or Word) menu, select Preferences. In the dialog box, under Output and Sharing, select Save. Under Font Embedding, select Embed fonts in the file.

How do you check if a font can be embedded?

Navigate to File > Properties. Click the Fonts tab. If a font has the phrase '(Embedded Subset)' after the font name, then embedding is allowed. If there is nothing after the name, then font embedding is most likely not allowed.

How do I embed fonts into Lulu?

On the Fonts tab select Embed all fonts. For Subset embedded fonts when percent of characters used is less than: Set the percentage to 1%. For Embedding, select the folder with the fonts you want to embed from the drop-down list. Check Never Embed Font box and remove any fonts in the box.

What does it mean when fonts are not embedded?

Embedding fonts in your pdf file allows anyone who opens your file to see the document as you intended. If you don't embed a font, the pdf viewer will substitute a font if it is not available on the computer viewing the document, and the result usually isn't what you intended.


1 Answers

It's most DEFINITIVELY a "dark art" to get embedded fonts to work right. I would first check if "SKA_75_marul_CE_extended" is the actual name the font has in its metadata (I used Suitcase Fusion to extract the name). I've also seen TTF fonts that Flash simply refuses to embed (perhaps invalid metadata causes the embed system to fault). I would continue testing with a known working font until you find the actual problem in case it is a font file problem.

One thing I noticed is "public static var SKA_75_marul_CE_extended:String;"... shouldn't this be of type Class?

FlashDevelop font embed reference from someone who had issues: http://www.flashdevelop.org/community/viewtopic.php?p=28301

like image 136
Jonathan Dunlap Avatar answered Oct 07 '22 21:10

Jonathan Dunlap