aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/getpostextpath.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-20 11:20:32 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-20 11:20:32 +0000
commitca0062ee5e74eddff886ada2a200d25946ea52cf (patch)
tree130654f093ac9557522eccbb1ffdedfad2f10fe7 /gm/getpostextpath.cpp
parent4df7a16f0a423c9cb8609d75fbda3809f2ef0119 (diff)
add SkPaint::getPosTextPath(), with gm to test it
Review URL: https://codereview.appspot.com/6427055 git-svn-id: http://skia.googlecode.com/svn/trunk@4684 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/getpostextpath.cpp')
-rw-r--r--gm/getpostextpath.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/gm/getpostextpath.cpp b/gm/getpostextpath.cpp
new file mode 100644
index 0000000000..6ef37caf70
--- /dev/null
+++ b/gm/getpostextpath.cpp
@@ -0,0 +1,59 @@
+/*
+ * 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 "SkPaint.h"
+#include "SkRandom.h"
+
+class GetPosTextPathGM : public skiagm::GM {
+public:
+ GetPosTextPathGM() {}
+
+protected:
+ SkString onShortName() {
+ return SkString("getpostextpath");
+ }
+
+ SkISize onISize() { return skiagm::make_isize(480, 780); }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ const char* text = "Hamburgefons";
+ size_t len = strlen(text);
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setTextSize(SkIntToScalar(48));
+
+ SkAutoTArray<SkPoint> pos(len);
+ SkAutoTArray<SkScalar> widths(len);
+ paint.getTextWidths(text, len, &widths[0]);
+
+ SkRandom rand;
+ SkScalar x = SkIntToScalar(20);
+ SkScalar y = SkIntToScalar(100);
+ for (size_t i = 0; i < len; ++i) {
+ pos[i].set(x, y + rand.nextSScalar1() * 24);
+ x += widths[i];
+ }
+
+ canvas->drawPosText(text, len, &pos[0], paint);
+
+ SkPath path;
+ paint.setColor(SK_ColorRED);
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.getPosTextPath(text, len, &pos[0], &path);
+ canvas->drawPath(path, paint);
+ }
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static skiagm::GM* F(void*) { return new GetPosTextPathGM; }
+
+static skiagm::GMRegistry gR(F);
+