• 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
SVGFilterElement.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4  Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
5 
6  This file is part of the KDE project
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include "config.h"
25 
26 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
27 #include "SVGFilterElement.h"
28 
29 #include "Attr.h"
30 #include "SVGResourceFilter.h"
31 #include "SVGFilterPrimitiveStandardAttributes.h"
32 #include "SVGLength.h"
33 #include "SVGNames.h"
34 #include "SVGUnitTypes.h"
35 
36 namespace WebCore {
37 
38 SVGFilterElement::SVGFilterElement(const QualifiedName& tagName, Document* doc)
39  : SVGStyledElement(tagName, doc)
40  , SVGURIReference()
41  , SVGLangSpace()
42  , SVGExternalResourcesRequired()
43  , m_filterUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
44  , m_primitiveUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
45  , m_x(this, LengthModeWidth)
46  , m_y(this, LengthModeHeight)
47  , m_width(this, LengthModeWidth)
48  , m_height(this, LengthModeHeight)
49  , m_filterResX(0)
50  , m_filterResY(0)
51 {
52  // Spec: If the attribute is not specified, the effect is as if a value of "-10%" were specified.
53  setXBaseValue(SVGLength(this, LengthModeWidth, "-10%"));
54  setYBaseValue(SVGLength(this, LengthModeHeight, "-10%"));
55 
56  // Spec: If the attribute is not specified, the effect is as if a value of "120%" were specified.
57  setWidthBaseValue(SVGLength(this, LengthModeWidth, "120%"));
58  setHeightBaseValue(SVGLength(this, LengthModeHeight, "120%"));
59 }
60 
61 SVGFilterElement::~SVGFilterElement()
62 {
63 }
64 
65 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, int, Enumeration, enumeration, FilterUnits, filterUnits, SVGNames::filterUnitsAttr, m_filterUnits)
66 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, int, Enumeration, enumeration, PrimitiveUnits, primitiveUnits, SVGNames::primitiveUnitsAttr, m_primitiveUnits)
67 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
68 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
69 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
70 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
71 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFilterElement, long, Integer, integer, FilterResX, filterResX, SVGNames::filterResAttr, "filterResX", m_filterResX)
72 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFilterElement, long, Integer, integer, FilterResY, filterResY, SVGNames::filterResAttr, "filterResY", m_filterResY)
73 
74 void SVGFilterElement::setFilterRes(unsigned long, unsigned long) const
75 {
76 }
77 
78 void SVGFilterElement::parseMappedAttribute(MappedAttribute* attr)
79 {
80  const String& value = attr->value();
81  if (attr->name() == SVGNames::filterUnitsAttr) {
82  if (value == "userSpaceOnUse")
83  setFilterUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
84  else if (value == "objectBoundingBox")
85  setFilterUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
86  } else if (attr->name() == SVGNames::primitiveUnitsAttr) {
87  if (value == "userSpaceOnUse")
88  setPrimitiveUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
89  else if (value == "objectBoundingBox")
90  setPrimitiveUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
91  } else if (attr->name() == SVGNames::xAttr)
92  setXBaseValue(SVGLength(this, LengthModeWidth, value));
93  else if (attr->name() == SVGNames::yAttr)
94  setYBaseValue(SVGLength(this, LengthModeHeight, value));
95  else if (attr->name() == SVGNames::widthAttr)
96  setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
97  else if (attr->name() == SVGNames::heightAttr)
98  setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
99  else {
100  if (SVGURIReference::parseMappedAttribute(attr)) return;
101  if (SVGLangSpace::parseMappedAttribute(attr)) return;
102  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) return;
103 
104  SVGStyledElement::parseMappedAttribute(attr);
105  }
106 }
107 
108 SVGResource* SVGFilterElement::canvasResource()
109 {
110  if (!attached())
111  return 0;
112 
113  if (!m_filter)
114  m_filter = new SVGResourceFilter();
115 
116  bool filterBBoxMode = filterUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
117  m_filter->setFilterBoundingBoxMode(filterBBoxMode);
118 
119  float _x, _y, _width, _height;
120 
121  if (filterBBoxMode) {
122  _x = x().valueAsPercentage();
123  _y = y().valueAsPercentage();
124  _width = width().valueAsPercentage();
125  _height = height().valueAsPercentage();
126  } else {
127  m_filter->setXBoundingBoxMode(x().unitType() == LengthTypePercentage);
128  m_filter->setYBoundingBoxMode(y().unitType() == LengthTypePercentage);
129 
130  _x = x().value();
131  _y = y().value();
132  _width = width().value();
133  _height = height().value();
134  }
135 
136  m_filter->setFilterRect(FloatRect(_x, _y, _width, _height));
137 
138  bool primitiveBBoxMode = primitiveUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
139  m_filter->setEffectBoundingBoxMode(primitiveBBoxMode);
140 
141  // TODO : use switch/case instead?
142  m_filter->clearEffects();
143  for (Node* n = firstChild(); n != 0; n = n->nextSibling()) {
144  SVGElement* element = 0;
145  if (n->isSVGElement())
146  element = static_cast<SVGElement*>(n);
147  if (element && element->isFilterEffect()) {
148  SVGFilterPrimitiveStandardAttributes* filterAttributes = static_cast<SVGFilterPrimitiveStandardAttributes*>(element);
149  SVGFilterEffect* filterEffect = filterAttributes->filterEffect(m_filter.get());
150  if (!filterEffect)
151  continue;
152 
153  m_filter->addFilterEffect(filterEffect);
154  }
155  }
156 
157  return m_filter.get();
158 }
159 
160 }
161 
162 #endif // ENABLE(SVG)
163 
164 // vim:ts=4:noet
WebCore::SVGNames::widthAttr
DOM::QualifiedName widthAttr
Definition: SVGNames.cpp:334
SVGFilterElement.h
SVGLength.h
WebCore::SVGNames::filterUnitsAttr
DOM::QualifiedName filterUnitsAttr
Definition: SVGNames.cpp:163
WebCore::SVGNames::filterResAttr
DOM::QualifiedName filterResAttr
Definition: SVGNames.cpp:162
WebCore::SVGNames::primitiveUnitsAttr
DOM::QualifiedName primitiveUnitsAttr
Definition: SVGNames.cpp:259
WebCore::SVGNames::yAttr
DOM::QualifiedName yAttr
Definition: SVGNames.cpp:343
WebCore::SVGNames::heightAttr
DOM::QualifiedName heightAttr
Definition: SVGNames.cpp:186
SVGNames.h
SVGResourceFilter.h
SVGFilterPrimitiveStandardAttributes.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
WebCore::SVGNames::xAttr
DOM::QualifiedName xAttr
Definition: SVGNames.cpp:338
SVGUnitTypes.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