aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/coloremoji.cpp
diff options
context:
space:
mode:
authorGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-17 15:30:21 +0000
committerGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-17 15:30:21 +0000
commit6def2a2dc7af2c5e62f1c2c05e9253254cf24aeb (patch)
tree00b12108549bef627855c7390ffc3b7198cc78ed /gm/coloremoji.cpp
parente1e084f10241c10692bb7c6864ec14bb9d4afdfd (diff)
Add a test for color bitmap fonts.
This CL also includes a sample font from https://code.google.com/p/color-emoji/ R=reed@google.com Review URL: https://codereview.chromium.org/24181002 git-svn-id: http://skia.googlecode.com/svn/trunk@11317 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/coloremoji.cpp')
-rw-r--r--gm/coloremoji.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp
new file mode 100644
index 0000000000..8316a3851c
--- /dev/null
+++ b/gm/coloremoji.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkStream.h"
+#include "SkTypeface.h"
+
+namespace skiagm {
+
+class ColorEmojiGM : public GM {
+public:
+ ColorEmojiGM() {
+ fTypeface = NULL;
+ }
+
+ ~ColorEmojiGM() {
+ SkSafeUnref(fTypeface);
+ }
+protected:
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
+
+ SkString filename(INHERITED::gResourcePath);
+ filename.append("/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 SkString onShortName() {
+ return SkString("coloremoji");
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(640, 480);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+
+ canvas->drawColor(SK_ColorGRAY);
+
+ SkPaint paint;
+ paint.setTypeface(fTypeface);
+ paint.setEmbeddedBitmapText(true);
+
+ const char* text = "hamburgerfons";
+
+ // draw text at different point sizes
+ const int textSize[] = { 10, 30, 50 };
+ const int textYOffset[] = { 10, 40, 100};
+ SkASSERT(sizeof(textSize) == sizeof(textYOffset));
+ for (size_t y = 0; y < sizeof(textSize) / sizeof(int); ++y) {
+ paint.setTextSize(textSize[y]);
+ canvas->drawText(text, strlen(text), 10, textYOffset[y], paint);
+ }
+
+ // setup work needed to draw text with different clips
+ canvas->translate(10, 160);
+ paint.setTextSize(40);
+
+ // compute the bounds of the text
+ SkRect bounds;
+ paint.measureText(text, strlen(text), &bounds);
+
+ const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
+ const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
+ const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
+ const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf;
+
+ SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
+ boundsHalfWidth, boundsHalfHeight);
+ SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.centerY(),
+ boundsHalfWidth, boundsHalfHeight);
+ SkRect interiorClip = bounds;
+ interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
+
+ const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip };
+
+ SkPaint clipHairline;
+ clipHairline.setColor(SK_ColorWHITE);
+ clipHairline.setStyle(SkPaint::kStroke_Style);
+
+ for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) {
+ canvas->save();
+ canvas->drawRect(clipRects[x], clipHairline);
+ paint.setAlpha(0x20);
+ canvas->drawText(text, strlen(text), 0, 0, paint);
+ canvas->clipRect(clipRects[x]);
+ paint.setAlpha(0xFF);
+ canvas->drawText(text, strlen(text), 0, 0, paint);
+ canvas->restore();
+ canvas->translate(0, bounds.height() + SkIntToScalar(25));
+ }
+ }
+
+private:
+ SkTypeface* fTypeface;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new ColorEmojiGM; }
+static GMRegistry reg(MyFactory);
+
+}