Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2002, 2003 The Karbon Developers
      3  * Copyright (C) 2006 Alexander Kellett <lypanov (at) kde.org>
      4  * Copyright (C) 2006, 2007 Rob Buis <buis (at) 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 blink {
     51 
     52 SVGPathSegListBuilder::SVGPathSegListBuilder()
     53     : m_pathElement(0)
     54     , m_pathSegList(nullptr)
     55 {
     56 }
     57 
     58 void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
     59 {
     60     ASSERT(m_pathElement);
     61     ASSERT(m_pathSegList);
     62     if (mode == AbsoluteCoordinates)
     63         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegMovetoAbs::create(m_pathElement, targetPoint.x(), targetPoint.y()));
     64     else
     65         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegMovetoRel::create(m_pathElement, targetPoint.x(), targetPoint.y()));
     66 }
     67 
     68 void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
     69 {
     70     ASSERT(m_pathElement);
     71     ASSERT(m_pathSegList);
     72     if (mode == AbsoluteCoordinates)
     73         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoAbs::create(m_pathElement, targetPoint.x(), targetPoint.y()));
     74     else
     75         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoRel::create(m_pathElement, targetPoint.x(), targetPoint.y()));
     76 }
     77 
     78 void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
     79 {
     80     ASSERT(m_pathElement);
     81     ASSERT(m_pathSegList);
     82     if (mode == AbsoluteCoordinates)
     83         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoHorizontalAbs::create(m_pathElement, x));
     84     else
     85         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoHorizontalRel::create(m_pathElement, x));
     86 }
     87 
     88 void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode)
     89 {
     90     ASSERT(m_pathElement);
     91     ASSERT(m_pathSegList);
     92     if (mode == AbsoluteCoordinates)
     93         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoVerticalAbs::create(m_pathElement, y));
     94     else
     95         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegLinetoVerticalRel::create(m_pathElement, y));
     96 }
     97 
     98 void SVGPathSegListBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
     99 {
    100     ASSERT(m_pathElement);
    101     ASSERT(m_pathSegList);
    102     if (mode == AbsoluteCoordinates)
    103         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicAbs::create(m_pathElement, targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y()));
    104     else
    105         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicRel::create(m_pathElement, targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y()));
    106 }
    107 
    108 void SVGPathSegListBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
    109 {
    110     ASSERT(m_pathElement);
    111     ASSERT(m_pathSegList);
    112     if (mode == AbsoluteCoordinates)
    113         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicSmoothAbs::create(m_pathElement, targetPoint.x(), targetPoint.y(), point2.x(), point2.y()));
    114     else
    115         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoCubicSmoothRel::create(m_pathElement, targetPoint.x(), targetPoint.y(), point2.x(), point2.y()));
    116 }
    117 
    118 void SVGPathSegListBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
    119 {
    120     ASSERT(m_pathElement);
    121     ASSERT(m_pathSegList);
    122     if (mode == AbsoluteCoordinates)
    123         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticAbs::create(m_pathElement, targetPoint.x(), targetPoint.y(), point1.x(), point1.y()));
    124     else
    125         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticRel::create(m_pathElement, targetPoint.x(), targetPoint.y(), point1.x(), point1.y()));
    126 }
    127 
    128 void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
    129 {
    130     ASSERT(m_pathElement);
    131     ASSERT(m_pathSegList);
    132     if (mode == AbsoluteCoordinates)
    133         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticSmoothAbs::create(m_pathElement, targetPoint.x(), targetPoint.y()));
    134     else
    135         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegCurvetoQuadraticSmoothRel::create(m_pathElement, targetPoint.x(), targetPoint.y()));
    136 }
    137 
    138 void SVGPathSegListBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
    139 {
    140     ASSERT(m_pathElement);
    141     ASSERT(m_pathSegList);
    142     if (mode == AbsoluteCoordinates)
    143         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegArcAbs::create(m_pathElement, targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag));
    144     else
    145         m_pathSegList->appendWithoutByteStreamSync(SVGPathSegArcRel::create(m_pathElement, targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag));
    146 }
    147 
    148 void SVGPathSegListBuilder::closePath()
    149 {
    150     ASSERT(m_pathElement);
    151     ASSERT(m_pathSegList);
    152     m_pathSegList->appendWithoutByteStreamSync(SVGPathSegClosePath::create(m_pathElement));
    153 }
    154 
    155 }
    156