blob: 4487f9ada224645d048e88b35406a5f7360e5495 [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
caryclarkcae3ca62015-07-15 08:58:12 -070013/* 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 */
23static 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
reed@google.com3e71a882012-01-10 18:44:37 +000050static void test_path(SkCanvas* canvas, const SkPath& path) {
51 SkPaint paint;
52 paint.setAntiAlias(true);
53 canvas->drawPath(path, paint);
rmistry@google.comd6176b02012-08-23 18:14:13 +000054
reed@google.com3e71a882012-01-10 18:44:37 +000055 paint.setStyle(SkPaint::kStroke_Style);
56 paint.setColor(SK_ColorRED);
57 canvas->drawPath(path, paint);
58}
59
60static void test_rev(SkCanvas* canvas, const SkPath& path) {
61 test_path(canvas, path);
62
63 SkPath rev;
64 rev.reverseAddPath(path);
65 canvas->save();
66 canvas->translate(150, 0);
67 test_path(canvas, rev);
68 canvas->restore();
69}
70
reed@google.com3e71a882012-01-10 18:44:37 +000071namespace skiagm {
72
73class PathReverseGM : public GM {
74public:
75 PathReverseGM() {
76
77 }
78
79protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000080
mtklein36352bf2015-03-25 18:17:31 -070081 SkString onShortName() override {
reed@google.com3e71a882012-01-10 18:44:37 +000082 return SkString("path-reverse");
83 }
84
mtklein36352bf2015-03-25 18:17:31 -070085 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070086 return SkISize::Make(640, 480);
reed@google.com3e71a882012-01-10 18:44:37 +000087 }
88
mtklein36352bf2015-03-25 18:17:31 -070089 void onDraw(SkCanvas* canvas) override {
reed@google.com3e71a882012-01-10 18:44:37 +000090 SkRect r = { 10, 10, 100, 60 };
rmistry@google.comd6176b02012-08-23 18:14:13 +000091
reed@google.com3e71a882012-01-10 18:44:37 +000092 SkPath path;
rmistry@google.comd6176b02012-08-23 18:14:13 +000093
reed@google.com3e71a882012-01-10 18:44:37 +000094 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.offset(20, 20);
98 path.addRect(r); test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +000099
reed@google.com3e71a882012-01-10 18:44:37 +0000100 canvas->translate(0, 100);
101 path.reset();
102 path.moveTo(10, 10); path.lineTo(30, 30);
103 path.addOval(r);
104 r.offset(50, 20);
105 path.addOval(r);
106 test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000107
caryclarkcae3ca62015-07-15 08:58:12 -0700108 path = hiragino_maru_goth_pro_e();
reed@google.com3e71a882012-01-10 18:44:37 +0000109 canvas->translate(0, 100);
110 test_rev(canvas, path);
111 }
112
113private:
114 typedef GM INHERITED;
115};
116
117//////////////////////////////////////////////////////////////////////////////
118
119static GM* MyFactory(void*) { return new PathReverseGM; }
120static GMRegistry reg(MyFactory);
121
122}