15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2002, 2003 The Karbon Developers
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) Research In Motion Limited 2010. All rights reserved.
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is free software; you can redistribute it and/or
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU Library General Public
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License as published by the Free Software Foundation; either
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * version 2 of the License, or (at your option) any later version.
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is distributed in the hope that it will be useful,
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Library General Public License for more details.
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU Library General Public License
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * along with this library; see the file COPYING.LIB.  If not, write to
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Boston, MA 02110-1301, USA.
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/svg/SVGPathSegListBuilder.h"
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/ExceptionCode.h"
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/svg/SVGPathElement.h"
30e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegArcAbs.h"
31e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegArcRel.h"
3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/svg/SVGPathSegClosePath.h"
33e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegCurvetoCubicAbs.h"
34e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegCurvetoCubicRel.h"
35e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegCurvetoCubicSmoothAbs.h"
36e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegCurvetoCubicSmoothRel.h"
37e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegCurvetoQuadraticAbs.h"
38e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegCurvetoQuadraticRel.h"
39e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegCurvetoQuadraticSmoothAbs.h"
40e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegCurvetoQuadraticSmoothRel.h"
41e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegLinetoAbs.h"
42e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegLinetoHorizontalAbs.h"
43e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegLinetoHorizontalRel.h"
44e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegLinetoRel.h"
45e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegLinetoVerticalAbs.h"
46e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegLinetoVerticalRel.h"
47e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegMovetoAbs.h"
48e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/svg/SVGPathSegMovetoRel.h"
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore {
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)SVGPathSegListBuilder::SVGPathSegListBuilder()
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    : m_pathElement(0)
54d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    , m_pathSegList(nullptr)
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_pathSegRole(PathSegUndefinedRole)
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
64d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegMovetoAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y()));
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
66d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegMovetoRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y()));
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
74d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y()));
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
76d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y()));
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
84d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoHorizontalAbs::create(m_pathElement, m_pathSegRole, x));
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
86d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoHorizontalRel::create(m_pathElement, m_pathSegRole, x));
875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode)
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
94d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoVerticalAbs::create(m_pathElement, m_pathSegRole, y));
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
96d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoVerticalRel::create(m_pathElement, m_pathSegRole, y));
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
104d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y()));
1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
106d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y()));
1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
114d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicSmoothAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point2.x(), point2.y()));
1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
116d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicSmoothRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point2.x(), point2.y()));
1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
124d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point1.x(), point1.y()));
1255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
126d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point1.x(), point1.y()));
1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
134d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticSmoothAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y()));
1355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
136d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticSmoothRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y()));
1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (mode == AbsoluteCoordinates)
144d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegArcAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag));
1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else
146d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_pathSegList->appendWithoutByteStreamSync(SVGPathSegArcRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag));
1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SVGPathSegListBuilder::closePath()
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathElement);
1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_pathSegList);
153d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    m_pathSegList->appendWithoutByteStreamSync(SVGPathSegClosePath::create(m_pathElement, m_pathSegRole));
1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
157