<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>guy in the chair . com &#187; compact font format</title>
	<atom:link href="http://guyinthechair.com/tag/compact-font-format/feed/" rel="self" type="application/rss+xml" />
	<link>http://guyinthechair.com</link>
	<description>//the blog of Paul Taylor</description>
	<lastBuildDate>Fri, 18 Nov 2011 01:22:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The Flash Text Engine, Part 1: Overview</title>
		<link>http://guyinthechair.com/2010/06/the-flash-text-engine-part-1/</link>
		<comments>http://guyinthechair.com/2010/06/the-flash-text-engine-part-1/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 10:18:20 +0000</pubDate>
		<dc:creator>Paul Taylor</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[advanced text rendering]]></category>
		<category><![CDATA[cff]]></category>
		<category><![CDATA[compact font format]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flash Text Engine]]></category>
		<category><![CDATA[FTE]]></category>
		<category><![CDATA[text layout]]></category>
		<category><![CDATA[Text Layout Framework]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[tiny tlf]]></category>
		<category><![CDATA[tinytlf]]></category>
		<category><![CDATA[TLF]]></category>

		<guid isPermaLink="false">http://guyinthechair.com/?p=250</guid>
		<description><![CDATA[This is the first post in what will be a multi-part series about the Flash Text Engine, a new low level text API in Flash Player 10. To clarify, this series isn&#8217;t about Adobe&#8217;s Text Layout Framework, which is an advanced typography and text layout framework. The Flash Text Engine is the low-level API that [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first post in what will be a multi-part series about the Flash Text Engine, a new low level text API in Flash Player 10.</p>
<p style="padding-left:15px;padding-right:15px;color:#999999">To clarify, this series isn&#8217;t about <a href="http://labs.adobe.com/technologies/textlayout/">Adobe&#8217;s Text Layout Framework</a>, which is an advanced typography and text layout framework. The Flash Text Engine is the low-level API that TLF is built on. In Flash Player 10, the FTE resides in the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/engine/package-detail.html">flash.text.engine</a> package.</p>
<p>The FTE is designed to render text &#8220;document style&#8221;. It&#8217;s primarily meant to replace the TextField for advanced uses, not provide a whole framework for text layout on the scale of an HTML rendering engine.</p>
<p>The FTE handles what I call <strong>flow</strong>: formatting that causes text to be pushed to the next line in a paragraph. I don&#8217;t know if that&#8217;s the official term, but it seems to fit. It does not do <strong>layout</strong>, which is things like bullet points, indentation, wrapping around images, padding, etc., nor does it handle <strong>decoration</strong>, things like underline, strikethrough, background color, selection, etc. I believe the FTE leaves these out because 1.) layout is a much more complicated and nuanced problem than flow, one that you wouldn&#8217;t necessarily want in the FP core, and 2.) decorations don&#8217;t cause <strong>reflow</strong>, or affect whether and how text is wrapped to the next line.</p>
<p>The FTE conforms to a small MVC architecture, there are about 10 core classes that provide most of the functionality, with the rest of them encapsulating constants. Something to note, every class in the FTE is final :( more on that later.</p>
<h2>The FTE Model</h2>
<p>The basis of the Flash Text Engine model is something called <a title="flash.text.engine.ContentElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/ContentElement.html" target="_blank">ContentElement</a>. ContentElement is an abstract base class. You never call <code>new ContentElement()</code> (it&#8217;s similar to DisplayObject in this regard), instead you instantiate one of its 3 subclasses: <a title="flash.text.engine.TextElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextElement.html" target="_blank">TextElement</a>, <a title="flash.text.engine.GraphicElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/GraphicElement.html" target="_blank">GraphicElement</a>, or <a title="flash.text.engine.GroupElement" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/GroupElement.html" target="_blank">GroupElement</a>. Collectively these classes describe a Tree hierarchy for text, but I want to talk a bit more about ContentElement before we get too deep into that.</p>
<h3>ContentElement</h3>
<p>Take a look at the constructor of ContentElement:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">ContentElement<span style="color: #000000;">&#40;</span>elementFormat<span style="color: #000066; font-weight: bold;">:</span>ElementFormat = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> eventMirror<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> textRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;rotate0&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>It has two important arguments, <strong>elementFormat</strong> and <strong>eventMirror</strong> (as well as a third less important argument, unless you&#8217;re one of the crazy types who likes to rotate text). I will come back to the eventMirror later, but for now lets just talk about <a title="flash.text.engine.ElementFormat" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/ElementFormat.html" target="_blank">ElementFormat</a>.</p>
<p>The ElementFormat class describes most of the properties that handle text flow. It has a fontDescription member, which is exactly what it sounds like. In <a title="flash.text.engine.FontDescription" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/FontDescription.html" target="_blank">FontDescription</a> you&#8217;ve got your standard <code>fontFamily</code>, <code>fontWeight</code>, <code>fontPosture</code> (which is traditionally the fontStyle in Flash), along with how the font is supposed to be retrieved from the depths of the Flash Player (as Compact Font Format or a device font).</p>
<p>ElementFormat has properties like <code>alpha</code>, <code>color</code>, <code>baselineShift</code>, <code>kerning</code>, etc. Basically anything that can affect <strong>reflow</strong>.</p>
<p>Ok, so that describes all you need to know for now about the ElementFormat and FontDescription objects. Now onto the implementation class you&#8217;ll use.</p>
<h3>TextElement</h3>
<p>Out of the three, TextElement is the most straightforward. It simply accepts a string of text to take care of:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">TextElement<span style="color: #000000;">&#40;</span><span style="color: #004993;">text</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> elementFormat<span style="color: #000066; font-weight: bold;">:</span>ElementFormat = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> eventMirror<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> textRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;rotate0&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>The ElementFormat you pass in is applied to the entire string of text that this TextElement owns. So if you specify an ElementFormat with a color of <span style="color: #ff0000;">red</span>, the entire string of text will render <span style="color: #ff0000;">red</span>.</p>
<h3>GraphicElement</h3>
<p>The next one to worry about is GraphicElement. He accepts <strong>any DisplayObject instance</strong> (<strong>instance!</strong>), as well as the width and height that you wish to allocate for the Graphic in the text:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">GraphicElement<span style="color: #000000;">&#40;</span>graphic<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> elementWidth<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">15.0</span><span style="color: #000066; font-weight: bold;">,</span> elementHeight<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">15.0</span><span style="color: #000066; font-weight: bold;">,</span> elementFormat<span style="color: #000066; font-weight: bold;">:</span>ElementFormat = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> eventMirror<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> textRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;rotate0&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Some of the properties of the ElementFormat will apply to the GraphicElement, such as <code>alpha</code>, <code>baselineShift</code>, etc. Obviously the GraphicElement doesn&#8217;t respect font-specific settings from the ElementFormat and FontDescription objects.</p>
<h3>GroupElement</h3>
<p>Lastly there&#8217;s the GroupElement:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">GroupElement<span style="color: #000000;">&#40;</span><span style="color: #004993;">elements</span><span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>ContentElement<span style="color: #000066; font-weight: bold;">&gt;</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> elementFormat<span style="color: #000066; font-weight: bold;">:</span>ElementFormat = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> eventMirror<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">EventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> textRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;rotate0&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>GroupElement is <strong>critical</strong>. GroupElement is a collection of any combination of TextElements, GraphicElements, or other GroupElements. GroupElement is the Tree functionality of FTE&#8217;s model. TextElement can&#8217;t have children, it controls a single String. Likewise, GraphicElement only describes a single DisplayObject instance. GroupElements tie it all together.</p>
<p>GroupElements provide an API for doing standard Tree functions; you can retrieve, split, merge, and group children using various methods. I speak from experience when I say you won&#8217;t often mess with this unless you&#8217;re writing an editable text field. And if you are writing an editable text field, God help you (just kidding, it is hella fun).</p>
<p>OK, enough Model talk. Onwards to&#8230;</p>
<h2>The FTE View</h2>
<p>There are two (<strong>2!</strong>) classes that make up the entirety of the Flash Text Engine&#8217;s <strong><em>View</em></strong> division: <a target="_blank" title="flash.text.engine.TextLine" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLine.html">TextLine</a> and <a target="_blank" title="flash.text.engine.TextLineMirrorRegion" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLineMirrorRegion.html">TextLineMirrorRegion</a>. Right now you can forget about TextLineMirrorRegion, as that has to do with interaction, which is a complicated topic and one which I will cover in detail later. So for now, only focus on TextLine.</p>
<h3>TextLine</h3>
<p>TextLine is a DisplayObjectContainer. Yes, that means it has the <code>get/add/removeChild</code> methods (<strong>they still work!</strong>), and is also an InteractiveObject. You can listen for all the normal interaction events. However, even though it inherits from InteractiveObject, there are a few properties that you can only read, not write. Those are detailed in the <a href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLine.html">documentation for TextLine</a>.</p>
<p>TextLine adds the concept of <em>atoms</em>, which are indivisible characters in a TextLine. Individual characters are atoms, as well as any graphics you have. The important thing to know here is that atoms can never be split between lines. The FTE will measure only to the atom level, no lower. </p>
<p>Atom information can be expensive to keep around&#8230; At first the TextLine only renders its text, it doesn&#8217;t know anything about the atoms it contains. However calling various methods will cause the TextLine to create its atom data. For example, if you call <code>getAtomIndexAtPoint()</code>, the TextLine must create the info about each atom so it can then calculate which atom occurs at the point you specify. This is all well and good, but be sure to call <code>flushAtomData()</code> once you&#8217;re done so the atom data will be GC&#8217;d.</p>
<p>TextLine has a reference to the previous and next lines, because TextLine is also a <a href="http://en.wikipedia.org/wiki/Doubly-linked_list">doubly-linked list</a>! How convenient! Of course, if there is no previous or next, you know you&#8217;re the first or last lines, respectively.</p>
<p>TextLine also has a <code>validity</code> status, which is whether the ContentElement that the line represents has changed since the line was rendered. Values are described in the <a href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextLineValidity.html">TextLineValidity</a> class.</p>
<p>One thing that TextLine definitely <strong>is not</strong>: a Sprite. No, TextLine is a DisplayObjectContainer. The most important implication from this is that TextLine has no <strong>graphics context</strong>. This means you can&#8217;t call textLine.graphics.draw. :( Oh well.</p>
<p>TextLine is a concrete class, you use it directly, but you cannot instantiate one by calling its constructor. To do that you need&#8230;</p>
<h2>The FTE Controller</h2>
<p>There is arguably <strong>one class</strong> in the FTE&#8217;s <strong><em>Controller</em></strong> division: <a target="_blank" title="flash.text.engine.TextBlock" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextBlock.html">TextBlock</a>. I say <em>arguably</em> because yeah, <a target="_blank" title="flash.text.engine.TextJustifier" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TextJustifier.html">TextJustifier</a> and <a target="_blank" title="flash.text.engine.TabStop" href="http://livedocs.adobe.com/flex/3/langref/flash/text/engine/TabStop.html">TabStop</a> exist, but they just affect how TextBlock does its rendering, not&#8230; hm. Ok, I&#8217;ve convinced myself that they count as Controller classes too, but only <em>barely</em>.</p>
<p>But believe me, you will come to think of TextBlock as the only Controller class too.</p>
<p>The TextBlock is a fairly standard Factory pattern implementation: TextBlock&#8217;s primary job is to accept a ContentElement as input and output as many TextLines as you want, given a width. <strong>ContentElement</strong> -> <strong>TextBlock</strong> -> <strong>TextLines</strong>. Got it? Me neither.</p>
<p>Ok, so TextBlock has this method called <code>createTextLine()</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">createTextLine<span style="color: #000000;">&#40;</span>previousLine<span style="color: #000066; font-weight: bold;">:</span>TextLine = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000066; font-weight: bold;">,</span> lineOffset<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">,</span> fitSomething<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>TextLine</pre></div></div>

<p>Ok so what you do is you pass in the <strong><em>previous</em></strong> line that you created, plus the width that you want the <strong><em>current</em></strong> line to be, and TextBlock will measure out a TextLine for you. Are you seeing the doubly-linked list yet?</p>
<p>If you want to create the first line from a TextBlock, you should just pass in <code>null</code> to the <code>createTextLine()</code> method; assuming the TextBlock has content in his <code>content</code> property, and that content has at least one atom (characters or graphics), passing in <code>null</code> will <em>always</em> return a TextLine. If there are no more lines to be created, TextBlock will return <code>null</code> from the call to <code>createTextLine()</code>.</p>
<p>So from this it is simple to render the lines for a TextBlock with width 200:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> line<span style="color: #000066; font-weight: bold;">:</span>TextLine = block<span style="color: #000066; font-weight: bold;">.</span>createTextLine<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= line<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">;</span>
    line<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>
    line = block<span style="color: #000066; font-weight: bold;">.</span>createTextLine<span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h3>Ok, I&#8217;ve detailed a lot so far, now it&#8217;s time to get to at an example.</h3>
<h3>Flash:</h3>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="450" height="32">
      <param name="movie" value="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://guyinthechair.com/wp-content/uploads/2010/06/SimpleDemo1.swf" width="450" height="32">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>Here&#8217;s the code for the above simple line rendering:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>ContentElement<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>ElementFormat<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>FontDescription<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>FontPosture<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>FontWeight<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>GroupElement<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>TextBlock<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>TextElement<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span>engine<span style="color: #000066; font-weight: bold;">.</span>TextLine<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
  <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;450&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;32&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SimpleDemo1 <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SimpleDemo1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> e1<span style="color: #000066; font-weight: bold;">:</span>TextElement = <span style="color: #0033ff; font-weight: bold;">new</span> TextElement<span style="color: #000000;">&#40;</span><span style="color: #990000;">'Consider, what makes a text line a '</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> ElementFormat<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FontDescription<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> e2<span style="color: #000066; font-weight: bold;">:</span>TextElement = <span style="color: #0033ff; font-weight: bold;">new</span> TextElement<span style="color: #000000;">&#40;</span><span style="color: #990000;">'text line'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> ElementFormat<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FontDescription<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_serif&quot;</span><span style="color: #000066; font-weight: bold;">,</span> FontWeight<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NORMAL</span><span style="color: #000066; font-weight: bold;">,</span> FontPosture<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ITALIC</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> e3<span style="color: #000066; font-weight: bold;">:</span>TextElement = <span style="color: #0033ff; font-weight: bold;">new</span> TextElement<span style="color: #000000;">&#40;</span><span style="color: #990000;">'?'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> ElementFormat<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FontDescription<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> e<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>e1<span style="color: #000066; font-weight: bold;">,</span> e2<span style="color: #000066; font-weight: bold;">,</span> e3<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> block<span style="color: #000066; font-weight: bold;">:</span>TextBlock = <span style="color: #0033ff; font-weight: bold;">new</span> TextBlock<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> GroupElement<span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> line<span style="color: #000066; font-weight: bold;">:</span>TextLine = block<span style="color: #000066; font-weight: bold;">.</span>createTextLine<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #6699cc; font-weight: bold;">var</span> _y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        _y <span style="color: #000066; font-weight: bold;">+</span>= line<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">;</span>
        line<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = _y<span style="color: #000066; font-weight: bold;">;</span>
        line = block<span style="color: #000066; font-weight: bold;">.</span>createTextLine<span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p style="font-size: 14px;"><strong>Holy crap Batman!</strong><br />
As you can see, it required <em>3 different TextElements <strong>and</strong> a GroupElement</em> to render some freakin&#8217; italic text in the middle of a sentence. Yeah. Par for the frickin&#8217; course.</p>
<p>In part 2 I&#8217;ll get into more details about interaction, TextBlock manipulation, all of it.<br />
Till then watch this project on github: <a target="_blank" title="tinytlf on github" href="http://github.com/guyinthechair/tinytlf">tinytlf</a>. It&#8217;s due for some major updates but it&#8217;s what I&#8217;m going to start talking about soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://guyinthechair.com/2010/06/the-flash-text-engine-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

