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

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • 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 
45 namespace WebCore {
46 
47 SVGPathElement::SVGPathElement(const QualifiedName& tagName, Document* doc)
48  : SVGStyledTransformableElement(tagName, doc)
49  , SVGTests()
50  , SVGLangSpace()
51  , SVGExternalResourcesRequired()
52  , m_pathLength(0.0f)
53 {
54 }
55 
56 SVGPathElement::~SVGPathElement()
57 {
58 }
59 
60 ANIMATED_PROPERTY_DEFINITIONS(SVGPathElement, float, Number, number, PathLength, pathLength, SVGNames::pathLengthAttr, m_pathLength)
61 
62 float 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 
68 FloatPoint 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 
75 unsigned long SVGPathElement::getPathSegAtLength(float length)
76 {
77  return pathSegList()->getPathSegAtLength(length);
78 }
79 
80 PassRefPtr<SVGPathSegClosePath> SVGPathElement::createSVGPathSegClosePath()
81 {
82  return SVGPathSegClosePath::create();
83 }
84 
85 PassRefPtr<SVGPathSegMovetoAbs> SVGPathElement::createSVGPathSegMovetoAbs(float x, float y)
86 {
87  return SVGPathSegMovetoAbs::create(x, y);
88 }
89 
90 PassRefPtr<SVGPathSegMovetoRel> SVGPathElement::createSVGPathSegMovetoRel(float x, float y)
91 {
92  return SVGPathSegMovetoRel::create(x, y);
93 }
94 
95 PassRefPtr<SVGPathSegLinetoAbs> SVGPathElement::createSVGPathSegLinetoAbs(float x, float y)
96 {
97  return SVGPathSegLinetoAbs::create(x, y);
98 }
99 
100 PassRefPtr<SVGPathSegLinetoRel> SVGPathElement::createSVGPathSegLinetoRel(float x, float y)
101 {
102  return SVGPathSegLinetoRel::create(x, y);
103 }
104 
105 PassRefPtr<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 
110 PassRefPtr<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 
115 PassRefPtr<SVGPathSegCurvetoQuadraticAbs> SVGPathElement::createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1)
116 {
117  return SVGPathSegCurvetoQuadraticAbs::create(x, y, x1, y1);
118 }
119 
120 PassRefPtr<SVGPathSegCurvetoQuadraticRel> SVGPathElement::createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1)
121 {
122  return SVGPathSegCurvetoQuadraticRel::create(x, y, x1, y1);
123 }
124 
125 PassRefPtr<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 
130 PassRefPtr<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 
135 PassRefPtr<SVGPathSegLinetoHorizontalAbs> SVGPathElement::createSVGPathSegLinetoHorizontalAbs(float x)
136 {
137  return SVGPathSegLinetoHorizontalAbs::create(x);
138 }
139 
140 PassRefPtr<SVGPathSegLinetoHorizontalRel> SVGPathElement::createSVGPathSegLinetoHorizontalRel(float x)
141 {
142  return SVGPathSegLinetoHorizontalRel::create(x);
143 }
144 
145 PassRefPtr<SVGPathSegLinetoVerticalAbs> SVGPathElement::createSVGPathSegLinetoVerticalAbs(float y)
146 {
147  return SVGPathSegLinetoVerticalAbs::create(y);
148 }
149 
150 PassRefPtr<SVGPathSegLinetoVerticalRel> SVGPathElement::createSVGPathSegLinetoVerticalRel(float y)
151 {
152  return SVGPathSegLinetoVerticalRel::create(y);
153 }
154 
155 PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> SVGPathElement::createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2)
156 {
157  return SVGPathSegCurvetoCubicSmoothAbs::create(x, y, x2, y2);
158 }
159 
160 PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> SVGPathElement::createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2)
161 {
162  return SVGPathSegCurvetoCubicSmoothRel::create(x, y, x2, y2);
163 }
164 
165 PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> SVGPathElement::createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y)
166 {
167  return SVGPathSegCurvetoQuadraticSmoothAbs::create(x, y);
168 }
169 
170 PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> SVGPathElement::createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y)
171 {
172  return SVGPathSegCurvetoQuadraticSmoothRel::create(x, y);
173 }
174 
175 void 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 
198 void 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 
213 SVGPathSegList* SVGPathElement::pathSegList() const
214 {
215  if (!m_pathSegList)
216  m_pathSegList = SVGPathSegList::create(SVGNames::dAttr);
217 
218  return m_pathSegList.get();
219 }
220 
221 SVGPathSegList* SVGPathElement::normalizedPathSegList() const
222 {
223  // TODO
224  return 0;
225 }
226 
227 SVGPathSegList* SVGPathElement::animatedPathSegList() const
228 {
229  // TODO
230  return 0;
231 }
232 
233 SVGPathSegList* SVGPathElement::animatedNormalizedPathSegList() const
234 {
235  // TODO
236  return 0;
237 }
238 
239 Path SVGPathElement::toPathData() const
240 {
241  return pathSegList()->toPathData();
242 }
243 
244 // KHTML ElementImpl pure virtual method
245 quint32 SVGPathElement::id() const
246 {
247  return SVGNames::pathTag.id();
248 }
249 
250 }
251 
252 #endif // ENABLE(SVG)
SVGPathSegList.h
SVGPathSegClosePath.h
SVGPathSegLinetoVertical.h
DOM::QualifiedName::id
unsigned id() const
Definition: QualifiedName.cpp:90
SVGPathSegCurvetoQuadratic.h
SVGParserUtilities.h
SVGPathSegCurvetoCubicSmooth.h
quint32
SVGPathSegLinetoHorizontal.h
WebCore::SVGNames::dAttr
DOM::QualifiedName dAttr
Definition: SVGNames.cpp:137
SVGPathSegCurvetoCubic.h
SVGPathSegLineto.h
SVGSVGElement.h
WebCore::Path
khtml::Path Path
Definition: PathTraversalState.h:37
SVGPathElement.h
WebCore::SVGNames::pathTag
DOM::QualifiedName pathTag
Definition: SVGNames.cpp:82
SVGNames.h
SVGPathSegCurvetoQuadraticSmooth.h
ok
KGuiItem ok()
SVGPathSegMoveto.h
WebCore::SVGNames::pathLengthAttr
DOM::QualifiedName pathLengthAttr
Definition: SVGNames.cpp:248
SVGPathSegArc.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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