| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 m_closePath = true; | 46 m_closePath = true; |
| 47 m_consumer->closePath(); | 47 m_consumer->closePath(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool SVGPathParser::parseMoveToSegment() | 50 bool SVGPathParser::parseMoveToSegment() |
| 51 { | 51 { |
| 52 FloatPoint targetPoint; | 52 FloatPoint targetPoint; |
| 53 if (!m_source->parseMoveToSegment(targetPoint)) | 53 if (!m_source->parseMoveToSegment(targetPoint)) |
| 54 return false; | 54 return false; |
| 55 | 55 |
| 56 if (m_pathParsingMode == NormalizedParsing) { | 56 if (m_pathParsingMode == UnalteredParsing) { |
| 57 if (m_mode == RelativeCoordinates) | |
| 58 m_currentPoint += targetPoint; | |
| 59 else | |
| 60 m_currentPoint = targetPoint; | |
| 61 m_subPathPoint = m_currentPoint; | |
| 62 m_consumer->moveTo(m_currentPoint, m_closePath, AbsoluteCoordinates); | |
| 63 } else | |
| 64 m_consumer->moveTo(targetPoint, m_closePath, m_mode); | 57 m_consumer->moveTo(targetPoint, m_closePath, m_mode); |
| 58 m_closePath = false; |
| 59 return true; |
| 60 } |
| 61 if (m_mode == RelativeCoordinates) |
| 62 m_currentPoint += targetPoint; |
| 63 else |
| 64 m_currentPoint = targetPoint; |
| 65 m_subPathPoint = m_currentPoint; |
| 66 m_consumer->moveTo(m_currentPoint, m_closePath, AbsoluteCoordinates); |
| 65 m_closePath = false; | 67 m_closePath = false; |
| 66 return true; | 68 return true; |
| 67 } | 69 } |
| 68 | 70 |
| 69 bool SVGPathParser::parseLineToSegment() | 71 bool SVGPathParser::parseLineToSegment() |
| 70 { | 72 { |
| 71 FloatPoint targetPoint; | 73 FloatPoint targetPoint; |
| 72 if (!m_source->parseLineToSegment(targetPoint)) | 74 if (!m_source->parseLineToSegment(targetPoint)) |
| 73 return false; | 75 return false; |
| 74 | 76 |
| 75 if (m_pathParsingMode == NormalizedParsing) { | 77 if (m_pathParsingMode == UnalteredParsing) { |
| 76 if (m_mode == RelativeCoordinates) | |
| 77 m_currentPoint += targetPoint; | |
| 78 else | |
| 79 m_currentPoint = targetPoint; | |
| 80 m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); | |
| 81 } else | |
| 82 m_consumer->lineTo(targetPoint, m_mode); | 78 m_consumer->lineTo(targetPoint, m_mode); |
| 79 return true; |
| 80 } |
| 81 if (m_mode == RelativeCoordinates) |
| 82 m_currentPoint += targetPoint; |
| 83 else |
| 84 m_currentPoint = targetPoint; |
| 85 m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); |
| 83 return true; | 86 return true; |
| 84 } | 87 } |
| 85 | 88 |
| 86 bool SVGPathParser::parseLineToHorizontalSegment() | 89 bool SVGPathParser::parseLineToHorizontalSegment() |
| 87 { | 90 { |
| 88 float toX; | 91 float toX; |
| 89 if (!m_source->parseLineToHorizontalSegment(toX)) | 92 if (!m_source->parseLineToHorizontalSegment(toX)) |
| 90 return false; | 93 return false; |
| 91 | 94 |
| 92 if (m_pathParsingMode == NormalizedParsing) { | 95 if (m_pathParsingMode == UnalteredParsing) { |
| 93 if (m_mode == RelativeCoordinates) | |
| 94 m_currentPoint.move(toX, 0); | |
| 95 else | |
| 96 m_currentPoint.setX(toX); | |
| 97 m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); | |
| 98 } else | |
| 99 m_consumer->lineToHorizontal(toX, m_mode); | 96 m_consumer->lineToHorizontal(toX, m_mode); |
| 97 return true; |
| 98 } |
| 99 if (m_mode == RelativeCoordinates) |
| 100 m_currentPoint.move(toX, 0); |
| 101 else |
| 102 m_currentPoint.setX(toX); |
| 103 m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); |
| 100 return true; | 104 return true; |
| 101 } | 105 } |
| 102 | 106 |
| 103 bool SVGPathParser::parseLineToVerticalSegment() | 107 bool SVGPathParser::parseLineToVerticalSegment() |
| 104 { | 108 { |
| 105 float toY; | 109 float toY; |
| 106 if (!m_source->parseLineToVerticalSegment(toY)) | 110 if (!m_source->parseLineToVerticalSegment(toY)) |
| 107 return false; | 111 return false; |
| 108 | 112 |
| 109 if (m_pathParsingMode == NormalizedParsing) { | 113 if (m_pathParsingMode == UnalteredParsing) { |
| 110 if (m_mode == RelativeCoordinates) | |
| 111 m_currentPoint.move(0, toY); | |
| 112 else | |
| 113 m_currentPoint.setY(toY); | |
| 114 m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); | |
| 115 } else | |
| 116 m_consumer->lineToVertical(toY, m_mode); | 114 m_consumer->lineToVertical(toY, m_mode); |
| 115 return true; |
| 116 } |
| 117 if (m_mode == RelativeCoordinates) |
| 118 m_currentPoint.move(0, toY); |
| 119 else |
| 120 m_currentPoint.setY(toY); |
| 121 m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); |
| 117 return true; | 122 return true; |
| 118 } | 123 } |
| 119 | 124 |
| 120 bool SVGPathParser::parseCurveToCubicSegment() | 125 bool SVGPathParser::parseCurveToCubicSegment() |
| 121 { | 126 { |
| 122 FloatPoint point1; | 127 FloatPoint point1; |
| 123 FloatPoint point2; | 128 FloatPoint point2; |
| 124 FloatPoint targetPoint; | 129 FloatPoint targetPoint; |
| 125 if (!m_source->parseCurveToCubicSegment(point1, point2, targetPoint)) | 130 if (!m_source->parseCurveToCubicSegment(point1, point2, targetPoint)) |
| 126 return false; | 131 return false; |
| 127 | 132 |
| 128 if (m_pathParsingMode == NormalizedParsing) { | 133 if (m_pathParsingMode == UnalteredParsing) { |
| 129 if (m_mode == RelativeCoordinates) { | 134 m_consumer->curveToCubic(point1, point2, targetPoint, m_mode); |
| 130 point1 += m_currentPoint; | 135 return true; |
| 131 point2 += m_currentPoint; | 136 } |
| 132 targetPoint += m_currentPoint; | 137 if (m_mode == RelativeCoordinates) { |
| 133 } | 138 point1 += m_currentPoint; |
| 134 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinate
s); | 139 point2 += m_currentPoint; |
| 140 targetPoint += m_currentPoint; |
| 141 } |
| 142 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); |
| 135 | 143 |
| 136 m_controlPoint = point2; | 144 m_controlPoint = point2; |
| 137 m_currentPoint = targetPoint; | 145 m_currentPoint = targetPoint; |
| 138 } else | |
| 139 m_consumer->curveToCubic(point1, point2, targetPoint, m_mode); | |
| 140 return true; | 146 return true; |
| 141 } | 147 } |
| 142 | 148 |
| 143 bool SVGPathParser::parseCurveToCubicSmoothSegment() | 149 bool SVGPathParser::parseCurveToCubicSmoothSegment() |
| 144 { | 150 { |
| 145 FloatPoint point2; | 151 FloatPoint point2; |
| 146 FloatPoint targetPoint; | 152 FloatPoint targetPoint; |
| 147 if (!m_source->parseCurveToCubicSmoothSegment(point2, targetPoint)) | 153 if (!m_source->parseCurveToCubicSmoothSegment(point2, targetPoint)) |
| 148 return false; | 154 return false; |
| 149 | 155 |
| 150 if (m_lastCommand != PathSegCurveToCubicAbs | 156 if (m_lastCommand != PathSegCurveToCubicAbs |
| 151 && m_lastCommand != PathSegCurveToCubicRel | 157 && m_lastCommand != PathSegCurveToCubicRel |
| 152 && m_lastCommand != PathSegCurveToCubicSmoothAbs | 158 && m_lastCommand != PathSegCurveToCubicSmoothAbs |
| 153 && m_lastCommand != PathSegCurveToCubicSmoothRel) | 159 && m_lastCommand != PathSegCurveToCubicSmoothRel) |
| 154 m_controlPoint = m_currentPoint; | 160 m_controlPoint = m_currentPoint; |
| 155 | 161 |
| 156 if (m_pathParsingMode == NormalizedParsing) { | 162 if (m_pathParsingMode == UnalteredParsing) { |
| 157 FloatPoint point1 = m_currentPoint; | 163 m_consumer->curveToCubicSmooth(point2, targetPoint, m_mode); |
| 158 point1.scale(2, 2); | 164 return true; |
| 159 point1.move(-m_controlPoint.x(), -m_controlPoint.y()); | 165 } |
| 160 if (m_mode == RelativeCoordinates) { | 166 FloatPoint point1 = m_currentPoint; |
| 161 point2 += m_currentPoint; | 167 point1.scale(2, 2); |
| 162 targetPoint += m_currentPoint; | 168 point1.move(-m_controlPoint.x(), -m_controlPoint.y()); |
| 163 } | 169 if (m_mode == RelativeCoordinates) { |
| 170 point2 += m_currentPoint; |
| 171 targetPoint += m_currentPoint; |
| 172 } |
| 164 | 173 |
| 165 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinate
s); | 174 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); |
| 166 | 175 |
| 167 m_controlPoint = point2; | 176 m_controlPoint = point2; |
| 168 m_currentPoint = targetPoint; | 177 m_currentPoint = targetPoint; |
| 169 } else | |
| 170 m_consumer->curveToCubicSmooth(point2, targetPoint, m_mode); | |
| 171 return true; | 178 return true; |
| 172 } | 179 } |
| 173 | 180 |
| 174 bool SVGPathParser::parseCurveToQuadraticSegment() | 181 bool SVGPathParser::parseCurveToQuadraticSegment() |
| 175 { | 182 { |
| 176 FloatPoint point1; | 183 FloatPoint point1; |
| 177 FloatPoint targetPoint; | 184 FloatPoint targetPoint; |
| 178 if (!m_source->parseCurveToQuadraticSegment(point1, targetPoint)) | 185 if (!m_source->parseCurveToQuadraticSegment(point1, targetPoint)) |
| 179 return false; | 186 return false; |
| 180 | 187 |
| 181 if (m_pathParsingMode == NormalizedParsing) { | 188 if (m_pathParsingMode == UnalteredParsing) { |
| 182 m_controlPoint = point1; | 189 m_consumer->curveToQuadratic(point1, targetPoint, m_mode); |
| 183 FloatPoint point1 = m_currentPoint; | 190 return true; |
| 184 point1.move(2 * m_controlPoint.x(), 2 * m_controlPoint.y()); | 191 } |
| 185 FloatPoint point2(targetPoint.x() + 2 * m_controlPoint.x(), targetPoint.
y() + 2 * m_controlPoint.y()); | 192 m_controlPoint = point1; |
| 186 if (m_mode == RelativeCoordinates) { | 193 point1 = m_currentPoint; |
| 187 point1.move(2 * m_currentPoint.x(), 2 * m_currentPoint.y()); | 194 point1.move(2 * m_controlPoint.x(), 2 * m_controlPoint.y()); |
| 188 point2.move(3 * m_currentPoint.x(), 3 * m_currentPoint.y()); | 195 FloatPoint point2(targetPoint.x() + 2 * m_controlPoint.x(), targetPoint.y()
+ 2 * m_controlPoint.y()); |
| 189 targetPoint += m_currentPoint; | 196 if (m_mode == RelativeCoordinates) { |
| 190 } | 197 point1.move(2 * m_currentPoint.x(), 2 * m_currentPoint.y()); |
| 191 point1.scale(gOneOverThree, gOneOverThree); | 198 point2.move(3 * m_currentPoint.x(), 3 * m_currentPoint.y()); |
| 192 point2.scale(gOneOverThree, gOneOverThree); | 199 targetPoint += m_currentPoint; |
| 200 } |
| 201 point1.scale(gOneOverThree, gOneOverThree); |
| 202 point2.scale(gOneOverThree, gOneOverThree); |
| 193 | 203 |
| 194 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinate
s); | 204 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); |
| 195 | 205 |
| 196 if (m_mode == RelativeCoordinates) | 206 if (m_mode == RelativeCoordinates) |
| 197 m_controlPoint += m_currentPoint; | 207 m_controlPoint += m_currentPoint; |
| 198 m_currentPoint = targetPoint; | 208 m_currentPoint = targetPoint; |
| 199 } else | |
| 200 m_consumer->curveToQuadratic(point1, targetPoint, m_mode); | |
| 201 return true; | 209 return true; |
| 202 } | 210 } |
| 203 | 211 |
| 204 bool SVGPathParser::parseCurveToQuadraticSmoothSegment() | 212 bool SVGPathParser::parseCurveToQuadraticSmoothSegment() |
| 205 { | 213 { |
| 206 FloatPoint targetPoint; | 214 FloatPoint targetPoint; |
| 207 if (!m_source->parseCurveToQuadraticSmoothSegment(targetPoint)) | 215 if (!m_source->parseCurveToQuadraticSmoothSegment(targetPoint)) |
| 208 return false; | 216 return false; |
| 209 | 217 |
| 210 if (m_lastCommand != PathSegCurveToQuadraticAbs | 218 if (m_lastCommand != PathSegCurveToQuadraticAbs |
| 211 && m_lastCommand != PathSegCurveToQuadraticRel | 219 && m_lastCommand != PathSegCurveToQuadraticRel |
| 212 && m_lastCommand != PathSegCurveToQuadraticSmoothAbs | 220 && m_lastCommand != PathSegCurveToQuadraticSmoothAbs |
| 213 && m_lastCommand != PathSegCurveToQuadraticSmoothRel) | 221 && m_lastCommand != PathSegCurveToQuadraticSmoothRel) |
| 214 m_controlPoint = m_currentPoint; | 222 m_controlPoint = m_currentPoint; |
| 215 | 223 |
| 216 if (m_pathParsingMode == NormalizedParsing) { | 224 if (m_pathParsingMode == UnalteredParsing) { |
| 217 FloatPoint cubicPoint = m_currentPoint; | 225 m_consumer->curveToQuadraticSmooth(targetPoint, m_mode); |
| 218 cubicPoint.scale(2, 2); | 226 return true; |
| 219 cubicPoint.move(-m_controlPoint.x(), -m_controlPoint.y()); | 227 } |
| 220 FloatPoint point1(m_currentPoint.x() + 2 * cubicPoint.x(), m_currentPoin
t.y() + 2 * cubicPoint.y()); | 228 FloatPoint cubicPoint = m_currentPoint; |
| 221 FloatPoint point2(targetPoint.x() + 2 * cubicPoint.x(), targetPoint.y()
+ 2 * cubicPoint.y()); | 229 cubicPoint.scale(2, 2); |
| 222 if (m_mode == RelativeCoordinates) { | 230 cubicPoint.move(-m_controlPoint.x(), -m_controlPoint.y()); |
| 223 point2 += m_currentPoint; | 231 FloatPoint point1(m_currentPoint.x() + 2 * cubicPoint.x(), m_currentPoint.y(
) + 2 * cubicPoint.y()); |
| 224 targetPoint += m_currentPoint; | 232 FloatPoint point2(targetPoint.x() + 2 * cubicPoint.x(), targetPoint.y() + 2
* cubicPoint.y()); |
| 225 } | 233 if (m_mode == RelativeCoordinates) { |
| 226 point1.scale(gOneOverThree, gOneOverThree); | 234 point2 += m_currentPoint; |
| 227 point2.scale(gOneOverThree, gOneOverThree); | 235 targetPoint += m_currentPoint; |
| 236 } |
| 237 point1.scale(gOneOverThree, gOneOverThree); |
| 238 point2.scale(gOneOverThree, gOneOverThree); |
| 228 | 239 |
| 229 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinate
s); | 240 m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); |
| 230 | 241 |
| 231 m_controlPoint = cubicPoint; | 242 m_controlPoint = cubicPoint; |
| 232 m_currentPoint = targetPoint; | 243 m_currentPoint = targetPoint; |
| 233 } else | |
| 234 m_consumer->curveToQuadraticSmooth(targetPoint, m_mode); | |
| 235 return true; | 244 return true; |
| 236 } | 245 } |
| 237 | 246 |
| 238 bool SVGPathParser::parseArcToSegment() | 247 bool SVGPathParser::parseArcToSegment() |
| 239 { | 248 { |
| 240 float rx; | 249 float rx; |
| 241 float ry; | 250 float ry; |
| 242 float angle; | 251 float angle; |
| 243 bool largeArc; | 252 bool largeArc; |
| 244 bool sweep; | 253 bool sweep; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 point2 = targetPoint; | 482 point2 = targetPoint; |
| 474 point2.move(t * sinEndTheta, -t * cosEndTheta); | 483 point2.move(t * sinEndTheta, -t * cosEndTheta); |
| 475 | 484 |
| 476 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform
.mapPoint(point2), | 485 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform
.mapPoint(point2), |
| 477 pointTransform.mapPoint(targetPoint), AbsoluteC
oordinates); | 486 pointTransform.mapPoint(targetPoint), AbsoluteC
oordinates); |
| 478 } | 487 } |
| 479 return true; | 488 return true; |
| 480 } | 489 } |
| 481 | 490 |
| 482 } | 491 } |
| OLD | NEW |