blob: 51c0d524b7da2e0dbc44e47881a77bded36e4cb6 [file] [log] [blame]
reed@google.com3e71a882012-01-10 18:44:37 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkPath.h"
11#include "SkTypeface.h"
12
13static void test_path(SkCanvas* canvas, const SkPath& path) {
14 SkPaint paint;
15 paint.setAntiAlias(true);
16 canvas->drawPath(path, paint);
rmistry@google.comd6176b02012-08-23 18:14:13 +000017
reed@google.com3e71a882012-01-10 18:44:37 +000018 paint.setStyle(SkPaint::kStroke_Style);
19 paint.setColor(SK_ColorRED);
20 canvas->drawPath(path, paint);
21}
22
23static void test_rev(SkCanvas* canvas, const SkPath& path) {
24 test_path(canvas, path);
25
26 SkPath rev;
27 rev.reverseAddPath(path);
28 canvas->save();
29 canvas->translate(150, 0);
30 test_path(canvas, rev);
31 canvas->restore();
32}
33
34static void test_rev(SkCanvas* canvas) {
35 SkRect r = { 10, 10, 100, 60 };
36
37 SkPath path;
38
39 path.addRect(r); test_rev(canvas, path);
40
41 canvas->translate(0, 100);
42 path.offset(20, 20);
43 path.addRect(r); test_rev(canvas, path);
44
45 canvas->translate(0, 100);
46 path.reset();
47 path.moveTo(10, 10); path.lineTo(30, 30);
48 path.addOval(r);
49 r.offset(50, 20);
50 path.addOval(r);
51 test_rev(canvas, path);
52
53 SkPaint paint;
54 paint.setTextSize(SkIntToScalar(100));
55 SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
56 SkSafeUnref(paint.setTypeface(hira));
57 path.reset();
58 paint.getTextPath("e", 1, 50, 50, &path);
59 canvas->translate(0, 100);
60 test_rev(canvas, path);
61}
62
63namespace skiagm {
64
65class PathReverseGM : public GM {
66public:
67 PathReverseGM() {
68
69 }
70
71protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000072 virtual uint32_t onGetFlags() const SK_OVERRIDE {
73 return kSkipTiled_Flag;
74 }
75
reed@google.com3e71a882012-01-10 18:44:37 +000076 virtual SkString onShortName() {
77 return SkString("path-reverse");
78 }
79
80 virtual SkISize onISize() {
81 return make_isize(640, 480);
82 }
83
84 virtual void onDraw(SkCanvas* canvas) {
caryclark@google.com13130862012-06-06 12:10:45 +000085 if (false) test_rev(canvas); // avoid bit rot, suppress warning
reed@google.com3e71a882012-01-10 18:44:37 +000086 SkRect r = { 10, 10, 100, 60 };
rmistry@google.comd6176b02012-08-23 18:14:13 +000087
reed@google.com3e71a882012-01-10 18:44:37 +000088 SkPath path;
rmistry@google.comd6176b02012-08-23 18:14:13 +000089
reed@google.com3e71a882012-01-10 18:44:37 +000090 path.addRect(r); test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +000091
reed@google.com3e71a882012-01-10 18:44:37 +000092 canvas->translate(0, 100);
93 path.offset(20, 20);
94 path.addRect(r); test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +000095
reed@google.com3e71a882012-01-10 18:44:37 +000096 canvas->translate(0, 100);
97 path.reset();
98 path.moveTo(10, 10); path.lineTo(30, 30);
99 path.addOval(r);
100 r.offset(50, 20);
101 path.addOval(r);
102 test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000103
reed@google.com3e71a882012-01-10 18:44:37 +0000104 SkPaint paint;
105 paint.setTextSize(SkIntToScalar(100));
106 SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
107 SkSafeUnref(paint.setTypeface(hira));
108 path.reset();
109 paint.getTextPath("e", 1, 50, 50, &path);
110 canvas->translate(0, 100);
111 test_rev(canvas, path);
112 }
113
114private:
115 typedef GM INHERITED;
116};
117
118//////////////////////////////////////////////////////////////////////////////
119
120static GM* MyFactory(void*) { return new PathReverseGM; }
121static GMRegistry reg(MyFactory);
122
123}