From 70276915db0c4ec604213c61cb69d8f0419e0e60 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Fri, 1 Jun 2018 13:46:46 -0400 Subject: 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 Commit-Queue: Brian Salomon Auto-Submit: Jim Van Verth --- samplecode/SampleGlyphTransform.cpp | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 samplecode/SampleGlyphTransform.cpp (limited to 'samplecode') 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 fTypeface; + const char* fText; + } fEmojiFont; + + SkVector fTranslate; + SkScalar fScale; + SkScalar fRotate; + + typedef SampleView INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static SkView* MyFactory() { return new GlyphTransformView; } +static SkViewRegister reg(MyFactory); -- cgit v1.2.3