Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » register_uformat()

This thread is locked; no one can reply to it. rss feed Print
register_uformat()
dawei chen
Member #2,985
December 2002

hello,
where can i find some example code about
function register_uformat().

i am using chinese.

thank you.

miran
Member #2,407
June 2002

Personally I never used this but as far as I can understand the documentation it's not easy. What you have to do is this:

1. implement all the character handling functions like u_getc(), u_setc(), u_width(), etc.:

1int chinese_getc(const char *s) {
2 // your implementation here
3}
4 
5int chinese_getx(const char **s) {
6 // your implementation here
7}
8 
9int chinese_setc(char *s, int c) {
10 // your implementation here
11}
12 
13int chinese_width(const char *s) {
14 // your implementation here
15}
16 
17int chinese_cwidth(int c) {
18 // your implementation here
19}
20 
21int chinese_isok(int c) {
22 // your implementation here
23}

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.

2. register your character handling functions with the register_uformat() function before initializing Allegro:

#define   U_CHINESE   AL_ID('C','H','N','S')
register_uformat(U_CHINESE, chinese_getc, chinese_getx, chinese_setc, chinese_width, chinese_cwidth, chinese_isok);

Again you can choose whatever ID you want, as long as it's not being used by something else (in this example I use CHNS for the ID and U_CHINESE for the define).

3. make Allegro use you character handlers by calling the set_uformat() function before initializing Allegro itself:

set_uformat(U_CHINESE);

4. 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.

EDIT:
To do all this you will of course need to know the exact format of the coding standard you're trying to use. When you say chinese I assume you mean the "Chinese GB-code format" mentioned in the Allegro documentation...

--
sig used to be here

dawei chen
Member #2,985
December 2002

thank you,i will try.

but if i want to display characters with WINAPI
TextOut(),what should i do then?

i am using the following code,but can not get
correct result.

#include <allegro.h>
#include <winalleg.h>

BITMAP *bmp01;
char chr01[]="hello,how are you.no,thank you.";
HDC hdc;

int main()
{
allegro_init();
set_color_depth(16);
set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);

bmp01=create_bitmap(640,480);
hdc=win_get_dc(bmp01);
SetTextColor(hdc,0x00ff00);
TextOut(hdc,0,0,chr01,20);

blit(bmp01,screen,0,0,0,0,640,480);
win_release_dc(bmp01,hdc);
destroy_bitmap(bmp01);

while(! key[KEY_ESC])
poll_keyboard();
allegro_exit();
return 0;
}

END_OF_MAIN();

miran
Member #2,407
June 2002

I don't know much about WINAPI but I'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't help you with outputting text in WINAPI one bit. To do what you're trying to do you will have to look into WINAPI itself. I'm sure there are extensions/libraries that do exactly what you want...

--
sig used to be here

dawei chen
Member #2,985
December 2002

thank you very much.:)

Go to: