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:
But if I used "Noto Color Emoji" as above emojiTypeface1 , it can not rendering out just a block:
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.