<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[al5]Drawing text line by line rather than char by char?</title>
		<link>http://www.allegro.cc/forums/view/606096</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 18 Jan 2011 22:42:16 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Would there be a very noticeable performance dent if I drew text char by char rather than line by line?</p><p>Say I have:</p><p>ABCDEF ABCDEF ABCDEF ABCDEF <br />GHIJK GHIJK GHIJK GHIJK GHIJK<br />ABCDEF ABCDEF ABCDEF ABCDEF <br />GHIJK GHIJK GHIJK GHIJK GHIJK<br />ABCDEF ABCDEF ABCDEF ABCDEF <br />GHIJK GHIJK GHIJK GHIJK GHIJK</p><p>(or about a good TextBox worth of text)</p><p>Would it be much slower to do:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">for</span> each <span class="k1">char</span>
draw <span class="k1">char</span> with its color
increase X by width of <span class="k1">char</span>
</pre></div></div><p>

rather than
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">for</span> each <a href="http://www.allegro.cc/manual/line"><span class="a">line</span></a> of text
draw the text
</pre></div></div><p>

The reason why is because I&#39;m thinking of doing the former for my Gui&#39;s TextBoxes. I want to have gradient text so each char has a different color.</p><p>When I tested it didn&#39;t seem to be much different, but I want a second opinion.</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Mon, 17 Jan 2011 07:55:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899012#target">jmasterx</a> said:</div><div class="quote"><p>Would there be a very noticeable performance dent if I drew text char by char rather than line by line?</p></div></div><p>Not so much.  Either way, you&#39;ll have a pretty strong hit drawing that much text regardless.  Text rendering can be <i>kindof</i> expensive if you do a lot.  If it&#39;s savings you&#39;re after, you&#39;ll get a bigger help by rendering your text to a separate bitmap and drawing the bitmap from that point on.</p><p>If you want to really measure the difference, you can:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">double</span> start <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">// do your rendering here</span>
<span class="k1">double</span> end <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">double</span> time_of_process <span class="k3">=</span> end <span class="k3">-</span> start<span class="k2">;</span>
</pre></div></div><p>

In my experience, drawing char by char isn&#39;t that much more expensive.  It&#39;s negligible.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 17 Jan 2011 08:01:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Using <span class="source-code"><a href="http://www.allegro.cc/manual/al_hold_bitmap_drawing"><span class="a">al_hold_bitmap_drawing</span></a><span class="k2">(</span><span class="k2">)</span></span> might help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 17 Jan 2011 08:04:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;ll probably get better looking text if you render line by line though. If you go char by char, you&#39;ll be missing out on some of the fancier hinting available with TTF fonts. This is assuming you&#39;re using TTFs, and not bitmap fonts. If you&#39;re using bitmap fonts, you can probably do as you like.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 17 Jan 2011 08:05:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899016#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>You&#39;ll probably get better looking text if you render line by line though. If you go char by char, you&#39;ll be missing out on some of the fancier hinting available with TTF fonts.</p></div></div><p>I don&#39;t think this is true.  Here I&#39;ve tested 4 TTF fonts, the top (white) is rendered char-by-char and the bottom (pink) is drawn by the line.  The hinting appears to be identical on both.</p><p><span class="remote-thumbnail"><span class="json">{"name":"603099","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/1\/a1fdbad69e02d26bcebf522cb3fb0987.png","w":801,"h":173,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/1\/a1fdbad69e02d26bcebf522cb3fb0987"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/1/a1fdbad69e02d26bcebf522cb3fb0987-240.jpg" alt="603099" width="240" height="51" /></span><br /><span class="remote-thumbnail"><span class="json">{"name":"603100","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/9\/a953a80079d7cc0f9cb44a97513c1e8f.png","w":645,"h":173,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/9\/a953a80079d7cc0f9cb44a97513c1e8f"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/9/a953a80079d7cc0f9cb44a97513c1e8f-240.jpg" alt="603100" width="240" height="64" /></span><br /><span class="remote-thumbnail"><span class="json">{"name":"603101","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/1\/211f87cc82371bb1e85733e94fb835d2.png","w":645,"h":173,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/1\/211f87cc82371bb1e85733e94fb835d2"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/1/211f87cc82371bb1e85733e94fb835d2-240.jpg" alt="603101" width="240" height="64" /></span><br /><span class="remote-thumbnail"><span class="json">{"name":"603102","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/ac424d7f6ffaa9d56065117586d35e30.png","w":901,"h":173,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/ac424d7f6ffaa9d56065117586d35e30"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/c/ac424d7f6ffaa9d56065117586d35e30-240.jpg" alt="603102" width="240" height="46" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 17 Jan 2011 08:19:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I could be wrong. But I could swear I&#39;ve seen fonts that don&#39;t display properly if you draw char by char since allegro doesn&#39;t let you access all of the hinting info... At most you get access to the &quot;advance&quot; which may be enough for many simple fonts? I dunno.</p><p>What I heard is the actual advance between any two characters can be different depending on which character pair is used. So an &quot;a&quot;s advance might not be the same depending on what character follows it. Simple examples like the above might not show any difference...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 17 Jan 2011 08:22:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Speedwise, it should be nearly the same as long as you hold drawing. As for hinting, you can probably compute it manually by computing widths of pairs of characters.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 17 Jan 2011 08:29:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You may be thinking of <a href="http://en.wikipedia.org/wiki/Kerning">kerning</a> and or kerning pairs.  I found that allegro neglects the kerning pairs between characters.  Take for example the font Trajan.  The top (white) is drawn by character, the second (pink) is drawn by line, and the third (green) I added with photoshop and includes the appropriate pairs (AV, AW, WA, etc).</p><p><span class="remote-thumbnail"><span class="json">{"name":"603103","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/6\/a6ccaca2717c7cc929bd871f8eb5cf8d.png","w":591,"h":173,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/6\/a6ccaca2717c7cc929bd871f8eb5cf8d"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/6/a6ccaca2717c7cc929bd871f8eb5cf8d-240.jpg" alt="603103" width="240" height="70" /></span></p><p>here is 3x zoom with hilights:<br /><span class="remote-thumbnail"><span class="json">{"name":"603105","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/5\/d5412f1bd98694d822eb61590f88a9ca.png","w":335,"h":313,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/5\/d5412f1bd98694d822eb61590f88a9ca"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/d/5/d5412f1bd98694d822eb61590f88a9ca-240.jpg" alt="603105" width="240" height="224" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 17 Jan 2011 08:34:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm... unless you load it with <span class="source-code">ALLEGRO_TTF_NO_KERNING</span> it should work in Allegro too... sounds like a bug.</p><p>EDIT:</p><p>Well, it works fine with the font used in ex_ttf... so it&#39;s a font specific bug.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 17 Jan 2011 08:38:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899025#target">SiegeLord</a> said:</div><div class="quote"><p>Well, it works fine with the font used in ex_ttf... so it&#39;s a font specific bug.</p></div></div><p>Interesting... I&#39;m finding that some OpenType .otf fonts are not rendering with pairs.  I now see that I am getting pairs for my TTF fonts.</p><p>here is Constantina (TTF)<br /><span class="remote-thumbnail"><span class="json">{"name":"603107","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/5\/75293a732e954414a74d4e1470bfe64c.png","w":591,"h":173,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/5\/75293a732e954414a74d4e1470bfe64c"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/7/5/75293a732e954414a74d4e1470bfe64c-240.jpg" alt="603107" width="240" height="70" /></span></p><p>doing more testing...</p><p>[edit]</p><p><span class="remote-thumbnail"><span class="json">{"name":"603109","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/d\/ed61b7cff515468aa9b8f70b81873732.png","w":670,"h":888,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/d\/ed61b7cff515468aa9b8f70b81873732"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/d/ed61b7cff515468aa9b8f70b81873732-240.jpg" alt="603109" width="240" height="318" /></span><br />the ones with the arrows are the fonts that do have kerning data but don&#39;t render correctly.  Each of these are Adobe Fonts (the best ones <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />) that came with Photoshop and are otf.  They&#39;re fonts that are part of font sets (bold, italic, regular, bold-italic) and so the kerning may be in the set data, or something fancy like separate glyphs.</p><p>dangit. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 17 Jan 2011 08:59:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How can one then get colored text while still maintaining kerning?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Mon, 17 Jan 2011 09:38:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>jmasterx are you using a5?  The 5.0 RC versions have color in the function call.</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 17 Jan 2011 09:45:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sorry, what I meant is, each letter having a different color. al_draw_text would almost need a callback to change the color.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Mon, 17 Jan 2011 09:47:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was going to suggest this:
</p><ol><li><p>Draw gradient with alpha = 0%.
</p></li><li><p>Draw font with rgb of 0,0,0 and alpha = 100% using ADD/ONE/ONE for the blender mode.
</p></li></ol><p>But I couldn&#39;t get it to work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 17 Jan 2011 10:12:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899035#target">Matthew Leverton</a> said:</div><div class="quote"><p>But I couldn&#39;t get it to work.
</p></div></div><p>I think something was borked in RC4 with the blenders (<a href="http://www.allegro.cc/forums/thread/605937/898164#target">fixed in SVN?</a>).  My 0.0f alpha images are all drawn as if they were additive blending with 1.0 transparency.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 17 Jan 2011 10:16:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmmm that won&#39;t be flexible enough, I&#39;m gonna be making colored textboxes for my gui api and I&#39;ll need to be able to color a selection.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Mon, 17 Jan 2011 10:21:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899036#target">Mark Oates</a> said:</div><div class="quote"><p> I think something was borked in RC4 with the blenders 
</p></div></div><p>That looks like a D3D thing (judging by Peter&#39;s comments), but I&#39;m on Linux (opengl).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 17 Jan 2011 10:23:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899021#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> But I could swear I&#39;ve seen fonts that don&#39;t display properly if you draw char by char since allegro doesn&#39;t let you access all of the hinting info...</p></div></div><p>IIRC, there&#39;s two kinds of &quot;hinting&quot;, one has narrow widths for narrow chars and vice versa, and the other patented kind takes the next char into account, such as &quot;TF&quot; vs. &quot;Tf&quot; (the serif on the f fits under the crossbar on the T).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Mon, 17 Jan 2011 16:04:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think <b>hinting</b> is patented and therefore not included in Freetype. <b>Kerning</b> however should work - I don&#39;t know why it seems to be missing for some fonts. Most likely a bug in the TTF addon.</p><p>To render char-by-char, the best way would probably be a special function for it. Right now if you render e.g. the text &quot;AV&quot;, then al_get_text_width(&quot;AV&quot;) will be smaller than al_get_text_width(&quot;A&quot;) + al_get_text_width(&quot;V&quot;) because of the kerning - the only way to get the exact position of the &quot;V&quot; would be if you could get the kerning offset of the &quot;AV&quot; pair. Maybe a function like</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">float</span> al_get_char_pos<span class="k2">(</span><span class="k1">float</span> x, <span class="k1">char</span> <span class="k1">const</span> <span class="k3">*</span>text, <span class="k1">char</span> <span class="k1">const</span> <span class="k3">*</span>letter<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Then if you call it as al_get_char_pos(0, &quot;A&quot;, &quot;V&quot;) it will return the exact position to draw the &quot;V&quot; to after the &quot;A&quot;. It would also work with something like al_get_char_pos(x, &quot;Alleg&quot;, &quot;ro&quot;) and return the position where to draw the &quot;r&quot;... but usually there would be no need to have more than one letter in either string.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 17 Jan 2011 16:15:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My only purpose for drawing char-by-char is to modify the letter spacing.</p><p>I think a <span class="source-code"><span class="k1">float</span> al_get_char_pos<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>text, <span class="k1">int</span> pos<span class="k2">)</span></span> would work nicely.</p><p>One could also invert that and get a cursor position for editing text given an (x,y) location in the string.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 18 Jan 2011 01:08:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899072#target">Elias</a> said:</div><div class="quote"><p>I think hinting is patented and therefore not included in Freetype.</p></div></div><p>
The last of the TrueType hinting patents expired in May 2010, at which point even the US versions of FreeType started shipping with the bytecode interpreter enabled by default.<br />(But yes, hinting and kerning are two completely different concepts. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />)</p><p>As for OpenType fonts,
</p><div class="quote_container"><div class="title">The FreeType docs said:</div><div class="quote"><p>Not all font formats contain kerning information, and not all kerning formats are supported by FreeType; in particular, for TrueType fonts, the API can only access kerning via the ‘kern’ table; <b>OpenType kerning via the ‘GPOS’ table is not supported.</b> You need a higher-level library like Pango or ICU to handle that.</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Tue, 18 Jan 2011 01:22:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://freetype.sourceforge.net/patents.html">patent info</a></p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899156#target">gnolam</a> said:</div><div class="quote"><p>As for OpenType fonts</p></div></div><p>Awesome.  Problem located.  Thanks gnolam!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 18 Jan 2011 01:49:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606096/899155#target">Mark Oates</a> said:</div><div class="quote"><p>I think a float al_get_char_pos(ALLEGRO_FONT *font, const char *text, int pos) would work nicely.</p></div></div><p>

Yeah, I like that. Should be easy to implement. I think it actually could be something like this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">float</span> al_get_char_pos<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>text, <span class="k1">int</span> pos<span class="k2">)</span> <span class="k2">{</span>
   <a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a> <span class="k3">*</span>u <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_ustr_new"><span class="a">al_ustr_new</span></a><span class="k2">(</span>text<span class="k2">)</span><span class="k2">;</span>
   <span class="k1">int</span> before <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_ustr_offset"><span class="a">al_ustr_offset</span></a><span class="k2">(</span>u, pos<span class="k2">)</span><span class="k2">;</span>
   <span class="k1">int</span> after <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_ustr_offset"><span class="a">al_ustr_offset</span></a><span class="k2">(</span>u, pos <span class="k3">+</span> <span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a> <span class="k3">*</span>u2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_ustr_dup_substr"><span class="a">al_ustr_dup_substr</span></a><span class="k2">(</span>u, before, after<span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/al_ustr_truncate"><span class="a">al_ustr_truncate</span></a><span class="k2">(</span>u, after<span class="k2">)</span><span class="k2">;</span>
   <span class="k1">float</span> x <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_ustr_width"><span class="a">al_get_ustr_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, u<span class="k2">)</span><span class="k2">;</span> <span class="c">/* length until after pos */</span>
   x <span class="k3">-</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_ustr_width"><span class="a">al_get_ustr_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, u2<span class="k2">)</span><span class="k2">;</span> <span class="c">/* subtract length of char at pos */</span>
   <a href="http://www.allegro.cc/manual/al_ustr_free"><span class="a">al_ustr_free</span></a><span class="k2">(</span>u<span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/al_ustr_free"><span class="a">al_ustr_free</span></a><span class="k2">(</span>u2<span class="k2">)</span><span class="k2">;</span>
   <span class="k1">return</span> x<span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 18 Jan 2011 04:32:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That works.</p><p>I&#39;d like to note in reference to the OP that drawing char by char with this function takes quite a bit longer than drawing by line (due to the two calls to <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_ustr_width"><span class="a">al_get_ustr_width</span></a><span class="k2">(</span><span class="k2">)</span></span> per call to <span class="source-code">al_get_char_pos<span class="k2">(</span><span class="k2">)</span></span>, though it&#39;s much faster than I thought it would be.)  So I would recommend cashing the data if you decide to do char-by-char.</p><p>drawing by line:<br /><span class="remote-thumbnail"><span class="json">{"name":"603128","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/7\/175a91d38b26a914f4855c5459595acb.png","w":1269,"h":940,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/7\/175a91d38b26a914f4855c5459595acb"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/7/175a91d38b26a914f4855c5459595acb-240.jpg" alt="603128" width="240" height="177" /></span><br />drawing by char with <span class="source-code">al_get_char_pos<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>text, <span class="k1">int</span> pos<span class="k2">)</span></span> for each letter:<br /><span class="remote-thumbnail"><span class="json">{"name":"603127","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/8\/a829ee419f2c1faa18397100e7f08ee7.png","w":1269,"h":940,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/8\/a829ee419f2c1faa18397100e7f08ee7"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/8/a829ee419f2c1faa18397100e7f08ee7-240.jpg" alt="603127" width="240" height="177" /></span></p><p>The vertical blue line in the profile box is when it affects framerates on my computer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 18 Jan 2011 08:26:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A better interface might be:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">float</span> al_get_substr_width<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a> <span class="k3">*</span>text, <span class="k1">int</span> start, <span class="k1">int</span> end<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

where start/end are counted in code units.<br />But that&#39;s only a convenience over <span class="source-code"><a href="http://www.allegro.cc/manual/al_ref_ustr"><span class="a">al_ref_ustr</span></a></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 18 Jan 2011 09:03:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It might also be faster if you allow the user to give a char* to a utf8 encoded c string, and then let them provide indexes. I use utf8 encoded std strings which work nice with char*</p><p>another option might be to provide a version of draw_text that also takes in an ALLEGRO_COLOR* which would be assumed to span the length of the text. This would probably be faster than the current solution.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Tue, 18 Jan 2011 22:42:16 +0000</pubDate>
	</item>
</rss>
