2014-09-04 42 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編碼。在編輯器的設置中搜索。