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

Side by Side Diff: Source/core/svg/SVGPathParser.cpp

Issue 1019853003: Add helper for computing the reflected control point for smooth segments (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2002, 2003 The Karbon Developers 2 * Copyright (C) 2002, 2003 The Karbon Developers
3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 point2 += m_currentPoint; 136 point2 += m_currentPoint;
137 targetPoint += m_currentPoint; 137 targetPoint += m_currentPoint;
138 } 138 }
139 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); 139 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
140 140
141 m_controlPoint = point2; 141 m_controlPoint = point2;
142 m_currentPoint = targetPoint; 142 m_currentPoint = targetPoint;
143 return true; 143 return true;
144 } 144 }
145 145
146 static FloatPoint reflectedPoint(const FloatPoint& reflectIn, const FloatPoint& pointToReflect)
147 {
148 return FloatPoint(2 * reflectIn.x() - pointToReflect.x(), 2 * reflectIn.y() - pointToReflect.y());
149 }
150
146 bool SVGPathParser::parseCurveToCubicSmoothSegment() 151 bool SVGPathParser::parseCurveToCubicSmoothSegment()
147 { 152 {
148 FloatPoint point2; 153 FloatPoint point2;
149 FloatPoint targetPoint; 154 FloatPoint targetPoint;
150 if (!m_source->parseCurveToCubicSmoothSegment(point2, targetPoint)) 155 if (!m_source->parseCurveToCubicSmoothSegment(point2, targetPoint))
151 return false; 156 return false;
152 157
153 if (m_pathParsingMode == UnalteredParsing) { 158 if (m_pathParsingMode == UnalteredParsing) {
154 m_consumer->curveToCubicSmooth(point2, targetPoint, m_mode); 159 m_consumer->curveToCubicSmooth(point2, targetPoint, m_mode);
155 return true; 160 return true;
156 } 161 }
157 if (m_lastCommand != PathSegCurveToCubicAbs 162 if (m_lastCommand != PathSegCurveToCubicAbs
158 && m_lastCommand != PathSegCurveToCubicRel 163 && m_lastCommand != PathSegCurveToCubicRel
159 && m_lastCommand != PathSegCurveToCubicSmoothAbs 164 && m_lastCommand != PathSegCurveToCubicSmoothAbs
160 && m_lastCommand != PathSegCurveToCubicSmoothRel) 165 && m_lastCommand != PathSegCurveToCubicSmoothRel)
161 m_controlPoint = m_currentPoint; 166 m_controlPoint = m_currentPoint;
162 167
163 FloatPoint point1 = m_currentPoint; 168 FloatPoint point1 = reflectedPoint(m_currentPoint, m_controlPoint);
164 point1.scale(2, 2);
165 point1.move(-m_controlPoint.x(), -m_controlPoint.y());
166 if (m_mode == RelativeCoordinates) { 169 if (m_mode == RelativeCoordinates) {
167 point2 += m_currentPoint; 170 point2 += m_currentPoint;
168 targetPoint += m_currentPoint; 171 targetPoint += m_currentPoint;
169 } 172 }
170 173
171 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); 174 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
172 175
173 m_controlPoint = point2; 176 m_controlPoint = point2;
174 m_currentPoint = targetPoint; 177 m_currentPoint = targetPoint;
175 return true; 178 return true;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if (m_pathParsingMode == UnalteredParsing) { 218 if (m_pathParsingMode == UnalteredParsing) {
216 m_consumer->curveToQuadraticSmooth(targetPoint, m_mode); 219 m_consumer->curveToQuadraticSmooth(targetPoint, m_mode);
217 return true; 220 return true;
218 } 221 }
219 if (m_lastCommand != PathSegCurveToQuadraticAbs 222 if (m_lastCommand != PathSegCurveToQuadraticAbs
220 && m_lastCommand != PathSegCurveToQuadraticRel 223 && m_lastCommand != PathSegCurveToQuadraticRel
221 && m_lastCommand != PathSegCurveToQuadraticSmoothAbs 224 && m_lastCommand != PathSegCurveToQuadraticSmoothAbs
222 && m_lastCommand != PathSegCurveToQuadraticSmoothRel) 225 && m_lastCommand != PathSegCurveToQuadraticSmoothRel)
223 m_controlPoint = m_currentPoint; 226 m_controlPoint = m_currentPoint;
224 227
225 FloatPoint cubicPoint = m_currentPoint; 228 FloatPoint cubicPoint = reflectedPoint(m_currentPoint, m_controlPoint);
226 cubicPoint.scale(2, 2);
227 cubicPoint.move(-m_controlPoint.x(), -m_controlPoint.y());
228 FloatPoint point1(m_currentPoint.x() + 2 * cubicPoint.x(), m_currentPoint.y( ) + 2 * cubicPoint.y()); 229 FloatPoint point1(m_currentPoint.x() + 2 * cubicPoint.x(), m_currentPoint.y( ) + 2 * cubicPoint.y());
229 FloatPoint point2(targetPoint.x() + 2 * cubicPoint.x(), targetPoint.y() + 2 * cubicPoint.y()); 230 FloatPoint point2(targetPoint.x() + 2 * cubicPoint.x(), targetPoint.y() + 2 * cubicPoint.y());
230 if (m_mode == RelativeCoordinates) { 231 if (m_mode == RelativeCoordinates) {
231 point2 += m_currentPoint; 232 point2 += m_currentPoint;
232 targetPoint += m_currentPoint; 233 targetPoint += m_currentPoint;
233 } 234 }
234 point1.scale(gOneOverThree, gOneOverThree); 235 point1.scale(gOneOverThree, gOneOverThree);
235 point2.scale(gOneOverThree, gOneOverThree); 236 point2.scale(gOneOverThree, gOneOverThree);
236 237
237 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); 238 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 point2 = targetPoint; 473 point2 = targetPoint;
473 point2.move(t * sinEndTheta, -t * cosEndTheta); 474 point2.move(t * sinEndTheta, -t * cosEndTheta);
474 475
475 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform .mapPoint(point2), 476 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform .mapPoint(point2),
476 pointTransform.mapPoint(targetPoint), AbsoluteC oordinates); 477 pointTransform.mapPoint(targetPoint), AbsoluteC oordinates);
477 } 478 }
478 return true; 479 return true;
479 } 480 }
480 481
481 } 482 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698