2014-09-04 96 views
0

我试图在我的Marmalade项目中使用IwGxFontDrawText函数显示西里尔字符串。我已经添加TimesNewRoman TTF文件,我的代码:使用IwGxFontDrawText显示西里尔字体

int main() 
{ 
    // Initialise Iw2D 
    Iw2DInit(); 

    // Create the font that is used to display the score 
    CIwGxFont *Font = IwGxFontCreateTTFont("TNR_B.ttf", 14); 
    IwGxLightingOn(); 
    IwGxFontSetFont(Font); 
    IwGxFontSetRect(CIwRect((int16)10, (int16)10, (int16)IwGxGetScreenWidth(), (int16)IwGxGetScreenHeight())); 

    int scores = 0; 

    while (!s3eDeviceCheckQuitRequest()) 
    { 
     // Clear background to blue 
     Iw2DSurfaceClear(0xff8080); 

     IwGxFontDrawText("Привет: "); 
     // Convert the score number to text 
     char str[32]; 
     snprintf(str, 32, "    %d", scores); 

     IwGxFontDrawText(str); 
     scores++; 

     // Flip the surface buffer to screen 
     Iw2DSurfaceShow(); 

     s3eDeviceYield(0); // Yield to OS 
    } 

    Iw2DTerminate(); 

    return 0; 
} 

当我展示拉丁文本 - 所有的作品,但是当我告诉古斯拉夫语 - 我得到一个错误 enter image description here

我如何可以显示西里尔文本?

+0

正如消息问:你的源代码(因此你的字符串文字)[UTF-8](http://en.wikipedia.org/wiki/UTF-8)编码?许多编辑者使用本机编码,而且Windows上不是UTF-8。 – Csq 2014-09-04 08:26:26

+0

@Csq,我怎样才能将我的字符串文字转换为UTF-8? – daleijn 2014-09-04 08:30:19

+1

你使用哪个编辑器?在其设置中搜索UTF-8编码。大多数编辑能够使用UTF-8。例如,Notepad ++可以保存(甚至转换)UTF-8文件(请参阅其编码菜单)。 – Csq 2014-09-04 08:33:14

回答

1

该消息表明您的字符串不是UTF-8编码的。由于您的字符串直接来自源代码,这意味着您的源代码不是UTF-8编码。无论你使用UTF-8作为你的源代码编码(无论如何,这不是一个坏主意,因为它使你的源代码可移植),或者你应该转换字符串文字的编码。我宁愿第一个。

许多编辑器和IDE使用平台特定的编码。 Windows上不是UTF-8。但是,大多数编辑器和IDE都支持UTF-8编码。在编辑器的设置中搜索。