blob: fd134041989ea76078d366b9ad7bc8439af7f948 [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));
Cary Clark992c7b02014-07-31 08:58:44 -040055 sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
reed@google.com3e71a882012-01-10 18:44:37 +000056 path.reset();
57 paint.getTextPath("e", 1, 50, 50, &path);
58 canvas->translate(0, 100);
59 test_rev(canvas, path);
60}
61
62namespace skiagm {
63
64class PathReverseGM : public GM {
65public:
66 PathReverseGM() {
67
68 }
69
70protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000071 virtual uint32_t onGetFlags() const SK_OVERRIDE {
72 return kSkipTiled_Flag;
73 }
74
reed@google.com3e71a882012-01-10 18:44:37 +000075 virtual SkString onShortName() {
76 return SkString("path-reverse");
77 }
78
79 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070080 return SkISize::Make(640, 480);
reed@google.com3e71a882012-01-10 18:44:37 +000081 }
82
83 virtual void onDraw(SkCanvas* canvas) {
caryclark@google.com13130862012-06-06 12:10:45 +000084 if (false) test_rev(canvas); // avoid bit rot, suppress warning
reed@google.com3e71a882012-01-10 18:44:37 +000085 SkRect r = { 10, 10, 100, 60 };
rmistry@google.comd6176b02012-08-23 18:14:13 +000086
reed@google.com3e71a882012-01-10 18:44:37 +000087 SkPath path;
rmistry@google.comd6176b02012-08-23 18:14:13 +000088
reed@google.com3e71a882012-01-10 18:44:37 +000089 path.addRect(r); test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +000090
reed@google.com3e71a882012-01-10 18:44:37 +000091 canvas->translate(0, 100);
92 path.offset(20, 20);
93 path.addRect(r); test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +000094
reed@google.com3e71a882012-01-10 18:44:37 +000095 canvas->translate(0, 100);
96 path.reset();
97 path.moveTo(10, 10); path.lineTo(30, 30);
98 path.addOval(r);
99 r.offset(50, 20);
100 path.addOval(r);
101 test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000102
reed@google.com3e71a882012-01-10 18:44:37 +0000103 SkPaint paint;
104 paint.setTextSize(SkIntToScalar(100));
Cary Clark992c7b02014-07-31 08:58:44 -0400105 sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
reed@google.com3e71a882012-01-10 18:44:37 +0000106 path.reset();
107 paint.getTextPath("e", 1, 50, 50, &path);
108 canvas->translate(0, 100);
109 test_rev(canvas, path);
110 }
111
112private:
113 typedef GM INHERITED;
114};
115
116//////////////////////////////////////////////////////////////////////////////
117
118static GM* MyFactory(void*) { return new PathReverseGM; }
119static GMRegistry reg(MyFactory);
120
121}