<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>register_uformat()</title>
		<link>http://www.allegro.cc/forums/view/224331</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 05 Dec 2002 18:48:54 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hello,<br />where can i find some example code about <br />function register_uformat().</p><p>i am using chinese.</p><p>thank you.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dawei chen)</author>
		<pubDate>Wed, 04 Dec 2002 15:33:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Personally I never used this but as far as I can understand the documentation it&#039;s not easy. What you have to do is this:</p><p><b>1.</b> implement all the character handling functions like u_getc(), u_setc(), u_width(), etc.:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">int</span> chinese_getc<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>s<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">2</td><td>   <span class="c">// your implementation here</span></td></tr><tr><td class="number">3</td><td><span class="k2">}</span></td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td><span class="k1">int</span> chinese_getx<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>s<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">6</td><td>   <span class="c">// your implementation here</span></td></tr><tr><td class="number">7</td><td><span class="k2">}</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td><span class="k1">int</span> chinese_setc<span class="k2">(</span><span class="k1">char</span> <span class="k3">*</span>s, <span class="k1">int</span> c<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">10</td><td>   <span class="c">// your implementation here</span></td></tr><tr><td class="number">11</td><td><span class="k2">}</span></td></tr><tr><td class="number">12</td><td>&#160;</td></tr><tr><td class="number">13</td><td><span class="k1">int</span> chinese_width<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>s<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">14</td><td>   <span class="c">// your implementation here</span></td></tr><tr><td class="number">15</td><td><span class="k2">}</span></td></tr><tr><td class="number">16</td><td>&#160;</td></tr><tr><td class="number">17</td><td><span class="k1">int</span> chinese_cwidth<span class="k2">(</span><span class="k1">int</span> c<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">18</td><td>   <span class="c">// your implementation here</span></td></tr><tr><td class="number">19</td><td><span class="k2">}</span></td></tr><tr><td class="number">20</td><td>&#160;</td></tr><tr><td class="number">21</td><td><span class="k1">int</span> chinese_isok<span class="k2">(</span><span class="k1">int</span> c<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">22</td><td>   <span class="c">// your implementation here</span></td></tr><tr><td class="number">23</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
You can choose whatever names for your functions of course. Look at the Unicode handlers in Allegro to see what exactly these functions do and how they work.</p><p><b>2.</b> register your character handling functions with the register_uformat() function before initializing Allegro:</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define   U_CHINESE   AL_ID('C','H','N','S')</span>
<a href="http://www.allegro.cc/manual/register_uformat" target="_blank"><span class="a">register_uformat</span></a><span class="k2">(</span>U_CHINESE, chinese_getc, chinese_getx, chinese_setc, chinese_width, chinese_cwidth, chinese_isok<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
Again you can choose whatever ID you want, as long as it&#039;s not being used by something else (in this example I use CHNS for the ID and U_CHINESE for the define).</p><p><b>3.</b> make Allegro use you character handlers by calling the set_uformat() function before initializing Allegro itself:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/set_uformat" target="_blank"><span class="a">set_uformat</span></a><span class="k2">(</span>U_CHINESE<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

<b>4.</b> use the Allegro Unicode text functions for manipulating strings, converting all ASCII strings to your format with the uconvert() function passing it U_CHINESE as the type parameter.</p><p>EDIT:<br />To do all this you will of course need to know the exact format of the coding standard you&#039;re trying to use. When you say chinese I assume you mean the &quot;Chinese GB-code format&quot; mentioned in the Allegro documentation...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Wed, 04 Dec 2002 21:18:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>thank you,i will try.</p><p>but if i want to display characters with WINAPI<br />TextOut(),what should i do then?</p><p>i am using the following code,but can not get <br />correct result.</p><p>#include &lt;allegro.h&gt;<br />#include &lt;winalleg.h&gt;</p><p>BITMAP *bmp01;<br />char chr01[]=&quot;hello,how are you.no,thank you.&quot;;<br />HDC hdc;</p><p>int main() <br />{ <br /> allegro_init();      <br /> set_color_depth(16);<br /> set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);</p><p> bmp01=create_bitmap(640,480);<br /> hdc=win_get_dc(bmp01);<br /> SetTextColor(hdc,0x00ff00);<br /> TextOut(hdc,0,0,chr01,20);</p><p> blit(bmp01,screen,0,0,0,0,640,480);<br /> win_release_dc(bmp01,hdc);<br /> destroy_bitmap(bmp01);</p><p>   while(! key[KEY_ESC])<br />   poll_keyboard();<br /> allegro_exit();<br /> return 0;     <br />}     </p><p>END_OF_MAIN();
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dawei chen)</author>
		<pubDate>Thu, 05 Dec 2002 09:38:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#039;t know much about WINAPI but I&#039;m quite certain that TextOut() from WINAPI and textout() from Allegro (and the entire text API in Allegro for that matter) have absolutely nothing in common. So adding a driver for your character encoding scheme like I suggested in my first post won&#039;t help you with outputting text in WINAPI one bit. To do what you&#039;re trying to do you will have to look into WINAPI itself. I&#039;m sure there are extensions/libraries that do exactly what you want...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Thu, 05 Dec 2002 13:29:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>thank you very much.:)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dawei chen)</author>
		<pubDate>Thu, 05 Dec 2002 18:48:54 +0000</pubDate>
	</item>
</rss>
