blob: 2e71a368e8b2a2f03c08836499676aa297b1205d [file] [log] [blame]
reed@google.com63d73742012-01-10 15:33:12 +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 test10(SkCanvas* canvas) {
14 SkPaint paint;
15 const char text[] = "Hello"; // "Hello";
16 const size_t len = sizeof(text) - 1;
17 paint.setAntiAlias(true);
18 paint.setTextSize(SkIntToScalar(100));
19 SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro",
20 SkTypeface::kNormal);
21 paint.setTypeface(hira);
22 SkScalar x = 180;
23 SkScalar y = 88;
24
25 canvas->drawText(text, len, x, y, paint);
26 paint.setFakeBoldText(true);
27 canvas->drawText(text, len, x, y + 100, paint);
28 paint.setStyle(SkPaint::kStrokeAndFill_Style);
29 paint.setStrokeWidth(5);
30
31 SkPath path;
32 path.setFillType(SkPath::kWinding_FillType);
33 path.addCircle(x, y + 200, 50, SkPath::kCW_Direction);
34 path.addCircle(x, y + 200, 40, SkPath::kCCW_Direction);
35 canvas->drawPath(path, paint);
36
37 SkPath path2;
38 path2.setFillType(SkPath::kWinding_FillType);
39 path2.addCircle(x + 120, y + 200, 50, SkPath::kCCW_Direction);
40 path2.addCircle(x + 120, y + 200, 40, SkPath::kCW_Direction);
41 canvas->drawPath(path2, paint);
42
43 path2.reset();
44 path2.addCircle(x + 240, y + 200, 50, SkPath::kCCW_Direction);
45 canvas->drawPath(path2, paint);
46
47 path2.reset();
48 path2.addCircle(x + 360, y + 200, 50, SkPath::kCW_Direction);
49 canvas->drawPath(path2, paint);
50}
51
52static void test_path(SkCanvas* canvas, const SkPath& path) {
53 SkPaint paint;
54 paint.setAntiAlias(true);
55 canvas->drawPath(path, paint);
56
57 paint.setStyle(SkPaint::kStroke_Style);
58 paint.setColor(SK_ColorRED);
59 canvas->drawPath(path, paint);
60}
61
62static void test_rev(SkCanvas* canvas, const SkPath& path) {
63 test_path(canvas, path);
64
65 SkPath rev;
66 rev.reverseAddPath(path);
67 canvas->save();
68 canvas->translate(150, 0);
69 test_path(canvas, rev);
70 canvas->restore();
71}
72
73static void test_rev(SkCanvas* canvas) {
74 SkRect r = { 10, 10, 100, 60 };
75
76 SkPath path;
77
78 path.addRect(r); test_rev(canvas, path);
79
80 canvas->translate(0, 100);
81 path.offset(20, 20);
82 path.addRect(r); test_rev(canvas, path);
83
84 canvas->translate(0, 100);
85 path.reset();
86 path.moveTo(10, 10); path.lineTo(30, 30);
87 path.addOval(r);
88 r.offset(50, 20);
89 path.addOval(r);
90 test_rev(canvas, path);
91
92 SkPaint paint;
93 paint.setTextSize(SkIntToScalar(100));
94 SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
95 SkSafeUnref(paint.setTypeface(hira));
96 path.reset();
97 paint.getTextPath("e", 1, 50, 50, &path);
98 canvas->translate(0, 100);
99 test_rev(canvas, path);
100}
101
102namespace skiagm {
103
104class StrokeFillGM : public GM {
105public:
106 StrokeFillGM() {
107
108 }
109
110protected:
111 virtual SkString onShortName() {
112 return SkString("stroke-fill");
113 }
114
115 virtual SkISize onISize() {
116 return make_isize(640, 480);
117 }
118
119 virtual void onDraw(SkCanvas* canvas) {
120 // test10(canvas);
121 test_rev(canvas);
122 }
123
124private:
125 typedef GM INHERITED;
126};
127
128//////////////////////////////////////////////////////////////////////////////
129
130static GM* MyFactory(void*) { return new StrokeFillGM; }
131static GMRegistry reg(MyFactory);
132
133}