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

KHTML

SVGFilterPrimitiveStandardAttributes.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
00003                   2004, 2005, 2006 Rob Buis <buis@kde.org>
00004 
00005     This file is part of the KDE project
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "config.h"
00024 
00025 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
00026 #include "SVGFilterPrimitiveStandardAttributes.h"
00027 
00028 #include "SVGFilterElement.h"
00029 #include "SVGFilterEffect.h"
00030 #include "SVGLength.h"
00031 #include "SVGNames.h"
00032 #include "SVGStyledElement.h"
00033 #include "SVGUnitTypes.h"
00034 
00035 namespace WebCore {
00036 
00037 SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document* doc)
00038     : SVGStyledElement(tagName, doc)
00039     , m_x(this, LengthModeWidth)
00040     , m_y(this, LengthModeHeight)
00041     , m_width(this, LengthModeWidth)
00042     , m_height(this, LengthModeHeight)
00043 {
00044     // Spec: If the attribute is not specified, the effect is as if a value of "0%" were specified.
00045     setXBaseValue(SVGLength(this, LengthModeWidth, "0%"));
00046     setYBaseValue(SVGLength(this, LengthModeHeight, "0%"));
00047 
00048     // Spec: If the attribute is not specified, the effect is as if a value of "100%" were specified.
00049     setWidthBaseValue(SVGLength(this, LengthModeWidth, "100%"));
00050     setHeightBaseValue(SVGLength(this, LengthModeHeight, "100%"));
00051 }
00052 
00053 SVGFilterPrimitiveStandardAttributes::~SVGFilterPrimitiveStandardAttributes()
00054 {
00055 }
00056 
00057 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
00058 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
00059 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
00060 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
00061 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, String, String, string, Result, result, SVGNames::resultAttr, m_result)
00062 
00063 void SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(MappedAttribute* attr)
00064 {
00065     const AtomicString& value = attr->value();
00066     if (attr->name() == SVGNames::xAttr)
00067         setXBaseValue(SVGLength(this, LengthModeWidth, value));
00068     else if (attr->name() == SVGNames::yAttr)
00069         setYBaseValue(SVGLength(this, LengthModeHeight, value));
00070     else if (attr->name() == SVGNames::widthAttr)
00071         setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
00072     else if (attr->name() == SVGNames::heightAttr)
00073         setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
00074     else if (attr->name() == SVGNames::resultAttr)
00075         setResultBaseValue(value);
00076     else
00077         return SVGStyledElement::parseMappedAttribute(attr);
00078 }
00079 
00080 void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(SVGFilterEffect* filterEffect) const
00081 {
00082     ASSERT(filterEffect);
00083     if (!filterEffect)
00084         return;
00085 
00086     ASSERT(filterEffect->filter());
00087 
00088     float _x, _y, _width, _height;
00089 
00090     if (filterEffect->filter()->effectBoundingBoxMode()) {
00091         _x = x().valueAsPercentage();
00092         _y = y().valueAsPercentage();
00093         _width = width().valueAsPercentage();
00094         _height = height().valueAsPercentage();
00095     } else {
00096         // We need to resolve any percentages in filter rect space.
00097         if (x().unitType() == LengthTypePercentage) {
00098             filterEffect->setXBoundingBoxMode(true);
00099             _x = x().valueAsPercentage();
00100         } else {
00101             filterEffect->setXBoundingBoxMode(false);
00102             _x = x().value();
00103         }
00104 
00105         if (y().unitType() == LengthTypePercentage) {
00106             filterEffect->setYBoundingBoxMode(true);
00107             _y = y().valueAsPercentage();
00108         } else {
00109             filterEffect->setYBoundingBoxMode(false);
00110             _y = y().value();
00111         }
00112 
00113         if (width().unitType() == LengthTypePercentage) {
00114             filterEffect->setWidthBoundingBoxMode(true);
00115             _width = width().valueAsPercentage();
00116         } else {
00117             filterEffect->setWidthBoundingBoxMode(false);
00118             _width = width().value();
00119         }
00120 
00121         if (height().unitType() == LengthTypePercentage) {
00122             filterEffect->setHeightBoundingBoxMode(true);
00123             _height = height().valueAsPercentage();
00124         } else {
00125             filterEffect->setHeightBoundingBoxMode(false);
00126             _height = height().value();
00127         }
00128     }
00129 
00130     filterEffect->setSubRegion(FloatRect(_x, _y, _width, _height));
00131     filterEffect->setResult(result());
00132 }
00133 
00134 }
00135 
00136 #endif // ENABLE(SVG)
00137 
00138 // 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