| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "config.h" | 24 #include "config.h" |
| 25 #include "core/svg/SVGPathParser.h" | 25 #include "core/svg/SVGPathParser.h" |
| 26 | 26 |
| 27 #include "core/svg/SVGPathSource.h" | 27 #include "core/svg/SVGPathSource.h" |
| 28 #include "platform/transforms/AffineTransform.h" | 28 #include "platform/transforms/AffineTransform.h" |
| 29 #include "wtf/MathExtras.h" | 29 #include "wtf/MathExtras.h" |
| 30 | 30 |
| 31 static const float gOneOverThree = 1 / 3.f; | |
| 32 | |
| 33 namespace blink { | 31 namespace blink { |
| 34 | 32 |
| 35 DEFINE_TRACE(SVGPathParser) | 33 DEFINE_TRACE(SVGPathParser) |
| 36 { | 34 { |
| 37 visitor->trace(m_source); | 35 visitor->trace(m_source); |
| 38 visitor->trace(m_consumer); | 36 visitor->trace(m_consumer); |
| 39 } | 37 } |
| 40 | 38 |
| 41 void SVGPathParser::parseClosePathSegment() | 39 void SVGPathParser::parseClosePathSegment() |
| 42 { | 40 { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 targetPoint += m_currentPoint; | 169 targetPoint += m_currentPoint; |
| 172 } | 170 } |
| 173 | 171 |
| 174 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); | 172 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); |
| 175 | 173 |
| 176 m_controlPoint = point2; | 174 m_controlPoint = point2; |
| 177 m_currentPoint = targetPoint; | 175 m_currentPoint = targetPoint; |
| 178 return true; | 176 return true; |
| 179 } | 177 } |
| 180 | 178 |
| 179 // Blend the points with a ratio (1/3):(2/3). |
| 180 static FloatPoint blendPoints(const FloatPoint& p1, const FloatPoint& p2) |
| 181 { |
| 182 const float oneOverThree = 1 / 3.f; |
| 183 return FloatPoint((p1.x() + 2 * p2.x()) * oneOverThree, (p1.y() + 2 * p2.y()
) * oneOverThree); |
| 184 } |
| 185 |
| 181 bool SVGPathParser::parseCurveToQuadraticSegment() | 186 bool SVGPathParser::parseCurveToQuadraticSegment() |
| 182 { | 187 { |
| 183 FloatPoint point1; | 188 FloatPoint point1; |
| 184 FloatPoint targetPoint; | 189 FloatPoint targetPoint; |
| 185 if (!m_source->parseCurveToQuadraticSegment(point1, targetPoint)) | 190 if (!m_source->parseCurveToQuadraticSegment(point1, targetPoint)) |
| 186 return false; | 191 return false; |
| 187 | 192 |
| 188 if (m_pathParsingMode == UnalteredParsing) { | 193 if (m_pathParsingMode == UnalteredParsing) { |
| 189 m_consumer->curveToQuadratic(point1, targetPoint, m_mode); | 194 m_consumer->curveToQuadratic(point1, targetPoint, m_mode); |
| 190 return true; | 195 return true; |
| 191 } | 196 } |
| 192 m_controlPoint = point1; | 197 m_controlPoint = point1; |
| 193 point1 = m_currentPoint; | 198 |
| 194 point1.move(2 * m_controlPoint.x(), 2 * m_controlPoint.y()); | |
| 195 FloatPoint point2(targetPoint.x() + 2 * m_controlPoint.x(), targetPoint.y()
+ 2 * m_controlPoint.y()); | |
| 196 if (m_mode == RelativeCoordinates) { | 199 if (m_mode == RelativeCoordinates) { |
| 197 point1.move(2 * m_currentPoint.x(), 2 * m_currentPoint.y()); | 200 m_controlPoint += m_currentPoint; |
| 198 point2.move(3 * m_currentPoint.x(), 3 * m_currentPoint.y()); | |
| 199 targetPoint += m_currentPoint; | 201 targetPoint += m_currentPoint; |
| 200 } | 202 } |
| 201 point1.scale(gOneOverThree, gOneOverThree); | 203 point1 = blendPoints(m_currentPoint, m_controlPoint); |
| 202 point2.scale(gOneOverThree, gOneOverThree); | 204 FloatPoint point2 = blendPoints(targetPoint, m_controlPoint); |
| 203 | 205 |
| 204 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); | 206 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); |
| 205 | 207 |
| 206 if (m_mode == RelativeCoordinates) | |
| 207 m_controlPoint += m_currentPoint; | |
| 208 m_currentPoint = targetPoint; | 208 m_currentPoint = targetPoint; |
| 209 return true; | 209 return true; |
| 210 } | 210 } |
| 211 | 211 |
| 212 bool SVGPathParser::parseCurveToQuadraticSmoothSegment() | 212 bool SVGPathParser::parseCurveToQuadraticSmoothSegment() |
| 213 { | 213 { |
| 214 FloatPoint targetPoint; | 214 FloatPoint targetPoint; |
| 215 if (!m_source->parseCurveToQuadraticSmoothSegment(targetPoint)) | 215 if (!m_source->parseCurveToQuadraticSmoothSegment(targetPoint)) |
| 216 return false; | 216 return false; |
| 217 | 217 |
| 218 if (m_pathParsingMode == UnalteredParsing) { | 218 if (m_pathParsingMode == UnalteredParsing) { |
| 219 m_consumer->curveToQuadraticSmooth(targetPoint, m_mode); | 219 m_consumer->curveToQuadraticSmooth(targetPoint, m_mode); |
| 220 return true; | 220 return true; |
| 221 } | 221 } |
| 222 if (m_lastCommand != PathSegCurveToQuadraticAbs | 222 if (m_lastCommand != PathSegCurveToQuadraticAbs |
| 223 && m_lastCommand != PathSegCurveToQuadraticRel | 223 && m_lastCommand != PathSegCurveToQuadraticRel |
| 224 && m_lastCommand != PathSegCurveToQuadraticSmoothAbs | 224 && m_lastCommand != PathSegCurveToQuadraticSmoothAbs |
| 225 && m_lastCommand != PathSegCurveToQuadraticSmoothRel) | 225 && m_lastCommand != PathSegCurveToQuadraticSmoothRel) |
| 226 m_controlPoint = m_currentPoint; | 226 m_controlPoint = m_currentPoint; |
| 227 | 227 |
| 228 FloatPoint cubicPoint = reflectedPoint(m_currentPoint, m_controlPoint); | 228 if (m_mode == RelativeCoordinates) |
| 229 FloatPoint point1(m_currentPoint.x() + 2 * cubicPoint.x(), m_currentPoint.y(
) + 2 * cubicPoint.y()); | |
| 230 FloatPoint point2(targetPoint.x() + 2 * cubicPoint.x(), targetPoint.y() + 2
* cubicPoint.y()); | |
| 231 if (m_mode == RelativeCoordinates) { | |
| 232 point2 += m_currentPoint; | |
| 233 targetPoint += m_currentPoint; | 229 targetPoint += m_currentPoint; |
| 234 } | 230 |
| 235 point1.scale(gOneOverThree, gOneOverThree); | 231 m_controlPoint = reflectedPoint(m_currentPoint, m_controlPoint); |
| 236 point2.scale(gOneOverThree, gOneOverThree); | 232 FloatPoint point1 = blendPoints(m_currentPoint, m_controlPoint); |
| 233 FloatPoint point2 = blendPoints(targetPoint, m_controlPoint); |
| 237 | 234 |
| 238 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); | 235 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); |
| 239 | 236 |
| 240 m_controlPoint = cubicPoint; | |
| 241 m_currentPoint = targetPoint; | 237 m_currentPoint = targetPoint; |
| 242 return true; | 238 return true; |
| 243 } | 239 } |
| 244 | 240 |
| 245 bool SVGPathParser::parseArcToSegment() | 241 bool SVGPathParser::parseArcToSegment() |
| 246 { | 242 { |
| 247 float rx; | 243 float rx; |
| 248 float ry; | 244 float ry; |
| 249 float angle; | 245 float angle; |
| 250 bool largeArc; | 246 bool largeArc; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 point2 = targetPoint; | 469 point2 = targetPoint; |
| 474 point2.move(t * sinEndTheta, -t * cosEndTheta); | 470 point2.move(t * sinEndTheta, -t * cosEndTheta); |
| 475 | 471 |
| 476 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform
.mapPoint(point2), | 472 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform
.mapPoint(point2), |
| 477 pointTransform.mapPoint(targetPoint), AbsoluteC
oordinates); | 473 pointTransform.mapPoint(targetPoint), AbsoluteC
oordinates); |
| 478 } | 474 } |
| 479 return true; | 475 return true; |
| 480 } | 476 } |
| 481 | 477 |
| 482 } | 478 } |
| OLD | NEW |