<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Bitmap Font doesn&#39;t draw any character after try to write a not defined char</title>
		<link>http://www.allegro.cc/forums/view/617697</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 21 Jan 2019 14:49:58 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was using al_draw_scaled to draw this string that has a &#39;á&#39; NON ASCII Character, this char was not defined on my bitmap font.</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span>footer_trademark <span class="k3">=</span> <span class="s">"Mega Man X is á registered trademark of Capcom Co., Ltd."</span><span class="k2">;</span>
</div></div><p>

I wanted to draw the other characters instead got this &#39;error&#39; <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (chanochambure)</author>
		<pubDate>Tue, 15 Jan 2019 02:41:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Undefined behavior is undefined...</p><p>So, don&#39;t do that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 15 Jan 2019 07:11:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What function are you using? <span class="source-code">al_draw_scaled</span> ??<br />Please can you post some more code?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Tue, 15 Jan 2019 15:44:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">void</span> Text::draw<span class="k2">(</span><span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_TRANSFORM"><span class="a">ALLEGRO_TRANSFORM</span></a> al_transform<span class="k2">;</span>
<span class="number">  4</span>    <a href="http://www.allegro.cc/manual/al_identity_transform"><span class="a">al_identity_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>al_transform<span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>    <a href="http://www.allegro.cc/manual/al_scale_transform"><span class="a">al_scale_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>al_transform, _V_scale_x<span class="k3">*</span>bitmap_scale_x, _V_scale_y<span class="k3">*</span>bitmap_scale_y<span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>    <a href="http://www.allegro.cc/manual/al_translate_transform"><span class="a">al_translate_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>al_transform,_V_pos_x,_V_pos_y<span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>    <a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>al_transform<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>    <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><span class="k3">*</span>_V_font,_V_color,<span class="n">0</span>,<span class="n">0</span>,_V_flag,_V_text.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>    <a href="http://www.allegro.cc/manual/al_identity_transform"><span class="a">al_identity_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>al_transform<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>    <a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>al_transform<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span><span class="k2">}</span>
</div></div><p>

I&#39;m using the function al_draw_text to draw the text <b><i>_V_text</i></b> with my font <b><i>_V_font</i></b> that was my bitmap font.</p><p>The problem is that i wanted to draw the text that the following joystick functions return me, and this values (for example in spanish) return me non-ascii characters like <i>&#39;Bot<b>ó</b>n 1&#39;</i>
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><a href="http://www.allegro.cc/manual/al_get_joystick_name"><span class="a">al_get_joystick_name</span></a>
<span class="number"> 2</span><a href="http://www.allegro.cc/manual/al_get_joystick_stick_name"><span class="a">al_get_joystick_stick_name</span></a>
<span class="number"> 3</span><a href="http://www.allegro.cc/manual/al_get_joystick_axis_name"><span class="a">al_get_joystick_axis_name</span></a>
<span class="number"> 4</span><a href="http://www.allegro.cc/manual/al_get_joystick_button_name"><span class="a">al_get_joystick_button_name</span></a>
</div></div><p>
<img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (chanochambure)</author>
		<pubDate>Wed, 16 Jan 2019 05:37:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So use a bitmap font with those characters in it. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 16 Jan 2019 05:41:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tracked through the code a bit and it seems that Allegro uses only the ANSI variants of the APIs (I am assuming you&#39;re using Windows?) so it probably is returning the names with characters from whatever code page you are using. (presumably <a href="https://docs.microsoft.com/en-us/windows/desktop/Intl/code-page-identifiers">1252 Ansi Latin 1</a>)<br />So, as Edgar says, if you want ó to appear you need a glyph for it in your bitmap font, but<br />you also seem to be saying that it doesn&#39;t print out any subsequent characters once it&#39;s hit an invalid character (looking at the megaman screenshot). If so, this might be a bug; Allegro should print a &#39;fallback&#39; character whenever it doesn&#39;t have a glyph but then carry on with the rest of the string.<br />Can you post your font bitmap ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Wed, 16 Jan 2019 15:41:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If the encoding is UTF16 then á will be encoded as \xe1\x00 and the &quot;\x00&quot; byte will terminate the string.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 16 Jan 2019 22:04:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If the encoding is UTF-16 then all ascii characters will be encoded as &lt;something&gt;\x00 and the \x00 byte will terminate the string.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Thu, 17 Jan 2019 01:12:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>See Al grab font from bitmap :</p><p><a href="https://liballeg.org/a5docs/trunk/font.html#al_grab_font_from_bitmap">https://liballeg.org/a5docs/trunk/font.html#al_grab_font_from_bitmap</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 18 Jan 2019 03:30:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Alright but has anyone go a bitmap suitable for feeding to <span class="source-code"><a href="http://www.allegro.cc/manual/al_grab_font_from_bitmap"><span class="a">al_grab_font_from_bitmap</span></a></span>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Fri, 18 Jan 2019 12:28:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There is my Font that i was using to draw my text, may the &#39;fallback&#39; character has a code on ASCII to set up with al_grab_font_from_bitmap. Or maybe this is the problem of an unicode that has the null character \x00.</p><p>I wanted to show the name of the button of the joystick that a user want to use in my game to configure the game controls, but imagine for example in spanish the button name return &quot;Botón 5&quot; with ó on another encoding, that allegro cannot find the ó and print at least something like &quot;Botn 5&quot;, to doesnt break that controls configuration is working!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (chanochambure)</author>
		<pubDate>Sat, 19 Jan 2019 11:28:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I see it too. I will investigate.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Mon, 21 Jan 2019 04:11:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You could write a program to read in a ttf file, and output a bitmap font. In theory it should be simple enough.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 21 Jan 2019 13:43:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What happens is:<br />1. Get the control name via <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_joystick_button_name"><span class="a">al_get_joystick_button_name</span></a></span> or whatever<br />2. (assuming you&#39;re on windows) Allegro uses the Windows ANSI API (not the unicode one) and returns a string using the active code page (assuming it&#39;s windows-1252)<br />3. This string may contain characters in the range 128-255  - for example ó which is 0xD3<br />4. Calling <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a></span> (other text functions end up in the same place anyway)<br />5. Calls <span class="source-code"><a href="http://www.allegro.cc/manual/al_ref_cstr"><span class="a">al_ref_cstr</span></a></span> on the text to create a UTF-8 string<br />6. Calls <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_ustr"><span class="a">al_draw_ustr</span></a></span> on the UTF-8 string<br />7. Calls <span class="source-code">font-&gt;vtable-&gt;render</span> which is <span class="source-code">color_render</span> in font.c<br />8. Uses <span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_get_next"><span class="a">al_ustr_get_next</span></a></span> to step through the string and renders each glyph.</p><p>Unfortunately <span class="source-code"><a href="http://www.allegro.cc/manual/al_ref_cstr"><span class="a">al_ref_cstr</span></a></span> does not &#39;create a UTF-8 string&#39;, it just references the data in a C string as if it were UTF-8. So, when <span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_get_next"><span class="a">al_ustr_get_next</span></a></span> comes to the 0xD3, it sees this as an invalid UTF-8 code, returning &#39;-2&#39;, and this in turn causes <span class="source-code">color_render</span> to stop. Hence no more characters are printed.<br />   <br />To solve this, you would need to use the Win32 API to convert the windows-1252 strings to genuine UTF-8, or Allegro would have to be modified, either:
</p><ul><li><p>Use unicode APIs for the joystick
</p></li><li><p>Cause <span class="source-code">color_render</span> to skip invalid UTF-8 sequences (printing the 404 character)</p></li></ul><p>In any case the docs for <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a></span> and friends should be a bit more specific on the input - they take UTF-8 and not just any C-string.</p><p>If anyone has any more thoughts please post them - might be worth filing an issue on github for this.</p><p>Example program:
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro_font.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;allegro5/allegro_image.h&gt;</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="k1">int</span> ranges<span class="k2">[</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span>
<span class="number">  6</span>    <span class="n">0x0020</span>, <span class="n">0x007F</span>,  <span class="c">/* ASCII */</span>
<span class="number">  7</span><span class="k2">}</span><span class="k2">;</span>
<span class="number">  8</span><span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> GOOD<span class="k3">=</span><span class="s">"Boton GOOD"</span><span class="k2">;</span>
<span class="number">  9</span><span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> BAD<span class="k3">=</span><span class="s">"Bot\323n BAD"</span><span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 12</span>  <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>  <a href="http://www.allegro.cc/manual/al_init_font_addon"><span class="a">al_init_font_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>  <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</span> display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">640</span>,<span class="n">480</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> mmx <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"mmx12_font_f1.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</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="k3">=</span> <a href="http://www.allegro.cc/manual/al_grab_font_from_bitmap"><span class="a">al_grab_font_from_bitmap</span></a><span class="k2">(</span>mmx, <span class="n">1</span>, ranges<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>  <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0x80</span>, <span class="n">0xff</span>, <span class="n">0x80</span><span class="k2">)</span>, <span class="n">5</span>.<span class="n">0f</span>, <span class="n">5</span>.<span class="n">0f</span>, <span class="n">0</span>, GOOD<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>  <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0xff</span>, <span class="n">0x80</span>, <span class="n">0x80</span><span class="k2">)</span>, <span class="n">5</span>.<span class="n">0f</span>, <span class="n">50</span>.<span class="n">0f</span>, <span class="n">0</span>, BAD<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>  <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>  <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">10</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 23</span><span class="k2">}</span>
</div></div><p>
Output:<br /><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/6/c/6cff80b9ffecb68ec0f7f1f12f0ec56e.png" alt="611858" width="232" height="167" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Mon, 21 Jan 2019 14:49:58 +0000</pubDate>
	</item>
</rss>
