2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
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.
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.
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.
23 #include "SVGPathSegListSource.h"
25 #include "SVGPathSegArc.h"
26 #include "SVGPathSegCurvetoCubic.h"
27 #include "SVGPathSegCurvetoCubicSmooth.h"
28 #include "SVGPathSegCurvetoQuadratic.h"
29 #include "SVGPathSegLinetoHorizontal.h"
30 #include "SVGPathSegLinetoVertical.h"
34 SVGPathSegListSource::SVGPathSegListSource(const SVGPathSegList& pathSegList)
35 : m_pathSegList(pathSegList)
38 m_itemEnd = m_pathSegList.size();
41 bool SVGPathSegListSource::hasMoreData() const
43 return m_itemCurrent < m_itemEnd;
46 bool SVGPathSegListSource::parseSVGSegmentType(SVGPathSegType& pathSegType)
48 m_segment = m_pathSegList.at(m_itemCurrent);
49 pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType());
54 SVGPathSegType SVGPathSegListSource::nextCommand(SVGPathSegType)
56 m_segment = m_pathSegList.at(m_itemCurrent);
57 SVGPathSegType pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType());
62 bool SVGPathSegListSource::parseMoveToSegment(FloatPoint& targetPoint)
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());
71 bool SVGPathSegListSource::parseLineToSegment(FloatPoint& targetPoint)
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());
80 bool SVGPathSegListSource::parseLineToHorizontalSegment(float& x)
83 ASSERT(m_segment->pathSegType() == PathSegLineToHorizontalAbs || m_segment->pathSegType() == PathSegLineToHorizontalRel);
84 SVGPathSegLinetoHorizontal* horizontal = static_cast<SVGPathSegLinetoHorizontal*>(m_segment.get());
89 bool SVGPathSegListSource::parseLineToVerticalSegment(float& y)
92 ASSERT(m_segment->pathSegType() == PathSegLineToVerticalAbs || m_segment->pathSegType() == PathSegLineToVerticalRel);
93 SVGPathSegLinetoVertical* vertical = static_cast<SVGPathSegLinetoVertical*>(m_segment.get());
98 bool SVGPathSegListSource::parseCurveToCubicSegment(FloatPoint& point1, FloatPoint& point2, FloatPoint& targetPoint)
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());
109 bool SVGPathSegListSource::parseCurveToCubicSmoothSegment(FloatPoint& point2, FloatPoint& targetPoint)
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());
119 bool SVGPathSegListSource::parseCurveToQuadraticSegment(FloatPoint& point1, FloatPoint& targetPoint)
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());
129 bool SVGPathSegListSource::parseCurveToQuadraticSmoothSegment(FloatPoint& targetPoint)
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());
138 bool SVGPathSegListSource::parseArcToSegment(float& rx, float& ry, float& angle, bool& largeArc, bool& sweep, FloatPoint& targetPoint)
141 ASSERT(m_segment->pathSegType() == PathSegArcAbs || m_segment->pathSegType() == PathSegArcRel);
142 SVGPathSegArc* arcTo = static_cast<SVGPathSegArc*>(m_segment.get());
145 angle = arcTo->angle();
146 largeArc = arcTo->largeArcFlag();
147 sweep = arcTo->sweepFlag();
148 targetPoint = FloatPoint(arcTo->x(), arcTo->y());
154 #endif // ENABLE(SVG)