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#if ENABLE(SVG)
27#include "SVGPathSegListBuilder.h"
28
29#include "ExceptionCode.h"
30#include "SVGPathElement.h"
31#include "SVGPathSegArc.h"
32#include "SVGPathSegClosePath.h"
33#include "SVGPathSegCurvetoCubic.h"
34#include "SVGPathSegCurvetoCubicSmooth.h"
35#include "SVGPathSegCurvetoQuadratic.h"
36#include "SVGPathSegCurvetoQuadraticSmooth.h"
37#include "SVGPathSegLineto.h"
38#include "SVGPathSegLinetoHorizontal.h"
39#include "SVGPathSegLinetoVertical.h"
40#include "SVGPathSegList.h"
41#include "SVGPathSegMoveto.h"
42
43namespace WebCore {
44
45SVGPathSegListBuilder::SVGPathSegListBuilder()
46    : m_pathElement(0)
47    , m_pathSegList(0)
48    , m_pathSegRole(PathSegUndefinedRole)
49{
50}
51
52void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
53{
54    ASSERT(m_pathElement);
55    ASSERT(m_pathSegList);
56    if (mode == AbsoluteCoordinates)
57        m_pathSegList->append(m_pathElement->createSVGPathSegMovetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
58    else
59        m_pathSegList->append(m_pathElement->createSVGPathSegMovetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
60}
61
62void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
63{
64    ASSERT(m_pathElement);
65    ASSERT(m_pathSegList);
66    if (mode == AbsoluteCoordinates)
67        m_pathSegList->append(m_pathElement->createSVGPathSegLinetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
68    else
69        m_pathSegList->append(m_pathElement->createSVGPathSegLinetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
70}
71
72void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
73{
74    ASSERT(m_pathElement);
75    ASSERT(m_pathSegList);
76    if (mode == AbsoluteCoordinates)
77        m_pathSegList->append(m_pathElement->createSVGPathSegLinetoHorizontalAbs(x, m_pathSegRole));
78    else
79        m_pathSegList->append(m_pathElement->createSVGPathSegLinetoHorizontalRel(x, m_pathSegRole));
80}
81
82void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode)
83{
84    ASSERT(m_pathElement);
85    ASSERT(m_pathSegList);
86    if (mode == AbsoluteCoordinates)
87        m_pathSegList->append(m_pathElement->createSVGPathSegLinetoVerticalAbs(y, m_pathSegRole));
88    else
89        m_pathSegList->append(m_pathElement->createSVGPathSegLinetoVerticalRel(y, m_pathSegRole));
90}
91
92void SVGPathSegListBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
93{
94    ASSERT(m_pathElement);
95    ASSERT(m_pathSegList);
96    if (mode == AbsoluteCoordinates)
97        m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));
98    else
99        m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));
100}
101
102void SVGPathSegListBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
103{
104    ASSERT(m_pathElement);
105    ASSERT(m_pathSegList);
106    if (mode == AbsoluteCoordinates)
107        m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothAbs(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));
108    else
109        m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothRel(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));
110}
111
112void SVGPathSegListBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
113{
114    ASSERT(m_pathElement);
115    ASSERT(m_pathSegList);
116    if (mode == AbsoluteCoordinates)
117        m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));
118    else
119        m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));
120}
121
122void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
123{
124    ASSERT(m_pathElement);
125    ASSERT(m_pathSegList);
126    if (mode == AbsoluteCoordinates)
127        m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
128    else
129        m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
130}
131
132void SVGPathSegListBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
133{
134    ASSERT(m_pathElement);
135    ASSERT(m_pathSegList);
136    if (mode == AbsoluteCoordinates)
137        m_pathSegList->append(m_pathElement->createSVGPathSegArcAbs(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));
138    else
139        m_pathSegList->append(m_pathElement->createSVGPathSegArcRel(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));
140}
141
142void SVGPathSegListBuilder::closePath()
143{
144    ASSERT(m_pathElement);
145    ASSERT(m_pathSegList);
146    m_pathSegList->append(m_pathElement->createSVGPathSegClosePath(m_pathSegRole));
147}
148
149}
150
151#endif // ENABLE(SVG)
152