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 #include "core/svg/SVGPathSegListSource.h" 23 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" 30 31 namespace blink { 32 33 SVGPathSegListSource::SVGPathSegListSource(SVGPathSegList::ConstIterator itBegin, SVGPathSegList::ConstIterator itEnd) 34 : m_itCurrent(itBegin) 35 , m_itEnd(itEnd) 36 { 37 } 38 39 bool SVGPathSegListSource::hasMoreData() const 40 { 41 return m_itCurrent != m_itEnd; 42 } 43 44 bool SVGPathSegListSource::parseSVGSegmentType(SVGPathSegType& pathSegType) 45 { 46 m_segment = *m_itCurrent; 47 pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType()); 48 ++m_itCurrent; 49 return true; 50 } 51 52 SVGPathSegType SVGPathSegListSource::nextCommand(SVGPathSegType) 53 { 54 m_segment = *m_itCurrent; 55 SVGPathSegType pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType()); 56 ++m_itCurrent; 57 return pathSegType; 58 } 59 60 bool SVGPathSegListSource::parseMoveToSegment(FloatPoint& targetPoint) 61 { 62 ASSERT(m_segment); 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()); 66 return true; 67 } 68 69 bool SVGPathSegListSource::parseLineToSegment(FloatPoint& targetPoint) 70 { 71 ASSERT(m_segment); 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()); 75 return true; 76 } 77 78 bool SVGPathSegListSource::parseLineToHorizontalSegment(float& x) 79 { 80 ASSERT(m_segment); 81 ASSERT(m_segment->pathSegType() == PathSegLineToHorizontalAbs || m_segment->pathSegType() == PathSegLineToHorizontalRel); 82 SVGPathSegLinetoHorizontal* horizontal = static_cast<SVGPathSegLinetoHorizontal*>(m_segment.get()); 83 x = horizontal->x(); 84 return true; 85 } 86 87 bool SVGPathSegListSource::parseLineToVerticalSegment(float& y) 88 { 89 ASSERT(m_segment); 90 ASSERT(m_segment->pathSegType() == PathSegLineToVerticalAbs || m_segment->pathSegType() == PathSegLineToVerticalRel); 91 SVGPathSegLinetoVertical* vertical = static_cast<SVGPathSegLinetoVertical*>(m_segment.get()); 92 y = vertical->y(); 93 return true; 94 } 95 96 bool SVGPathSegListSource::parseCurveToCubicSegment(FloatPoint& point1, FloatPoint& point2, FloatPoint& targetPoint) 97 { 98 ASSERT(m_segment); 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()); 104 return true; 105 } 106 107 bool SVGPathSegListSource::parseCurveToCubicSmoothSegment(FloatPoint& point2, FloatPoint& targetPoint) 108 { 109 ASSERT(m_segment); 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()); 114 return true; 115 } 116 117 bool SVGPathSegListSource::parseCurveToQuadraticSegment(FloatPoint& point1, FloatPoint& targetPoint) 118 { 119 ASSERT(m_segment); 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()); 124 return true; 125 } 126 127 bool SVGPathSegListSource::parseCurveToQuadraticSmoothSegment(FloatPoint& targetPoint) 128 { 129 ASSERT(m_segment); 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()); 133 return true; 134 } 135 136 bool SVGPathSegListSource::parseArcToSegment(float& rx, float& ry, float& angle, bool& largeArc, bool& sweep, FloatPoint& targetPoint) 137 { 138 ASSERT(m_segment); 139 ASSERT(m_segment->pathSegType() == PathSegArcAbs || m_segment->pathSegType() == PathSegArcRel); 140 SVGPathSegArc* arcTo = static_cast<SVGPathSegArc*>(m_segment.get()); 141 rx = arcTo->r1(); 142 ry = arcTo->r2(); 143 angle = arcTo->angle(); 144 largeArc = arcTo->largeArcFlag(); 145 sweep = arcTo->sweepFlag(); 146 targetPoint = FloatPoint(arcTo->x(), arcTo->y()); 147 return true; 148 } 149 150 } 151