【发布时间】:2018-03-04 06:24:00
【问题描述】:
我正在尝试使用最新的 freetype 2.8.1(我从没有单线程或多线程的源代码编译 x64 调试版本)和 OpenGL 来渲染来自 Windows“Segoe UI Emoji”字体的彩色字形。所以我使用Windows\Fonts 目录中的seguiemj.ttf (SHA256 = d67717a6fe84e21bc580443add16ec920e6988ca067041d0461c641f75074a8c),但 FT_HAS_COLOR 总是返回 false。
我还用eosrei from github 的EmojiOneColor-SVGinOT.ttf 进行了尝试,结果相同。
当为 android 使用 this 文件时,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 中的表情符号
我的应用程序中的表情符号
有什么可以解决的还是我做错了什么?
【问题讨论】:
-
在minimal reproducible example 中编辑。另外,链接 Github 字体并在您尝试的 Microsoft 字体的 md5sum/sha256 中编辑。
-
face−>glyph−>format在FT_Load_Glyph()调用之后是否设置为FT_GLYPH_FORMAT_BITMAP? -
两种字体都设置为
FT_GLYPH_FORMAT_OUTLINE。 -
嘿,你还有所有生成彩色表情的代码吗?
标签: c++ windows opengl fonts freetype