aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/typeface.cpp
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-27 20:39:19 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-27 20:39:19 +0000
commit3cb969f27de56df0d9116c13f18bd31ee0715f1a (patch)
tree12ac8e97fc06bcdbe56d7cb4e7da29b0263eb8cb /gm/typeface.cpp
parentcc6e5efe03bfeda903d67d2bacd9ed0be58572ba (diff)
In SkGPipe, only serialize SkTypefaces in cross process mode.
Also make SkGPipeController ref the recording canvas to ensure that objects used by SkGPipeCanvas (e.g. SharedHeap and fTypefaceSet, which hold references to objects to which pointers are written to the stream) survive to be played back even if SkGPipeWriter.endRecording() is called. BUG= TEST=TypefaceGM Review URL: https://codereview.appspot.com/6447055 git-svn-id: http://skia.googlecode.com/svn/trunk@4817 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/typeface.cpp')
-rw-r--r--gm/typeface.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/gm/typeface.cpp b/gm/typeface.cpp
new file mode 100644
index 0000000000..af04725a3f
--- /dev/null
+++ b/gm/typeface.cpp
@@ -0,0 +1,83 @@
+
+/*
+ * Copyright 2012 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 "SkString.h"
+#include "SkTypeface.h"
+#include "SkTypes.h"
+
+namespace skiagm {
+
+const char* gFaces[] = {
+ "Times Roman",
+ "Hiragino Maru Gothic Pro",
+ "Papyrus",
+ "Helvetica",
+ "Courier New"
+};
+
+class TypefaceGM : public GM {
+public:
+ TypefaceGM() {
+ fFaces = new SkTypeface*[SK_ARRAY_COUNT(gFaces)];
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
+ fFaces[i] = SkTypeface::CreateFromName(gFaces[i], SkTypeface::kNormal);
+ }
+ }
+
+ virtual ~TypefaceGM() {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
+ fFaces[i]->unref();
+ }
+ delete fFaces;
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("typeface");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(640, 480);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkString text("Typefaces are fun!");
+ SkScalar y = 0;
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
+ this->drawWithFace(text, i, y, paint, canvas);
+ }
+ // Now go backwards
+ for (int i = SK_ARRAY_COUNT(gFaces) - 1; i >= 0; i--) {
+ this->drawWithFace(text, i, y, paint, canvas);
+ }
+ }
+
+private:
+ void drawWithFace(const SkString& text, int i, SkScalar& y, SkPaint& paint,
+ SkCanvas* canvas) {
+ paint.setTypeface(fFaces[i]);
+ y += paint.getFontMetrics(NULL);
+ canvas->drawText(text.c_str(), text.size(), 0, y, paint);
+ }
+
+ SkTypeface** fFaces;
+
+ typedef GM INHERITED;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new TypefaceGM; }
+static GMRegistry reg(MyFactory);
+
+} // skiagm