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 50namespace WebCore { 51 52SVGPathSegListBuilder::SVGPathSegListBuilder() 53 : m_pathElement(0) 54 , m_pathSegList(nullptr) 55 , m_pathSegRole(PathSegUndefinedRole) 56{ 57} 58 59void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode) 60{ 61 ASSERT(m_pathElement); 62 ASSERT(m_pathSegList); 63 if (mode == AbsoluteCoordinates) 64 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegMovetoAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y())); 65 else 66 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegMovetoRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y())); 67} 68 69void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) 70{ 71 ASSERT(m_pathElement); 72 ASSERT(m_pathSegList); 73 if (mode == AbsoluteCoordinates) 74 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y())); 75 else 76 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y())); 77} 78 79void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode) 80{ 81 ASSERT(m_pathElement); 82 ASSERT(m_pathSegList); 83 if (mode == AbsoluteCoordinates) 84 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoHorizontalAbs::create(m_pathElement, m_pathSegRole, x)); 85 else 86 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoHorizontalRel::create(m_pathElement, m_pathSegRole, x)); 87} 88 89void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode) 90{ 91 ASSERT(m_pathElement); 92 ASSERT(m_pathSegList); 93 if (mode == AbsoluteCoordinates) 94 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoVerticalAbs::create(m_pathElement, m_pathSegRole, y)); 95 else 96 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoVerticalRel::create(m_pathElement, m_pathSegRole, y)); 97} 98 99void 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->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y())); 105 else 106 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y())); 107} 108 109void 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->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicSmoothAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point2.x(), point2.y())); 115 else 116 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicSmoothRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point2.x(), point2.y())); 117} 118 119void 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->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point1.x(), point1.y())); 125 else 126 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), point1.x(), point1.y())); 127} 128 129void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) 130{ 131 ASSERT(m_pathElement); 132 ASSERT(m_pathSegList); 133 if (mode == AbsoluteCoordinates) 134 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticSmoothAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y())); 135 else 136 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticSmoothRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y())); 137} 138 139void 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->appendWithoutByteStreamSync(SVGPathSegArcAbs::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag)); 145 else 146 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegArcRel::create(m_pathElement, m_pathSegRole, targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag)); 147} 148 149void SVGPathSegListBuilder::closePath() 150{ 151 ASSERT(m_pathElement); 152 ASSERT(m_pathSegList); 153 m_pathSegList->appendWithoutByteStreamSync(SVGPathSegClosePath::create(m_pathElement, m_pathSegRole)); 154} 155 156} 157