Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: gm/arcto.cpp

Issue 1613303002: Add svg path arcto (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use enums for arcto's sweep and largeArc params Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/core/SkPath.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "SkParsePath.h"
10 #include "SkPath.h"
11
12 /*
13 The arcto test below should draw the same as this SVG:
14 (Note that Skia's arcTo Direction parameter value is opposite SVG's sweep value, e.g. 0 / 1)
15
16 <svg width="500" height="600">
17 <path d="M 50,100 A50,50, 0,0,1, 150,200" style="stroke:#660000; fill:none; st roke-width:2" />
18 <path d="M100,100 A50,100, 0,0,1, 200,200" style="stroke:#660000; fill:none; st roke-width:2" />
19 <path d="M150,100 A50,50, 45,0,1, 250,200" style="stroke:#660000; fill:none; st roke-width:2" />
20 <path d="M200,100 A50,100, 45,0,1, 300,200" style="stroke:#660000; fill:none; st roke-width:2" />
21
22 <path d="M150,200 A50,50, 0,1,0, 150,300" style="stroke:#660000; fill:none; st roke-width:2" />
23 <path d="M200,200 A50,100, 0,1,0, 200,300" style="stroke:#660000; fill:none; st roke-width:2" />
24 <path d="M250,200 A50,50, 45,1,0, 250,300" style="stroke:#660000; fill:none; st roke-width:2" />
25 <path d="M300,200 A50,100, 45,1,0, 300,300" style="stroke:#660000; fill:none; st roke-width:2" />
26
27 <path d="M250,400 A120,80 0 0,0 250,500"
28 fill="none" stroke="red" stroke-width="5" />
29
30 <path d="M250,400 A120,80 0 1,1 250,500"
31 fill="none" stroke="green" stroke-width="5"/>
32
33 <path d="M250,400 A120,80 0 1,0 250,500"
34 fill="none" stroke="purple" stroke-width="5"/>
35
36 <path d="M250,400 A120,80 0 0,1 250,500"
37 fill="none" stroke="blue" stroke-width="5"/>
38 </svg>
39 */
40
41 DEF_SIMPLE_GM(arcto, canvas, 500, 600) {
42 SkPaint paint;
43 paint.setAntiAlias(true);
44 paint.setStyle(SkPaint::kStroke_Style);
45 paint.setStrokeWidth(2);
46 paint.setColor(0xFF660000);
47 canvas->scale(2, 2);
48 SkRect oval = SkRect::MakeXYWH(100, 100, 100, 100);
49 SkPath svgArc;
50
51 for (int angle = 0; angle <= 45; angle += 45) {
52 for (int oHeight = 2; oHeight >= 1; --oHeight) {
53 SkScalar ovalHeight = oval.height() / oHeight;
54 svgArc.moveTo(oval.fLeft, oval.fTop);
55 svgArc.arcTo(oval.width() / 2, ovalHeight, SkIntToScalar(angle), SkP ath::kSmall_ArcSize,
56 SkPath::kCW_Direction, oval.right(), oval.bottom());
57 canvas->drawPath(svgArc, paint);
58 svgArc.reset();
59
60 svgArc.moveTo(oval.fLeft + 100, oval.fTop + 100);
61 svgArc.arcTo(oval.width() / 2, ovalHeight, SkIntToScalar(angle), SkP ath::kLarge_ArcSize,
62 SkPath::kCCW_Direction, oval.right(), oval.bottom() + 100);
63 canvas->drawPath(svgArc, paint);
64 oval.offset(50, 0);
65 svgArc.reset();
66
67 }
68 }
69
70 paint.setStrokeWidth(5);
71 const SkColor purple = 0xFF800080;
72 const SkColor darkgreen = 0xFF008000;
73 const SkColor colors[] = { SK_ColorRED, darkgreen, purple, SK_ColorBLUE };
74 const char* arcstrs[] = {
75 "M250,400 A120,80 0 0,0 250,500",
76 "M250,400 A120,80 0 1,1 250,500",
77 "M250,400 A120,80 0 1,0 250,500",
78 "M250,400 A120,80 0 0,1 250,500"
79 };
80 int cIndex = 0;
81 for (const char* arcstr : arcstrs) {
82 SkParsePath::FromSVGString(arcstr, &svgArc);
83 paint.setColor(colors[cIndex++]);
84 canvas->drawPath(svgArc, paint);
85 }
86 }
OLDNEW
« no previous file with comments | « no previous file | include/core/SkPath.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698