aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-01-25 05:39:04 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-25 05:39:04 -0800
commitfc75253c82f838d0e687d05f5d7f82ebe6f26d5b (patch)
tree44f440615c5c001a844abba5e64315d98913a798
parent6bd8639f8c142eedf543f4e5f3b02d2bf11df308 (diff)
fix arcto exception handling
To match SVG behavior, draw a line when either radius is zero, or when the end point equals the start point. Update the GM to include these tests, and take the scale used to test it on a highres display. R=fmalita@chromium.org BUG=skia:4849 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1627423002 Review URL: https://codereview.chromium.org/1627423002
-rw-r--r--gm/arcto.cpp20
-rw-r--r--src/core/SkPath.cpp2
2 files changed, 21 insertions, 1 deletions
diff --git a/gm/arcto.cpp b/gm/arcto.cpp
index 900c6b30ea..aac9bde1b3 100644
--- a/gm/arcto.cpp
+++ b/gm/arcto.cpp
@@ -35,6 +35,12 @@ The arcto test below should draw the same as this SVG:
<path d="M250,400 A120,80 0 0,1 250,500"
fill="none" stroke="blue" stroke-width="5"/>
+
+<path d="M100,100 A 0, 0 0 0,1 200,200"
+ fill="none" stroke="blue" stroke-width="5" stroke-linecap="round"/>
+
+<path d="M200,100 A 80,80 0 0,1 200,100"
+ fill="none" stroke="blue" stroke-width="5" stroke-linecap="round"/>
</svg>
*/
@@ -44,7 +50,7 @@ DEF_SIMPLE_GM(arcto, canvas, 500, 600) {
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2);
paint.setColor(0xFF660000);
- canvas->scale(2, 2);
+// canvas->scale(2, 2); // for testing on retina
SkRect oval = SkRect::MakeXYWH(100, 100, 100, 100);
SkPath svgArc;
@@ -83,4 +89,16 @@ DEF_SIMPLE_GM(arcto, canvas, 500, 600) {
paint.setColor(colors[cIndex++]);
canvas->drawPath(svgArc, paint);
}
+
+ // test that zero length arcs still draw round cap
+ paint.setStrokeCap(SkPaint::kRound_Cap);
+ SkPath path;
+ path.moveTo(100, 100);
+ path.arcTo(0, 0, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 200);
+ canvas->drawPath(path, paint);
+
+ path.reset();
+ path.moveTo(200, 100);
+ path.arcTo(80, 80, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 100);
+ canvas->drawPath(path, paint);
}
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 40ca50b5ca..75a4cdcd7a 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -1271,12 +1271,14 @@ void SkPath::arcTo(SkScalar rx, SkScalar ry, SkScalar angle, SkPath::ArcSize arc
// joining the endpoints.
// http://www.w3.org/TR/SVG/implnote.html#ArcOutOfRangeParameters
if (!rx || !ry) {
+ this->lineTo(x, y);
return;
}
// If the current point and target point for the arc are identical, it should be treated as a
// zero length path. This ensures continuity in animations.
srcPts[1].set(x, y);
if (srcPts[0] == srcPts[1]) {
+ this->lineTo(x, y);
return;
}
rx = SkScalarAbs(rx);