• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Embedded font does not show up on Android

New Here ,
Jun 30, 2011 Jun 30, 2011

Copy link to clipboard

Copied

I am using CS5.5 and have added the following to my class:

[Embed(source = "C:\\Windows\\fonts\\Kinds_Plain.ttf", fontFamily = "KidsPlain", embedAsCFF = "false")]

It works when running on the desktop.  The text typed is in this font.  But when I packaged and installed the app on my Android device, the text typed is changed to the default font.

Any help is appreciated!

Thanks in advance,

aimaob

TOPICS
Development

Views

4.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Jul 02, 2011 Jul 02, 2011

When you input text in a text field, the runtime positions a native text input control over the Flash TextField object. Since native controls can't use embedded fonts, the closest system font is used. On Android (but not iOS) you can use TLF to create a text input control that is entirely drawn in Flash and thus can use embedded fonts during input. (I'm not sure if the Flex components support this on mobile, though, so you might still have to make your own if using Flex.)

Votes

Translate

Translate
Mentor ,
Jul 01, 2011 Jul 01, 2011

Copy link to clipboard

Copied

C:\\Windows\\fonts\\Kinds_Plain.ttf  Is this the same path you used to show on android?

use just like:

[Embed(source = "Kinds_Plain.ttf", fontFamily = "KidsPlain", embedAsCFF = "false")]

and attach the file with the swf while packaging.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2011 Jul 01, 2011

Copy link to clipboard

Copied

Thanks for you reply!

I have tried it and packaged the font together with the rest of the files.  It still does not work.

The library class file with the Embed statement is under a directory com/directory/directory and I have put the font file in the same directory of this class file.  The main class file resides in another directory.  In my main class file, I use the import statement to import the library class file.

Compilation is fine and the font shows up when running on the desktop.  Somehow, it still does not work on Android.  Is there something I am missing?  Should all files reside in the same directory in order for it to work?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 01, 2011 Jul 01, 2011

Copy link to clipboard

Copied

Are you publishing with flash cs5.5 then embed your font within your flash file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 02, 2011 Jul 02, 2011

Copy link to clipboard

Copied

Oops!  I forgot to embed it in CS5.5.

I also created a class "Kids" (Text -> Font Embedding -> ActionScript),  and removed the Embed statement from the code.

I write the following code to set up the messageArea:

private var kidsPlainFont:Font = new Kids();

private var textFormat:TextFormat;

private var messageArea:TextField;

textFormat = new TextFormat();

textFormat.font = kidsPlainFont.fontName;

messageArea.defaultTextFormat = textFormat;

addChild(messageArea);

Again, it works on the desktop but does not work on the Android device.  What am I missing?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 02, 2011 Jul 02, 2011

Copy link to clipboard

Copied

When you input text in a text field, the runtime positions a native text input control over the Flash TextField object. Since native controls can't use embedded fonts, the closest system font is used. On Android (but not iOS) you can use TLF to create a text input control that is entirely drawn in Flash and thus can use embedded fonts during input. (I'm not sure if the Flex components support this on mobile, though, so you might still have to make your own if using Flex.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2011 Jul 06, 2011

Copy link to clipboard

Copied

Yes, this looks like this is the problem.  I created a TLFTextField and ran into another problem and have posted my message on Action Script 3 Discussions which I think this problem is more relevant to AS3 in general.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2011 Jul 07, 2011

Copy link to clipboard

Copied

I have written the following test program to use TLFTextField:

---------------------------------------------------------------------------------------------

import fl.text.TLFTextField;

import flashx.textLayout.formats.TextLayoutFormat;

import flashx.textLayout.elements.TextFlow;

[Embed(source = "Kids_Plain.ttf", fontFamily = "Kids", embedAsCFF = "false")]

var kids:Class;

var myFormat:TextLayoutFormat = new TextLayoutFormat();

myFormat.fontFamily = "Kids";

myFormat.fontSize = 24;

var tlfTextField:TLFTextField = new TLFTextField();

tlfTextField.x = 50;

tlfTextField.y = 50;

tlfTextField.width = 200;

addChild(tlfTextField);

var myTextFlow:TextFlow = tlfTextField.textFlow;

myTextFlow.hostFormat = myFormat;

myTextFlow.flowComposer.updateAllControllers();

tlfTextField.appendText("Testing this");

----------------------------------------------------------------------------------------------------

I am using CS5.5, have added the Flex library path, and chosen "Merge into code".

It runs perfectly on the desktop, but not on the Android.  I have already included the Kids_Plain.ttf file in the apk.  The text shows but the font is the system default font.

Any help is appreciated!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2011 Jul 07, 2011

Copy link to clipboard

Copied

Finally got it working with FontDescription.  The code is as follows:

import flash.text.engine.FontDescription;

import flash.text.engine.ElementFormat;

import flash.text.engine.TextBlock;

import flash.text.engine.TextElement;

import flash.text.engine.TextLine;

[Embed(source = "Kids_Plain.ttf", fontFamily = "Kids", embedAsCFF="true")]

var Kids:Class;

var fd:FontDescription = new FontDescription();

fd.fontLookup = flash.text.engine.FontLookup.EMBEDDED_CFF;

fd.fontName = "Kids";

var elementFormat:ElementFormat = new ElementFormat(fd);

var string:String = "This is a test";

var textBlock:TextBlock = new TextBlock();

var textElement:TextElement = new TextElement(string, elementFormat);

textBlock.content = textElement;

var line:TextLine = textBlock.createTextLine(null, 100);

line.x = 50;

line.y = 50;

addChild(line);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 07, 2011 Jul 07, 2011

Copy link to clipboard

Copied

Great!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 12, 2011 Aug 12, 2011

Copy link to clipboard

Copied

LATEST

It works on AIR2.6 running Android, but not AIR2.5.  Better open a new post since this question is tagged as answerd.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines