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 29 matching lines...) Expand all Loading... |
40 { | 40 { |
41 // If the path is empty it is still valid, so return true. | 41 // If the path is empty it is still valid, so return true. |
42 if (!m_source->hasMoreData()) | 42 if (!m_source->hasMoreData()) |
43 return true; | 43 return true; |
44 | 44 |
45 SVGPathSegType command = m_source->peekSegmentType(); | 45 SVGPathSegType command = m_source->peekSegmentType(); |
46 // Path must start with moveTo. | 46 // Path must start with moveTo. |
47 return command == PathSegMoveToAbs || command == PathSegMoveToRel; | 47 return command == PathSegMoveToAbs || command == PathSegMoveToRel; |
48 } | 48 } |
49 | 49 |
50 | |
51 class NormalizingConsumer { | 50 class NormalizingConsumer { |
52 STACK_ALLOCATED(); | 51 STACK_ALLOCATED(); |
53 public: | 52 public: |
54 NormalizingConsumer(SVGPathConsumer* consumer) | 53 NormalizingConsumer(SVGPathConsumer* consumer) |
55 : m_consumer(consumer) | 54 : m_consumer(consumer) |
56 , m_lastCommand(PathSegUnknown) | 55 , m_lastCommand(PathSegUnknown) |
57 { | 56 { |
58 ASSERT(m_consumer); | 57 ASSERT(m_consumer); |
59 } | 58 } |
60 | 59 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // decomposeArcToCubic() has already emitted the normalized | 189 // decomposeArcToCubic() has already emitted the normalized |
191 // segments, so set command to PathSegArcAbs, to skip any further | 190 // segments, so set command to PathSegArcAbs, to skip any further |
192 // emit. | 191 // emit. |
193 segment.command = PathSegArcAbs; | 192 segment.command = PathSegArcAbs; |
194 } | 193 } |
195 break; | 194 break; |
196 default: | 195 default: |
197 ASSERT_NOT_REACHED(); | 196 ASSERT_NOT_REACHED(); |
198 } | 197 } |
199 | 198 |
200 switch (segment.command) { | 199 if (segment.command != PathSegArcAbs) |
201 case PathSegMoveToAbs: | 200 m_consumer->emitSegment(segment); |
202 m_consumer->moveTo(segment.targetPoint, AbsoluteCoordinates); | |
203 break; | |
204 case PathSegLineToAbs: | |
205 m_consumer->lineTo(segment.targetPoint, AbsoluteCoordinates); | |
206 break; | |
207 case PathSegClosePath: | |
208 m_consumer->closePath(); | |
209 break; | |
210 case PathSegCurveToCubicAbs: | |
211 m_consumer->curveToCubic(segment.point1, segment.point2, segment.targetP
oint, AbsoluteCoordinates); | |
212 break; | |
213 case PathSegArcAbs: | |
214 break; | |
215 default: | |
216 ASSERT_NOT_REACHED(); | |
217 } | |
218 | 201 |
219 m_currentPoint = segment.targetPoint; | 202 m_currentPoint = segment.targetPoint; |
220 | 203 |
221 if (!isCubicCommand(originalCommand) && !isQuadraticCommand(originalCommand)
) | 204 if (!isCubicCommand(originalCommand) && !isQuadraticCommand(originalCommand)
) |
222 m_controlPoint = m_currentPoint; | 205 m_controlPoint = m_currentPoint; |
223 | 206 |
224 m_lastCommand = originalCommand; | 207 m_lastCommand = originalCommand; |
225 } | 208 } |
226 | 209 |
227 bool SVGPathParser::parsePathDataFromSource(PathParsingMode pathParsingMode, boo
l checkForInitialMoveTo) | 210 bool SVGPathParser::parsePathDataFromSource(PathParsingMode pathParsingMode, boo
l checkForInitialMoveTo) |
228 { | 211 { |
229 ASSERT(m_source); | 212 ASSERT(m_source); |
230 ASSERT(m_consumer); | 213 ASSERT(m_consumer); |
231 | 214 |
232 if (checkForInitialMoveTo && !initialCommandIsMoveTo()) | 215 if (checkForInitialMoveTo && !initialCommandIsMoveTo()) |
233 return false; | 216 return false; |
234 | 217 |
235 NormalizingConsumer normalizer(m_consumer); | 218 NormalizingConsumer normalizer(m_consumer); |
236 | 219 |
237 while (m_source->hasMoreData()) { | 220 while (m_source->hasMoreData()) { |
238 PathSegmentData segment = m_source->parseSegment(); | 221 PathSegmentData segment = m_source->parseSegment(); |
239 if (segment.command == PathSegUnknown) | 222 if (segment.command == PathSegUnknown) |
240 return false; | 223 return false; |
241 | 224 |
242 if (pathParsingMode == NormalizedParsing) { | 225 if (pathParsingMode == NormalizedParsing) { |
243 normalizer.emitSegment(segment); | 226 normalizer.emitSegment(segment); |
244 } else { | 227 } else { |
245 PathCoordinateMode mode = AbsoluteCoordinates; | 228 m_consumer->emitSegment(segment); |
246 | |
247 switch (segment.command) { | |
248 case PathSegMoveToRel: | |
249 mode = RelativeCoordinates; | |
250 case PathSegMoveToAbs: | |
251 m_consumer->moveTo(segment.targetPoint, mode); | |
252 break; | |
253 case PathSegLineToRel: | |
254 mode = RelativeCoordinates; | |
255 case PathSegLineToAbs: | |
256 m_consumer->lineTo(segment.targetPoint, mode); | |
257 break; | |
258 case PathSegLineToHorizontalRel: | |
259 mode = RelativeCoordinates; | |
260 case PathSegLineToHorizontalAbs: | |
261 m_consumer->lineToHorizontal(segment.targetPoint.x(), mode); | |
262 break; | |
263 case PathSegLineToVerticalRel: | |
264 mode = RelativeCoordinates; | |
265 case PathSegLineToVerticalAbs: | |
266 m_consumer->lineToVertical(segment.targetPoint.y(), mode); | |
267 break; | |
268 case PathSegClosePath: | |
269 m_consumer->closePath(); | |
270 break; | |
271 case PathSegCurveToCubicRel: | |
272 mode = RelativeCoordinates; | |
273 case PathSegCurveToCubicAbs: | |
274 m_consumer->curveToCubic(segment.point1, segment.point2, segment
.targetPoint, mode); | |
275 break; | |
276 case PathSegCurveToCubicSmoothRel: | |
277 mode = RelativeCoordinates; | |
278 case PathSegCurveToCubicSmoothAbs: | |
279 m_consumer->curveToCubicSmooth(segment.point2, segment.targetPoi
nt, mode); | |
280 break; | |
281 case PathSegCurveToQuadraticRel: | |
282 mode = RelativeCoordinates; | |
283 case PathSegCurveToQuadraticAbs: | |
284 m_consumer->curveToQuadratic(segment.point1, segment.targetPoint
, mode); | |
285 break; | |
286 case PathSegCurveToQuadraticSmoothRel: | |
287 mode = RelativeCoordinates; | |
288 case PathSegCurveToQuadraticSmoothAbs: | |
289 m_consumer->curveToQuadraticSmooth(segment.targetPoint, mode); | |
290 break; | |
291 case PathSegArcRel: | |
292 mode = RelativeCoordinates; | |
293 case PathSegArcAbs: | |
294 m_consumer->arcTo(segment.arcRadii().x(), segment.arcRadii().y()
, segment.arcAngle(), segment.arcLarge, segment.arcSweep, segment.targetPoint, m
ode); | |
295 break; | |
296 default: | |
297 ASSERT_NOT_REACHED(); | |
298 } | |
299 } | 229 } |
300 | 230 |
301 if (!m_consumer->continueConsuming()) | 231 if (!m_consumer->continueConsuming()) |
302 return true; | 232 return true; |
303 | 233 |
304 if (m_source->hasMoreData()) | 234 if (m_source->hasMoreData()) |
305 m_consumer->incrementPathSegmentCount(); | 235 m_consumer->incrementPathSegmentCount(); |
306 } | 236 } |
307 return true; | 237 return true; |
308 } | 238 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 float sinEndTheta = sinf(endTheta); | 324 float sinEndTheta = sinf(endTheta); |
395 float cosEndTheta = cosf(endTheta); | 325 float cosEndTheta = cosf(endTheta); |
396 | 326 |
397 point1 = FloatPoint(cosStartTheta - t * sinStartTheta, sinStartTheta + t
* cosStartTheta); | 327 point1 = FloatPoint(cosStartTheta - t * sinStartTheta, sinStartTheta + t
* cosStartTheta); |
398 point1.move(centerPoint.x(), centerPoint.y()); | 328 point1.move(centerPoint.x(), centerPoint.y()); |
399 FloatPoint targetPoint = FloatPoint(cosEndTheta, sinEndTheta); | 329 FloatPoint targetPoint = FloatPoint(cosEndTheta, sinEndTheta); |
400 targetPoint.move(centerPoint.x(), centerPoint.y()); | 330 targetPoint.move(centerPoint.x(), centerPoint.y()); |
401 point2 = targetPoint; | 331 point2 = targetPoint; |
402 point2.move(t * sinEndTheta, -t * cosEndTheta); | 332 point2.move(t * sinEndTheta, -t * cosEndTheta); |
403 | 333 |
404 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform
.mapPoint(point2), | 334 PathSegmentData cubicSegment; |
405 pointTransform.mapPoint(targetPoint), AbsoluteC
oordinates); | 335 cubicSegment.command = PathSegCurveToCubicAbs; |
| 336 cubicSegment.point1 = pointTransform.mapPoint(point1); |
| 337 cubicSegment.point2 = pointTransform.mapPoint(point2); |
| 338 cubicSegment.targetPoint = pointTransform.mapPoint(targetPoint); |
| 339 |
| 340 m_consumer->emitSegment(cubicSegment); |
406 } | 341 } |
407 return true; | 342 return true; |
408 } | 343 } |
409 | 344 |
410 } | 345 } |
OLD | NEW |