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

Side by Side Diff: Source/core/html/canvas/CanvasPathMethods.cpp

Issue 14298022: Add support for new canvas ellipse method. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012 Intel Corporation. All rights reserved.
9 * Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 FloatPoint p2 = FloatPoint(x2, y2); 123 FloatPoint p2 = FloatPoint(x2, y2);
124 124
125 if (!m_path.hasCurrentPoint()) 125 if (!m_path.hasCurrentPoint())
126 m_path.moveTo(p1); 126 m_path.moveTo(p1);
127 else if (p1 == m_path.currentPoint() || p1 == p2 || !r) 127 else if (p1 == m_path.currentPoint() || p1 == p2 || !r)
128 lineTo(x1, y1); 128 lineTo(x1, y1);
129 else 129 else
130 m_path.addArcTo(p1, p2, r); 130 m_path.addArcTo(p1, p2, r);
131 } 131 }
132 132
133 static float adjustEndAngle(float sa, float ea, bool anticlockwise)
134 {
135 // If 'sa' and 'ea' differ by more than 2Pi, just add a circle starting/endi ng at 'sa'.
136 if (anticlockwise && sa - ea >= 2 * piFloat)
137 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
138 if (!anticlockwise && ea - sa >= 2 * piFloat)
139 return sa + 2 * piFloat;
140 return ea;
141 }
142
133 void CanvasPathMethods::arc(float x, float y, float r, float sa, float ea, bool anticlockwise, ExceptionCode& ec) 143 void CanvasPathMethods::arc(float x, float y, float r, float sa, float ea, bool anticlockwise, ExceptionCode& ec)
134 { 144 {
135 ec = 0; 145 ec = 0;
136 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(r) || !std::isf inite(sa) || !std::isfinite(ea)) 146 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(r) || !std::isf inite(sa) || !std::isfinite(ea))
137 return; 147 return;
138 148
139 if (r < 0) { 149 if (r < 0) {
140 ec = INDEX_SIZE_ERR; 150 ec = INDEX_SIZE_ERR;
141 return; 151 return;
142 } 152 }
143 153
144 if (!r || sa == ea) { 154 if (!r || sa == ea) {
145 // The arc is empty but we still need to draw the connecting line. 155 // The arc is empty but we still need to draw the connecting line.
146 lineTo(x + r * cosf(sa), y + r * sinf(sa)); 156 lineTo(x + r * cosf(sa), y + r * sinf(sa));
147 return; 157 return;
148 } 158 }
149 159
150 if (!isTransformInvertible()) 160 if (!isTransformInvertible())
151 return; 161 return;
152 162
153 // If 'sa' and 'ea' differ by more than 2Pi, just add a circle starting/endi ng at 'sa'. 163 float adjustedEndAngle = adjustEndAngle(sa, ea, anticlockwise);
154 if (anticlockwise && sa - ea >= 2 * piFloat) { 164 m_path.addArc(FloatPoint(x, y), r, sa, adjustedEndAngle, anticlockwise);
155 m_path.addArc(FloatPoint(x, y), r, sa, sa - 2 * piFloat, anticlockwise); 165 }
166
167 void CanvasPathMethods::ellipse(float x, float y, float rx, float ry, float rot, float sa, float ea, bool anticlockwise, ExceptionCode& ec)
168 {
169 ec = 0;
170 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(rx) || !std::is finite(ry) || !std::isfinite(rot) || !std::isfinite(sa) || !std::isfinite(ea))
156 return; 171 return;
157 } 172
158 if (!anticlockwise && ea - sa >= 2 * piFloat) { 173 if (rx < 0 || ry < 0) {
159 m_path.addArc(FloatPoint(x, y), r, sa, sa + 2 * piFloat, anticlockwise); 174 ec = INDEX_SIZE_ERR;
160 return; 175 return;
161 } 176 }
162 177
163 m_path.addArc(FloatPoint(x, y), r, sa, ea, anticlockwise); 178 if (!rx || !ry || sa == ea) {
179 // The ellipse is empty but we still need to draw the connecting line to start point.
180 lineTo(x + rx * cosf(sa + rot), y + rx * sinf(sa + rot));
181 return;
182 }
183
184 if (!isTransformInvertible())
185 return;
186
187 float adjustedEndAngle = adjustEndAngle(sa, ea, anticlockwise);
188 m_path.addEllipse(FloatPoint(x, y), rx, ry, rot, sa, adjustedEndAngle, antic lockwise);
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
164 } 189 }
165 190
191
192
166 void CanvasPathMethods::rect(float x, float y, float width, float height) 193 void CanvasPathMethods::rect(float x, float y, float width, float height)
167 { 194 {
168 if (!isTransformInvertible()) 195 if (!isTransformInvertible())
169 return; 196 return;
170 197
171 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) || !std: :isfinite(height)) 198 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) || !std: :isfinite(height))
172 return; 199 return;
173 200
174 if (!width && !height) { 201 if (!width && !height) {
175 m_path.moveTo(FloatPoint(x, y)); 202 m_path.moveTo(FloatPoint(x, y));
176 return; 203 return;
177 } 204 }
178 205
179 m_path.addRect(FloatRect(x, y, width, height)); 206 m_path.addRect(FloatRect(x, y, width, height));
180 } 207 }
181 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698