| 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, 2015 Apple Inc. All rights reserved. |
| 6 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 7 | * Copyright (C) 2019 Apple Inc. All rights reserved. |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU Library General Public |
| 11 | * License as published by the Free Software Foundation; either |
| 12 | * version 2 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * Library General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Library General Public License |
| 20 | * along with this library; see the file COPYING.LIB. If not, write to |
| 21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 | * Boston, MA 02110-1301, USA. |
| 23 | */ |
| 24 | |
| 25 | #include "config.h" |
| 26 | #include "SVGPathSegListBuilder.h" |
| 27 | |
| 28 | #include "SVGPathSegImpl.h" |
| 29 | #include "SVGPathSegList.h" |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | SVGPathSegListBuilder::SVGPathSegListBuilder(SVGPathSegList& pathSegList) |
| 34 | : m_pathSegList(pathSegList) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode) |
| 39 | { |
| 40 | if (mode == AbsoluteCoordinates) |
| 41 | m_pathSegList.append(SVGPathSegMovetoAbs::create(targetPoint.x(), targetPoint.y())); |
| 42 | else |
| 43 | m_pathSegList.append(SVGPathSegMovetoRel::create(targetPoint.x(), targetPoint.y())); |
| 44 | } |
| 45 | |
| 46 | void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) |
| 47 | { |
| 48 | if (mode == AbsoluteCoordinates) |
| 49 | m_pathSegList.append(SVGPathSegLinetoAbs::create(targetPoint.x(), targetPoint.y())); |
| 50 | else |
| 51 | m_pathSegList.append(SVGPathSegLinetoRel::create(targetPoint.x(), targetPoint.y())); |
| 52 | } |
| 53 | |
| 54 | void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode) |
| 55 | { |
| 56 | if (mode == AbsoluteCoordinates) |
| 57 | m_pathSegList.append(SVGPathSegLinetoHorizontalAbs::create(x)); |
| 58 | else |
| 59 | m_pathSegList.append(SVGPathSegLinetoHorizontalRel::create(x)); |
| 60 | } |
| 61 | |
| 62 | void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode) |
| 63 | { |
| 64 | if (mode == AbsoluteCoordinates) |
| 65 | m_pathSegList.append(SVGPathSegLinetoVerticalAbs::create(y)); |
| 66 | else |
| 67 | m_pathSegList.append(SVGPathSegLinetoVerticalRel::create(y)); |
| 68 | } |
| 69 | |
| 70 | void SVGPathSegListBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) |
| 71 | { |
| 72 | if (mode == AbsoluteCoordinates) |
| 73 | m_pathSegList.append(SVGPathSegCurvetoCubicAbs::create(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y())); |
| 74 | else |
| 75 | m_pathSegList.append(SVGPathSegCurvetoCubicRel::create(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y())); |
| 76 | } |
| 77 | |
| 78 | void SVGPathSegListBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) |
| 79 | { |
| 80 | if (mode == AbsoluteCoordinates) |
| 81 | m_pathSegList.append(SVGPathSegCurvetoCubicSmoothAbs::create(targetPoint.x(), targetPoint.y(), point2.x(), point2.y())); |
| 82 | else |
| 83 | m_pathSegList.append(SVGPathSegCurvetoCubicSmoothRel::create(targetPoint.x(), targetPoint.y(), point2.x(), point2.y())); |
| 84 | } |
| 85 | |
| 86 | void SVGPathSegListBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode) |
| 87 | { |
| 88 | if (mode == AbsoluteCoordinates) |
| 89 | m_pathSegList.append(SVGPathSegCurvetoQuadraticAbs::create(targetPoint.x(), targetPoint.y(), point1.x(), point1.y())); |
| 90 | else |
| 91 | m_pathSegList.append(SVGPathSegCurvetoQuadraticRel::create(targetPoint.x(), targetPoint.y(), point1.x(), point1.y())); |
| 92 | } |
| 93 | |
| 94 | void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) |
| 95 | { |
| 96 | if (mode == AbsoluteCoordinates) |
| 97 | m_pathSegList.append(SVGPathSegCurvetoQuadraticSmoothAbs::create(targetPoint.x(), targetPoint.y())); |
| 98 | else |
| 99 | m_pathSegList.append(SVGPathSegCurvetoQuadraticSmoothRel::create(targetPoint.x(), targetPoint.y())); |
| 100 | } |
| 101 | |
| 102 | void SVGPathSegListBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode) |
| 103 | { |
| 104 | if (mode == AbsoluteCoordinates) |
| 105 | m_pathSegList.append(SVGPathSegArcAbs::create(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag)); |
| 106 | else |
| 107 | m_pathSegList.append(SVGPathSegArcRel::create(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag)); |
| 108 | } |
| 109 | |
| 110 | void SVGPathSegListBuilder::closePath() |
| 111 | { |
| 112 | m_pathSegList.append(SVGPathSegClosePath::create()); |
| 113 | } |
| 114 | |
| 115 | } |
| 116 | |