Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: gm/pathreverse.cpp

Issue 1230703005: make path-reverse gm portable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
11 #include "SkTypeface.h" 11 #include "SkTypeface.h"
12 12
13 /* The hiragino_maru_goth_pro_e path was generated with Mac-specific code:
14 *
15 * paint.setTextSize(SkIntToScalar(100));
16 * paint.setTypeface(SkTypeface::CreateFromName("Hiragino Maru Gothic Pro"));
17 * paint.getTextPath("e", 1, 50, 50, &path);
18 *
19 * The path data is duplicated here to allow the test to
20 * run on all platforms and to remove the bug dependency
21 * should future Macs edit or delete the font.
22 */
23 static SkPath hiragino_maru_goth_pro_e() {
24 SkPath path;
25 path.moveTo(98.6f, 24.7f);
26 path.cubicTo(101.7f, 24.7f, 103.6f, 22.8f, 103.6f, 19.2f);
27 path.cubicTo(103.6f, 18.9f, 103.6f, 18.7f, 103.6f, 18.4f);
28 path.cubicTo(102.6f, 5.3f, 94.4f, -6.1f, 79.8f, -6.1f);
29 path.cubicTo(63.5f, -6.1f, 54.5f, 6, 54.5f, 23.3f);
30 path.cubicTo(54.5f, 40.6f, 64, 52.2f, 80.4f, 52.2f);
31 path.cubicTo(93.4f, 52.2f, 99.2f, 45.6f, 102.4f, 39);
32 path.cubicTo(102.8f, 38.4f, 102.9f, 37.8f, 102.9f, 37.2f);
33 path.cubicTo(102.9f, 35.4f, 101.5f, 34.2f, 99.8f, 33.7f);
34 path.cubicTo(99.1f, 33.5f, 98.4f, 33.3f, 97.7f, 33.3f);
35 path.cubicTo(96.3f, 33.3f, 95, 34, 94.1f, 35.8f);
36 path.cubicTo(91.7f, 41.1f, 87.7f, 44.7f, 80.5f, 44.7f);
37 path.cubicTo(69.7f, 44.7f, 63.6f, 37, 63.4f, 24.7f);
38 path.lineTo(98.6f, 24.7f);
39 path.close();
40 path.moveTo(63.7f, 17.4f);
41 path.cubicTo(65, 7.6f, 70.2f, 1.2f, 79.8f, 1.2f);
42 path.cubicTo(89, 1.2f, 93.3f, 8.5f, 94.5f, 15.6f);
43 path.cubicTo(94.5f, 15.8f, 94.5f, 16, 94.5f, 16.1f);
44 path.cubicTo(94.5f, 17, 94.1f, 17.4f, 93, 17.4f);
45 path.lineTo(63.7f, 17.4f);
46 path.close();
47 return path;
48 }
49
13 static void test_path(SkCanvas* canvas, const SkPath& path) { 50 static void test_path(SkCanvas* canvas, const SkPath& path) {
14 SkPaint paint; 51 SkPaint paint;
15 paint.setAntiAlias(true); 52 paint.setAntiAlias(true);
16 canvas->drawPath(path, paint); 53 canvas->drawPath(path, paint);
17 54
18 paint.setStyle(SkPaint::kStroke_Style); 55 paint.setStyle(SkPaint::kStroke_Style);
19 paint.setColor(SK_ColorRED); 56 paint.setColor(SK_ColorRED);
20 canvas->drawPath(path, paint); 57 canvas->drawPath(path, paint);
21 } 58 }
22 59
23 static void test_rev(SkCanvas* canvas, const SkPath& path) { 60 static void test_rev(SkCanvas* canvas, const SkPath& path) {
24 test_path(canvas, path); 61 test_path(canvas, path);
25 62
26 SkPath rev; 63 SkPath rev;
27 rev.reverseAddPath(path); 64 rev.reverseAddPath(path);
28 canvas->save(); 65 canvas->save();
29 canvas->translate(150, 0); 66 canvas->translate(150, 0);
30 test_path(canvas, rev); 67 test_path(canvas, rev);
31 canvas->restore(); 68 canvas->restore();
32 } 69 }
33 70
34 static 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 sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
56 path.reset();
57 paint.getTextPath("e", 1, 50, 50, &path);
58 canvas->translate(0, 100);
59 test_rev(canvas, path);
60 }
61
62 namespace skiagm { 71 namespace skiagm {
63 72
64 class PathReverseGM : public GM { 73 class PathReverseGM : public GM {
65 public: 74 public:
66 PathReverseGM() { 75 PathReverseGM() {
67 76
68 } 77 }
69 78
70 protected: 79 protected:
71 80
72 SkString onShortName() override { 81 SkString onShortName() override {
73 return SkString("path-reverse"); 82 return SkString("path-reverse");
74 } 83 }
75 84
76 SkISize onISize() override { 85 SkISize onISize() override {
77 return SkISize::Make(640, 480); 86 return SkISize::Make(640, 480);
78 } 87 }
79 88
80 void onDraw(SkCanvas* canvas) override { 89 void onDraw(SkCanvas* canvas) override {
81 if (false) test_rev(canvas); // avoid bit rot, suppress warning
82 SkRect r = { 10, 10, 100, 60 }; 90 SkRect r = { 10, 10, 100, 60 };
83 91
84 SkPath path; 92 SkPath path;
85 93
86 path.addRect(r); test_rev(canvas, path); 94 path.addRect(r); test_rev(canvas, path);
87 95
88 canvas->translate(0, 100); 96 canvas->translate(0, 100);
89 path.offset(20, 20); 97 path.offset(20, 20);
90 path.addRect(r); test_rev(canvas, path); 98 path.addRect(r); test_rev(canvas, path);
91 99
92 canvas->translate(0, 100); 100 canvas->translate(0, 100);
93 path.reset(); 101 path.reset();
94 path.moveTo(10, 10); path.lineTo(30, 30); 102 path.moveTo(10, 10); path.lineTo(30, 30);
95 path.addOval(r); 103 path.addOval(r);
96 r.offset(50, 20); 104 r.offset(50, 20);
97 path.addOval(r); 105 path.addOval(r);
98 test_rev(canvas, path); 106 test_rev(canvas, path);
99 107
100 SkPaint paint; 108 path = hiragino_maru_goth_pro_e();
101 paint.setTextSize(SkIntToScalar(100));
102 sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro") ;
103 path.reset();
104 paint.getTextPath("e", 1, 50, 50, &path);
105 canvas->translate(0, 100); 109 canvas->translate(0, 100);
106 test_rev(canvas, path); 110 test_rev(canvas, path);
107 } 111 }
108 112
109 private: 113 private:
110 typedef GM INHERITED; 114 typedef GM INHERITED;
111 }; 115 };
112 116
113 ////////////////////////////////////////////////////////////////////////////// 117 //////////////////////////////////////////////////////////////////////////////
114 118
115 static GM* MyFactory(void*) { return new PathReverseGM; } 119 static GM* MyFactory(void*) { return new PathReverseGM; }
116 static GMRegistry reg(MyFactory); 120 static GMRegistry reg(MyFactory);
117 121
118 } 122 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698