• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
test_path(SkCanvas * canvas,const SkPath & path)13 static void test_path(SkCanvas* canvas, const SkPath& path) {
14     SkPaint paint;
15     paint.setAntiAlias(true);
16     canvas->drawPath(path, paint);
17 
18     paint.setStyle(SkPaint::kStroke_Style);
19     paint.setColor(SK_ColorRED);
20     canvas->drawPath(path, paint);
21 }
22 
test_rev(SkCanvas * canvas,const SkPath & path)23 static 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 
test_rev(SkCanvas * canvas)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     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 
63 namespace skiagm {
64 
65 class PathReverseGM : public GM {
66 public:
PathReverseGM()67     PathReverseGM() {
68 
69     }
70 
71 protected:
onShortName()72     virtual SkString onShortName() {
73         return SkString("path-reverse");
74     }
75 
onISize()76     virtual SkISize onISize() {
77         return make_isize(640, 480);
78     }
79 
onDraw(SkCanvas * canvas)80     virtual void onDraw(SkCanvas* canvas) {
81         SkRect r = { 10, 10, 100, 60 };
82 
83         SkPath path;
84 
85         path.addRect(r); test_rev(canvas, path);
86 
87         canvas->translate(0, 100);
88         path.offset(20, 20);
89         path.addRect(r); test_rev(canvas, path);
90 
91         canvas->translate(0, 100);
92         path.reset();
93         path.moveTo(10, 10); path.lineTo(30, 30);
94         path.addOval(r);
95         r.offset(50, 20);
96         path.addOval(r);
97         test_rev(canvas, path);
98 
99         SkPaint paint;
100         paint.setTextSize(SkIntToScalar(100));
101         SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
102         SkSafeUnref(paint.setTypeface(hira));
103         path.reset();
104         paint.getTextPath("e", 1, 50, 50, &path);
105         canvas->translate(0, 100);
106         test_rev(canvas, path);
107     }
108 
109 private:
110     typedef GM INHERITED;
111 };
112 
113 //////////////////////////////////////////////////////////////////////////////
114 
MyFactory(void *)115 static GM* MyFactory(void*) { return new PathReverseGM; }
116 static GMRegistry reg(MyFactory);
117 
118 }
119