Create a gist now

Instantly share code, notes, and snippets.

@loudoweb /FixText.hx
Last active Feb 15, 2016

What would you like to do?
Fix font embedding issue in flash for TextField made with FlashCC/OpenFL plugin
package;
import openfl.display.DisplayObjectContainer;
import openfl.text.TextField;
/**
* ...
* @author loudo
*/
class FixText
{
public static var fixTxt:TextField;
public static var parent:DisplayObjectContainer;
public function new()
{
}
/**
* Re-create the textfield in flash to fix font embedding issue on textfield made with FlashCC (https://github.com/openfl/swf/issues/56)
* @param txt textfield
* @param text text of the textfield
* @param html use htmlText
*/
public static function fixFont(txt:TextField, text:String, html:Bool = false):TextField
{
#if flash
if (!txt.embedFonts)
{
fixTxt = new TextField();
fixTxt.name = txt.name;
fixTxt.defaultTextFormat = txt.defaultTextFormat;
fixTxt.embedFonts = true;
fixTxt.x = txt.x;
fixTxt.y = txt.y + Math.round(fixTxt.defaultTextFormat.size/5);//fix because new textfield seems not be placed in the same position
fixTxt.width = txt.width;
fixTxt.height = txt.height;
fixTxt.multiline = txt.multiline;
fixTxt.wordWrap = txt.wordWrap;
fixTxt.rotation = txt.rotation;
fixTxt.selectable = txt.selectable;
parent = txt.parent;
parent.removeChild(txt);
parent.addChild(fixTxt);
if(!html)
fixTxt.text = text;
else
fixTxt.htmlText = text;
return fixTxt;
}else {
if(!html)
txt.text = text;
else
txt.htmlText = text;
return txt;
}
#else
if(!html)
txt.text = text;
else
txt.htmlText = text;
return txt;
#end
}
/*
*
*/
inline public static function fixReturn(text:String):String
{
return StringTools.replace(text, '\n', '');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment