【问题标题】:How can I render colored glyphs from "Segoe UI Emoji" with freetype?如何使用 freetype 从“Segoe UI Emoji”渲染彩色字形?
【发布时间】: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 githubEmojiOneColor-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−>formatFT_Load_Glyph() 调用之后是否设置为FT_GLYPH_FORMAT_BITMAP
  • 两种字体都设置为FT_GLYPH_FORMAT_OUTLINE
  • 嘿,你还有所有生成彩色表情的代码吗?

标签: c++ windows opengl fonts freetype


【解决方案1】:

带有 FT_LOAD_COLOR 的 FT_Load_Glyph 将字体的位图版本加载到字形槽中。之后,您的代码调用 FT_Render_Glyph 并从轮廓渲染字形,从而有效地替换先前加载的位图。

跳过 FT_Render_Glyph 应该没问题。

【讨论】:

  • 你是对的。但只有当我将 FT_LOAD_RENDER 添加到 FT_Load_Glyph 函数时,我才能跳过 FT_Render_Glyph 调用并填充位图缓冲区。可能是因为没有可用的颜色。
  • @code_hunter 等等。运行 FT_Load_Glyph(..., FT_LOAD_COLOR) 时位图未填充?将 FT_LOAD_RENDER 放在那里相当于在加载后运行 FT_Render_Glyph,这正是您不想做的。那是我的猜测。如果我错了,我会收回答案
  • 你是绝对正确的。 FT_Render_Glyph 仅在您不想要不同的渲染模式时才需要。只使用 FT_LOAD_COLOR 应该是对的。
猜你喜欢
  • 1970-01-01
  • 2018-04-04
  • 2021-09-23
  • 1970-01-01
  • 2019-05-20
  • 2019-07-13
  • 2014-07-23
  • 1970-01-01
相关资源
最近更新 更多