Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro 5 Unicode textDraw

This thread is locked; no one can reply to it. rss feed Print
Allegro 5 Unicode textDraw
APrince
Member #12,698
March 2011

Hi, I've been trying for very long time to somehow manage to print wchart_t string to the screen. This part of documentation if kind of misty, so I had a lot of problems with it. After several hours I found this note:

Quote:

There are problems with UTF-8 string literals under MSVC.
There appear to be two cases:
1. It thinks our source file use the local file encoding. This mostly
works okay: the UTF-8 strings look like strings in an 8-bit charset and
will be passed through directly. But in other locales (e.g. East Asian)
it won't work.
2. If we add a UTF-8 byte order mark (signature) then MSVC will recognise
the source file as UTF-8, but will then try to re-encode the strings
into the local charset.
So, unfortunately, for portability to MSVC, we have to externalise UTF-8
strings or write them out using escape codes.

Does it mean that it doesn't work in Visual Studio at all?

All i'd like to do is to print simple wchar_t array to the screen. No loading from config files or whatever...

Thanks a lot.

gnolam
Member #2,030
March 2002
avatar

wchar_t isn't UTF-8.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

SiegeLord
Member #7,827
October 2006
avatar

From stuff I read, using UTF-8 string literals is impossible in MSVC. A5 even disables the example that has those literals because no solution was found.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Elias
Member #358
May 2000

Well, if you have wchar_t, all you need to do is convert it to UTF8. I wouldn't know how to get string literals into wchar_t or how to convert wchar_t to UTF8 - both of those are done outside of Allegro.

--
"Either help out or stop whining" - Evert

jmasterx
Member #11,410
October 2009

Elias
Member #358
May 2000

Yeah, so the next step is to get a string literal into an LPCWSTR. I guess you should use the UTF8 BOM and use L"" instead of "" for the string literal, supposedly making VC convert from UTF8 to UTF16 which WideCharToMultiByte can convert back to UTF8 to be passed to Allegro.

--
"Either help out or stop whining" - Evert

APrince
Member #12,698
March 2011

Well I'm not fixed to wchar_t, it just seemed to me the best way to ensure some portability (if I decided to port the application to Linux for whatever reason). The thing is there's another library built atop of the Allegro and must not be dependent on it. So the better way may be to define my own string type (abstract class) which could have conversion methods and than make a child for Allegro which would inherit and override those... Or do you suppose anything rather easier?

Elias
Member #358
May 2000

The issue you quoted only concerns string literals in your source code. There should be no problem if you load the strings in another way (reading from a file).

And wchar_t all by itself isn't really portable as it depends on the current locale. If you don't call setlocale() in your program then wchar_t is limited to 7-bit ASCII since the default locale ("C" locale) of libc supports nothing else. (That's my understanding at least.)

--
"Either help out or stop whining" - Evert

Go to: