moock.org is supported in part by


August 12, 2008

workaround for 127px font size limit

In ActionScript, text fields formatted via TextFormat, CSS, or HTML have an undocumented maximum font size of 127px. The limitation is based on historical requirements placed on Flash Player by the operating system. The limit also applies to dynamic and input text created in the Flash authoring tool, but not to static text.

Fortunately, the 127 font-size limit can be overcome with an ugly little workaround: set the font size, then scale the text field using scaleX and scaleY. For example, the following code sets a text field's effective font size to 200 by first setting TextFormat.size to 100, then scaling by 2.

var format:TextFormat = new TextFormat();
format.size = 100;
      
var t:TextField = new TextField();
t.autoSize = TextFieldAutoSize.LEFT;
t.text = "Nice and big.";
t.setTextFormat(format);
t.scaleX = 2;
t.scaleY = 2;
addChild(t);

As of Flash Player 10, the 127px font size limit continues to apply to traditional text, but has been removed for text rendered via the new Flash Text Engine (FTE). The following code, courtesy of Flash Player engineer Jeff Mott, sets the font size of a TextElement to 300.

var ef:ElementFormat = new ElementFormat();
ef.fontSize = 300;
var te:TextElement = new TextElement ("Nice and big.", ef);
var tb:TextBlock = new TextBlock (te);
var tl:TextLine = tb.createTextLine();
tl.x = 20;
tl.y = 300;
addChild (tl);

The 127px limit will also be removed for Flash's new Text Layout Components when they are released.

Posted by moock at August 12, 2008 01:09 AM