aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/dftext.cpp
diff options
context:
space:
mode:
authorGravatar jvanverth <jvanverth@google.com>2014-10-20 13:12:54 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-20 13:12:55 -0700
commitfca302ccf464933e44e00255654d27a7705abb7f (patch)
tree10b63a4c4a197460c663393e1430e0f0f16605e4 /gm/dftext.cpp
parentc7eb58c8b46c72cca3cea1582c7f860293a1cbe9 (diff)
Add color emoji fallback for distance field text.
Diffstat (limited to 'gm/dftext.cpp')
-rwxr-xr-xgm/dftext.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/gm/dftext.cpp b/gm/dftext.cpp
index 6f75c46713..16fe4bd385 100755
--- a/gm/dftext.cpp
+++ b/gm/dftext.cpp
@@ -5,30 +5,44 @@
* found in the LICENSE file.
*/
#include "gm.h"
+#include "Resources.h"
+#include "SkCanvas.h"
+#include "SkStream.h"
#include "SkSurface.h"
#include "SkTypeface.h"
-namespace skiagm {
-
-class DFTextGM : public GM {
+class DFTextGM : public skiagm::GM {
public:
DFTextGM() {
this->setBGColor(0xFFFFFFFF);
+ fTypeface = NULL;
}
virtual ~DFTextGM() {
+ SkSafeUnref(fTypeface);
}
protected:
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
+ SkString filename = GetResourcePath("/Funkster.ttf");
+ SkAutoTUnref<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
+ if (!stream->isValid()) {
+ SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n");
+ return;
+ }
+
+ fTypeface = SkTypeface::CreateFromStream(stream);
+ }
+
virtual uint32_t onGetFlags() const SK_OVERRIDE {
return kGPUOnly_Flag;
}
- virtual SkString onShortName() {
+ virtual SkString onShortName() SK_OVERRIDE {
return SkString("dftext");
}
- virtual SkISize onISize() {
+ virtual SkISize onISize() SK_OVERRIDE {
return SkISize::Make(1024, 768);
}
@@ -185,6 +199,10 @@ protected:
y += paint.getFontMetrics(NULL);
}
+ // check color emoji
+ paint.setTypeface(fTypeface);
+ canvas->drawText(text, textLen, 670, 100, paint);
+
#if SK_SUPPORT_GPU
// render offscreen buffer
if (surface) {
@@ -199,12 +217,9 @@ protected:
}
private:
- typedef GM INHERITED;
-};
+ SkTypeface* fTypeface;
-//////////////////////////////////////////////////////////////////////////////
-
-static GM* MyFactory(void*) { return new DFTextGM; }
-static GMRegistry reg(MyFactory);
+ typedef skiagm::GM INHERITED;
+};
-}
+DEF_GM( return SkNEW(DFTextGM); )