AS3: Arabic Embed Fonts - actionscript-3

I am using as3 and trying to use embed fonts with Arabic text but it doesn't work
So is there a way that I can access from .tff file the shape of the character or make it works using embed fonts
As using system fonts works but at same time its bad as on some machines it is reverted so I want to use embed font
Hope anyone can help

I found code by some one to change the input arabic text to the correct shape based on the position in text and I modified it to work perfectly with my code :)
here the AS3 code file: http://www.akhalifa.com/testing/ArabicAS3File/ArabicStringUtils.as
and here an example on how to use it: http://www.akhalifa.com/testing/ArabicAS3File/Main.as

You can use any arabic/persian input language like Maryam4
then write your sentence in this program after that copy it and paste in your code
also as #Goran Mottram said embed your font (for this situation if you use Maryam you must select F_fonts)
but noticed that in your code if you paste your arabic language it shows you wired character like ÂMoø , but dont worry if you publish you see a correct arabic word with rtl support

If you have the font installed on your system, make sure to import the font into your library and tick the box "Export for ActionScript" and give it an appropriate name, say MyArabicFont, then bind it to textfield using the following code:
// create the font
var myFont:Font = new MyArabicFont();
// assign to textformat
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = myFont.fontName;
// assign to textfield
var myTextField:TextField = new TextField();
myTextField.defaultTextFormat = myTextFormat;
myTextField.embedFonts = true;
myTextField.text = "Hello, world";
this.addChild(myTextField);

Related

How do I make a text box in ActionScript 3?

I'm trying to learn ActionScript 3, but right now I'm hung up on getting a basic interface set up. I've found out that newTextField will make one, but I don't know how to put it where I want.
I've checked out some source code for other projects using the same IDE (Adobe Flash CS6) and they seem to have access to a textbox symbol. So how do I make one of the textbox symbols with the IDE, or using some code?
var tf:TextField = new TextField;
tf.text = "Hello World!";
addChild(tf);
These will create black text reading 'Hello World!'.
Find out more about text fields here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html

Starling Font Fallback

I'm using bitmap fonts to display text.
In case of special characters such as Chinese, I'd like to be able to fall back to system default instead of having all possible characters in the world in the bitmap font.
Is that possible?
Starling's TextField does not provide a way to specify fallback fonts. You will need to check which language you are using beforehand and pass in the font name (in your case system default) that you know will work for the current language.
How to embed a font:
[Embed(source="../embeds/fonts/FuturaLTPro-Book.ttf", embedAsCFF="false", fontFamily="FuturaLTPro-Book")]
public static const Font_FuturaLTPro_Book:Class;
// create a TextFormat instance and use it instead of your bitmap font
var textFormat:TextFormat = new TextFormat(Font_FuturaLTPro_Book:Class, 18, 0x000000);

AS3 - Hindi font half letters getting converted

I have some text in Hindi language that should appear as क्या appears as क् या (without the space) which is not the way I want.
I am embedding fonts, but however flash is auto converting the "half letters". These sentences are getting read from an XML (which is UTF-8 encoded) and being directly applied into the textfield. In Flash Professional it shows up fine but when I check it in the app it appears as above. Anything that I am missing out on here?
Here is the textfield settings in my code:
tf.multiline = true;
tf.wordWrap = true;
tf.autoSize = TextFieldAutoSize.LEFT;
TLFTextField is the way to go. I had to convert all of my text fields in an application to TLFTextFields in order to show international characters. A TLFTextField is much larger in size then a regular TextField. You will notice when you compile the swf that it will grow quite large if you have many TLFTextField's.

Dynamic font embedding and formatting textflow with them

I am loading multiple swf files containing the different fonts at run-time. I am having problem when I am applying it to textflow in Rich Editable Text. Any Idea how to apply those custom fonts to the textflow ?
Here is the part of my code.
For registering the fonts
var FontClass:*;
var dom:ApplicationDomain = response.target.applicationDomain;
FontClass = dom.getDefinition(fileName) as Class;
Font.registerFont(FontClass);
Works!
For applying the font to textflow.
var cf:TextLayoutFormat = new TextLayoutFormat();
cf.fontFamily = mFontName; //Font Name
cf.fontLookup = FontLookup.EMBEDDED_CFF;
var editManager: IEditManager = IEditManager(textflow.interactionManager);
editManager.applyLeafFormat(cf);
No crash! Works!
But the applied font is not correct. Any suggestion please.
IEditManager is an interface, it doesn't do anything. You should be using EditManager.
Interfaces are not working classes, they used to define a common set of functions, any class that implements an interface, has to create working versions of all functions defined in the interface, or the compiler will fail. Further reading here

ActionScript 3 & font embedding

I have a problem with doing proper font embedding in a actionscript 3 project (flash CS4, not flex).
I followed this Adobe guide to do font embedding:
http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/
the guide tells to set the Textfield.embedFonts property to true. if I do so and try to display a text with another font in this textfield, then nothing is displayed - that's fine, i expect it like this.
But now I have this particular problem:
i embed the font "Arial" in Regular style and create two input Textfields on the stage. one of them i set the embedFonts property to true (as described in the guide) the other i leave as is. Now I publish the thing as swf and try to enter the following (Turkish) string into the textfield
Yeni Yılın Barış ve Mutluluk Getirmesini Dileriz.
now the problem is, that the untouched textfield displays the string correctly - but the one with embedFonts set to true is missing some of the letters (for example ş is not displayed). But the Arial font does have this letter since it is displayed correctly in static - so why does it not render correctly when i set this property (as told in the guide)?
in my final app there shall be a single textField, but multiple embedded fonts and a way to switch between them (for example the user must be able to choose another font for entering chinese text).
can someone tell me how to do it properly?
thanks!
Embedding fonts in Flash is not as straight forward as it should be, and there are a bunch of special cases... One way to ensure that you are embedding the correct characters of your font is enabling "Generate size report" in the Flash Publish Settings.... there you will see all characters of all fonts that are being embedded. The only exception is that fonts embedded using the [EMBED tag do not show there.
Adding the font to the library doesn't embed the whole set of characters of that font (Arial for instance is about 8mb)... it only embeds a subset of them... I'm not sure if its always the standard occidental Latin set, or if it depends on the computer language.
You can extend this set manually using any textfield in your movie (with the "Character embedding..." dialog) as long as you use the actual Library Font name (it shows in the font list with an asterisc at the end... in your case it would be "Arial*").
You can also use the [EMBED tag with the unicodeRange to declare de character set, but bare in mind that the fonts you declare there wont be available in the Flash IDE during editing time... you need to set them at runtime with ActionScript (TextFormat, StyleSheet, etc...), which is not very practical when working with Flash.
I use the system fonts, and avoid the embedded ones like Arial.
public function get availableFonts(): Array
{
var font: Font = null;
var allFonts: Array = Font.enumerateFonts(true).sortOn("fontName", Array.CASEINSENSITIVE);
var embeddedFonts: Array = Font.enumerateFonts(false);
var excludeList: Object = {}
for each(font in embeddedFonts)
{
excludeList[font.fontName] = '';
}
var ourFonts: Array = [];
for each(font in allFonts)
{
if (!excludeList.hasOwnProperty(font.fontName))
{
ourFonts.push(font);
}
}
return ourFonts;
}
The list of fonts that this returns are going to have all their letters.
(wouldn't it be nice if ActionScript had some easier way of doing set difference built in?)
If you're looking for a more robust font loading solution that can load the different fonts at runtime, I've posted some code here (http://labs.tomasino.org/2009/07/16/flash-as3-runtime-font-manager/) and explanations of how to use it.