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

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: add int-to-float (good catch, windows!) 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') | include/core/SkPath.h » ('J')
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
15 <svg width="500" height="600">
16 <path d="M 50,100 A50,50, 0,0,1, 150,200" style="stroke:#660000; fill:none; st roke-width:2" />
17 <path d="M100,100 A50,100, 0,0,1, 200,200" style="stroke:#660000; fill:none; st roke-width:2" />
18 <path d="M150,100 A50,50, 45,0,1, 250,200" style="stroke:#660000; fill:none; st roke-width:2" />
19 <path d="M200,100 A50,100, 45,0,1, 300,200" style="stroke:#660000; fill:none; st roke-width:2" />
20
21 <path d="M150,200 A50,50, 0,1,0, 150,300" style="stroke:#660000; fill:none; st roke-width:2" />
22 <path d="M200,200 A50,100, 0,1,0, 200,300" style="stroke:#660000; fill:none; st roke-width:2" />
23 <path d="M250,200 A50,50, 45,1,0, 250,300" style="stroke:#660000; fill:none; st roke-width:2" />
24 <path d="M300,200 A50,100, 45,1,0, 300,300" style="stroke:#660000; fill:none; st roke-width:2" />
25
26 <path d="M250,400 A120,80 0 0,0 250,500"
27 fill="none" stroke="red" stroke-width="5" />
28
29 <path d="M250,400 A120,80 0 1,1 250,500"
30 fill="none" stroke="green" stroke-width="5"/>
31
32 <path d="M250,400 A120,80 0 1,0 250,500"
33 fill="none" stroke="purple" stroke-width="5"/>
34
35 <path d="M250,400 A120,80 0 0,1 250,500"
36 fill="none" stroke="blue" stroke-width="5"/>
37 </svg>
38 */
39
40 DEF_SIMPLE_GM(arcto, canvas, 500, 600) {
41 SkPaint paint;
42 paint.setAntiAlias(true);
43 paint.setStyle(SkPaint::kStroke_Style);
44 paint.setStrokeWidth(2);
45 paint.setColor(0xFF660000);
46 canvas->scale(2, 2);
47 SkRect oval = SkRect::MakeXYWH(100, 100, 100, 100);
48 SkPath svgArc;
49
50 for (int angle = 0; angle <= 45; angle += 45) {
51 for (int oHeight = 2; oHeight >= 1; --oHeight) {
52 SkScalar ovalHeight = oval.height() / oHeight;
53 svgArc.moveTo(oval.fLeft, oval.fTop);
54 svgArc.arcTo(oval.width() / 2, ovalHeight, SkIntToScalar(angle), fal se, true,
55 oval.right(), oval.bottom());
56 canvas->drawPath(svgArc, paint);
57 svgArc.reset();
58
59 svgArc.moveTo(oval.fLeft + 100, oval.fTop + 100);
60 svgArc.arcTo(oval.width() / 2, ovalHeight, SkIntToScalar(angle), tru e, false,
61 oval.right(), oval.bottom() + 100);
62 canvas->drawPath(svgArc, paint);
63 oval.offset(50, 0);
64 svgArc.reset();
65
66 }
67 }
68
69 paint.setStrokeWidth(5);
70 const SkColor purple = 0xFF800080;
71 const SkColor darkgreen = 0xFF008000;
72 const SkColor colors[] = { SK_ColorRED, darkgreen, purple, SK_ColorBLUE };
73 const char* arcstrs[] = {
74 "M250,400 A120,80 0 0,0 250,500",
75 "M250,400 A120,80 0 1,1 250,500",
76 "M250,400 A120,80 0 1,0 250,500",
77 "M250,400 A120,80 0 0,1 250,500"
78 };
79 int cIndex = 0;
80 for (const char* arcstr : arcstrs) {
81 SkParsePath::FromSVGString(arcstr, &svgArc);
82 paint.setColor(colors[cIndex++]);
83 canvas->drawPath(svgArc, paint);
84 }
85 }
OLDNEW
« no previous file with comments | « no previous file | include/core/SkPath.h » ('j') | include/core/SkPath.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698