libsdl-org/SDL_ttf

Cannot render full color emoji font

TylerJNA opened this issue · 2 comments

Please excuse my ignorance, I'm very unfamiliar with both SDL_ttf and freetype.

I am using mingw32/GCC and CMake. I built freetype 2.13.2 with FT_REQUIRE_PNG and FT_CONFIG_OPTION_USE_PNG, then I built SDL2_ttf 2.22.0. I am building and running my program with the libfreetype.dll/SDL2_ttf.dll that I built.

When I try to render an emoji glyph with TTF_Render*_Blended, I get "Couldn't find glyph".

When I try to render an emoji glyph with a non-blended render mode, there is no error but no glyph is actually rendered.

Everything renders as expected with non-colored fonts, including the notocolor B&W font.

Example:

    TTF_GetFreeTypeVersion(major, minor, patch);
    logMessage(gamestate, "Freetype version: " + std::to_string(*major) + "." + std::to_string(*minor) + "." + std::to_string(*patch)  );
    TTF_Font *testfont = TTF_OpenFont( "fonts/notocoloremoji/NotoColorEmoji-Regular.ttf", 64 );
    if (testfont == NULL) {
        logMessage(gamestate, "Failed to load testfont.");
    } else {
        logMessage(gamestate, "Successfully loaded testfont.");
    }

    int char_provided = TTF_GlyphIsProvided32(testfont, 129315); //'🤣'
    if (char_provided) {
        logMessage(gamestate, "testfont provides glyph 129315");
    } else {
        logMessage(gamestate, "testfont does not provide glyph 129315");
    }

    char_provided = TTF_GlyphIsProvided32(testfont, 76); 'L'
    if (char_provided) {
        logMessage(gamestate, "testfont provides glyph 76");
    } else {
        logMessage(gamestate, "testfont does not provide glyph 76");
    }


    SDL_Color test_color = { 255, 255, 255, 255 };
    SDL_Color test_color2 = { 255, 0, 0, 15 };

    SDL_Surface *test_surface = TTF_RenderUTF8_Blended(testfont,
                gamestate->LOCSTRINGMAP["EmojiTest"]->strings["ENG"].c_str(), test_color); //This string contains '🤣🤣🤣'

   if (test_surface == NULL) {
        string ttf_error = TTF_GetError();
        logMessage(gamestate, "Failed to render testfont: " + ttf_error);
    } else {
        logMessage(gamestate, "Successfully rendered testfont.");
    }

    SDL_FreeSurface(test_surface);
    test_surface  = TTF_RenderGlyph32_Blended(testfont, 129315, test_color);
    if (test_surface == NULL) {
        string ttf_error = TTF_GetError();
        logMessage(gamestate, "Failed to render testfont: " + ttf_error);
    } else {
        logMessage(gamestate, "Successfully rendered testfont.");
    }

    SDL_FreeSurface(test_surface);
    test_surface  = TTF_RenderGlyph32_Solid(testfont, 129315, test_color);
    if (test_surface == NULL) {
        string ttf_error = TTF_GetError();
        logMessage(gamestate, "Failed to render testfont: " + ttf_error);
    } else {
        logMessage(gamestate, "Successfully rendered testfont.");
    }

Output:

Freetype version: 2.13.2
Successfully loaded testfont.
testfont provides glyph 129315
testfont does not provide glyph 76
Failed to render testfont: Couldn't find glyph
Failed to render testfont: Couldn't find glyph
Successfully rendered testfont.

Have I done something wrong during the build process, or am I misunderstanding how to use SDL_ttf with colored glyphs?

Well, it seems the problem was actually the font itself. Apparently 'NotoColorEmoji-Regular.ttf' is vector based. The correct font is 'NotoColorEmoji.ttf'.