schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 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 | */ |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkFont.h" |
| 12 | #include "include/core/SkMatrix.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkPaint.h" |
| 14 | #include "include/core/SkPath.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 15 | #include "include/core/SkPoint.h" |
| 16 | #include "include/core/SkRect.h" |
| 17 | #include "include/core/SkScalar.h" |
| 18 | #include "include/core/SkSize.h" |
| 19 | #include "include/core/SkString.h" |
| 20 | #include "include/core/SkTypeface.h" |
| 21 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "include/utils/SkRandom.h" |
| 23 | #include "tools/ToolUtils.h" |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 24 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 25 | // https://bug.skia.org/1316 shows that this cubic, when slightly clipped, creates big |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 26 | // (incorrect) changes to its control points. |
| 27 | class ClippedCubicGM : public skiagm::GM { |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 28 | SkString onShortName() override { return SkString("clippedcubic"); } |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 29 | |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 30 | SkISize onISize() override { return {1240, 390}; } |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 31 | |
John Stiles | 1cf2c8d | 2020-08-13 22:58:04 -0400 | [diff] [blame] | 32 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 33 | SkPath path; |
| 34 | path.moveTo(0, 0); |
| 35 | path.cubicTo(140, 150, 40, 10, 170, 150); |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 36 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 37 | SkPaint paint; |
| 38 | SkRect bounds = path.getBounds(); |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 39 | |
reed@google.com | 0f8990c | 2013-05-23 19:47:05 +0000 | [diff] [blame] | 40 | for (SkScalar dy = -1; dy <= 1; dy += 1) { |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 41 | canvas->save(); |
reed@google.com | 0f8990c | 2013-05-23 19:47:05 +0000 | [diff] [blame] | 42 | for (SkScalar dx = -1; dx <= 1; dx += 1) { |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 43 | canvas->save(); |
| 44 | canvas->clipRect(bounds); |
| 45 | canvas->translate(dx, dy); |
| 46 | canvas->drawPath(path, paint); |
| 47 | canvas->restore(); |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 48 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 49 | canvas->translate(bounds.width(), 0); |
| 50 | } |
| 51 | canvas->restore(); |
| 52 | canvas->translate(0, bounds.height()); |
| 53 | } |
| 54 | } |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 57 | |
| 58 | class ClippedCubic2GM : public skiagm::GM { |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 59 | SkString onShortName() override { return SkString("clippedcubic2"); } |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 60 | |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 61 | SkISize onISize() override { return {1240, 390}; } |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 62 | |
| 63 | void onDraw(SkCanvas* canvas) override { |
| 64 | canvas->save(); |
caryclark | 05424f7 | 2015-08-20 10:35:43 -0700 | [diff] [blame] | 65 | canvas->translate(-2, 120); |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 66 | drawOne(canvas, fPath, SkRect::MakeLTRB(0, 0, 80, 150)); |
| 67 | canvas->translate(0, 170); |
| 68 | drawOne(canvas, fPath, SkRect::MakeLTRB(0, 0, 80, 100)); |
| 69 | canvas->translate(0, 170); |
| 70 | drawOne(canvas, fPath, SkRect::MakeLTRB(0, 0, 30, 150)); |
| 71 | canvas->translate(0, 170); |
| 72 | drawOne(canvas, fPath, SkRect::MakeLTRB(0, 0, 10, 150)); |
| 73 | canvas->restore(); |
caryclark | 05424f7 | 2015-08-20 10:35:43 -0700 | [diff] [blame] | 74 | canvas->save(); |
| 75 | canvas->translate(20, -2); |
| 76 | drawOne(canvas, fFlipped, SkRect::MakeLTRB(0, 0, 150, 80)); |
| 77 | canvas->translate(170, 0); |
| 78 | drawOne(canvas, fFlipped, SkRect::MakeLTRB(0, 0, 100, 80)); |
| 79 | canvas->translate(170, 0); |
| 80 | drawOne(canvas, fFlipped, SkRect::MakeLTRB(0, 0, 150, 30)); |
| 81 | canvas->translate(170, 0); |
| 82 | drawOne(canvas, fFlipped, SkRect::MakeLTRB(0, 0, 150, 10)); |
| 83 | canvas->restore(); |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void drawOne(SkCanvas* canvas, const SkPath& path, const SkRect& clip) { |
| 87 | SkPaint framePaint, fillPaint; |
| 88 | framePaint.setStyle(SkPaint::kStroke_Style); |
| 89 | canvas->drawRect(clip, framePaint); |
| 90 | canvas->drawPath(path, framePaint); |
| 91 | canvas->save(); |
| 92 | canvas->clipRect(clip); |
| 93 | canvas->drawPath(path, fillPaint); |
| 94 | canvas->restore(); |
| 95 | } |
| 96 | |
| 97 | void onOnceBeforeDraw() override { |
| 98 | fPath.moveTo(69.7030518991886f, 0); |
| 99 | fPath.cubicTo( 69.7030518991886f, 21.831149999999997f, |
| 100 | 58.08369508178456f, 43.66448333333333f, 34.8449814469765f, 65.5f); |
| 101 | fPath.cubicTo( 11.608591683531916f, 87.33115f, -0.010765133872116195f, 109.16448333333332f, |
| 102 | -0.013089005235602302f, 131); |
| 103 | fPath.close(); |
caryclark | 05424f7 | 2015-08-20 10:35:43 -0700 | [diff] [blame] | 104 | fFlipped = fPath; |
| 105 | SkMatrix matrix; |
| 106 | matrix.reset(); |
| 107 | matrix.setScaleX(0); |
| 108 | matrix.setScaleY(0); |
| 109 | matrix.setSkewX(1); |
| 110 | matrix.setSkewY(1); |
| 111 | fFlipped.transform(matrix); |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | SkPath fPath; |
caryclark | 05424f7 | 2015-08-20 10:35:43 -0700 | [diff] [blame] | 115 | SkPath fFlipped; |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 116 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 117 | using INHERITED = skiagm::GM; |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 121 | class CubicPathGM : public skiagm::GM { |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 122 | SkString onShortName() override { return SkString("cubicpath"); } |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 123 | |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 124 | SkISize onISize() override { return {1240, 390}; } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 125 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 126 | void drawPath(SkPath& path,SkCanvas* canvas,SkColor color, |
| 127 | const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join, |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 128 | SkPaint::Style style, SkPathFillType fill, |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 129 | SkScalar strokeWidth) { |
| 130 | path.setFillType(fill); |
| 131 | SkPaint paint; |
| 132 | paint.setStrokeCap(cap); |
| 133 | paint.setStrokeWidth(strokeWidth); |
| 134 | paint.setStrokeJoin(join); |
| 135 | paint.setColor(color); |
| 136 | paint.setStyle(style); |
| 137 | canvas->save(); |
| 138 | canvas->clipRect(clip); |
| 139 | canvas->drawPath(path, paint); |
| 140 | canvas->restore(); |
| 141 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 142 | |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 143 | void onDraw(SkCanvas* canvas) override { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 144 | struct FillAndName { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 145 | SkPathFillType fFill; |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 146 | const char* fName; |
| 147 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 148 | constexpr FillAndName gFills[] = { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 149 | {SkPathFillType::kWinding, "Winding"}, |
| 150 | {SkPathFillType::kEvenOdd, "Even / Odd"}, |
| 151 | {SkPathFillType::kInverseWinding, "Inverse Winding"}, |
| 152 | {SkPathFillType::kInverseEvenOdd, "Inverse Even / Odd"}, |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 153 | }; |
| 154 | struct StyleAndName { |
| 155 | SkPaint::Style fStyle; |
| 156 | const char* fName; |
| 157 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 158 | constexpr StyleAndName gStyles[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 159 | {SkPaint::kFill_Style, "Fill"}, |
| 160 | {SkPaint::kStroke_Style, "Stroke"}, |
| 161 | {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, |
| 162 | }; |
| 163 | struct CapAndName { |
| 164 | SkPaint::Cap fCap; |
| 165 | SkPaint::Join fJoin; |
| 166 | const char* fName; |
| 167 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 168 | constexpr CapAndName gCaps[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 169 | {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
| 170 | {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
| 171 | {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
| 172 | }; |
| 173 | struct PathAndName { |
| 174 | SkPath fPath; |
| 175 | const char* fName; |
| 176 | }; |
| 177 | PathAndName path; |
| 178 | path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1); |
| 179 | path.fPath.cubicTo(40*SK_Scalar1, 20*SK_Scalar1, |
| 180 | 60*SK_Scalar1, 20*SK_Scalar1, |
| 181 | 75*SK_Scalar1, 10*SK_Scalar1); |
| 182 | path.fName = "moveTo-cubic"; |
| 183 | |
| 184 | SkPaint titlePaint; |
| 185 | titlePaint.setColor(SK_ColorBLACK); |
| 186 | titlePaint.setAntiAlias(true); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 187 | SkFont font(ToolUtils::create_portable_typeface(), 15); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 188 | const char title[] = "Cubic Drawn Into Rectangle Clips With " |
| 189 | "Indicated Style, Fill and Linecaps, with stroke width 10"; |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 190 | canvas->drawString(title, 20, 20, font, titlePaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 191 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 192 | SkRandom rand; |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 193 | SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1); |
| 194 | canvas->save(); |
| 195 | canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1); |
| 196 | canvas->save(); |
| 197 | for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 198 | if (0 < cap) { |
| 199 | canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0); |
| 200 | } |
| 201 | canvas->save(); |
| 202 | for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 203 | if (0 < fill) { |
| 204 | canvas->translate(0, rect.height() + 40 * SK_Scalar1); |
| 205 | } |
| 206 | canvas->save(); |
| 207 | for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 208 | if (0 < style) { |
| 209 | canvas->translate(rect.width() + 40 * SK_Scalar1, 0); |
| 210 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 211 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 212 | SkColor color = 0xff007000; |
| 213 | this->drawPath(path.fPath, canvas, color, rect, |
| 214 | gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle, |
| 215 | gFills[fill].fFill, SK_Scalar1*10); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 216 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 217 | SkPaint rectPaint; |
| 218 | rectPaint.setColor(SK_ColorBLACK); |
| 219 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 220 | rectPaint.setStrokeWidth(-1); |
| 221 | rectPaint.setAntiAlias(true); |
| 222 | canvas->drawRect(rect, rectPaint); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 223 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 224 | SkPaint labelPaint; |
| 225 | labelPaint.setColor(color); |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 226 | font.setSize(10); |
| 227 | canvas->drawString(gStyles[style].fName, 0, rect.height() + 12, font, labelPaint); |
| 228 | canvas->drawString(gFills[fill].fName, 0, rect.height() + 24, font, labelPaint); |
| 229 | canvas->drawString(gCaps[cap].fName, 0, rect.height() + 36, font, labelPaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 230 | } |
| 231 | canvas->restore(); |
| 232 | } |
| 233 | canvas->restore(); |
| 234 | } |
| 235 | canvas->restore(); |
| 236 | canvas->restore(); |
| 237 | } |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 238 | }; |
| 239 | |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 240 | class CubicClosePathGM : public skiagm::GM { |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 241 | SkString onShortName() override { return SkString("cubicclosepath"); } |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 242 | |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 243 | SkISize onISize() override { return {1240, 390}; } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 244 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 245 | void drawPath(SkPath& path,SkCanvas* canvas,SkColor color, |
| 246 | const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join, |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 247 | SkPaint::Style style, SkPathFillType fill, |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 248 | SkScalar strokeWidth) { |
| 249 | path.setFillType(fill); |
| 250 | SkPaint paint; |
| 251 | paint.setStrokeCap(cap); |
| 252 | paint.setStrokeWidth(strokeWidth); |
| 253 | paint.setStrokeJoin(join); |
| 254 | paint.setColor(color); |
| 255 | paint.setStyle(style); |
| 256 | canvas->save(); |
| 257 | canvas->clipRect(clip); |
| 258 | canvas->drawPath(path, paint); |
| 259 | canvas->restore(); |
| 260 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 261 | |
John Stiles | 1cf2c8d | 2020-08-13 22:58:04 -0400 | [diff] [blame] | 262 | void onDraw(SkCanvas* canvas) override { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 263 | struct FillAndName { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 264 | SkPathFillType fFill; |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 265 | const char* fName; |
| 266 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 267 | constexpr FillAndName gFills[] = { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 268 | {SkPathFillType::kWinding, "Winding"}, |
| 269 | {SkPathFillType::kEvenOdd, "Even / Odd"}, |
| 270 | {SkPathFillType::kInverseWinding, "Inverse Winding"}, |
| 271 | {SkPathFillType::kInverseEvenOdd, "Inverse Even / Odd"}, |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 272 | }; |
| 273 | struct StyleAndName { |
| 274 | SkPaint::Style fStyle; |
| 275 | const char* fName; |
| 276 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 277 | constexpr StyleAndName gStyles[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 278 | {SkPaint::kFill_Style, "Fill"}, |
| 279 | {SkPaint::kStroke_Style, "Stroke"}, |
| 280 | {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, |
| 281 | }; |
| 282 | struct CapAndName { |
| 283 | SkPaint::Cap fCap; |
| 284 | SkPaint::Join fJoin; |
| 285 | const char* fName; |
| 286 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 287 | constexpr CapAndName gCaps[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 288 | {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
| 289 | {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
| 290 | {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
| 291 | }; |
| 292 | struct PathAndName { |
| 293 | SkPath fPath; |
| 294 | const char* fName; |
| 295 | }; |
| 296 | PathAndName path; |
| 297 | path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1); |
| 298 | path.fPath.cubicTo(40*SK_Scalar1, 20*SK_Scalar1, |
| 299 | 60*SK_Scalar1, 20*SK_Scalar1, |
| 300 | 75*SK_Scalar1, 10*SK_Scalar1); |
| 301 | path.fPath.close(); |
| 302 | path.fName = "moveTo-cubic-close"; |
| 303 | |
| 304 | SkPaint titlePaint; |
| 305 | titlePaint.setColor(SK_ColorBLACK); |
| 306 | titlePaint.setAntiAlias(true); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 307 | SkFont font(ToolUtils::create_portable_typeface(), 15); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 308 | const char title[] = "Cubic Closed Drawn Into Rectangle Clips With " |
| 309 | "Indicated Style, Fill and Linecaps, with stroke width 10"; |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 310 | canvas->drawString(title, 20, 20, font, titlePaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 311 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 312 | SkRandom rand; |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 313 | SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1); |
| 314 | canvas->save(); |
| 315 | canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1); |
| 316 | canvas->save(); |
| 317 | for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 318 | if (0 < cap) { |
| 319 | canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0); |
| 320 | } |
| 321 | canvas->save(); |
| 322 | for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 323 | if (0 < fill) { |
| 324 | canvas->translate(0, rect.height() + 40 * SK_Scalar1); |
| 325 | } |
| 326 | canvas->save(); |
| 327 | for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 328 | if (0 < style) { |
| 329 | canvas->translate(rect.width() + 40 * SK_Scalar1, 0); |
| 330 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 331 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 332 | SkColor color = 0xff007000; |
| 333 | this->drawPath(path.fPath, canvas, color, rect, |
| 334 | gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle, |
| 335 | gFills[fill].fFill, SK_Scalar1*10); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 336 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 337 | SkPaint rectPaint; |
| 338 | rectPaint.setColor(SK_ColorBLACK); |
| 339 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 340 | rectPaint.setStrokeWidth(-1); |
| 341 | rectPaint.setAntiAlias(true); |
| 342 | canvas->drawRect(rect, rectPaint); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 343 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 344 | SkPaint labelPaint; |
| 345 | labelPaint.setColor(color); |
| 346 | labelPaint.setAntiAlias(true); |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 347 | font.setSize(10); |
| 348 | canvas->drawString(gStyles[style].fName, 0, rect.height() + 12, font, labelPaint); |
| 349 | canvas->drawString(gFills[fill].fName, 0, rect.height() + 24, font, labelPaint); |
| 350 | canvas->drawString(gCaps[cap].fName, 0, rect.height() + 36, font, labelPaint); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 351 | } |
| 352 | canvas->restore(); |
| 353 | } |
| 354 | canvas->restore(); |
| 355 | } |
| 356 | canvas->restore(); |
| 357 | canvas->restore(); |
| 358 | } |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 359 | }; |
| 360 | |
caryclark | 4693a17 | 2016-04-06 08:54:06 -0700 | [diff] [blame] | 361 | DEF_SIMPLE_GM(bug5099, canvas, 50, 50) { |
| 362 | SkPaint p; |
| 363 | p.setColor(SK_ColorRED); |
| 364 | p.setAntiAlias(true); |
| 365 | p.setStyle(SkPaint::kStroke_Style); |
| 366 | p.setStrokeWidth(10); |
| 367 | |
| 368 | SkPath path; |
| 369 | path.moveTo(6, 27); |
| 370 | path.cubicTo(31.5f, 1.5f, 3.5f, 4.5f, 29, 29); |
| 371 | canvas->drawPath(path, p); |
| 372 | } |
| 373 | |
Cary Clark | d463198 | 2017-01-05 12:08:38 -0500 | [diff] [blame] | 374 | DEF_SIMPLE_GM(bug6083, canvas, 100, 50) { |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 375 | SkPaint p; |
| 376 | p.setColor(SK_ColorRED); |
| 377 | p.setAntiAlias(true); |
| 378 | p.setStyle(SkPaint::kStroke_Style); |
| 379 | p.setStrokeWidth(15); |
| 380 | canvas->translate(-500, -130); |
| 381 | SkPath path; |
| 382 | path.moveTo(500.988f, 155.200f); |
| 383 | path.lineTo(526.109f, 155.200f); |
| 384 | SkPoint p1 = { 526.109f, 155.200f }; |
| 385 | SkPoint p2 = { 525.968f, 212.968f }; |
| 386 | SkPoint p3 = { 526.109f, 241.840f }; |
| 387 | path.cubicTo(p1, p2, p3); |
| 388 | canvas->drawPath(path, p); |
| 389 | canvas->translate(50, 0); |
| 390 | path.reset(); |
| 391 | p2.set(525.968f, 213.172f); |
| 392 | path.moveTo(500.988f, 155.200f); |
| 393 | path.lineTo(526.109f, 155.200f); |
| 394 | path.cubicTo(p1, p2, p3); |
| 395 | canvas->drawPath(path, p); |
Cary Clark | d463198 | 2017-01-05 12:08:38 -0500 | [diff] [blame] | 396 | } |
| 397 | |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 398 | ////////////////////////////////////////////////////////////////////////////// |
| 399 | |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 400 | DEF_GM( return new CubicPathGM; ) |
| 401 | DEF_GM( return new CubicClosePathGM; ) |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 402 | DEF_GM( return new ClippedCubicGM; ) |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 403 | DEF_GM( return new ClippedCubic2GM; ) |