How to visualize colored glyphs from "Segoe UI Emoji" using freetype?

I am trying to display colored glyphs from Windows "Segoe UI Emoji" -Font with the latest freetype 2.8.1 (I compiled the x64 debug version from the source code without single or multi-threading) and OpenGL. So I use seguiemj.ttf from the Windows\Fonts directory (SHA256 = d67717a6fe84e21bc580443add16ec920e6988ca067041d0461c641f75074a8c ), but FT_HAS_COLOR always returns false. I also tried this with EmojiOneColor-SVGinOT.ttf eosrei from github , which leads to the same behavior.

When using this file for android, FT_HAS_COLOR returns true, but the bitmap slot does not fill up anyway.

 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"); ... } 

I mainly use the code above, which can only get a monochrome bitmap image of these font files, and the pixel mode is always FT_PIXEL_MODE_GRAY.

Emojis in Word / Firefox

Emojis in Word / Firefox

Emoji in my application

Emojis in my application

Is it possible to fix something or is something wrong?

+5
source share
1 answer

FT_Load_Glyph with FT_LOAD_COLOR load the raster version of the font into the glyph slot. After that, your code calls FT_Render_Glyph and displays the glyph from the outlines, effectively replacing the previously loaded bitmap.

You should be fine if you miss FT_Render_Glyph.

+1
source

Source: https://habr.com/ru/post/1272047/


All Articles