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.
22 #include "core/svg/SVGPathSegListSource.h"
24 #include "core/svg/SVGPathSegArc.h"
25 #include "core/svg/SVGPathSegCurvetoCubic.h"
26 #include "core/svg/SVGPathSegCurvetoCubicSmooth.h"
27 #include "core/svg/SVGPathSegCurvetoQuadratic.h"
28 #include "core/svg/SVGPathSegLinetoHorizontal.h"
29 #include "core/svg/SVGPathSegLinetoVertical.h"
33 SVGPathSegListSource::SVGPathSegListSource(SVGPathSegList::ConstIterator itBegin, SVGPathSegList::ConstIterator itEnd)
34 : m_itCurrent(itBegin)
39 bool SVGPathSegListSource::hasMoreData() const
41 return m_itCurrent != m_itEnd;
44 bool SVGPathSegListSource::parseSVGSegmentType(SVGPathSegType& pathSegType)
46 m_segment = *m_itCurrent;
47 pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType());
52 SVGPathSegType SVGPathSegListSource::nextCommand(SVGPathSegType)
54 m_segment = *m_itCurrent;
55 SVGPathSegType pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType());
60 bool SVGPathSegListSource::parseMoveToSegment(FloatPoint& targetPoint)
63 ASSERT(m_segment->pathSegType() == PathSegMoveToAbs || m_segment->pathSegType() == PathSegMoveToRel);
64 SVGPathSegSingleCoordinate* moveTo = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get());
65 targetPoint = FloatPoint(moveTo->x(), moveTo->y());
69 bool SVGPathSegListSource::parseLineToSegment(FloatPoint& targetPoint)
72 ASSERT(m_segment->pathSegType() == PathSegLineToAbs || m_segment->pathSegType() == PathSegLineToRel);
73 SVGPathSegSingleCoordinate* lineTo = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get());
74 targetPoint = FloatPoint(lineTo->x(), lineTo->y());
78 bool SVGPathSegListSource::parseLineToHorizontalSegment(float& x)
81 ASSERT(m_segment->pathSegType() == PathSegLineToHorizontalAbs || m_segment->pathSegType() == PathSegLineToHorizontalRel);
82 SVGPathSegLinetoHorizontal* horizontal = static_cast<SVGPathSegLinetoHorizontal*>(m_segment.get());
87 bool SVGPathSegListSource::parseLineToVerticalSegment(float& y)
90 ASSERT(m_segment->pathSegType() == PathSegLineToVerticalAbs || m_segment->pathSegType() == PathSegLineToVerticalRel);
91 SVGPathSegLinetoVertical* vertical = static_cast<SVGPathSegLinetoVertical*>(m_segment.get());
96 bool SVGPathSegListSource::parseCurveToCubicSegment(FloatPoint& point1, FloatPoint& point2, FloatPoint& targetPoint)
99 ASSERT(m_segment->pathSegType() == PathSegCurveToCubicAbs || m_segment->pathSegType() == PathSegCurveToCubicRel);
100 SVGPathSegCurvetoCubic* cubic = static_cast<SVGPathSegCurvetoCubic*>(m_segment.get());
101 point1 = FloatPoint(cubic->x1(), cubic->y1());
102 point2 = FloatPoint(cubic->x2(), cubic->y2());
103 targetPoint = FloatPoint(cubic->x(), cubic->y());
107 bool SVGPathSegListSource::parseCurveToCubicSmoothSegment(FloatPoint& point2, FloatPoint& targetPoint)
110 ASSERT(m_segment->pathSegType() == PathSegCurveToCubicSmoothAbs || m_segment->pathSegType() == PathSegCurveToCubicSmoothRel);
111 SVGPathSegCurvetoCubicSmooth* cubicSmooth = static_cast<SVGPathSegCurvetoCubicSmooth*>(m_segment.get());
112 point2 = FloatPoint(cubicSmooth->x2(), cubicSmooth->y2());
113 targetPoint = FloatPoint(cubicSmooth->x(), cubicSmooth->y());
117 bool SVGPathSegListSource::parseCurveToQuadraticSegment(FloatPoint& point1, FloatPoint& targetPoint)
120 ASSERT(m_segment->pathSegType() == PathSegCurveToQuadraticAbs || m_segment->pathSegType() == PathSegCurveToQuadraticRel);
121 SVGPathSegCurvetoQuadratic* quadratic = static_cast<SVGPathSegCurvetoQuadratic*>(m_segment.get());
122 point1 = FloatPoint(quadratic->x1(), quadratic->y1());
123 targetPoint = FloatPoint(quadratic->x(), quadratic->y());
127 bool SVGPathSegListSource::parseCurveToQuadraticSmoothSegment(FloatPoint& targetPoint)
130 ASSERT(m_segment->pathSegType() == PathSegCurveToQuadraticSmoothAbs || m_segment->pathSegType() == PathSegCurveToQuadraticSmoothRel);
131 SVGPathSegSingleCoordinate* quadraticSmooth = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get());
132 targetPoint = FloatPoint(quadraticSmooth->x(), quadraticSmooth->y());
136 bool SVGPathSegListSource::parseArcToSegment(float& rx, float& ry, float& angle, bool& largeArc, bool& sweep, FloatPoint& targetPoint)
139 ASSERT(m_segment->pathSegType() == PathSegArcAbs || m_segment->pathSegType() == PathSegArcRel);
140 SVGPathSegArc* arcTo = static_cast<SVGPathSegArc*>(m_segment.get());
143 angle = arcTo->angle();
144 largeArc = arcTo->largeArcFlag();
145 sweep = arcTo->sweepFlag();
146 targetPoint = FloatPoint(arcTo->x(), arcTo->y());