Skip to content

Instantly share code, notes, and snippets.

@loudoweb
Last active February 15, 2016 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loudoweb/8229711420c7a1bd0e72 to your computer and use it in GitHub Desktop.
Save loudoweb/8229711420c7a1bd0e72 to your computer and use it in GitHub Desktop.
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