Chromium Code Reviews| Index: Source/core/html/canvas/CanvasPathMethods.cpp |
| diff --git a/Source/core/html/canvas/CanvasPathMethods.cpp b/Source/core/html/canvas/CanvasPathMethods.cpp |
| index 0226af21d52095cce66cdd6c9ba0d00b2dd05aa8..0b8610a1fd3d717f4eb8013f7020d8f84f68ac9d 100644 |
| --- a/Source/core/html/canvas/CanvasPathMethods.cpp |
| +++ b/Source/core/html/canvas/CanvasPathMethods.cpp |
| @@ -130,10 +130,20 @@ void CanvasPathMethods::arcTo(float x1, float y1, float x2, float y2, float r, E |
| m_path.addArcTo(p1, p2, r); |
| } |
| -void CanvasPathMethods::arc(float x, float y, float r, float sa, float ea, bool anticlockwise, ExceptionCode& ec) |
| +static float adjustEndAngle(float startAngle, float endAngle, bool anticlockwise) |
| +{ |
| + // If 'sa' and 'ea' differ by more than 2Pi, just add a circle starting/ending at 'sa'. |
| + if (anticlockwise && startAngle - endAngle >= 2 * piFloat) |
| + return startAngle - 2 * piFloat; |
| + if (!anticlockwise && endAngle - startAngle >= 2 * piFloat) |
| + return startAngle + 2 * piFloat; |
| + return endAngle; |
| +} |
| + |
| +void CanvasPathMethods::arc(float x, float y, float r, float startAngle, float endAngle, bool anticlockwise, ExceptionCode& ec) |
| { |
| ec = 0; |
| - if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(r) || !std::isfinite(sa) || !std::isfinite(ea)) |
| + if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(r) || !std::isfinite(startAngle) || !std::isfinite(endAngle)) |
| return; |
| if (r < 0) { |
| @@ -141,26 +151,41 @@ void CanvasPathMethods::arc(float x, float y, float r, float sa, float ea, bool |
| return; |
| } |
| - if (!r || sa == ea) { |
| + if (!r || startAngle == endAngle) { |
| // The arc is empty but we still need to draw the connecting line. |
| - lineTo(x + r * cosf(sa), y + r * sinf(sa)); |
| + lineTo(x + r * cosf(startAngle), y + r * sinf(startAngle)); |
| return; |
| } |
| 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(startAngle, endAngle, anticlockwise); |
| + m_path.addArc(FloatPoint(x, y), r, startAngle, adjustedEndAngle, anticlockwise); |
| +} |
| + |
| +void CanvasPathMethods::ellipse(float x, float y, float rx, float ry, float rot, float sa, float endAngle, 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(endAngle)) |
| + 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 == endAngle) { |
|
aandrey
2013/07/09 13:49:56
sa -> startAngle
dshwang
2013/07/09 14:42:05
oops, thx!
alph
2013/07/09 14:43:09
If one of radii is not zero I'd expect the stroked
|
| + // 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)); |
|
alph
2013/07/09 14:16:00
rx used twice here.
Also I suppose rotation should
dshwang
2013/07/09 14:42:05
thx for review. Yeah, using rx twice is wrong.
ho
alph
2013/07/09 15:16:35
I don't like it. It works for arc because its radi
|
| return; |
| } |
| - m_path.addArc(FloatPoint(x, y), r, sa, ea, anticlockwise); |
| + if (!isTransformInvertible()) |
| + return; |
| + |
| + float adjustedEndAngle = adjustEndAngle(sa, endAngle, anticlockwise); |
| + m_path.addEllipse(FloatPoint(x, y), rx, ry, rot, sa, adjustedEndAngle, anticlockwise); |
| } |
| void CanvasPathMethods::rect(float x, float y, float width, float height) |