| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2  * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 
| 3  * | 3  * | 
| 4  * This library is free software; you can redistribute it and/or | 4  * This library is free software; you can redistribute it and/or | 
| 5  * modify it under the terms of the GNU Library General Public | 5  * modify it under the terms of the GNU Library General Public | 
| 6  * License as published by the Free Software Foundation; either | 6  * License as published by the Free Software Foundation; either | 
| 7  * version 2 of the License, or (at your option) any later version. | 7  * version 2 of the License, or (at your option) any later version. | 
| 8  * | 8  * | 
| 9  * This library is distributed in the hope that it will be useful, | 9  * This library is distributed in the hope that it will be useful, | 
| 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
| 12  * Library General Public License for more details. | 12  * Library General Public License for more details. | 
| 13  * | 13  * | 
| 14  * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 
| 17  * Boston, MA 02110-1301, USA. | 17  * Boston, MA 02110-1301, USA. | 
| 18  */ | 18  */ | 
| 19 | 19 | 
| 20 #include "config.h" | 20 #include "config.h" | 
| 21 |  | 
| 22 #include "core/svg/SVGPathSegListSource.h" | 21 #include "core/svg/SVGPathSegListSource.h" | 
| 23 | 22 | 
| 24 #include "core/svg/SVGPathElement.h" | 23 #include "core/svg/SVGPathElement.h" | 
| 25 #include "core/svg/SVGPathSegArc.h" | 24 #include "core/svg/SVGPathSegArc.h" | 
| 26 #include "core/svg/SVGPathSegCurvetoCubic.h" | 25 #include "core/svg/SVGPathSegCurvetoCubic.h" | 
| 27 #include "core/svg/SVGPathSegCurvetoCubicSmooth.h" | 26 #include "core/svg/SVGPathSegCurvetoCubicSmooth.h" | 
| 28 #include "core/svg/SVGPathSegCurvetoQuadratic.h" | 27 #include "core/svg/SVGPathSegCurvetoQuadratic.h" | 
| 29 #include "core/svg/SVGPathSegLinetoHorizontal.h" | 28 #include "core/svg/SVGPathSegLinetoHorizontal.h" | 
| 30 #include "core/svg/SVGPathSegLinetoVertical.h" | 29 #include "core/svg/SVGPathSegLinetoVertical.h" | 
| 31 | 30 | 
| 32 namespace blink { | 31 namespace blink { | 
| 33 | 32 | 
| 34 SVGPathSegListSource::SVGPathSegListSource(SVGPathSegList::ConstIterator itBegin
     , SVGPathSegList::ConstIterator itEnd) | 33 SVGPathSegListSource::SVGPathSegListSource(SVGPathSegList::ConstIterator itBegin
     , SVGPathSegList::ConstIterator itEnd) | 
| 35     : m_itCurrent(itBegin) | 34     : m_itCurrent(itBegin) | 
| 36     , m_itEnd(itEnd) | 35     , m_itEnd(itEnd) | 
| 37 { | 36 { | 
| 38 } | 37 } | 
| 39 | 38 | 
| 40 DEFINE_TRACE(SVGPathSegListSource) |  | 
| 41 { |  | 
| 42     visitor->trace(m_segment); |  | 
| 43     SVGPathSource::trace(visitor); |  | 
| 44 } |  | 
| 45 |  | 
| 46 bool SVGPathSegListSource::hasMoreData() const | 39 bool SVGPathSegListSource::hasMoreData() const | 
| 47 { | 40 { | 
| 48     return m_itCurrent != m_itEnd; | 41     return m_itCurrent != m_itEnd; | 
| 49 } | 42 } | 
| 50 | 43 | 
| 51 bool SVGPathSegListSource::parseSVGSegmentType(SVGPathSegType& pathSegType) | 44 SVGPathSegType SVGPathSegListSource::peekSegmentType() | 
| 52 { | 45 { | 
| 53     m_segment = *m_itCurrent; | 46     ASSERT(hasMoreData()); | 
| 54     pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType()); | 47     return static_cast<SVGPathSegType>(m_itCurrent->pathSegType()); | 
| 55     ++m_itCurrent; |  | 
| 56     return true; |  | 
| 57 } | 48 } | 
| 58 | 49 | 
| 59 SVGPathSegType SVGPathSegListSource::nextCommand(SVGPathSegType) | 50 PathSegmentData SVGPathSegListSource::parseSegment() | 
| 60 { | 51 { | 
| 61     m_segment = *m_itCurrent; | 52     ASSERT(hasMoreData()); | 
| 62     SVGPathSegType pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegT
     ype()); | 53     PathSegmentData segment; | 
|  | 54     RefPtrWillBeRawPtr<SVGPathSeg> pathSegment = *m_itCurrent; | 
|  | 55     segment.command = static_cast<SVGPathSegType>(pathSegment->pathSegType()); | 
| 63     ++m_itCurrent; | 56     ++m_itCurrent; | 
| 64     return pathSegType; |  | 
| 65 } |  | 
| 66 | 57 | 
| 67 bool SVGPathSegListSource::parseMoveToSegment(FloatPoint& targetPoint) | 58     switch (segment.command) { | 
| 68 { | 59     case PathSegMoveToRel: | 
| 69     ASSERT(m_segment); | 60     case PathSegMoveToAbs: | 
| 70     ASSERT(m_segment->pathSegType() == PathSegMoveToAbs || m_segment->pathSegTyp
     e() == PathSegMoveToRel); | 61     case PathSegLineToRel: | 
| 71     SVGPathSegSingleCoordinate* moveTo = static_cast<SVGPathSegSingleCoordinate*
     >(m_segment.get()); | 62     case PathSegLineToAbs: | 
| 72     targetPoint = FloatPoint(moveTo->x(), moveTo->y()); | 63     case PathSegCurveToQuadraticSmoothRel: | 
| 73     return true; | 64     case PathSegCurveToQuadraticSmoothAbs: { | 
| 74 } | 65         SVGPathSegSingleCoordinate* singleCoordinate = static_cast<SVGPathSegSin
     gleCoordinate*>(pathSegment.get()); | 
| 75 | 66         segment.targetPoint = FloatPoint(singleCoordinate->x(), singleCoordinate
     ->y()); | 
| 76 bool SVGPathSegListSource::parseLineToSegment(FloatPoint& targetPoint) | 67         break; | 
| 77 { | 68     } | 
| 78     ASSERT(m_segment); | 69     case PathSegLineToHorizontalRel: | 
| 79     ASSERT(m_segment->pathSegType() == PathSegLineToAbs || m_segment->pathSegTyp
     e() == PathSegLineToRel); | 70     case PathSegLineToHorizontalAbs: { | 
| 80     SVGPathSegSingleCoordinate* lineTo = static_cast<SVGPathSegSingleCoordinate*
     >(m_segment.get()); | 71         SVGPathSegLinetoHorizontal* horizontal = static_cast<SVGPathSegLinetoHor
     izontal*>(pathSegment.get()); | 
| 81     targetPoint = FloatPoint(lineTo->x(), lineTo->y()); | 72         segment.targetPoint.setX(horizontal->x()); | 
| 82     return true; | 73         break; | 
| 83 } | 74     } | 
| 84 | 75     case PathSegLineToVerticalRel: | 
| 85 bool SVGPathSegListSource::parseLineToHorizontalSegment(float& x) | 76     case PathSegLineToVerticalAbs: { | 
| 86 { | 77         SVGPathSegLinetoVertical* vertical = static_cast<SVGPathSegLinetoVertica
     l*>(pathSegment.get()); | 
| 87     ASSERT(m_segment); | 78         segment.targetPoint.setY(vertical->y()); | 
| 88     ASSERT(m_segment->pathSegType() == PathSegLineToHorizontalAbs || m_segment->
     pathSegType() == PathSegLineToHorizontalRel); | 79         break; | 
| 89     SVGPathSegLinetoHorizontal* horizontal = static_cast<SVGPathSegLinetoHorizon
     tal*>(m_segment.get()); | 80     } | 
| 90     x = horizontal->x(); | 81     case PathSegClosePath: | 
| 91     return true; | 82         break; | 
| 92 } | 83     case PathSegCurveToCubicRel: | 
| 93 | 84     case PathSegCurveToCubicAbs: { | 
| 94 bool SVGPathSegListSource::parseLineToVerticalSegment(float& y) | 85         SVGPathSegCurvetoCubic* cubic = static_cast<SVGPathSegCurvetoCubic*>(pat
     hSegment.get()); | 
| 95 { | 86         segment.point1 = FloatPoint(cubic->x1(), cubic->y1()); | 
| 96     ASSERT(m_segment); | 87         segment.point2 = FloatPoint(cubic->x2(), cubic->y2()); | 
| 97     ASSERT(m_segment->pathSegType() == PathSegLineToVerticalAbs || m_segment->pa
     thSegType() == PathSegLineToVerticalRel); | 88         segment.targetPoint = FloatPoint(cubic->x(), cubic->y()); | 
| 98     SVGPathSegLinetoVertical* vertical = static_cast<SVGPathSegLinetoVertical*>(
     m_segment.get()); | 89         break; | 
| 99     y = vertical->y(); | 90     } | 
| 100     return true; | 91     case PathSegCurveToCubicSmoothRel: | 
| 101 } | 92     case PathSegCurveToCubicSmoothAbs: { | 
| 102 | 93         SVGPathSegCurvetoCubicSmooth* cubicSmooth = static_cast<SVGPathSegCurvet
     oCubicSmooth*>(pathSegment.get()); | 
| 103 bool SVGPathSegListSource::parseCurveToCubicSegment(FloatPoint& point1, FloatPoi
     nt& point2, FloatPoint& targetPoint) | 94         segment.point2 = FloatPoint(cubicSmooth->x2(), cubicSmooth->y2()); | 
| 104 { | 95         segment.targetPoint = FloatPoint(cubicSmooth->x(), cubicSmooth->y()); | 
| 105     ASSERT(m_segment); | 96         break; | 
| 106     ASSERT(m_segment->pathSegType() == PathSegCurveToCubicAbs || m_segment->path
     SegType() == PathSegCurveToCubicRel); | 97     } | 
| 107     SVGPathSegCurvetoCubic* cubic = static_cast<SVGPathSegCurvetoCubic*>(m_segme
     nt.get()); | 98     case PathSegCurveToQuadraticRel: | 
| 108     point1 = FloatPoint(cubic->x1(), cubic->y1()); | 99     case PathSegCurveToQuadraticAbs: { | 
| 109     point2 = FloatPoint(cubic->x2(), cubic->y2()); | 100         SVGPathSegCurvetoQuadratic* quadratic = static_cast<SVGPathSegCurvetoQua
     dratic*>(pathSegment.get()); | 
| 110     targetPoint = FloatPoint(cubic->x(), cubic->y()); | 101         segment.point1 = FloatPoint(quadratic->x1(), quadratic->y1()); | 
| 111     return true; | 102         segment.targetPoint = FloatPoint(quadratic->x(), quadratic->y()); | 
| 112 } | 103         break; | 
| 113 | 104     } | 
| 114 bool SVGPathSegListSource::parseCurveToCubicSmoothSegment(FloatPoint& point2, Fl
     oatPoint& targetPoint) | 105     case PathSegArcRel: | 
| 115 { | 106     case PathSegArcAbs: { | 
| 116     ASSERT(m_segment); | 107         SVGPathSegArc* arcTo = static_cast<SVGPathSegArc*>(pathSegment.get()); | 
| 117     ASSERT(m_segment->pathSegType() == PathSegCurveToCubicSmoothAbs || m_segment
     ->pathSegType() == PathSegCurveToCubicSmoothRel); | 108         segment.point1 = FloatPoint(arcTo->r1(), arcTo->r2()); | 
| 118     SVGPathSegCurvetoCubicSmooth* cubicSmooth = static_cast<SVGPathSegCurvetoCub
     icSmooth*>(m_segment.get()); | 109         segment.point2.setX(arcTo->angle()); | 
| 119     point2 = FloatPoint(cubicSmooth->x2(), cubicSmooth->y2()); | 110         segment.arcLarge = arcTo->largeArcFlag(); | 
| 120     targetPoint = FloatPoint(cubicSmooth->x(), cubicSmooth->y()); | 111         segment.arcSweep = arcTo->sweepFlag(); | 
| 121     return true; | 112         segment.targetPoint = FloatPoint(arcTo->x(), arcTo->y()); | 
| 122 } | 113         break; | 
| 123 | 114     } | 
| 124 bool SVGPathSegListSource::parseCurveToQuadraticSegment(FloatPoint& point1, Floa
     tPoint& targetPoint) | 115     default: | 
| 125 { | 116         ASSERT_NOT_REACHED(); | 
| 126     ASSERT(m_segment); | 117     } | 
| 127     ASSERT(m_segment->pathSegType() == PathSegCurveToQuadraticAbs || m_segment->
     pathSegType() == PathSegCurveToQuadraticRel); | 118     return segment; | 
| 128     SVGPathSegCurvetoQuadratic* quadratic = static_cast<SVGPathSegCurvetoQuadrat
     ic*>(m_segment.get()); |  | 
| 129     point1 = FloatPoint(quadratic->x1(), quadratic->y1()); |  | 
| 130     targetPoint = FloatPoint(quadratic->x(), quadratic->y()); |  | 
| 131     return true; |  | 
| 132 } |  | 
| 133 |  | 
| 134 bool SVGPathSegListSource::parseCurveToQuadraticSmoothSegment(FloatPoint& target
     Point) |  | 
| 135 { |  | 
| 136     ASSERT(m_segment); |  | 
| 137     ASSERT(m_segment->pathSegType() == PathSegCurveToQuadraticSmoothAbs || m_seg
     ment->pathSegType() == PathSegCurveToQuadraticSmoothRel); |  | 
| 138     SVGPathSegSingleCoordinate* quadraticSmooth = static_cast<SVGPathSegSingleCo
     ordinate*>(m_segment.get()); |  | 
| 139     targetPoint = FloatPoint(quadraticSmooth->x(), quadraticSmooth->y()); |  | 
| 140     return true; |  | 
| 141 } |  | 
| 142 |  | 
| 143 bool SVGPathSegListSource::parseArcToSegment(float& rx, float& ry, float& angle,
      bool& largeArc, bool& sweep, FloatPoint& targetPoint) |  | 
| 144 { |  | 
| 145     ASSERT(m_segment); |  | 
| 146     ASSERT(m_segment->pathSegType() == PathSegArcAbs || m_segment->pathSegType()
      == PathSegArcRel); |  | 
| 147     SVGPathSegArc* arcTo = static_cast<SVGPathSegArc*>(m_segment.get()); |  | 
| 148     rx = arcTo->r1(); |  | 
| 149     ry = arcTo->r2(); |  | 
| 150     angle = arcTo->angle(); |  | 
| 151     largeArc = arcTo->largeArcFlag(); |  | 
| 152     sweep = arcTo->sweepFlag(); |  | 
| 153     targetPoint = FloatPoint(arcTo->x(), arcTo->y()); |  | 
| 154     return true; |  | 
| 155 } | 119 } | 
| 156 | 120 | 
| 157 } | 121 } | 
| OLD | NEW | 
|---|