• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • svg
SVGPathElement.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include "config.h"
24#include "wtf/Platform.h"
25
26#if ENABLE(SVG)
27#include "SVGPathElement.h"
28
29#include "RenderPath.h"
30#include "SVGNames.h"
31#include "SVGParserUtilities.h"
32#include "SVGPathSegArc.h"
33#include "SVGPathSegClosePath.h"
34#include "SVGPathSegCurvetoCubic.h"
35#include "SVGPathSegCurvetoCubicSmooth.h"
36#include "SVGPathSegCurvetoQuadratic.h"
37#include "SVGPathSegCurvetoQuadraticSmooth.h"
38#include "SVGPathSegLineto.h"
39#include "SVGPathSegLinetoHorizontal.h"
40#include "SVGPathSegLinetoVertical.h"
41#include "SVGPathSegList.h"
42#include "SVGPathSegMoveto.h"
43#include "SVGSVGElement.h"
44
45namespace WebCore {
46
47SVGPathElement::SVGPathElement(const QualifiedName& tagName, Document* doc)
48 : SVGStyledTransformableElement(tagName, doc)
49 , SVGTests()
50 , SVGLangSpace()
51 , SVGExternalResourcesRequired()
52 , m_pathLength(0.0f)
53{
54}
55
56SVGPathElement::~SVGPathElement()
57{
58}
59
60ANIMATED_PROPERTY_DEFINITIONS(SVGPathElement, float, Number, number, PathLength, pathLength, SVGNames::pathLengthAttr, m_pathLength)
61
62float SVGPathElement::getTotalLength()
63{
64 // FIXME: this may wish to use the pathSegList instead of the pathdata if that's cheaper to build (or cached)
65 return toPathData().length();
66}
67
68FloatPoint SVGPathElement::getPointAtLength(float length)
69{
70 // FIXME: this may wish to use the pathSegList instead of the pathdata if that's cheaper to build (or cached)
71 bool ok = false;
72 return toPathData().pointAtLength(length, ok);
73}
74
75unsigned long SVGPathElement::getPathSegAtLength(float length)
76{
77 return pathSegList()->getPathSegAtLength(length);
78}
79
80PassRefPtr<SVGPathSegClosePath> SVGPathElement::createSVGPathSegClosePath()
81{
82 return SVGPathSegClosePath::create();
83}
84
85PassRefPtr<SVGPathSegMovetoAbs> SVGPathElement::createSVGPathSegMovetoAbs(float x, float y)
86{
87 return SVGPathSegMovetoAbs::create(x, y);
88}
89
90PassRefPtr<SVGPathSegMovetoRel> SVGPathElement::createSVGPathSegMovetoRel(float x, float y)
91{
92 return SVGPathSegMovetoRel::create(x, y);
93}
94
95PassRefPtr<SVGPathSegLinetoAbs> SVGPathElement::createSVGPathSegLinetoAbs(float x, float y)
96{
97 return SVGPathSegLinetoAbs::create(x, y);
98}
99
100PassRefPtr<SVGPathSegLinetoRel> SVGPathElement::createSVGPathSegLinetoRel(float x, float y)
101{
102 return SVGPathSegLinetoRel::create(x, y);
103}
104
105PassRefPtr<SVGPathSegCurvetoCubicAbs> SVGPathElement::createSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1, float x2, float y2)
106{
107 return SVGPathSegCurvetoCubicAbs::create(x, y, x1, y1, x2, y2);
108}
109
110PassRefPtr<SVGPathSegCurvetoCubicRel> SVGPathElement::createSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1, float x2, float y2)
111{
112 return SVGPathSegCurvetoCubicRel::create(x, y, x1, y1, x2, y2);
113}
114
115PassRefPtr<SVGPathSegCurvetoQuadraticAbs> SVGPathElement::createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1)
116{
117 return SVGPathSegCurvetoQuadraticAbs::create(x, y, x1, y1);
118}
119
120PassRefPtr<SVGPathSegCurvetoQuadraticRel> SVGPathElement::createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1)
121{
122 return SVGPathSegCurvetoQuadraticRel::create(x, y, x1, y1);
123}
124
125PassRefPtr<SVGPathSegArcAbs> SVGPathElement::createSVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag)
126{
127 return SVGPathSegArcAbs::create(x, y, r1, r2, angle, largeArcFlag, sweepFlag);
128}
129
130PassRefPtr<SVGPathSegArcRel> SVGPathElement::createSVGPathSegArcRel(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag)
131{
132 return SVGPathSegArcRel::create(x, y, r1, r2, angle, largeArcFlag, sweepFlag);
133}
134
135PassRefPtr<SVGPathSegLinetoHorizontalAbs> SVGPathElement::createSVGPathSegLinetoHorizontalAbs(float x)
136{
137 return SVGPathSegLinetoHorizontalAbs::create(x);
138}
139
140PassRefPtr<SVGPathSegLinetoHorizontalRel> SVGPathElement::createSVGPathSegLinetoHorizontalRel(float x)
141{
142 return SVGPathSegLinetoHorizontalRel::create(x);
143}
144
145PassRefPtr<SVGPathSegLinetoVerticalAbs> SVGPathElement::createSVGPathSegLinetoVerticalAbs(float y)
146{
147 return SVGPathSegLinetoVerticalAbs::create(y);
148}
149
150PassRefPtr<SVGPathSegLinetoVerticalRel> SVGPathElement::createSVGPathSegLinetoVerticalRel(float y)
151{
152 return SVGPathSegLinetoVerticalRel::create(y);
153}
154
155PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> SVGPathElement::createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2)
156{
157 return SVGPathSegCurvetoCubicSmoothAbs::create(x, y, x2, y2);
158}
159
160PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> SVGPathElement::createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2)
161{
162 return SVGPathSegCurvetoCubicSmoothRel::create(x, y, x2, y2);
163}
164
165PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> SVGPathElement::createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y)
166{
167 return SVGPathSegCurvetoQuadraticSmoothAbs::create(x, y);
168}
169
170PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> SVGPathElement::createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y)
171{
172 return SVGPathSegCurvetoQuadraticSmoothRel::create(x, y);
173}
174
175void SVGPathElement::parseMappedAttribute(MappedAttribute* attr)
176{
177 if (attr->name() == SVGNames::dAttr) {
178 ExceptionCode ec;
179 pathSegList()->clear(ec);
180 pathSegListFromSVGData(pathSegList(), attr->value(), true);
181 /*FIXME khtml if (!pathSegListFromSVGData(pathSegList(), attr->value(), true))
182 document()->accessSVGExtensions()->reportError("Problem parsing d=\"" + attr->value() + "\"");*/
183 } else if (attr->name() == SVGNames::pathLengthAttr) {
184 m_pathLength = attr->value().toFloat();
185 if (m_pathLength < 0.0f)
186 document()->accessSVGExtensions()->reportError("A negative value for path attribute <pathLength> is not allowed");
187 } else {
188 if (SVGTests::parseMappedAttribute(attr))
189 return;
190 if (SVGLangSpace::parseMappedAttribute(attr))
191 return;
192 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
193 return;
194 SVGStyledTransformableElement::parseMappedAttribute(attr);
195 }
196}
197
198void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName)
199{
200 SVGStyledTransformableElement::svgAttributeChanged(attrName);
201
202 if (!renderer())
203 return;
204
205 if (attrName == SVGNames::dAttr || attrName == SVGNames::pathLengthAttr ||
206 SVGTests::isKnownAttribute(attrName) ||
207 SVGLangSpace::isKnownAttribute(attrName) ||
208 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
209 SVGStyledTransformableElement::isKnownAttribute(attrName))
210 renderer()->setNeedsLayout(true);
211}
212
213SVGPathSegList* SVGPathElement::pathSegList() const
214{
215 if (!m_pathSegList)
216 m_pathSegList = SVGPathSegList::create(SVGNames::dAttr);
217
218 return m_pathSegList.get();
219}
220
221SVGPathSegList* SVGPathElement::normalizedPathSegList() const
222{
223 // TODO
224 return 0;
225}
226
227SVGPathSegList* SVGPathElement::animatedPathSegList() const
228{
229 // TODO
230 return 0;
231}
232
233SVGPathSegList* SVGPathElement::animatedNormalizedPathSegList() const
234{
235 // TODO
236 return 0;
237}
238
239Path SVGPathElement::toPathData() const
240{
241 return pathSegList()->toPathData();
242}
243
244// KHTML ElementImpl pure virtual method
245quint32 SVGPathElement::id() const
246{
247 return SVGNames::pathTag.id();
248}
249
250}
251
252#endif // ENABLE(SVG)
SVGNames.h
SVGParserUtilities.h
SVGPathElement.h
SVGPathSegArc.h
SVGPathSegClosePath.h
SVGPathSegCurvetoCubicSmooth.h
SVGPathSegCurvetoCubic.h
SVGPathSegCurvetoQuadraticSmooth.h
SVGPathSegCurvetoQuadratic.h
SVGPathSegLinetoHorizontal.h
SVGPathSegLinetoVertical.h
SVGPathSegLineto.h
SVGPathSegList.h
SVGPathSegMoveto.h
SVGSVGElement.h
ok
KGuiItem ok()
WebCore
Definition: CSSHelper.h:7
WebCore::Path
khtml::Path Path
Definition: PathTraversalState.h:37
khtml::ExceptionCode
unsigned short ExceptionCode
Definition: ExceptionCode.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal