Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
nitrog7
Posts: 10
Registered: ‎12-09-2010
My Device: Not Specified

Embedding Fonts

Have been trying to embed fonts and can't seem to get it to work. Have copied and pasted code from existing AS3 projects that successfully embedded fonts using the Flex 4.1 SDK. I am using the BlackBerry 0.9.1 SDK and am testing outside of the simulator.

 

All the code is completely in AS3. And looks like the code below:

 

[Embed(source="fonts/FontName.ttf", fontName='Extended', fontStyle="normal", fontWeight="normal")]

public static var FontExtended:Class;

 

Is anyone else being able to embed fonts?

 

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Embedding Fonts

hey nitro,

 

try the following line, i noticed you were missing some attributes in your line:

 

 

[Embed(source='fonts/FontName.ttf', fontName='Extended', fontStyle='normal', fontWeight='normal', mimeType='application/x-font' )]
private var FontExtended:Class;

 

and also what gets most people is the path to their font. make sure that is correct and you should be golden. good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Contributor
nitrog7
Posts: 10
Registered: ‎12-09-2010
My Device: Not Specified

Re: Embedding Fonts

I've actually gotten it to work without the mimeType in Flex 4.1. Tried that property in the my Blackberry OS SDK and it still does not work. Does it work for you?

Regular Contributor
renaun
Posts: 86
Registered: ‎10-25-2010
My Device: Not Specified

Re: Embedding Fonts

In the newer Flex SDK's the mxmlc compiler by default embeds the fonts in the newer CFF format that is compatible with the newer Text Layout Engine (TLF), which runs on the Flash Player's newer (FP 10+) FTE APIs.

 

To embed the Fonts in the older font type to use with non-TLF objects you need to add to the metadata embedAsCFF=false.

 

Here is some more info:

http://renaun.com/blog/2010/07/using-mxmlc-embed-fonts-with-textfield/

blog: http://renaun.com
twitter: @renaun
Contributor
nitrog7
Posts: 10
Registered: ‎12-09-2010
My Device: Not Specified

Re: Embedding Fonts

I had tried the embedAsCFF="false" as well but with no success. Had gotten that solution on your video on the Adobe site last night.

 

I've also tried out various fonts in case the actual font was a problem.

 

[Embed(source="fonts/myFont.ttf", fontName='myFontName', fontStyle="normal", fontWeight="normal", embedAsCFF="false", mimeType="application/x-font")]

 

I'm using the TextFlowTextLayoutFormat, and ContainerController to create the text box.

 

Some of the properties set are:

 

textLayoutFormat.fontFamily = 'myFontName';

textLayoutFormat.renderingMode = 'cff';

textLayoutFormat.fontLookup = 'embeddedCFF';

 

I've tried commenting these out to use the default values but still a no go. I'm testing on a Mac using Flash Builder 4.

 

Regular Contributor
renaun
Posts: 86
Registered: ‎10-25-2010
My Device: Not Specified

Re: Embedding Fonts

TextFlow is a TLF class so try setting embedAsCFF=true. If you can post a simple code sample that is not working for you I can try it on my end.

blog: http://renaun.com
twitter: @renaun
Contributor
nitrog7
Posts: 10
Registered: ‎12-09-2010
My Device: Not Specified

Re: Embedding Fonts

Thanks for your help. The library I am using is on github, called LiquidGear. It can be downloaded at:

https://github.com/nitrog7/LiquidGear

 

The main AS file would simply the following code, which works on Flex 4.1 but not the Blackberry Tablet SDK. 

 

package {

  import lg.flash.elements.Text;

 

  [SWF(width="1024", height="600", backgroundColor="#000000", frameRate="30")]

 

   

  public class MyApp extends Sprite {

    [Embed(source="fonts/svenings.ttf", fontName='Extended', fontStyle="normal", fontWeight="normal", embedAsCFF="true", mimeType="application/x-font")]

      public static var FontExtended:Class;

 

    public function MyApp() {

 

 

      var test:Text = new Text({id:'test', x:0, text:'Test', font:'Extended', embedFonts:true, size:48, color:0xffffff});

 

         addChild(test);

    }

  }

}

 

Thanks again, 

Giraldo

 

New Developer
jjackson
Posts: 18
Registered: ‎11-14-2010
My Device: Not Specified

Re: Embedding Fonts

I can't get any font to embed with the playbook either, no errors or anything, just not working. Also works fine in everything else.

 

Regular Contributor
renaun
Posts: 86
Registered: ‎10-25-2010
My Device: Not Specified

Re: Embedding Fonts

This code worked for me on the PlayBook Simulator:

 

 

package 
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;

import lg.flash.elements.Text;

[SWF(width="1024", height="600", backgroundColor="#000000", frameRate="30")]
public class MyApp extends Sprite
{
	
	[Embed(source="fonts/Webdings.ttf", fontName='MyFontName', fontStyle="normal", fontWeight="normal", embedAsCFF="false", mimeType="application/x-font")]
	public static var FontExtended:Class;
	
	public function MyApp() 
	{
		var test:Text = new Text({id:'test', x:0, text:'Test', font:'MyFontName', embedFonts:true, size:32, color:0xffffff});
		addChild(test);
	}
}	
}

 

So I would try a different font .ttf file to see if its a font file issue.

 

blog: http://renaun.com
twitter: @renaun
New Developer
ryantan
Posts: 20
Registered: ‎11-24-2010
My Device: Not Specified

Re: Embedding Fonts

Just got mine to work with:

 

 

package classes
{
	public class AssetManager
	{
		//Embed the .ttf in my src/fonts folder. Note the fontName
		[Embed(source='/fonts/arial.ttf', fontName="TestFont", mimeType="application/x-font-truetype")]
		public static const TestFontTTF:String;
		
		public function AssetManager() {
			
		}
	}
}

 

In main app:

 

 

package 
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import classes.AssetManager;

	[SWF(width="1024", height="600", backgroundColor="#1b263e", frameRate="30")]
	public class TestApp extends Sprite
	{
		public function TestApp(){
			var assetManager:AssetManager = new AssetManager();
		
			var testTF:TextFormat = new TextFormat("TestFont",15,0xFFFFFF);
					
			var testText:TextField = new TextField();
			testText.defaultTextFormat = testTF;
			testText.embedFonts = true;
			testText.text = 'Testing embed font';
			testText.x = 300;
			testText.y = 300;
			testText.textColor = 0x0000FF;
			
			addChild(testText);
		}
	}
}

 

 

 

cheers,
Ryan