2 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
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.
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.
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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
25 #include "SVGMarkerElement.h"
28 #include "KRenderingDevice.h"
29 #include "PlatformString.h"
30 #include "RenderSVGContainer.h"
32 #include "SVGFitToViewBox.h"
33 #include "SVGHelper.h"
34 #include "SVGLength.h"
35 #include "SVGMatrix.h"
37 #include "SVGPreserveAspectRatio.h"
38 #include "SVGSVGElement.h"
43 SVGMarkerElement::SVGMarkerElement(const QualifiedName& tagName, Document *doc)
44 : SVGStyledElement(tagName, doc)
46 , SVGExternalResourcesRequired()
48 , m_refX(new SVGLength(this, LM_WIDTH, viewportElement()))
49 , m_refY(new SVGLength(this, LM_HEIGHT, viewportElement()))
50 , m_markerWidth(new SVGLength(this, LM_WIDTH, viewportElement()))
51 , m_markerHeight(new SVGLength(this, LM_HEIGHT, viewportElement()))
52 , m_markerUnits(SVG_MARKERUNITS_STROKEWIDTH)
54 , m_orientAngle(new SVGAngle(this))
59 SVGMarkerElement::~SVGMarkerElement()
64 void SVGMarkerElement::parseMappedAttribute(MappedAttribute *attr)
66 const AtomicString& value = attr->value();
67 if (attr->name() == SVGNames::markerUnitsAttr) {
68 if (value == "userSpaceOnUse")
69 setMarkerUnitsBaseValue(SVG_MARKERUNITS_USERSPACEONUSE);
70 } else if (attr->name() == SVGNames::refXAttr)
71 refXBaseValue()->setValueAsString(value);
72 else if (attr->name() == SVGNames::refYAttr)
73 refYBaseValue()->setValueAsString(value);
74 else if (attr->name() == SVGNames::markerWidthAttr)
75 markerWidthBaseValue()->setValueAsString(value);
76 else if (attr->name() == SVGNames::markerHeightAttr)
77 markerHeightBaseValue()->setValueAsString(value);
78 else if (attr->name() == SVGNames::orientAttr) {
82 SVGAngle* angle = new SVGAngle(0);
83 angle->setValueAsString(value);
84 setOrientToAngle(angle);
87 if (SVGLangSpace::parseMappedAttribute(attr))
89 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
91 if (SVGFitToViewBox::parseMappedAttribute(attr))
94 SVGStyledElement::parseMappedAttribute(attr);
98 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGLength*, Length, length, RefX, refX, SVGNames::refXAttr.localName(), m_refX.get())
99 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGLength*, Length, length, RefY, refY, SVGNames::refYAttr.localName(), m_refY.get())
100 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, int, Enumeration, enumeration, MarkerUnits, markerUnits, SVGNames::markerUnitsAttr.localName(), m_markerUnits)
101 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGLength*, Length, length, MarkerWidth, markerWidth, SVGNames::markerWidthAttr.localName(), m_markerWidth.get())
102 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGLength*, Length, length, MarkerHeight, markerHeight, SVGNames::markerHeightAttr.localName(), m_markerHeight.get())
103 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, int, Enumeration, enumeration, OrientType, orientType, "orientType", m_orientType)
104 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGAngle*, Angle, angle, OrientAngle, orientAngle, "orientAngle", m_orientAngle.get())
106 void SVGMarkerElement::setOrientToAuto()
108 setOrientTypeBaseValue(SVG_MARKER_ORIENT_AUTO);
111 void SVGMarkerElement::setOrientToAngle(SVGAngle *angle)
113 setOrientTypeBaseValue(SVG_MARKER_ORIENT_ANGLE);
114 setOrientAngleBaseValue(angle);
117 KCanvasMarker *SVGMarkerElement::canvasResource()
120 m_marker = static_cast<KCanvasMarker*>(renderingDevice()->createResource(RS_MARKER));
122 m_marker->setMarker(static_cast<RenderSVGContainer*>(renderer()));
124 // Spec: If the attribute is not specified, the effect is as if a
125 // value of "0" were specified.
127 setOrientToAngle(SVGSVGElement::createSVGAngle());
129 if (orientType() == SVG_MARKER_ORIENT_ANGLE)
130 m_marker->setAngle(orientAngle()->value());
132 m_marker->setAutoAngle();
134 m_marker->setRef(refX()->value(), refY()->value());
135 m_marker->setUseStrokeWidth(markerUnits() == SVG_MARKERUNITS_STROKEWIDTH);
140 RenderObject* SVGMarkerElement::createRenderer(RenderArena* arena, RenderStyle* style)
142 RenderSVGContainer* markerContainer = new (arena) RenderSVGContainer(this);
143 markerContainer->setViewBox(viewBox());
144 markerContainer->setAlign(KCAlign(preserveAspectRatio()->align() - 1));
145 markerContainer->setSlice(preserveAspectRatio()->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE);
146 markerContainer->setDrawsContents(false); // Marker contents will be explicitly drawn.
147 return markerContainer;
153 #endif // SVG_SUPPORT