diff options
author | 2016-06-01 08:31:28 -0700 | |
---|---|---|
committer | 2016-06-01 08:31:28 -0700 | |
commit | c4b091543b4082fd1a2f356ef3b478073c5f9418 (patch) | |
tree | 7c8c9906ce58ab635405a510988894594c55b986 /tools/sk_tool_utils.cpp | |
parent | 740cc88ee3d63c75e52d31238f2a32600cc57a8c (diff) |
Implement support for rendering color emoji on Windows
This change adds support to the DirectWrite scaler context
for detection of color fonts. If it detects a color font and
the glyph is a color glyph, it will use DirectWrite's
TranslateColorGlyphRun API and generate an image of the
glyph that can then be rendered.
Chromium tests: https://codereview.chromium.org/2003853002
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1984943002
Review-Url: https://codereview.chromium.org/1984943002
Diffstat (limited to 'tools/sk_tool_utils.cpp')
-rw-r--r-- | tools/sk_tool_utils.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index 9278c84807..8303f0979d 100644 --- a/tools/sk_tool_utils.cpp +++ b/tools/sk_tool_utils.cpp @@ -12,6 +12,8 @@ #include "SkBitmap.h" #include "SkCanvas.h" #include "SkCommonFlags.h" +#include "SkFontMgr.h" +#include "SkFontStyle.h" #include "SkPoint3.h" #include "SkShader.h" #include "SkTestScalerContext.h" @@ -72,6 +74,9 @@ const char* platform_os_emoji() { if (!strncmp(osName, "Mac", 3)) { return "SBIX"; } + if (!strncmp(osName, "Win", 3)) { + return "COLR"; + } return ""; } @@ -82,6 +87,23 @@ sk_sp<SkTypeface> emoji_typeface() { if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX")) { return SkTypeface::MakeFromName("Apple Color Emoji", SkFontStyle()); } + if (!strcmp(sk_tool_utils::platform_os_emoji(), "COLR")) { + sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); + const char *colorEmojiFontName = "Segoe UI Emoji"; + sk_sp<SkTypeface> typeface(fm->matchFamilyStyle(colorEmojiFontName, SkFontStyle())); + if (typeface) { + return typeface; + } + sk_sp<SkTypeface> fallback(fm->matchFamilyStyleCharacter( + colorEmojiFontName, SkFontStyle(), nullptr /* bcp47 */, 0 /* bcp47Count */, + 0x1f4b0 /* character: 💰 */)); + if (fallback) { + return fallback; + } + // If we don't have Segoe UI Emoji and can't find a fallback, try Segoe UI Symbol. + // Windows 7 does not have Segoe UI Emoji; Segoe UI Symbol has the (non - color) emoji. + return SkTypeface::MakeFromName("Segoe UI Symbol", SkFontStyle()); + } return nullptr; } @@ -89,7 +111,9 @@ const char* emoji_sample_text() { if (!strcmp(sk_tool_utils::platform_os_emoji(), "CBDT")) { return "Hamburgefons"; } - if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX")) { + if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX") || + !strcmp(sk_tool_utils::platform_os_emoji(), "COLR")) + { return "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E\x85" // 💰🏡🎅 "\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A\x80" // 🍪🍕🚀 "\xF0\x9F\x9A\xBB" "\xF0\x9F\x92\xA9" "\xF0\x9F\x93\xB7" // 🚻💩📷 |