Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problem writing text with al_draw_text

This thread is locked; no one can reply to it. rss feed Print
Problem writing text with al_draw_text
Cisco Mir
Member #13,959
January 2012

This is my code:

#SelectExpand
1bitmap = al_load_bitmap("font.pcx"); 2 3int ranges[] = {0, 255}; 4font = al_grab_font_from_bitmap(programa,1,ranges); 5 6al_draw_text(font,color,103,103,0,"Prova de caràcters especials: aàáÀÁ");

When it founds the first special char: "à" it stops writing text.

I included those characters on my font... all the chars are there.

It's al_draw_text uncapable of writing those special chars or I'm doing something absolutely wrong?

In fact, the same thing happens to me with al_show_native_message_box, beeing the strings finished when some special character like á, é, í is found.

I have to change the language code for the whole program or something like that?

Matthew Leverton
Supreme Loser
January 1999
avatar

Make sure your strings are UTF-8 encoded for Allegro's text output.

However, the native dialogs don't support UTF-8 (on Windows), so you'll have to use ASCII for that.

AMCerasoli
Member #11,955
May 2010
avatar

And al_set_window_title() doesn't work with utf-8 neither...

Matthew Leverton
Supreme Loser
January 1999
avatar

None of the Window platform calls support UTF-8 strings. It could, but somebody would have to update Allegro to convert all 8-bit strings into 16-bit Window strings before calling the Win32 API.

But al_draw_text() will work fine if given UTF-8 strings, which is mainly what this thread is about.

Cisco Mir
Member #13,959
January 2012

Then the chars à,á,è,é,i,ï,ò,ó,ù,ú are not UTF-8?

Because with al_draw_text it finishes writing when it founds a char like those ones, important chars on my language btw!

AMCerasoli
Member #11,955
May 2010
avatar

Configure your IDE to save the document UTF-8 encoded. For example in C::B

{"name":"605530","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/e\/fe7e1946666de65c13a7c1b6af9c9693.png","w":847,"h":304,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/e\/fe7e1946666de65c13a7c1b6af9c9693"}605530

Cisco Mir
Member #13,959
January 2012

The problem is solved, thank you very much! :)

Matthew Leverton
Supreme Loser
January 1999
avatar

Cisco Mir said:

Then the chars à,á,è,é,i,ï,ò,ó,ù,ú are not UTF-8?

UTF-8 is just an encoding. Your editor was probably saving in regular "ASCII" mode. The first 127 characters are identical between UTF-8 and ASCII, which is why most of the letters were working fine. But as soon as something 128 or higher was found, it would have been an invalid UTF-8 encoding, triggering an error.

Go to: