diff options
author | Jim Van Verth <jvanverth@google.com> | 2018-03-02 10:41:43 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-02 16:03:20 +0000 |
commit | 080a928a249115ec425771dd055682edf74d5258 (patch) | |
tree | f90fb3234de2e92d0251960abba0957e2b9e9251 /gm | |
parent | e28f9c65f614b605afdfb17d345d386b35f3f3b1 (diff) |
Various fixes for scaled emojis
Bug: skia:7562
Change-Id: I66cf290ca4541ceae7ee1009a1524046a2c5893e
Reviewed-on: https://skia-review.googlesource.com/111481
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'gm')
-rw-r--r-- | gm/scaledemoji.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/gm/scaledemoji.cpp b/gm/scaledemoji.cpp index c4a4c34499..ac8b3c6d51 100644 --- a/gm/scaledemoji.cpp +++ b/gm/scaledemoji.cpp @@ -61,11 +61,75 @@ protected: } +private: + typedef GM INHERITED; +}; + +class ScaledEmojiPosGM : public GM { +public: + ScaledEmojiPosGM() {} + +protected: + struct EmojiFont { + sk_sp<SkTypeface> fTypeface; + const char* fText; + } fEmojiFont; + + void onOnceBeforeDraw() override { + fEmojiFont.fTypeface = sk_tool_utils::emoji_typeface(); + fEmojiFont.fText = sk_tool_utils::emoji_sample_text(); + } + + SkString onShortName() override { + SkString name("scaledemojipos"); + name.append(sk_tool_utils::platform_font_manager()); + return name; + } + + SkISize onISize() override { return SkISize::Make(1200, 1200); } + + void onDraw(SkCanvas* canvas) override { + + canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY)); + + SkPaint paint; + paint.setTypeface(fEmojiFont.fTypeface); + const char* text = fEmojiFont.fText; + + // draw text at different point sizes + // Testing GPU bitmap path, SDF path with no scaling, + // SDF path with scaling, path rendering with scaling + SkPaint::FontMetrics metrics; + SkScalar y = 0; + for (SkScalar textSize : { 70, 180, 270, 340 }) { + paint.setTextSize(textSize); + paint.getFontMetrics(&metrics); + y += -metrics.fAscent; + + int len = SkToInt(strlen(text)); + SkAutoTArray<SkPoint> pos(len); + SkAutoTArray<SkScalar> widths(len); + paint.getTextWidths(text, len, &widths[0]); + + SkScalar x = SkIntToScalar(10); + for (int i = 0; i < len; ++i) { + pos[i].set(x, y); + x += widths[i]; + } + + canvas->drawPosText(text, len, &pos[0], paint); + y += metrics.fDescent + metrics.fLeading; + } + + } + +private: typedef GM INHERITED; }; ////////////////////////////////////////////////////////////////////////////// DEF_GM(return new ScaledEmojiGM;) +DEF_GM(return new ScaledEmojiPosGM;) } |