In my “RPi Matrix” project I wanted to render UTF-8 fonts on a 2D-Raster. To rasterize and vector fonts I used a library called FreeType, which accepts unsigned long* as input to render a single character. So I had to get the (uni-)codes for each character from my string. The confusion already started with the difference between UTF-8 and unicode. So my conclusion was I had to convert UTF-8 to some other encoding. Probably some encoding which supports one long (or wchar_t) per character.
The problem even get’s bigger if you want cross-platform support. On the linux side you have iconv. On windows you have some ugly MultiByteToWideChar(…) function. Luckily I only have to support linux.
So let’s get started with some code:
Note: the wchar_t array has to be freed!
Now convert the wchar_t array to a unsigned long array and pass each long to the FreeType function FT_Get_Char_Index(face, c);.