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