我正在尝试使用最新的 freetype 2.8.1(我从源代码编译了 x64 调试版本,没有单线程或多线程)和 OpenGL 从 Windows“Segoe UI Emoji”字体渲染彩色字形。所以我用seguiemj.ttf
来自Windows\Fonts
目录(SHA256 =d67717a6fe84e21bc580443add16ec920e6988ca067041d0461c641f75074a8c
),但 FT_HAS_COLOR 始终返回 false。
我也尝试过EmojiOneColor-SVGinOT.ttf https://github.com/eosrei/emojione-color-font/releases/download/v1.3/EmojiOneColor-SVGinOT-1.3.zip by 来自 github 的 eosrei https://github.com/eosrei/EmojiOne-Color-Font,这会导致相同的行为。
使用时this https://github.com/emojione/emojione/raw/2.2.7/assets/fonts/emojione-android.ttf安卓文件,FT_HAS_COLOR
返回 true 并且位图槽无论如何都不会被填充。
FT_Library library;
FT_Face face;
FT_Init_FreeType(&library);
FT_New_Face(library, "resources/fonts/seguiemj.ttf", 0, &face);
bool has_color = FT_HAS_COLOR(face);
debug(LOG_INFO, 0, "font has colors: %s", has_color ? "yes" : "no");
std::u32string s = U"???? ???? ???? ???? ???? ???? ???? ????";
FT_GlyphSlot slot = face->glyph;
for (auto c : s)
{
int glyph_index = FT_Get_Char_Index(face, c);
FT_Error error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT|FT_LOAD_COLOR);
if (error)
continue;
error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
if (error)
continue;
if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA)
debug(LOG_INFO, 0, "glyph is colored");
...
}
基本上我使用上面的代码,它只能接收该字体文件的单色位图,并且像素模式始终为 FT_PIXEL_MODE_GRAY。
Word/Firefox 中的表情符号
我的应用程序中的表情符号
有什么办法可以解决这个问题还是我做错了什么?