c++ - 带有 unicode 的 FreeType [错误]

标签 c++ text unicode freetype

我按如下方式初始化 FreeType:

if (FT_Init_FreeType(&ft)) {
        printf("couldn't init freetype\n");
        exit(1);
    }
    std::string fontPath = "D:/fonts/newscycle-bold.ttf";
    if (FT_New_Face(ft, fontPath.c_str(), 0, &face)) {
        printf("couldn't open font\n");
        exit(1);
    }

    FT_Select_Charmap(face, ft_encoding_unicode);
    FT_Set_Pixel_Sizes(face, 0, size);
    g = face->glyph; // declaration like FT_GlyphSlot g;

我得到如下字形:

    // load the w_char into the face object
if (FT_Load_Char(face, c, FT_LOAD_RENDER))
    printf("freetype is unable to load char: %c\n", c); // this runs if error was occured

我使用 wchar_t*wchar_t 类型。

但我看到以下内容: enter image description here

最佳答案

我对unicode字符有同样的问题,最后我发现问题是从UTF8字符串到UTF16(wstring)的转换。我正在使用 mbstowcs 函数进行转换,但像“€”这样的符号没有按预期转换。它适用于我的方式是使用新的 C++11 std::wstring_convert 类。试试这个:

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> convert;
const std::wstring wideText = convert.from_bytes(_text);

现在将 wideText 字符串传递给 FreeType。

关于c++ - 带有 unicode 的 FreeType [错误],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22234407/

相关文章:

c++ - 有没有办法刷新与程序相关的整个CPU缓存?

c++ - 使用boost将给定目录中每个最低级别文件夹的文件递归复制到另一个目录 - C++

c++ - 读取二进制数据问题

java - Textwatchers afterTextChanged() 不断崩溃

c++ - 从 boost::chrono::steady_clock::now() 获得双倍

html - 拒绝 BeautifulSoup 中的一些 HTML 标签

ios - 如何删除 UITextView Swift 中文本的顶部填充

java - Kotlin/Java - 如何识别全角字符?

css - OL-LI 列出 Unicode 中的数字

c - 如何计算C中unicode字符串中的字符