TextLayoutFormat for Arabic Text

Pretty straight forward and you can use fancy fonts as well, in the example I’ve used GE SS Two Medium font.

/**
* ...
* @author Rahmat Hidayat
*/
import fl.text.TLFTextField;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.elements.TextFlow;
import flash.text.TextFormat;
import flash.text.AntiAliasType;
import flash.text.FontStyle;
import flash.text.Font;
import flash.text.engine.FontLookup;
import flashx.textLayout.edit.ISelectionManager;
import flashx.textLayout.edit.EditManager;
import flashx.textLayout.edit.SelectionState;
import flashx.textLayout.formats.Direction;

var tField:TLFTextField = new TLFTextField();
var applyFont:Font = new Arabic();

/**
* Things that matter
*/
tField.text = "أغنية لشعبولا عن مقتل معمر القذافي";
tField.direction = Direction.RTL;
tField.width = 300;
tField.x = (stage.stageWidth - tField.width)/2;
tField.y = 100;
tField.wordWrap = true;

tField.embedFonts = true;

addChild(tField)

var tFormat:TextLayoutFormat = new TextLayoutFormat();
tFormat.fontFamily = applyFont.fontName;
tFormat.color	= 0xffffff;
tFormat.fontLookup = FontLookup.EMBEDDED_CFF;
tFormat.fontSize	= 30;

/**
*  Just blindly copy and paste the below
*/

tField.textFlow.invalidateAllFormats();
tField.textFlow.hostFormat = tFormat;

var prevManager:ISelectionManager = tField.textFlow.interactionManager;
var editManager:EditManager = new EditManager();
var sel:SelectionState = new SelectionState(tField.textFlow, 0, tField.text.length);
tField.textFlow.interactionManager = editManager;
editManager.applyLeafFormat(tFormat, sel);
tField.textFlow.interactionManager = prevManager;

tField.textFlow.flowComposer.updateAllControllers();
  1. Nice to see that this isn’t anywhere near as painful as it used to be! Was it Al Rassam?! *shiver*

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *