<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>About utf8 fonts</title>
		<link>http://www.allegro.cc/forums/view/617435</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 11 Jun 2018 15:39:10 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I try to use my native language: Chinese.<br />It doesn&#39;t show up.<br />English can be displayed.</p><p> <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> Utf8 supports Chinese, why so?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (keprast)</author>
		<pubDate>Sat, 02 Jun 2018 16:55:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you using a font that supports Chinese characters?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 03 Jun 2018 04:52:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Also, make sure that the input text really is in utf8 format. If you use visual studio, constant C strings will normally <b>not</b> be utf8. Try to read the string from a file in stead.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Sun, 03 Jun 2018 10:02:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>text?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (keprast)</author>
		<pubDate>Sun, 03 Jun 2018 10:37:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Input text here refers in a very general way to any string that you might display in your program.</p><p>This string could either be generated by your own program or input by the user through some sort of textbox you design.</p><p>Unfortunately, normal C-style strings are not really UTF-8 compatible. It just so happens that normal English characters map to the same values in both ASCII and UTF-8 encodings.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rodolfo Lam)</author>
		<pubDate>Sun, 10 Jun 2018 07:31:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think that he understands a lot of English, maybe it&#39;s better to rephrase a bit?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 10 Jun 2018 07:40:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah... I figured that might be part of the issue.</p><p>Still, UTF-8 is somewhat complicated to understand at first. Many pieces need to be fitted in the correct order and way for it to work as intended.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rodolfo Lam)</author>
		<pubDate>Sun, 10 Jun 2018 07:47:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This probably a smart guy, but he lives in a different world language-wise then either of us. People from South Asia have on average higher IQ than Europeans, you know :p
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 10 Jun 2018 07:51:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>C strings are 1 byte, UTF-8 needs much more to store the larger numbers.</p><p>Allegro has UTF-8 functions.  Also, the IDE you use to program with may need to have UTF8 enabled.  I don&#39;t know about Visual Studio, but with Code::Blocks you go to SETTINGS-&gt;EDITOR and under the ENCODING SETTINGS tab you can set the encoding it uses to UTF-8.</p><p>Notepad++ also has a similar option.  I use it sometimes as well.  I would imagine Visual Studio has such an option, I just wouldn&#39;t know where.</p><p>In my Deluxe Pacman 2 game, which supports UTF-8, I use functions in my Highscore routine like:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_fread32le"><span class="a">al_fread32le</span></a><span class="k2">(</span><span class="k2">)</span></span> to read in names etc... from the high score file.<br /><span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_new_from_buffer"><span class="a">al_ustr_new_from_buffer</span></a><span class="k2">(</span><span class="k2">)</span></span> etc...  </p><p>here&#39;s a short snippit from my highscore function which reads in names from the file...</p><div class="source-code snippet"><div class="inner"><pre>cstrsize <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fread32le"><span class="a">al_fread32le</span></a><span class="k2">(</span>hiscore_file<span class="k2">[</span>i<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
cstrname <span class="k3">=</span> <span class="k2">(</span><span class="k1">char</span> <span class="k3">*</span><span class="k2">)</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_551.html" target="_blank">malloc</a><span class="k2">(</span>cstrsize<span class="k2">)</span><span class="k2">;</span>  <span class="c">// allocate memory for name</span>
<span class="k1">if</span><span class="k2">(</span>cstrname <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span> <span class="k2">{</span>
   <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>hiscore_file<span class="k2">[</span>i<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"%s(%d): memory allocation failed.\n"</span>, __FILE__, __LINE__<span class="k2">)</span><span class="k2">;</span>
   <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span>
<span class="k2">}</span>
<a href="http://www.allegro.cc/manual/al_fread"><span class="a">al_fread</span></a><span class="k2">(</span>hiscore_file<span class="k2">[</span>i<span class="k2">]</span>, cstrname, cstrsize<span class="k2">)</span><span class="k2">;</span>
<span class="c">// assign the c string to the ustr variable from buffer</span>
hiscore<span class="k2">[</span>i<span class="k2">]</span><span class="k2">[</span>j<span class="k2">]</span>.name <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_ustr_new_from_buffer"><span class="a">al_ustr_new_from_buffer</span></a><span class="k2">(</span>cstrname, cstrsize<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.delorie.com/djgpp/doc/libc/libc_350.html" target="_blank">free</a><span class="k2">(</span>cstrname<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

And my hiscore[].name is an <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a></span> variable.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Sun, 10 Jun 2018 09:10:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Keprast,<br />This was discussed a while ago - see <a href="https://www.allegro.cc/forums/thread/611547">https://www.allegro.cc/forums/thread/611547</a></p><p>I was able to display some chinese characters on Windows using the following 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 "stdafx.h"</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;allegro5/allegro_font.h&gt;</span>
<span class="number">  4</span><span class="p">#include &lt;allegro5/allegro_ttf.h&gt;</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="number">  7</span><span class="k2">{</span>
<span class="number">  8</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">  9</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"> 10</span>  <a href="http://www.allegro.cc/manual/al_init_ttf_addon"><span class="a">al_init_ttf_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</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">320</span>, <span class="n">240</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</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_load_font"><span class="a">al_load_font</span></a><span class="k2">(</span><span class="s">"c:\\windows\\fonts\\simsun.ttc"</span>, <span class="n">12</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</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">255</span>, <span class="n">255</span>, <span class="n">255</span><span class="k2">)</span>, <span class="n">10</span>.<span class="n">0f</span>, <span class="n">100</span>.<span class="n">0f</span>, <span class="n">0</span>, <span class="s">"你好，世界"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</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"> 15</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="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 17</span><span class="k2">}</span>
</div></div><p>
<span class="remote-thumbnail"><span class="json">{"name":"611509","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/4\/148e9c34c58c0c2586c120b96142ba5e.jpg","w":343,"h":296,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/4\/148e9c34c58c0c2586c120b96142ba5e"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/4/148e9c34c58c0c2586c120b96142ba5e-240.jpg" alt="611509" width="240" height="207" /></span></p><p>The important thing was to follow this advice: <a href="https://docs.microsoft.com/en-gb/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8">https://docs.microsoft.com/en-gb/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8</a><br />which was to add <span class="source-code"><span class="k3">/</span>utf-8</span> to the options for the project.</p><p>Please note I don&#39;t speak Chinese so I apologise if the text is wrong!<br />[edit]: I think the first font I put up was Japanese, sorry. Sim Sun is a Chinese font though, isn&#39;t it? (<a href="https://www.pinyinjoe.com/windows-7/win7-chinese-fonts.htm">https://www.pinyinjoe.com/windows-7/win7-chinese-fonts.htm</a>)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Mon, 11 Jun 2018 15:39:10 +0000</pubDate>
	</item>
</rss>
