<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro text and foreign characters</title>
		<link>http://www.allegro.cc/forums/view/610146</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 03 May 2012 18:52:29 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello all.<br />First, let me demonstrate quickly the problem:</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>std::string texte<span class="k2">(</span><span class="s">"La diffraction'1234567890123456789 0123456789012345678901234567890.123"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</span><span class="k1">int</span> totalWidth <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, texte.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p> gives a value of 535 for totalWidth (retrieved with the debugger), whilst (notice the ç in the text):
</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>std::string texte<span class="k2">(</span><span class="s">"La diffraction'123ç4567890123456789 0123456789012345678901234567890.123"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</span><span class="k1">int</span> totalWidth <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, texte.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p> gives a value of 127.</p><p>So the problem here is that Allegro seems to stumble on the awkward ç (it&#39;s a French character, I don&#39;t think you have it on English keyboard) and stop computing the string. I can put whatever I want after it, it won&#39;t change the value.<br />This also happen with é, à and I suppose a lot of other foreign characters.</p><p>After finding this, I tried to just use al_draw_text with a ç in it: same problem, the drawing stop and the ç and whatever is after is lost.</p><p>So I think to myself &quot;OK, Allegro is English, it&#39;s normal he don&#39;t like foreign character. I&#39;ll try with ALLEGRO_USTR&quot;. But:
</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>std::string texte<span class="k2">(</span><span class="s">"La diffraction'123ç4567890123456789 0123456789012345678901234567890.123"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</span><a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a><span class="k3">*</span> ustr <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>texte.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 3</span><span class="k1">int</span> totalWidth <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>, ustr<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 4</span><a href="http://www.allegro.cc/manual/al_ustr_free"><span class="a">al_ustr_free</span></a><span class="k2">(</span>ustr<span class="k2">)</span><span class="k2">;</span>
</div></div><p> still gives a 127 result. And it won&#39;t draw either.</p><p>This is becoming troublesome. So I wondered &quot;Does that symbol even exist in this font?&quot;. I&#39;m using ATNQUAB.TTF (Book Antiqua Bold, found within Windows Xp default fonts). When I launch Microsoft Word and try to write in this font, he write ç without problems.<br />So, does Word has a way to infer foreign character from TTF font that Allegro doesn&#39;t use?<br />Or are foreign messing with Allegro internal way of handling text?<br />And finally, is there a way around, knowing that I&#39;ll someday want to translate the program in French and other langage?</p><p>Informations:<br />I&#39;m using Allegro v5.0 with Code::Block and MinGW on a Window Xp up to date.</p><p>Note:<br />This remind me of a linked bug, less important: al_show_native_message_box() has the same problem: if the string contains any foreign character, it stop writing. I have overcome that by writing my error messages in English.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (URB753)</author>
		<pubDate>Wed, 02 May 2012 03:10:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you saving the file with the correct encoding? Check Edit-&gt;File Encoding and make sure it&#39;s UTF-8.</p><p>It works fine on Linux, incidentally.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Wed, 02 May 2012 03:47:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How could I not think of that? And why doesn&#39;t Code::Blocks (or the compiler) yell that there is a foreign character he&#39;ll have trouble with?</p><p>Anyway, thanks it seems to work. Surprisingly, it works even with al_draw_text. But I suppose it would go wild on another machine, since the value would be used for another character.<br />So I&#39;ll be using UTF-8, to make sure of the portability.</p><p>Just to be sure: if I have extern document, like .txt, and make sure I save them in UTF-8 using Notepad++, I should have no problem opening them with std::fstream in binary mode and copy it in a string, will I? I&#39;ll just have to then use this string to create an ALLEGRO_USTR and it should be correctly interpreted.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (URB753)</author>
		<pubDate>Wed, 02 May 2012 16:50:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes. Don&#39;t even need an USTR as long as it is utf8. al_set_window_title also is supposed to work, there just is a bug in the windows implementation right now I think.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 02 May 2012 18:40:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The entire Windows port needs to be updated to work with Unicode, from dialogs to file paths, etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 02 May 2012 18:41:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I forgot again, was there some difficult problem to solve (like dropping XP support entirely) - or would it be a matter of replacing a few <span class="source-code">SetWindowTitleA<span class="k2">(</span>title<span class="k2">)</span></span> calls with <span class="source-code">SetWindowTitleW<span class="k2">(</span>al_utf8_to_utf16<span class="k2">(</span>title<span class="k2">)</span><span class="k2">)</span></span>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 02 May 2012 19:50:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just set the UNICODE define (_UNICODE?) and compile Allegro. It immediately crashes due to the file system being 404. That&#39;s as far as I looked into it.</p><p>I think to be proper it should support both via ifdefs, but I really don&#39;t know what I&#39;m talking about.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 02 May 2012 20:30:51 +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/610146/954023#target">Elias</a> said:</div><div class="quote"><p>Yes. Don&#39;t even need an USTR as long as it is utf8.</p></div></div><p>

What is the purpose of ALLEGRO_USTR then if it&#39;s not to handle correctly utf8?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (URB753)</author>
		<pubDate>Wed, 02 May 2012 21:32:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a></span> lets you easily manipulate multibyte strings. If your strings are read-only, you can just use utf8 c-strings.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 02 May 2012 21:36:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>String manipulation. Using strcpy/strcat and so on is very error prone and there is no way to for example get a sub-string (with UTF8). And the wide char versions don&#39;t allow enforcing UTF8 (they require some archaic concept of querying &quot;locales&quot; first) so they can&#39;t be used either.</p><p>Which means yes, in all likelihood you will use ALLEGRO_USTR. I just meant for simply reading a string from a file and displaying it you don&#39;t need it. <span class="source-code">std::string text<span class="k2">;</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_642.html" target="_blank">read</a> from stream into text<span class="k2">;</span> <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>text.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span> will work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 02 May 2012 21:43:25 +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/610146/954029#target">Matthew Leverton</a> said:</div><div class="quote"><p> It immediately crashes due to the file system being 404. </p></div></div><p>Say what?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 02 May 2012 22:41:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Once you switch on Unicode in the Windows build, it crashes because Allegro tries to stuff 8-bit strings into 16-bit Windows functions. So no files can be opened because the paths are invalid. Technically, I think <span class="source-code"><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> fails (or some similar function) and then subsequent functions crash.</p><p>It&#39;s been months since I tried it. All I&#39;m really getting at is that if somebody does try to fix it, it should just be done properly (whatever that looks like) as opposed to just throwing in some calls to W functions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 02 May 2012 23:31:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, my questions have been answered. Thanks everybody!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (URB753)</author>
		<pubDate>Thu, 03 May 2012 17:40:57 +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/610146/954049#target">Matthew Leverton</a> said:</div><div class="quote"><p>It&#39;s been months since I tried it. All I&#39;m really getting at is that if somebody does try to fix it, it should just be done properly (whatever that looks like) as opposed to just throwing in some calls to W functions.</p></div></div><p>Ah. Yeah, looks like it&#39;d take some doing. All of the windows interface code will have to up convert all input to 16bit unicode.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 03 May 2012 18:52:29 +0000</pubDate>
	</item>
</rss>
