gpt4 book ai didi

c++ - 如何使用 freetype 从 "Segoe UI Emoji"渲染彩色字形?

转载 作者:可可西里 更新时间:2023-11-01 12:44:04 24 4
gpt4 key购买 nike

我正在尝试使用最新的 freetype 2.8.1(我从没有单线程或多线程的源代码编译 x64 调试版本)和 OpenGL 渲染来自 Windows“Segoe UI Emoji”字体的彩色字形。所以我使用 Windows\Fonts 目录中的 seguiemj.ttf (SHA256 = d67717a6fe84e21bc580443add16ec920e6988ca067041d0461c641f75074a8c),但 FT_HAS_COLOR 始终返回 false。我也用 EmojiOneColor-SVGinOT.ttf 试过了通过 eosrei from github ,这会导致相同的行为。

使用 this 时对于 android 的文件,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 中的表情符号

Emojis in Word/Firefox

我的应用程序中的表情符号

Emojis in my applicaton

有什么办法可以解决这个问题还是我做错了什么?

最佳答案

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

如果您跳过 FT_Render_Glyph,应该没问题。

关于c++ - 如何使用 freetype 从 "Segoe UI Emoji"渲染彩色字形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46368673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com