Index: Source/core/html/canvas/CanvasPathMethods.cpp |
diff --git a/Source/core/html/canvas/CanvasPathMethods.cpp b/Source/core/html/canvas/CanvasPathMethods.cpp |
index 5053696562cb38d7d19c84453fc190fb0964628e..5ea30de9a4d2158e44de10ef4aa9dfa25e885762 100644 |
--- a/Source/core/html/canvas/CanvasPathMethods.cpp |
+++ b/Source/core/html/canvas/CanvasPathMethods.cpp |
@@ -130,6 +130,16 @@ void CanvasPathMethods::arcTo(float x1, float y1, float x2, float y2, float r, E |
m_path.addArcTo(p1, p2, r); |
} |
+static float adjustEndAngle(float sa, float ea, bool anticlockwise) |
+{ |
+ // If 'sa' and 'ea' differ by more than 2Pi, just add a circle starting/ending at 'sa'. |
+ if (anticlockwise && sa - ea >= 2 * piFloat) |
+ return sa - 2 * piFloat; |
Stephen Chennney
2013/04/26 14:51:03
This is not correct. If they differ by more than 4
Stephen Chennney
2013/04/26 14:57:56
I see, it is correct according to the spec. But th
|
+ if (!anticlockwise && ea - sa >= 2 * piFloat) |
+ return sa + 2 * piFloat; |
+ return ea; |
+} |
+ |
void CanvasPathMethods::arc(float x, float y, float r, float sa, float ea, bool anticlockwise, ExceptionCode& ec) |
{ |
ec = 0; |
@@ -150,19 +160,36 @@ void CanvasPathMethods::arc(float x, float y, float r, float sa, float ea, bool |
if (!isTransformInvertible()) |
return; |
- // If 'sa' and 'ea' differ by more than 2Pi, just add a circle starting/ending at 'sa'. |
- if (anticlockwise && sa - ea >= 2 * piFloat) { |
- m_path.addArc(FloatPoint(x, y), r, sa, sa - 2 * piFloat, anticlockwise); |
+ float adjustedEndAngle = adjustEndAngle(sa, ea, anticlockwise); |
+ m_path.addArc(FloatPoint(x, y), r, sa, adjustedEndAngle, anticlockwise); |
+} |
+ |
+void CanvasPathMethods::ellipse(float x, float y, float rx, float ry, float rot, float sa, float ea, bool anticlockwise, ExceptionCode& ec) |
+{ |
+ ec = 0; |
+ if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(rx) || !std::isfinite(ry) || !std::isfinite(rot) || !std::isfinite(sa) || !std::isfinite(ea)) |
+ return; |
+ |
+ if (rx < 0 || ry < 0) { |
+ ec = INDEX_SIZE_ERR; |
return; |
} |
- if (!anticlockwise && ea - sa >= 2 * piFloat) { |
- m_path.addArc(FloatPoint(x, y), r, sa, sa + 2 * piFloat, anticlockwise); |
+ |
+ if (!rx || !ry || sa == ea) { |
+ // The ellipse is empty but we still need to draw the connecting line to start point. |
+ lineTo(x + rx * cosf(sa + rot), y + rx * sinf(sa + rot)); |
return; |
} |
- m_path.addArc(FloatPoint(x, y), r, sa, ea, anticlockwise); |
+ if (!isTransformInvertible()) |
+ return; |
+ |
+ float adjustedEndAngle = adjustEndAngle(sa, ea, anticlockwise); |
+ m_path.addEllipse(FloatPoint(x, y), rx, ry, rot, sa, adjustedEndAngle, anticlockwise); |
Stephen Chennney
2013/04/26 14:51:03
You should catch the common case of an entire elli
dshwang
2013/04/26 15:23:33
Thank you for review, Stephen. Yes, your opinion i
Stephen Chennney
2013/04/26 16:02:04
You can certainly change both ellipse and arc. I'm
|
} |
+ |
+ |
void CanvasPathMethods::rect(float x, float y, float width, float height) |
{ |
if (!isTransformInvertible()) |