blob: 1773303f0c8d04306e15e25c43ebeb97901d59ed [file] [log] [blame]
reed@google.com8d850be2012-07-13 15:55:15 +00001/*
2 * Copyright 2012 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 "SkParsePath.h"
12#include "SkDashPathEffect.h"
13
14/*
15 * Inspired by http://code.google.com/p/chromium/issues/detail?id=112145
16 */
halcanary2a243382015-09-09 08:16:41 -070017static void flower(SkCanvas* canvas, const SkPath& path,
18 SkScalar intervals[2], SkPaint::Join join) {
caryclark6df8e342015-02-23 12:47:03 -080019 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0);
20
21 SkPaint paint;
22 paint.setAntiAlias(true);
23 paint.setStyle(SkPaint::kStroke_Style);
24 paint.setStrokeJoin(join);
25 paint.setStrokeWidth(42);
26 canvas->drawPath(path, paint);
27
28 paint.setColor(SK_ColorRED);
29 paint.setStrokeWidth(21);
30 paint.setPathEffect(pe)->unref();
31 canvas->drawPath(path, paint);
32
33 paint.setColor(SK_ColorGREEN);
halcanary96fcdcc2015-08-27 07:41:13 -070034 paint.setPathEffect(nullptr);
caryclark6df8e342015-02-23 12:47:03 -080035 paint.setStrokeWidth(0);
36 canvas->drawPath(path, paint);
halcanary2a243382015-09-09 08:16:41 -070037}
reed@google.com8d850be2012-07-13 15:55:15 +000038
halcanary2a243382015-09-09 08:16:41 -070039DEF_SIMPLE_GM(dashcubics, canvas, 860, 700) {
reed@google.com8d850be2012-07-13 15:55:15 +000040 SkPath path;
41 const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 250,212"
42 "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231"
43 "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250"
44 "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269"
45 "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288"
46 "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269"
47 "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250"
48 "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231"
49 "C 283,231 344,195 338,98";
50
51 SkParsePath::FromSVGString(d, &path);
caryclark6df8e342015-02-23 12:47:03 -080052 canvas->translate(-35.f, -55.f);
53 for (int x = 0; x < 2; ++x) {
54 for (int y = 0; y < 2; ++y) {
55 canvas->save();
56 canvas->translate(x * 430.f, y * 355.f);
57 SkScalar intervals[] = { 5 + (x ? 0 : 0.0001f + 0.0001f), 10 };
58 flower(canvas, path, intervals, y ? SkPaint::kDefault_Join : SkPaint::kRound_Join);
59 canvas->restore();
60 }
61 }
halcanary2a243382015-09-09 08:16:41 -070062}