al_draw_text() and special characters
DrFail

Hey, i'm currently working on some sort of game-engine for a school project.
But i have some troubles with the al_draw_text() function. The problem is, that i can't print special characters (especially ä,ö and ü), which are used often in german.
I already tried stuff like char(129) or "\x81" but it didn't work.
I also found the function al_draw_ustr(), but i never did anything with unicode and i'm not sure how it works.
Is there a way to print these characters?

Arthur Kalliokoski

I'm far from expert, but I'd think al_ustr_new_from_buffer() would work. You'd have to free the utf string yourself to avoid memory leaks.

DrFail
#SelectExpand
1string text = "äöüÄÖÜ"; 2ALLEGRO_USTR* uText = al_ustr_new(text.c_str()); 3al_draw_ustr(myFont, myColor, 42, 42, 0, uText); 4al_ustr_free(uText);

This would do the same as al_draw_text(), but print the special characters?

SiegeLord

al_draw_text can print special characters just fine (e.g. this is demonstrated in the ex_tff). There are two possible issues which might break it in your case.

1. Your source file must be encoded using UTF-8
2. Your font must have glyphs for those special characters

Now... you say that you tried explicit unicode characters... so perhaps it's the second issue?

DrFail

When I use
al_draw_text(myFont, myColor, 42, 42, 0, "test_ä_end");
the output is just "test_". The rest is missing.
But I'm pretty sure that the font (arial.ttf) has those letters.

Maybe it's the first case. I'm using Dev-C++ 5.3, but i don't know if it uses UTF-8.

Is there a way to find out?
Or any other possible solution?

SiegeLord
DrFail said:

Is there a way to find out?
Or any other possible solution?

Nobody uses DevCpp, so there's no way to find out. The workabout that always works is to load the strings from a separate file which is UTF-8 encoded (you can be sure of that by using an editor that explicitly allows the option). This is in fact what ex_ttf does for MSVC compatibility.

DrFail

I just messed around a little and luckily found a solution :)
With the escape sequence "\u" it's possible to print the letters.

#SelectExpand
1string test = "test \u00E4\u00C4\u00F6\u00D6\u00FC\u00DC end"; 2al_draw_text(font, color, 42, 42, 0, test.c_str());

This does exactly what i wanted.

SiegeLord said:

... load the strings from a separate file which is UTF-8 encoded.

Good you mentioned that.
This makes it possible to get text from files with with special characters and print it on the screen, without extra code.

Thanks for the help!

Thread #611123. Printed from Allegro.cc