package { import flash.display.Sprite; import flash.events.EventDispatcher; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.text.engine.*; import flash.utils.Dictionary; [SWF(width="250", height="110")] public class FTEDemo5 extends Sprite { public function FTEDemo5() { super(); // Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. -Albert Einstein var e1:TextElement = new TextElement('"Only ', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 16)); var e2:TextElement = new TextElement('two things', new ElementFormat( new FontDescription("Times", FontWeight.BOLD, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 24), new EventDispatcher()); var e3:TextElement = new TextElement(' are infinite, ', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 16)); var e4:TextElement = new TextElement('the universe', new ElementFormat( new FontDescription("Times", FontWeight.BOLD, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 26)); var e5:TextElement = new TextElement(' and ', new ElementFormat( new FontDescription("Times", FontWeight.BOLD, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 16)); var e6:TextElement = new TextElement('human stupidity', new ElementFormat( new FontDescription("Times", FontWeight.BOLD, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 26)); var e7:TextElement = new TextElement(', and ', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF), 16)); var e8:TextElement = new TextElement('I\'m not sure about the former.', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.ITALIC, FontLookup.EMBEDDED_CFF), 26), new EventDispatcher()); var e9:TextElement = new TextElement('" -', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.ITALIC, FontLookup.EMBEDDED_CFF), 16)); var e10:TextElement = new TextElement('Albert Einstein', new ElementFormat( new FontDescription("Times", FontWeight.NORMAL, FontPosture.ITALIC, FontLookup.EMBEDDED_CFF), 16), new EventDispatcher()); var colors:Array = [0x00FF00, 0xFF6600, 0x0066FF]; var mirrors:Dictionary = new Dictionary(); var color:uint; var regions:Vector.; var region:TextLineMirrorRegion; var bounds:Rectangle; var vec:Vector. = new Vector.(); vec.push(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); var block:TextBlock = new TextBlock(new GroupElement(vec)); var line:TextLine = block.createTextLine(null, 250); var _y:Number = 0; while(line) { addChild(line); _y += line.height; line.y = _y; regions = line.mirrorRegions; while(regions && regions.length) { region = regions.pop(); if(region.mirror in mirrors) color = mirrors[region.mirror]; else color = colors.pop(); mirrors[region.mirror] = color; bounds = region.bounds; graphics.beginFill(color, 0.3); graphics.drawRect(bounds.x, bounds.y + line.y, bounds.width, bounds.height); } line = block.createTextLine(line, 250); } } [Embed(source="assets/Times New Roman.ttf", embedAsCFF="true", fontFamily="Times")] private var times:Class; } }