KHtml

SVGFilterPrimitiveStandardAttributes.cpp
1 /*
2  Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006 Rob Buis <[email protected]>
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 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
24 #include "SVGFilterPrimitiveStandardAttributes.h"
25 
26 #include "SVGFilterElement.h"
27 #include "SVGFilterEffect.h"
28 #include "SVGLength.h"
29 #include "SVGNames.h"
30 #include "SVGUnitTypes.h"
31 
32 namespace WebCore
33 {
34 
35 SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName &tagName, Document *doc)
36  : SVGStyledElement(tagName, doc)
37  , m_x(this, LengthModeWidth)
38  , m_y(this, LengthModeHeight)
39  , m_width(this, LengthModeWidth)
40  , m_height(this, LengthModeHeight)
41 {
42  // Spec: If the attribute is not specified, the effect is as if a value of "0%" were specified.
43  setXBaseValue(SVGLength(this, LengthModeWidth, "0%"));
44  setYBaseValue(SVGLength(this, LengthModeHeight, "0%"));
45 
46  // Spec: If the attribute is not specified, the effect is as if a value of "100%" were specified.
47  setWidthBaseValue(SVGLength(this, LengthModeWidth, "100%"));
48  setHeightBaseValue(SVGLength(this, LengthModeHeight, "100%"));
49 }
50 
51 SVGFilterPrimitiveStandardAttributes::~SVGFilterPrimitiveStandardAttributes()
52 {
53 }
54 
55 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
56 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
57 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
58 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
59 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, String, String, string, Result, result, SVGNames::resultAttr, m_result)
60 
61 void SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(MappedAttribute *attr)
62 {
63  const AtomicString &value = attr->value();
64  if (attr->name() == SVGNames::xAttr) {
65  setXBaseValue(SVGLength(this, LengthModeWidth, value));
66  } else if (attr->name() == SVGNames::yAttr) {
67  setYBaseValue(SVGLength(this, LengthModeHeight, value));
68  } else if (attr->name() == SVGNames::widthAttr) {
69  setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
70  } else if (attr->name() == SVGNames::heightAttr) {
71  setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
72  } else if (attr->name() == SVGNames::resultAttr) {
73  setResultBaseValue(value);
74  } else {
75  return SVGStyledElement::parseMappedAttribute(attr);
76  }
77 }
78 
79 void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(SVGFilterEffect *filterEffect) const
80 {
81  ASSERT(filterEffect);
82  if (!filterEffect) {
83  return;
84  }
85 
86  ASSERT(filterEffect->filter());
87 
88  float _x, _y, _width, _height;
89 
90  if (filterEffect->filter()->effectBoundingBoxMode()) {
91  _x = x().valueAsPercentage();
92  _y = y().valueAsPercentage();
93  _width = width().valueAsPercentage();
94  _height = height().valueAsPercentage();
95  } else {
96  // We need to resolve any percentages in filter rect space.
97  if (x().unitType() == LengthTypePercentage) {
98  filterEffect->setXBoundingBoxMode(true);
99  _x = x().valueAsPercentage();
100  } else {
101  filterEffect->setXBoundingBoxMode(false);
102  _x = x().value();
103  }
104 
105  if (y().unitType() == LengthTypePercentage) {
106  filterEffect->setYBoundingBoxMode(true);
107  _y = y().valueAsPercentage();
108  } else {
109  filterEffect->setYBoundingBoxMode(false);
110  _y = y().value();
111  }
112 
113  if (width().unitType() == LengthTypePercentage) {
114  filterEffect->setWidthBoundingBoxMode(true);
115  _width = width().valueAsPercentage();
116  } else {
117  filterEffect->setWidthBoundingBoxMode(false);
118  _width = width().value();
119  }
120 
121  if (height().unitType() == LengthTypePercentage) {
122  filterEffect->setHeightBoundingBoxMode(true);
123  _height = height().valueAsPercentage();
124  } else {
125  filterEffect->setHeightBoundingBoxMode(false);
126  _height = height().value();
127  }
128  }
129 
130  filterEffect->setSubRegion(FloatRect(_x, _y, _width, _height));
131  filterEffect->setResult(result());
132 }
133 
134 }
135 
136 #endif // ENABLE(SVG)
137 
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.