2 * Copyright 2017 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
13 // Test thin stroked rect (stroked "by hand", not by stroking).
14 void draw_thin_stroked_rect(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
16 path.moveTo(10 + width, 10 + width);
17 path.lineTo(40, 10 + width);
19 path.lineTo(10 + width, 20);
21 path.lineTo(10, 20 + width);
22 path.lineTo(40 + width, 20 + width);
23 path.lineTo(40 + width, 10);
24 canvas->drawPath(path, paint);
27 void draw_thin_right_angle(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
29 path.moveTo(10 + width, 10 + width);
30 path.lineTo(40, 10 + width);
32 path.lineTo(40 + width, 20 + width);
33 path.lineTo(40 + width, 10);
35 canvas->drawPath(path, paint);
38 // Test thin horizontal line (<1 pixel) which should give lower alpha.
39 void draw_golf_club(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
43 path.lineTo(80, 10 + width);
44 path.lineTo(30, 10 + width);
47 canvas->drawPath(path, paint);
50 // Test thin lines between two filled regions. The outer edges overlap, but
51 // there are no inverted edges to fix.
52 void draw_barbell(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
53 SkScalar offset = width * 0.5f;
56 path.lineTo(40 - offset, 15 - offset);
57 path.lineTo(60 + offset, 15 - offset);
60 path.lineTo(60 + offset, 15 + offset);
61 path.lineTo(40 - offset, 15 + offset);
63 canvas->drawPath(path, paint);
66 // Test a thin rectangle and triangle. The top and bottom inner edges of the
67 // rectangle and all inner edges of the triangle invert on stroking.
68 void draw_thin_rect_and_triangle(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
71 path.lineTo(30 + width, 5);
72 path.lineTo(30 + width, 25);
75 path.lineTo(40 + width, 5);
77 canvas->drawPath(path, paint);
80 // Two triangles joined by a very thin bridge. The tiny triangle formed
81 // by the inner edges at the bridge is inverted.
82 // (These are actually now more phat pants than hipster pants.)
83 void draw_hipster_pants(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
87 path.lineTo(50, 10 + width);
90 canvas->drawPath(path, paint);
93 // A thin z-shape whose interior inverts on stroking. The top and bottom inner edges invert, and
94 // the connector edges at the "elbows" intersect the inner edges.
95 void draw_skinny_snake(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
97 path.moveTo(20 + width, 10);
98 path.lineTo(20 + width, 20);
99 path.lineTo(10 + width, 30);
100 path.lineTo(10 + width, 40);
101 path.lineTo(10 - width, 40);
102 path.lineTo(10 - width, 30);
103 path.lineTo(20 - width, 20);
104 path.lineTo(20 - width, 10);
105 canvas->drawPath(path, paint);
108 // Test pointy features whose outer edges extend far to the right on stroking.
109 void draw_pointy_golf_club(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
112 path.lineTo(80, 10 + width * 0.5);
113 path.lineTo(30, 10 + width);
116 canvas->drawPath(path, paint);
121 DEF_SIMPLE_GM(thinconcavepaths, canvas, 550, 400) {
124 paint.setAntiAlias(true);
125 paint.setStyle(SkPaint::kFill_Style);
128 for (SkScalar width = 0.5f; width < 2.05f; width += 0.25f) {
129 draw_thin_stroked_rect(canvas, paint, width);
130 canvas->translate(0, 25);
133 canvas->translate(50, 0);
135 for (SkScalar width = 0.5f; width < 2.05f; width += 0.25f) {
136 draw_thin_right_angle(canvas, paint, width);
137 canvas->translate(0, 25);
140 canvas->translate(40, 0);
142 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
143 draw_golf_club(canvas, paint, width);
144 canvas->translate(0, 30);
147 canvas->translate(70, 0);
149 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
150 draw_thin_rect_and_triangle(canvas, paint, width);
151 canvas->translate(0, 30);
154 canvas->translate(30, 0);
157 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
158 draw_barbell(canvas, paint, width);
159 canvas->translate(0, 30);
162 canvas->translate(80, 0);
164 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
165 draw_hipster_pants(canvas, paint, width);
166 canvas->translate(0, 30);
169 canvas->translate(100, 0);
171 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
172 draw_skinny_snake(canvas, paint, width);
173 canvas->translate(0, 30);
176 canvas->translate(30, 0);
178 for (SkScalar width = 0.2f; width < 2.1f; width += 0.2f) {
179 draw_pointy_golf_club(canvas, paint, width);
180 canvas->translate(0, 30);
183 canvas->translate(100, 0);