1 /*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21
22 #if ENABLE(SVG)
23 #include "SVGPathSegListSource.h"
24
25 #include "SVGPathSegArc.h"
26 #include "SVGPathSegCurvetoCubic.h"
27 #include "SVGPathSegCurvetoCubicSmooth.h"
28 #include "SVGPathSegCurvetoQuadratic.h"
29 #include "SVGPathSegLinetoHorizontal.h"
30 #include "SVGPathSegLinetoVertical.h"
31
32 namespace WebCore {
33
SVGPathSegListSource(const SVGPathSegList & pathSegList)34 SVGPathSegListSource::SVGPathSegListSource(const SVGPathSegList& pathSegList)
35 : m_pathSegList(pathSegList)
36 {
37 m_itemCurrent = 0;
38 m_itemEnd = m_pathSegList.size();
39 }
40
hasMoreData() const41 bool SVGPathSegListSource::hasMoreData() const
42 {
43 return m_itemCurrent < m_itemEnd;
44 }
45
parseSVGSegmentType(SVGPathSegType & pathSegType)46 bool SVGPathSegListSource::parseSVGSegmentType(SVGPathSegType& pathSegType)
47 {
48 m_segment = m_pathSegList.at(m_itemCurrent);
49 pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType());
50 ++m_itemCurrent;
51 return true;
52 }
53
nextCommand(SVGPathSegType)54 SVGPathSegType SVGPathSegListSource::nextCommand(SVGPathSegType)
55 {
56 m_segment = m_pathSegList.at(m_itemCurrent);
57 SVGPathSegType pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType());
58 ++m_itemCurrent;
59 return pathSegType;
60 }
61
parseMoveToSegment(FloatPoint & targetPoint)62 bool SVGPathSegListSource::parseMoveToSegment(FloatPoint& targetPoint)
63 {
64 ASSERT(m_segment);
65 ASSERT(m_segment->pathSegType() == PathSegMoveToAbs || m_segment->pathSegType() == PathSegMoveToRel);
66 SVGPathSegSingleCoordinate* moveTo = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get());
67 targetPoint = FloatPoint(moveTo->x(), moveTo->y());
68 return true;
69 }
70
parseLineToSegment(FloatPoint & targetPoint)71 bool SVGPathSegListSource::parseLineToSegment(FloatPoint& targetPoint)
72 {
73 ASSERT(m_segment);
74 ASSERT(m_segment->pathSegType() == PathSegLineToAbs || m_segment->pathSegType() == PathSegLineToRel);
75 SVGPathSegSingleCoordinate* lineTo = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get());
76 targetPoint = FloatPoint(lineTo->x(), lineTo->y());
77 return true;
78 }
79
parseLineToHorizontalSegment(float & x)80 bool SVGPathSegListSource::parseLineToHorizontalSegment(float& x)
81 {
82 ASSERT(m_segment);
83 ASSERT(m_segment->pathSegType() == PathSegLineToHorizontalAbs || m_segment->pathSegType() == PathSegLineToHorizontalRel);
84 SVGPathSegLinetoHorizontal* horizontal = static_cast<SVGPathSegLinetoHorizontal*>(m_segment.get());
85 x = horizontal->x();
86 return true;
87 }
88
parseLineToVerticalSegment(float & y)89 bool SVGPathSegListSource::parseLineToVerticalSegment(float& y)
90 {
91 ASSERT(m_segment);
92 ASSERT(m_segment->pathSegType() == PathSegLineToVerticalAbs || m_segment->pathSegType() == PathSegLineToVerticalRel);
93 SVGPathSegLinetoVertical* vertical = static_cast<SVGPathSegLinetoVertical*>(m_segment.get());
94 y = vertical->y();
95 return true;
96 }
97
parseCurveToCubicSegment(FloatPoint & point1,FloatPoint & point2,FloatPoint & targetPoint)98 bool SVGPathSegListSource::parseCurveToCubicSegment(FloatPoint& point1, FloatPoint& point2, FloatPoint& targetPoint)
99 {
100 ASSERT(m_segment);
101 ASSERT(m_segment->pathSegType() == PathSegCurveToCubicAbs || m_segment->pathSegType() == PathSegCurveToCubicRel);
102 SVGPathSegCurvetoCubic* cubic = static_cast<SVGPathSegCurvetoCubic*>(m_segment.get());
103 point1 = FloatPoint(cubic->x1(), cubic->y1());
104 point2 = FloatPoint(cubic->x2(), cubic->y2());
105 targetPoint = FloatPoint(cubic->x(), cubic->y());
106 return true;
107 }
108
parseCurveToCubicSmoothSegment(FloatPoint & point2,FloatPoint & targetPoint)109 bool SVGPathSegListSource::parseCurveToCubicSmoothSegment(FloatPoint& point2, FloatPoint& targetPoint)
110 {
111 ASSERT(m_segment);
112 ASSERT(m_segment->pathSegType() == PathSegCurveToCubicSmoothAbs || m_segment->pathSegType() == PathSegCurveToCubicSmoothRel);
113 SVGPathSegCurvetoCubicSmooth* cubicSmooth = static_cast<SVGPathSegCurvetoCubicSmooth*>(m_segment.get());
114 point2 = FloatPoint(cubicSmooth->x2(), cubicSmooth->y2());
115 targetPoint = FloatPoint(cubicSmooth->x(), cubicSmooth->y());
116 return true;
117 }
118
parseCurveToQuadraticSegment(FloatPoint & point1,FloatPoint & targetPoint)119 bool SVGPathSegListSource::parseCurveToQuadraticSegment(FloatPoint& point1, FloatPoint& targetPoint)
120 {
121 ASSERT(m_segment);
122 ASSERT(m_segment->pathSegType() == PathSegCurveToQuadraticAbs || m_segment->pathSegType() == PathSegCurveToQuadraticRel);
123 SVGPathSegCurvetoQuadratic* quadratic = static_cast<SVGPathSegCurvetoQuadratic*>(m_segment.get());
124 point1 = FloatPoint(quadratic->x1(), quadratic->y1());
125 targetPoint = FloatPoint(quadratic->x(), quadratic->y());
126 return true;
127 }
128
parseCurveToQuadraticSmoothSegment(FloatPoint & targetPoint)129 bool SVGPathSegListSource::parseCurveToQuadraticSmoothSegment(FloatPoint& targetPoint)
130 {
131 ASSERT(m_segment);
132 ASSERT(m_segment->pathSegType() == PathSegCurveToQuadraticSmoothAbs || m_segment->pathSegType() == PathSegCurveToQuadraticSmoothRel);
133 SVGPathSegSingleCoordinate* quadraticSmooth = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get());
134 targetPoint = FloatPoint(quadraticSmooth->x(), quadraticSmooth->y());
135 return true;
136 }
137
parseArcToSegment(float & rx,float & ry,float & angle,bool & largeArc,bool & sweep,FloatPoint & targetPoint)138 bool SVGPathSegListSource::parseArcToSegment(float& rx, float& ry, float& angle, bool& largeArc, bool& sweep, FloatPoint& targetPoint)
139 {
140 ASSERT(m_segment);
141 ASSERT(m_segment->pathSegType() == PathSegArcAbs || m_segment->pathSegType() == PathSegArcRel);
142 SVGPathSegArc* arcTo = static_cast<SVGPathSegArc*>(m_segment.get());
143 rx = arcTo->r1();
144 ry = arcTo->r2();
145 angle = arcTo->angle();
146 largeArc = arcTo->largeArcFlag();
147 sweep = arcTo->sweepFlag();
148 targetPoint = FloatPoint(arcTo->x(), arcTo->y());
149 return true;
150 }
151
152 }
153
154 #endif // ENABLE(SVG)
155