简体   繁体   English

sdl ttf Windows-1250编码

[英]sdl ttf windows-1250 encoding

In file text.txt I have this sentenc: 在文件text.txt中,我有以下标签:

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

(I think Windows uses Windows-1250 code page to represent this text.) (我认为Windows使用Windows-1250代码页来表示此文本。)

In my program I save it to a buffer 在我的程序中,我将其保存到缓冲区

char string[1000]

and render string with ttf to SDL_Surface *surface 并使用ttf将字符串渲染为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? 是否可以使用ttf正确呈现此句子?

(I tried also TTF_RenderUTF8_Blended, TTF_RenderUNICODE_Solid... with worse result.) (我也尝试了TTF_RenderUTF8_Blended,TTF_RenderUNICODE_Solid ...效果较差。)

The docs for TTF_RenderText_Blended say that it takes a Latin-1 string (Windows-1252) - this will be why it isn't working. TTF_RenderText_Blended的文档说它需要一个Latin-1字符串(Windows-1252)-这就是为什么它不起作用的原因。

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. 您需要将输入文本转换为UTF-8并使用RenderUTF8,或转换为UTF-16并使用RenderUNICODE以确保正确解释。

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. 如何执行此操作取决于您的应用程序所针对的平台-如果是Windows,那么最简单的方法是使用MultiByteToWideChar Win32 API将其转换为UTF-16,然后使用TTF_RenderUNICODE_Blended进行绘制。

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. 我将省略sdl_ttf。 It has some advantages and disadvantages but I think it will work for my purposes. 它有一些优点和缺点,但是我认为它可以满足我的目的。

Thanks for all responses 感谢您的所有回复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM