diff options
author | Jim Van Verth <jvanverth@google.com> | 2018-06-01 13:46:46 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-01 18:31:47 +0000 |
commit | 70276915db0c4ec604213c61cb69d8f0419e0e60 (patch) | |
tree | d14b0dad8c1c3745df84b88f0dcec33ebda6098b /samplecode | |
parent | 8683037a2ea9d75d1aea8915bf8acdc9cc6f4d24 (diff) |
Set bounds correctly for color emoji that need post-cache transfoms
We need to handle the bounds for transformed color emoji the same
way we handle the bounds for distance field text. Without this
bounds correction, the glyphs were being clipped out.
Also adds a sample to test this case.
Bug: 848616
Change-Id: I39dedbe2fd19331ad67978c95519f5c9d46f59fc
Reviewed-on: https://skia-review.googlesource.com/131523
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleGlyphTransform.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/samplecode/SampleGlyphTransform.cpp b/samplecode/SampleGlyphTransform.cpp new file mode 100644 index 0000000000..b5d44f8bfc --- /dev/null +++ b/samplecode/SampleGlyphTransform.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SampleCode.h" +#include "sk_tool_utils.h" + +#include "SkAnimTimer.h" +#include "SkCanvas.h" +#include "SkPath.h" +#include "SkRandom.h" +#include "SkRRect.h" +#include "SkTypeface.h" + +// Implementation in C++ of Animated Emoji +// See https://t.d3fc.io/status/705212795936247808 + +class GlyphTransformView : public SampleView { +public: + GlyphTransformView() {} + +protected: + void onOnceBeforeDraw() override { + fEmojiFont.fTypeface = sk_tool_utils::emoji_typeface(); + fEmojiFont.fText = sk_tool_utils::emoji_sample_text(); + } + + // overrides from SkEventSink + bool onQuery(SkEvent* evt) override { + if (SampleCode::TitleQ(*evt)) { + SampleCode::TitleR(evt, "Glyph Transform"); + return true; + } + return this->INHERITED::onQuery(evt); + } + + void onDrawContent(SkCanvas* canvas) override { + SkPaint paint; + paint.setTypeface(fEmojiFont.fTypeface); + const char* text = fEmojiFont.fText; + + canvas->scale(4, 4); + + canvas->drawLine(0, 200, 600, 200, paint); + SkMatrix ctm; + ctm.setRotate(SkRadiansToDegrees(fRotate)); + ctm.postScale(fScale, fScale); + ctm.postTranslate(fTranslate.fX, fTranslate.fY); + canvas->concat(ctm); + canvas->drawString(text, 0, 0, paint); + } + + bool onAnimate(const SkAnimTimer& timer) override { + double t = timer.secs(); + + fTranslate.set(99 + sin(t / 3.0e3) - t / 1024, 200 + sin(t / 999) / t); + fScale = 4.5 - t*t / 99; + fRotate = sin(t / 734); + + return true; + } + +private: + struct EmojiFont { + sk_sp<SkTypeface> fTypeface; + const char* fText; + } fEmojiFont; + + SkVector fTranslate; + SkScalar fScale; + SkScalar fRotate; + + typedef SampleView INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static SkView* MyFactory() { return new GlyphTransformView; } +static SkViewRegister reg(MyFactory); |