Can not rendering Noto Color Emoji on Windows11

395 views
Skip to first unread message

aisnote com

unread,
Sep 16, 2024, 8:21:00 PM9/16/24
to skia-d...@googlegroups.com
Tested branch: chrome/m129

Code as below:
int main_draw_simple_emoji()
{
// Initialize Skia
SkGraphics::Init();

// Prepare emoji text
const std::wstring text = L"Here are some emojis: \U0001F600"; // 😀 😃 😄

    // Convert wide string to UTF-8 for Skia
auto utf8Text = GemDemoUtils::wstring2utf8str(text);

    //GemDemoUtilsFonts::c_fontFilePath_emoji_regular = "NotoColorEmoji-Regular.ttf";
    auto emojiFontFile = GetFontFileFullPath(GemDemoUtilsFonts::c_fontFilePath_emoji_regular);
sk_sp<SkTypeface> emojiTypeface1 = SkTypeface::MakeFromFile(emojiFontFile.c_str());

sk_sp<SkFontMgr> fontMgr = SkFontMgr::RefDefault();
sk_sp<SkTypeface> emojiTypeface2 ( fontMgr->matchFamilyStyle("Segoe UI Emoji", SkFontStyle()));

SkFont font(emojiTypeface1, 64);  // Set the font size as required
// SkFont font(emojiTypeface2, 64);  // Set the font size as required
// font.setEdging(SkFont::Edging::kAlias);  // Anti-aliasing

    // Create a SkSurface to draw on
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(800, 200);
SkCanvas* canvas = surface->getCanvas();

// Clear the canvas
canvas->drawColor(SK_ColorWHITE);

// Set the text paint (color, etc.)
SkPaint paint;
paint.setColor(SK_ColorBLACK);

// Draw the text with drawSimpleText
canvas->drawSimpleText(
utf8Text.c_str(),                  // Text in UTF-8 format
utf8Text.size(),                   // Size of the text
SkTextEncoding::kUTF8,             // Text encoding (UTF-8)
10, 100,                           // X, Y position to draw the text
font,                              // Font to use for drawing
paint                              // Paint object for styling (color)
);

// Save the result to an image file (e.g., PNG)
sk_sp<SkImage> image = surface->makeImageSnapshot();
if (image) {
sk_sp<SkData> pngData = image->encodeToData();
if (pngData) {
std::ofstream outFile("emoji_output_simple.png", std::ios::binary);
outFile.write((const char*)pngData->data(), pngData->size());
outFile.close();
std::cout << "Image saved to emoji_output.png" << std::endl;
}
else {
std::cerr << "Failed to encode image to PNG." << std::endl;
}
}
else {
std::cerr << "Failed to create image snapshot." << std::endl;
}

// Cleanup (optional since smart pointers handle it)
SkGraphics::PurgeAllCaches();

return 0;
}

If I used system's font as emojiTypeface2 , it can rendering out the windows emoji as below picture:
image.png

But if I used "Noto Color Emoji" as above emojiTypeface1 , it can not rendering out just a block:
image.png
The Emoji font file I used from: https://github.com/googlefonts/noto-emoji/tree/main/fonts 

Below 4 font files I used, all are failed.

 const std::string c_fontFilePath_emoji_windows_compatible{"NotoColorEmoji_WindowsCompatible.ttf"};

const std::string c_fontFilePath_emoji_colrv1_compatible{ "Noto-COLRv1-emojicompat.ttf" };
const std::string c_fontFilePath_emoji_colrv1{"Noto-COLRv1.ttf" };
const std::string c_fontFilePath_emoji{"NotoColorEmoji.ttf" };

Thanks.

bungeman

unread,
Sep 17, 2024, 10:33:39 AM9/17/24
to skia-discuss
As noted in RELEASE_NOTES.md, SkTypeface::MakeFromFile was deprecated in 120. It was removed in 122 (38e85e85079f4140158a8f83c7bbceb7a1ac5ca5). (While there is an entry in relation to  SkFontMgr::RefDefault() being removed in the release notes, this probably should have mentioned explicitly everything that was removed as a result.)

aisnote com

unread,
Sep 17, 2024, 8:22:19 PM9/17/24
to skia-d...@googlegroups.com
I changed the code and using the GDI fontmgr, but still can not render out the Emoji with NotoColorEmoji font file. Code as below:

sk_sp<SkFontMgr> mgr = ToolUtils::TestFontMgr();
    sk_sp<SkTypeface> emojiTypefaceTest = mgr->makeFromFile(emojiFontFile.c_str());

    if (!emojiTypefaceTest)
    {
        std::cerr << "create emoji font from file failed" << std::endl;
return -1;
    }

SkFont font(emojiTypefaceTest, 64);  // Set the font size as required


    // Create a SkSurface to draw on
    SkImageInfo skImgInfo = SkImageInfo::MakeN32Premul(800, 200);

sk_sp<SkSurface> surface = SkSurfaces::Raster(skImgInfo);


SkCanvas* canvas = surface->getCanvas();

// Clear the canvas
canvas->drawColor(SK_ColorWHITE);

// Set the text paint (color, etc.)
SkPaint paint;
paint.setColor(SK_ColorBLACK);

// Draw the text with drawSimpleText
canvas->drawSimpleText(
utf8Text.c_str(),                  // Text in UTF-8 format
utf8Text.size(),                   // Size of the text
SkTextEncoding::kUTF8,             // Text encoding (UTF-8)
10, 100,                           // X, Y position to draw the text
font,                              // Font to use for drawing
paint                              // Paint object for styling (color)
);

// Save the result to an image file (e.g., PNG)
sk_sp<SkImage> image = surface->makeImageSnapshot();
if (image) {
        sk_sp<SkData> pngData = SkPngEncoder::Encode(nullptr, image.get(), {});

if (pngData) {
std::ofstream outFile("emoji_output_simple.png", std::ios::binary);
outFile.write((const char*)pngData->data(), pngData->size());
outFile.close();
std::cout << "Image saved to emoji_output.png" << std::endl;
}
else {
std::cerr << "Failed to encode image to PNG." << std::endl;
}
}
else {
std::cerr << "Failed to create image snapshot." << std::endl;
}

// Cleanup (optional since smart pointers handle it)
SkGraphics::PurgeAllCaches();

return 0;



sk_sp<SkFontMgr> TestFontMgr() {
    static sk_sp<SkFontMgr> mgr;
    static SkOnce once;
    once([] {
        if (!FLAGS_nativeFonts) {
            mgr = MakePortableFontMgr();
        }
#if defined(SK_BUILD_FOR_WIN) && defined(SK_FONTMGR_GDI_AVAILABLE)
        else if (FLAGS_gdi) {
            mgr = SkFontMgr_New_GDI();
        }

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/35b89112-686e-4207-9695-468469aa6b80n%40googlegroups.com.

bungeman

unread,
Sep 17, 2024, 10:24:59 PM9/17/24
to skia-discuss
I don't believe GDI supports color fonts. You may wish to use the DirectWrite font manager instead.

aisnote com

unread,
Sep 17, 2024, 10:54:29 PM9/17/24
to skia-d...@googlegroups.com
thanks, but actually, I replaced it with  SkFontMgr_New_DirectWrite  , the emoji still can not render out with NotoColorEmoji font. 

But worked with " "Segoe UI Emoji"

mgr = SkFontMgr_New_DirectWrite();

But can render out with system font: 
 sk_sp<SkFontMgr> mgr = ToolUtils::TestFontMgr();

sk_sp<SkTypeface> emojiTypefaceSys ( mgr->matchFamilyStyle("Segoe UI Emoji", SkFontStyle()));  // worked


    sk_sp<SkFontMgr> mgr = ToolUtils::TestFontMgr();
    sk_sp<SkTypeface> emojiTypefaceTest = mgr->makeFromFile(emojiFontFile.c_str()); // not worked.  with "NotoColorEmoji-Regular.ttf";


Any suggestions?

Thanks a lot.



bungeman

unread,
Sep 17, 2024, 11:16:20 PM9/17/24
to skia-discuss
I'm not sure which version of NotoColorEmoji-Regular.ttf you have, but if it has the bytes `CBDT` and `CBLC` somewhere near the beginning of the file it probably won't work with DirectWrite either. To use a CBDT/CBLC style font one would need to create a FreeType backed SkTypeface. Also, I'm not sure which version of DirectWrite you're using, since earlier versions did not have support for various formats (which didn't eist at the time).

aisnote com

unread,
Sep 17, 2024, 11:45:24 PM9/17/24
to skia-d...@googlegroups.com
I dump out this font as below, no CBDT/ CBLC can be found.
GlyphOrder
  head
  hhea
  maxp
  OS/2
  hmtx
  cmap
  loca
  glyf
  name
  post
  COLR
  CPAL
  GSUB
  SVG
  vhea
  vmtx


And I debug into skia, my code used dwrite.dll:

if (!dWriteCreateFactoryProc) {
        dWriteCreateFactoryProc = reinterpret_cast<DWriteCreateFactoryProc>(GetProcAddress(
                LoadLibraryExW(L"dwrite.dll", NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS),
                "DWriteCreateFactory"));
    }

(Get-Item "C:\Windows\System32\DWrite.dll").VersionInfo

ProductVersion   FileVersion      FileName
--------------   -----------      --------
10.0.22621.1     10.0.22621.1 ... C:\Windows\System32\DWrite.dll

aisnote com

unread,
Sep 18, 2024, 4:34:02 PM9/18/24
to skia-d...@googlegroups.com
Any suggestions?  thanks.
Reply all
Reply to author
Forward
0 new messages