c++ - 使用 IwGxFontDrawText 显示西里尔字体

标签 c++ character-encoding truetype marmalade

<分区>

我正在尝试使用 IwGxFontDrawText 函数在我的 Marmalade 项目中显示西里尔文字符串。我添加了 TimesNewRoman ttf 文件和我的代码:

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

如何显示西里尔文字?

最佳答案

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

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

关于c++ - 使用 IwGxFontDrawText 显示西里尔字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25660362/

相关文章:

css - 使用 WKHTMLTOPDF 显示为正方形的汉字

javascript - CSS:如何判断某个ttf字体具有的特征?

fonts - 如何判断 .woff 字体是否有提示?

java - fop 2.1 在 weblogic 服务器上加载字体时达到 EOF

c++ - 实现观察者模式时出现问题 : "Member reference base type ________ is not a structure or union"

c++ - 使用 OpenAL 重新加载声音

C#:字节到 UTF-8 字符串的转换。为什么它不起作用?

c++ - 以位为单位加一列是什么意思?

c++ - 编译后数组和指向数组的指针之间的区别?

c# - IsSingleByte Encoding的GetByteCount为什么要进行计算