• 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
SVGMarkerElement.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2006, 2007, 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 
25 #if ENABLE(SVG)
26 #include "SVGMarkerElement.h"
27 
28 #include "PlatformString.h"
29 #include "RenderSVGViewportContainer.h"
30 #include "SVGAngle.h"
31 #include "SVGFitToViewBox.h"
32 #include "SVGLength.h"
33 #include "SVGNames.h"
34 #include "SVGPreserveAspectRatio.h"
35 #include "SVGSVGElement.h"
36 
37 namespace WebCore {
38 
39 SVGMarkerElement::SVGMarkerElement(const QualifiedName& tagName, Document* doc)
40  : SVGStyledElement(tagName, doc)
41  , SVGLangSpace()
42  , SVGExternalResourcesRequired()
43  , SVGFitToViewBox()
44  , m_refX(this, LengthModeWidth)
45  , m_refY(this, LengthModeHeight)
46  , m_markerWidth(this, LengthModeWidth)
47  , m_markerHeight(this, LengthModeHeight)
48  , m_markerUnits(SVG_MARKERUNITS_STROKEWIDTH)
49  , m_orientType(0)
50  , m_orientAngle(new SVGAngle())
51 {
52  // Spec: If the attribute is not specified, the effect is as if a value of "3" were specified.
53  setMarkerWidthBaseValue(SVGLength(this, LengthModeWidth, "3"));
54  setMarkerHeightBaseValue(SVGLength(this, LengthModeHeight, "3"));
55 }
56 
57 SVGMarkerElement::~SVGMarkerElement()
58 {
59 }
60 
61 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGLength, Length, length, RefX, refX, SVGNames::refXAttr, m_refX)
62 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGLength, Length, length, RefY, refY, SVGNames::refYAttr, m_refY)
63 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, int, Enumeration, enumeration, MarkerUnits, markerUnits, SVGNames::markerUnitsAttr, m_markerUnits)
64 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGLength, Length, length, MarkerWidth, markerWidth, SVGNames::markerWidthAttr, m_markerWidth)
65 ANIMATED_PROPERTY_DEFINITIONS(SVGMarkerElement, SVGLength, Length, length, MarkerHeight, markerHeight, SVGNames::markerHeightAttr, m_markerHeight)
66 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGMarkerElement, int, Enumeration, enumeration, OrientType, orientType, SVGNames::orientAttr, "orientType", m_orientType)
67 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGMarkerElement, SVGAngle*, Angle, angle, OrientAngle, orientAngle, SVGNames::orientAttr, "orientAngle", m_orientAngle.get())
68 
69 void SVGMarkerElement::parseMappedAttribute(MappedAttribute* attr)
70 {
71  if (attr->name() == SVGNames::markerUnitsAttr) {
72  if (attr->value() == "userSpaceOnUse")
73  setMarkerUnitsBaseValue(SVG_MARKERUNITS_USERSPACEONUSE);
74  } else if (attr->name() == SVGNames::refXAttr)
75  setRefXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
76  else if (attr->name() == SVGNames::refYAttr)
77  setRefYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
78  else if (attr->name() == SVGNames::markerWidthAttr)
79  setMarkerWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
80  else if (attr->name() == SVGNames::markerHeightAttr)
81  setMarkerHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
82  else if (attr->name() == SVGNames::orientAttr) {
83  if (attr->value() == "auto")
84  setOrientToAuto();
85  else {
86  SVGAngle* angle = new SVGAngle();
87  angle->setValueAsString(attr->value());
88  setOrientToAngle(angle);
89  }
90  } else {
91  if (SVGLangSpace::parseMappedAttribute(attr))
92  return;
93  if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
94  return;
95  if (SVGFitToViewBox::parseMappedAttribute(attr))
96  return;
97 
98  SVGStyledElement::parseMappedAttribute(attr);
99  }
100 }
101 
102 void SVGMarkerElement::svgAttributeChanged(const QualifiedName& attrName)
103 {
104  SVGStyledElement::svgAttributeChanged(attrName);
105 
106  if (!m_marker)
107  return;
108 
109  if (attrName == SVGNames::markerUnitsAttr || attrName == SVGNames::refXAttr ||
110  attrName == SVGNames::refYAttr || attrName == SVGNames::markerWidthAttr ||
111  attrName == SVGNames::markerHeightAttr || attrName == SVGNames::orientAttr ||
112  SVGLangSpace::isKnownAttribute(attrName) ||
113  SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
114  SVGFitToViewBox::isKnownAttribute(attrName) ||
115  SVGStyledElement::isKnownAttribute(attrName)) {
116  if (renderer())
117  renderer()->setNeedsLayout(true);
118 
119  m_marker->invalidate();
120  }
121 }
122 
123 void SVGMarkerElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
124 {
125  SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
126 
127  if (renderer())
128  renderer()->setNeedsLayout(true);
129 
130  if (m_marker)
131  m_marker->invalidate();
132 }
133 
134 void SVGMarkerElement::setOrientToAuto()
135 {
136  setOrientTypeBaseValue(SVG_MARKER_ORIENT_AUTO);
137 }
138 
139 void SVGMarkerElement::setOrientToAngle(SVGAngle* angle)
140 {
141  setOrientTypeBaseValue(SVG_MARKER_ORIENT_ANGLE);
142  setOrientAngleBaseValue(angle);
143 }
144 
145 SVGResource* SVGMarkerElement::canvasResource()
146 {
147  if (!m_marker)
148  m_marker = SVGResourceMarker::create();
149 
150  m_marker->setMarker(static_cast<RenderSVGViewportContainer*>(renderer()));
151 
152  // Spec: If the attribute is not specified, the effect is as if a
153  // value of "0" were specified.
154  if (!m_orientType)
155  setOrientToAngle(SVGSVGElement::createSVGAngle());
156 
157  if (orientType() == SVG_MARKER_ORIENT_ANGLE)
158  m_marker->setAngle(orientAngle()->value());
159  else
160  m_marker->setAutoAngle();
161 
162  m_marker->setRef(refX().value(), refY().value());
163  m_marker->setUseStrokeWidth(markerUnits() == SVG_MARKERUNITS_STROKEWIDTH);
164 
165  return m_marker.get();
166 }
167 
168 RenderObject* SVGMarkerElement::createRenderer(RenderArena* arena, RenderStyle* style)
169 {
170  RenderSVGViewportContainer* markerContainer = new (arena) RenderSVGViewportContainer(this);
171  markerContainer->setDrawsContents(false); // Marker contents will be explicitly drawn.
172  return markerContainer;
173 }
174 
175 }
176 
177 #endif // ENABLE(SVG)
SVGMarkerElement.h
WebCore::SVGNames::markerWidthAttr
DOM::QualifiedName markerWidthAttr
Definition: SVGNames.cpp:217
SVGAngle.h
WebCore::SVGNames::orientAttr
DOM::QualifiedName orientAttr
Definition: SVGNames.cpp:240
WebCore::SVGNames::markerHeightAttr
DOM::QualifiedName markerHeightAttr
Definition: SVGNames.cpp:215
SVGLength.h
SVGSVGElement.h
WebCore::SVGNames::refXAttr
DOM::QualifiedName refXAttr
Definition: SVGNames.cpp:262
SVGPreserveAspectRatio.h
SVGFitToViewBox.h
SVGNames.h
WebCore::SVGNames::refYAttr
DOM::QualifiedName refYAttr
Definition: SVGNames.cpp:263
WebCore::SVGNames::markerUnitsAttr
DOM::QualifiedName markerUnitsAttr
Definition: SVGNames.cpp:216
PlatformString.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