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

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: Match addEllipse impl to addArc style. Add 4 more layout tests. Created 7 years, 5 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 void CanvasPathMethods::arc(float x, float y, float r, float sa, float ea, bool anticlockwise, ExceptionCode& ec) 133 static float adjustEndAngle(float startAngle, float endAngle, 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 && startAngle - endAngle >= 2 * piFloat)
137 return startAngle - 2 * piFloat;
138 if (!anticlockwise && endAngle - startAngle >= 2 * piFloat)
139 return startAngle + 2 * piFloat;
140 return endAngle;
141 }
142
143 void CanvasPathMethods::arc(float x, float y, float r, float startAngle, float e ndAngle, 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(startAngle) || !std::isfinite(endAngle))
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 || startAngle == endAngle) {
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(startAngle), y + r * sinf(startAngle));
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(startAngle, endAngle, anticlockwise) ;
154 if (anticlockwise && sa - ea >= 2 * piFloat) { 164 m_path.addArc(FloatPoint(x, y), r, startAngle, adjustedEndAngle, anticlockwi se);
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 endAngle, 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(endAng le))
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 == 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
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));
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
181 return;
182 }
183
184 if (!isTransformInvertible())
185 return;
186
187 float adjustedEndAngle = adjustEndAngle(sa, endAngle, anticlockwise);
188 m_path.addEllipse(FloatPoint(x, y), rx, ry, rot, sa, adjustedEndAngle, antic lockwise);
164 } 189 }
165 190
166 void CanvasPathMethods::rect(float x, float y, float width, float height) 191 void CanvasPathMethods::rect(float x, float y, float width, float height)
167 { 192 {
168 if (!isTransformInvertible()) 193 if (!isTransformInvertible())
169 return; 194 return;
170 195
171 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) || !std: :isfinite(height)) 196 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) || !std: :isfinite(height))
172 return; 197 return;
173 198
174 if (!width && !height) { 199 if (!width && !height) {
175 m_path.moveTo(FloatPoint(x, y)); 200 m_path.moveTo(FloatPoint(x, y));
176 return; 201 return;
177 } 202 }
178 203
179 m_path.addRect(FloatRect(x, y, width, height)); 204 m_path.addRect(FloatRect(x, y, width, height));
180 } 205 }
181 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698