00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include "wtf/Platform.h"
00025
00026 #if ENABLE(SVG)
00027 #include "SVGPathElement.h"
00028
00029 #include "RenderPath.h"
00030 #include "SVGNames.h"
00031 #include "SVGParserUtilities.h"
00032 #include "SVGPathSegArc.h"
00033 #include "SVGPathSegClosePath.h"
00034 #include "SVGPathSegCurvetoCubic.h"
00035 #include "SVGPathSegCurvetoCubicSmooth.h"
00036 #include "SVGPathSegCurvetoQuadratic.h"
00037 #include "SVGPathSegCurvetoQuadraticSmooth.h"
00038 #include "SVGPathSegLineto.h"
00039 #include "SVGPathSegLinetoHorizontal.h"
00040 #include "SVGPathSegLinetoVertical.h"
00041 #include "SVGPathSegList.h"
00042 #include "SVGPathSegMoveto.h"
00043 #include "SVGSVGElement.h"
00044
00045 namespace WebCore {
00046
00047 SVGPathElement::SVGPathElement(const QualifiedName& tagName, Document* doc)
00048 : SVGStyledTransformableElement(tagName, doc)
00049 , SVGTests()
00050 , SVGLangSpace()
00051 , SVGExternalResourcesRequired()
00052 , m_pathLength(0.0f)
00053 {
00054 }
00055
00056 SVGPathElement::~SVGPathElement()
00057 {
00058 }
00059
00060 ANIMATED_PROPERTY_DEFINITIONS(SVGPathElement, float, Number, number, PathLength, pathLength, SVGNames::pathLengthAttr, m_pathLength)
00061
00062 float SVGPathElement::getTotalLength()
00063 {
00064
00065 return toPathData().length();
00066 }
00067
00068 FloatPoint SVGPathElement::getPointAtLength(float length)
00069 {
00070
00071 bool ok = false;
00072 return toPathData().pointAtLength(length, ok);
00073 }
00074
00075 unsigned long SVGPathElement::getPathSegAtLength(float length)
00076 {
00077 return pathSegList()->getPathSegAtLength(length);
00078 }
00079
00080 PassRefPtr<SVGPathSegClosePath> SVGPathElement::createSVGPathSegClosePath()
00081 {
00082 return SVGPathSegClosePath::create();
00083 }
00084
00085 PassRefPtr<SVGPathSegMovetoAbs> SVGPathElement::createSVGPathSegMovetoAbs(float x, float y)
00086 {
00087 return SVGPathSegMovetoAbs::create(x, y);
00088 }
00089
00090 PassRefPtr<SVGPathSegMovetoRel> SVGPathElement::createSVGPathSegMovetoRel(float x, float y)
00091 {
00092 return SVGPathSegMovetoRel::create(x, y);
00093 }
00094
00095 PassRefPtr<SVGPathSegLinetoAbs> SVGPathElement::createSVGPathSegLinetoAbs(float x, float y)
00096 {
00097 return SVGPathSegLinetoAbs::create(x, y);
00098 }
00099
00100 PassRefPtr<SVGPathSegLinetoRel> SVGPathElement::createSVGPathSegLinetoRel(float x, float y)
00101 {
00102 return SVGPathSegLinetoRel::create(x, y);
00103 }
00104
00105 PassRefPtr<SVGPathSegCurvetoCubicAbs> SVGPathElement::createSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1, float x2, float y2)
00106 {
00107 return SVGPathSegCurvetoCubicAbs::create(x, y, x1, y1, x2, y2);
00108 }
00109
00110 PassRefPtr<SVGPathSegCurvetoCubicRel> SVGPathElement::createSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1, float x2, float y2)
00111 {
00112 return SVGPathSegCurvetoCubicRel::create(x, y, x1, y1, x2, y2);
00113 }
00114
00115 PassRefPtr<SVGPathSegCurvetoQuadraticAbs> SVGPathElement::createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1)
00116 {
00117 return SVGPathSegCurvetoQuadraticAbs::create(x, y, x1, y1);
00118 }
00119
00120 PassRefPtr<SVGPathSegCurvetoQuadraticRel> SVGPathElement::createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1)
00121 {
00122 return SVGPathSegCurvetoQuadraticRel::create(x, y, x1, y1);
00123 }
00124
00125 PassRefPtr<SVGPathSegArcAbs> SVGPathElement::createSVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag)
00126 {
00127 return SVGPathSegArcAbs::create(x, y, r1, r2, angle, largeArcFlag, sweepFlag);
00128 }
00129
00130 PassRefPtr<SVGPathSegArcRel> SVGPathElement::createSVGPathSegArcRel(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag)
00131 {
00132 return SVGPathSegArcRel::create(x, y, r1, r2, angle, largeArcFlag, sweepFlag);
00133 }
00134
00135 PassRefPtr<SVGPathSegLinetoHorizontalAbs> SVGPathElement::createSVGPathSegLinetoHorizontalAbs(float x)
00136 {
00137 return SVGPathSegLinetoHorizontalAbs::create(x);
00138 }
00139
00140 PassRefPtr<SVGPathSegLinetoHorizontalRel> SVGPathElement::createSVGPathSegLinetoHorizontalRel(float x)
00141 {
00142 return SVGPathSegLinetoHorizontalRel::create(x);
00143 }
00144
00145 PassRefPtr<SVGPathSegLinetoVerticalAbs> SVGPathElement::createSVGPathSegLinetoVerticalAbs(float y)
00146 {
00147 return SVGPathSegLinetoVerticalAbs::create(y);
00148 }
00149
00150 PassRefPtr<SVGPathSegLinetoVerticalRel> SVGPathElement::createSVGPathSegLinetoVerticalRel(float y)
00151 {
00152 return SVGPathSegLinetoVerticalRel::create(y);
00153 }
00154
00155 PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> SVGPathElement::createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2)
00156 {
00157 return SVGPathSegCurvetoCubicSmoothAbs::create(x, y, x2, y2);
00158 }
00159
00160 PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> SVGPathElement::createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2)
00161 {
00162 return SVGPathSegCurvetoCubicSmoothRel::create(x, y, x2, y2);
00163 }
00164
00165 PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> SVGPathElement::createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y)
00166 {
00167 return SVGPathSegCurvetoQuadraticSmoothAbs::create(x, y);
00168 }
00169
00170 PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> SVGPathElement::createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y)
00171 {
00172 return SVGPathSegCurvetoQuadraticSmoothRel::create(x, y);
00173 }
00174
00175 void SVGPathElement::parseMappedAttribute(MappedAttribute* attr)
00176 {
00177 if (attr->name() == SVGNames::dAttr) {
00178 ExceptionCode ec;
00179 pathSegList()->clear(ec);
00180 pathSegListFromSVGData(pathSegList(), attr->value(), true);
00181
00182
00183 } else if (attr->name() == SVGNames::pathLengthAttr) {
00184 m_pathLength = attr->value().toFloat();
00185 if (m_pathLength < 0.0f)
00186 document()->accessSVGExtensions()->reportError("A negative value for path attribute <pathLength> is not allowed");
00187 } else {
00188 if (SVGTests::parseMappedAttribute(attr))
00189 return;
00190 if (SVGLangSpace::parseMappedAttribute(attr))
00191 return;
00192 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
00193 return;
00194 SVGStyledTransformableElement::parseMappedAttribute(attr);
00195 }
00196 }
00197
00198 void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName)
00199 {
00200 SVGStyledTransformableElement::svgAttributeChanged(attrName);
00201
00202 if (!renderer())
00203 return;
00204
00205 if (attrName == SVGNames::dAttr || attrName == SVGNames::pathLengthAttr ||
00206 SVGTests::isKnownAttribute(attrName) ||
00207 SVGLangSpace::isKnownAttribute(attrName) ||
00208 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
00209 SVGStyledTransformableElement::isKnownAttribute(attrName))
00210 renderer()->setNeedsLayout(true);
00211 }
00212
00213 SVGPathSegList* SVGPathElement::pathSegList() const
00214 {
00215 if (!m_pathSegList)
00216 m_pathSegList = SVGPathSegList::create(SVGNames::dAttr);
00217
00218 return m_pathSegList.get();
00219 }
00220
00221 SVGPathSegList* SVGPathElement::normalizedPathSegList() const
00222 {
00223
00224 return 0;
00225 }
00226
00227 SVGPathSegList* SVGPathElement::animatedPathSegList() const
00228 {
00229
00230 return 0;
00231 }
00232
00233 SVGPathSegList* SVGPathElement::animatedNormalizedPathSegList() const
00234 {
00235
00236 return 0;
00237 }
00238
00239 Path SVGPathElement::toPathData() const
00240 {
00241 return pathSegList()->toPathData();
00242 }
00243
00244
00245 quint32 SVGPathElement::id() const
00246 {
00247 return SVGNames::pathTag.id();
00248 }
00249
00250 }
00251
00252 #endif // ENABLE(SVG)