• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2002, 2003 The Karbon Developers
3  * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
4  * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
5  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
6  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #include "config.h"
25 
26 #include "core/svg/SVGPathSegListBuilder.h"
27 
28 #include "core/dom/ExceptionCode.h"
29 #include "core/svg/SVGPathElement.h"
30 #include "core/svg/SVGPathSegArcAbs.h"
31 #include "core/svg/SVGPathSegArcRel.h"
32 #include "core/svg/SVGPathSegClosePath.h"
33 #include "core/svg/SVGPathSegCurvetoCubicAbs.h"
34 #include "core/svg/SVGPathSegCurvetoCubicRel.h"
35 #include "core/svg/SVGPathSegCurvetoCubicSmoothAbs.h"
36 #include "core/svg/SVGPathSegCurvetoCubicSmoothRel.h"
37 #include "core/svg/SVGPathSegCurvetoQuadraticAbs.h"
38 #include "core/svg/SVGPathSegCurvetoQuadraticRel.h"
39 #include "core/svg/SVGPathSegCurvetoQuadraticSmoothAbs.h"
40 #include "core/svg/SVGPathSegCurvetoQuadraticSmoothRel.h"
41 #include "core/svg/SVGPathSegLinetoAbs.h"
42 #include "core/svg/SVGPathSegLinetoHorizontalAbs.h"
43 #include "core/svg/SVGPathSegLinetoHorizontalRel.h"
44 #include "core/svg/SVGPathSegLinetoRel.h"
45 #include "core/svg/SVGPathSegLinetoVerticalAbs.h"
46 #include "core/svg/SVGPathSegLinetoVerticalRel.h"
47 #include "core/svg/SVGPathSegMovetoAbs.h"
48 #include "core/svg/SVGPathSegMovetoRel.h"
49 
50 namespace WebCore {
51 
SVGPathSegListBuilder()52 SVGPathSegListBuilder::SVGPathSegListBuilder()
53     : m_pathElement(0)
54     , m_pathSegList(0)
55     , m_pathSegRole(PathSegUndefinedRole)
56 {
57 }
58 
moveTo(const FloatPoint & targetPoint,bool,PathCoordinateMode mode)59 void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
60 {
61     ASSERT(m_pathElement);
62     ASSERT(m_pathSegList);
63     if (mode == AbsoluteCoordinates)
64         m_pathSegList->append(m_pathElement->createSVGPathSegMovetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
65     else
66         m_pathSegList->append(m_pathElement->createSVGPathSegMovetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
67 }
68 
lineTo(const FloatPoint & targetPoint,PathCoordinateMode mode)69 void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
70 {
71     ASSERT(m_pathElement);
72     ASSERT(m_pathSegList);
73     if (mode == AbsoluteCoordinates)
74         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
75     else
76         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
77 }
78 
lineToHorizontal(float x,PathCoordinateMode mode)79 void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
80 {
81     ASSERT(m_pathElement);
82     ASSERT(m_pathSegList);
83     if (mode == AbsoluteCoordinates)
84         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoHorizontalAbs(x, m_pathSegRole));
85     else
86         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoHorizontalRel(x, m_pathSegRole));
87 }
88 
lineToVertical(float y,PathCoordinateMode mode)89 void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode)
90 {
91     ASSERT(m_pathElement);
92     ASSERT(m_pathSegList);
93     if (mode == AbsoluteCoordinates)
94         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoVerticalAbs(y, m_pathSegRole));
95     else
96         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoVerticalRel(y, m_pathSegRole));
97 }
98 
curveToCubic(const FloatPoint & point1,const FloatPoint & point2,const FloatPoint & targetPoint,PathCoordinateMode mode)99 void SVGPathSegListBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
100 {
101     ASSERT(m_pathElement);
102     ASSERT(m_pathSegList);
103     if (mode == AbsoluteCoordinates)
104         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));
105     else
106         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));
107 }
108 
curveToCubicSmooth(const FloatPoint & point2,const FloatPoint & targetPoint,PathCoordinateMode mode)109 void SVGPathSegListBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
110 {
111     ASSERT(m_pathElement);
112     ASSERT(m_pathSegList);
113     if (mode == AbsoluteCoordinates)
114         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothAbs(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));
115     else
116         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothRel(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));
117 }
118 
curveToQuadratic(const FloatPoint & point1,const FloatPoint & targetPoint,PathCoordinateMode mode)119 void SVGPathSegListBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
120 {
121     ASSERT(m_pathElement);
122     ASSERT(m_pathSegList);
123     if (mode == AbsoluteCoordinates)
124         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));
125     else
126         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));
127 }
128 
curveToQuadraticSmooth(const FloatPoint & targetPoint,PathCoordinateMode mode)129 void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
130 {
131     ASSERT(m_pathElement);
132     ASSERT(m_pathSegList);
133     if (mode == AbsoluteCoordinates)
134         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
135     else
136         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
137 }
138 
arcTo(float r1,float r2,float angle,bool largeArcFlag,bool sweepFlag,const FloatPoint & targetPoint,PathCoordinateMode mode)139 void SVGPathSegListBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
140 {
141     ASSERT(m_pathElement);
142     ASSERT(m_pathSegList);
143     if (mode == AbsoluteCoordinates)
144         m_pathSegList->append(m_pathElement->createSVGPathSegArcAbs(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));
145     else
146         m_pathSegList->append(m_pathElement->createSVGPathSegArcRel(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));
147 }
148 
closePath()149 void SVGPathSegListBuilder::closePath()
150 {
151     ASSERT(m_pathElement);
152     ASSERT(m_pathSegList);
153     m_pathSegList->append(m_pathElement->createSVGPathSegClosePath(m_pathSegRole));
154 }
155 
156 }
157