0

In file text.txt I have this sentenc:

"Příliš žluťoučký kůň úpěl ďábelské ódy."

(I think Windows uses Windows-1250 code page to represent this text.)

In my program I save it to a buffer

char string[1000]

and render string with ttf to SDL_Surface *surface

surface = TTF_RenderText_Blended(font, string, color);
/*(font is true type and support this text)*/

But it gives me not correct result:

I need some reputation points to post images so I can only describe that ř,í,š,ž,ť,ů,ň,ď are not displayed correctly.

Is it possible to use ttf for rendering this sentence correctly?

(I tried also TTF_RenderUTF8_Blended, TTF_RenderUNICODE_Solid... with worse result.)

genpfault
  • 51,148
  • 11
  • 85
  • 139
Fanda
  • 325
  • 5
  • 14
  • Looks like the usual 8-bit encoding misery. Wrong code page, ISO-8859-1 is assumed, but it can't handle Czech very well, no support for Č, č, Ř, ř, Š, š, Ž, ž, ch. You'd better fall back to utf-8, make sure you tell your text editor to save the file with that encoding. – Hans Passant Sep 14 '14 at 18:59
  • I have my file in UTF-8 and calling RenderUTF8. It doesn`t work. Still bad symbols. – Fanda Sep 16 '14 at 06:16

2 Answers2

1

The docs for TTF_RenderText_Blended say that it takes a Latin-1 string (Windows-1252) - this will be why it isn't working.

You'll need to convert your input text to UTF-8 and use RenderUTF8, or to UTF-16 and use RenderUNICODE to ensure it is interpreted correctly.

How you do this depends on what platform your app is targeted to - if it is Windows, then the easiest way would be to use the MultiByteToWideChar Win32 API to convert it to UTF-16 and then use the TTF_RenderUNICODE_Blended to draw it.

runrevmark
  • 311
  • 1
  • 2
  • I have my file in UTF-8 and calling RenderUTF8. It doesn`t work. Still bad symbols. I don`t want to use Win32 API functions if it is not a part of SDL or TTF library. – Fanda Sep 16 '14 at 06:19
0

My solution will be this:

Three input files. In first file there will be a set of symbols from czech alphabet. Second file will be sprite bitmap file where graphic symbols will be sorted in the same order as in first file. In my program symbols from third input file will be compared with symbols from first file and right section of sprite will be copied on sreen one by one.

I will leave out sdl_ttf. It has some advantages and disadvantages but I think it will work for my purposes.

Thanks for all responses

Fanda
  • 325
  • 5
  • 14