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

KHTML

SVGFilterElement.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
00003     Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
00004     Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
00005 
00006     This file is part of the KDE project
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "config.h"
00025 
00026 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
00027 #include "SVGFilterElement.h"
00028 
00029 #include "Attr.h"
00030 #include "SVGResourceFilter.h"
00031 #include "SVGFilterPrimitiveStandardAttributes.h"
00032 #include "SVGLength.h"
00033 #include "SVGNames.h"
00034 #include "SVGUnitTypes.h"
00035 
00036 namespace WebCore {
00037 
00038 SVGFilterElement::SVGFilterElement(const QualifiedName& tagName, Document* doc)
00039     : SVGStyledElement(tagName, doc)
00040     , SVGURIReference()
00041     , SVGLangSpace()
00042     , SVGExternalResourcesRequired()
00043     , m_filterUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
00044     , m_primitiveUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
00045     , m_x(this, LengthModeWidth)
00046     , m_y(this, LengthModeHeight)
00047     , m_width(this, LengthModeWidth)
00048     , m_height(this, LengthModeHeight)
00049     , m_filterResX(0)
00050     , m_filterResY(0)
00051 {
00052     // Spec: If the attribute is not specified, the effect is as if a value of "-10%" were specified.
00053     setXBaseValue(SVGLength(this, LengthModeWidth, "-10%"));
00054     setYBaseValue(SVGLength(this, LengthModeHeight, "-10%"));
00055  
00056     // Spec: If the attribute is not specified, the effect is as if a value of "120%" were specified.
00057     setWidthBaseValue(SVGLength(this, LengthModeWidth, "120%"));
00058     setHeightBaseValue(SVGLength(this, LengthModeHeight, "120%"));
00059 }
00060 
00061 SVGFilterElement::~SVGFilterElement()
00062 {
00063 }
00064 
00065 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, int, Enumeration, enumeration, FilterUnits, filterUnits, SVGNames::filterUnitsAttr, m_filterUnits)
00066 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, int, Enumeration, enumeration, PrimitiveUnits, primitiveUnits, SVGNames::primitiveUnitsAttr, m_primitiveUnits)
00067 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
00068 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
00069 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
00070 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
00071 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFilterElement, long, Integer, integer, FilterResX, filterResX, SVGNames::filterResAttr, "filterResX", m_filterResX)
00072 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFilterElement, long, Integer, integer, FilterResY, filterResY, SVGNames::filterResAttr, "filterResY", m_filterResY)
00073 
00074 void SVGFilterElement::setFilterRes(unsigned long, unsigned long) const
00075 {
00076 }
00077 
00078 void SVGFilterElement::parseMappedAttribute(MappedAttribute* attr)
00079 {
00080     const String& value = attr->value();
00081     if (attr->name() == SVGNames::filterUnitsAttr) {
00082         if (value == "userSpaceOnUse")
00083             setFilterUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
00084         else if (value == "objectBoundingBox")
00085             setFilterUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
00086     } else if (attr->name() == SVGNames::primitiveUnitsAttr) {
00087         if (value == "userSpaceOnUse")
00088             setPrimitiveUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
00089         else if (value == "objectBoundingBox")
00090             setPrimitiveUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
00091     } else if (attr->name() == SVGNames::xAttr)
00092         setXBaseValue(SVGLength(this, LengthModeWidth, value));
00093     else if (attr->name() == SVGNames::yAttr)
00094         setYBaseValue(SVGLength(this, LengthModeHeight, value));
00095     else if (attr->name() == SVGNames::widthAttr)
00096         setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
00097     else if (attr->name() == SVGNames::heightAttr)
00098         setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
00099     else {
00100         if (SVGURIReference::parseMappedAttribute(attr)) return;
00101         if (SVGLangSpace::parseMappedAttribute(attr)) return;
00102         if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) return;
00103 
00104         SVGStyledElement::parseMappedAttribute(attr);
00105     }
00106 }
00107 
00108 SVGResource* SVGFilterElement::canvasResource()
00109 {
00110     if (!attached())
00111         return 0;
00112 
00113     if (!m_filter)
00114         m_filter = new SVGResourceFilter();
00115 
00116     bool filterBBoxMode = filterUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
00117     m_filter->setFilterBoundingBoxMode(filterBBoxMode);
00118 
00119     float _x, _y, _width, _height;
00120 
00121     if (filterBBoxMode) {
00122         _x = x().valueAsPercentage();
00123         _y = y().valueAsPercentage();
00124         _width = width().valueAsPercentage();
00125         _height = height().valueAsPercentage();
00126     } else {
00127         m_filter->setXBoundingBoxMode(x().unitType() == LengthTypePercentage);
00128         m_filter->setYBoundingBoxMode(y().unitType() == LengthTypePercentage);
00129 
00130         _x = x().value();
00131         _y = y().value();
00132         _width = width().value();
00133         _height = height().value();
00134     } 
00135 
00136     m_filter->setFilterRect(FloatRect(_x, _y, _width, _height));
00137 
00138     bool primitiveBBoxMode = primitiveUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
00139     m_filter->setEffectBoundingBoxMode(primitiveBBoxMode);
00140 
00141     // TODO : use switch/case instead?
00142     m_filter->clearEffects();
00143     for (Node* n = firstChild(); n != 0; n = n->nextSibling()) {
00144         SVGElement* element = 0;
00145         if (n->isSVGElement())
00146             element = static_cast<SVGElement*>(n);
00147         if (element && element->isFilterEffect()) {
00148             SVGFilterPrimitiveStandardAttributes* filterAttributes = static_cast<SVGFilterPrimitiveStandardAttributes*>(element);
00149             SVGFilterEffect* filterEffect = filterAttributes->filterEffect(m_filter.get());
00150             if (!filterEffect)
00151                 continue;
00152 
00153             m_filter->addFilterEffect(filterEffect);
00154         }
00155     }
00156 
00157     return m_filter.get();
00158 }
00159 
00160 }
00161 
00162 #endif // ENABLE(SVG)
00163 
00164 // vim:ts=4:noet

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal