我按如下方式初始化 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
类型。
但我看到以下内容:
最佳答案
我对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/