2 Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
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.
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.
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.
25 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
26 #include "SVGFilterPrimitiveStandardAttributes.h"
28 #include "SVGFilterElement.h"
29 #include "SVGFilterEffect.h"
30 #include "SVGLength.h"
32 #include "SVGStyledElement.h"
33 #include "SVGUnitTypes.h"
37 SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName
& tagName
, Document
* doc
)
38 : SVGStyledElement(tagName
, doc
)
39 , m_x(this, LengthModeWidth
)
40 , m_y(this, LengthModeHeight
)
41 , m_width(this, LengthModeWidth
)
42 , m_height(this, LengthModeHeight
)
44 // Spec: If the attribute is not specified, the effect is as if a value of "0%" were specified.
45 setXBaseValue(SVGLength(this, LengthModeWidth
, "0%"));
46 setYBaseValue(SVGLength(this, LengthModeHeight
, "0%"));
48 // Spec: If the attribute is not specified, the effect is as if a value of "100%" were specified.
49 setWidthBaseValue(SVGLength(this, LengthModeWidth
, "100%"));
50 setHeightBaseValue(SVGLength(this, LengthModeHeight
, "100%"));
53 SVGFilterPrimitiveStandardAttributes::~SVGFilterPrimitiveStandardAttributes()
57 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes
, SVGLength
, Length
, length
, X
, x
, SVGNames::xAttr
, m_x
)
58 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes
, SVGLength
, Length
, length
, Y
, y
, SVGNames::yAttr
, m_y
)
59 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes
, SVGLength
, Length
, length
, Width
, width
, SVGNames::widthAttr
, m_width
)
60 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes
, SVGLength
, Length
, length
, Height
, height
, SVGNames::heightAttr
, m_height
)
61 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes
, String
, String
, string
, Result
, result
, SVGNames::resultAttr
, m_result
)
63 void SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(MappedAttribute
* attr
)
65 const AtomicString
& value
= attr
->value();
66 if (attr
->name() == SVGNames::xAttr
)
67 setXBaseValue(SVGLength(this, LengthModeWidth
, value
));
68 else if (attr
->name() == SVGNames::yAttr
)
69 setYBaseValue(SVGLength(this, LengthModeHeight
, value
));
70 else if (attr
->name() == SVGNames::widthAttr
)
71 setWidthBaseValue(SVGLength(this, LengthModeWidth
, value
));
72 else if (attr
->name() == SVGNames::heightAttr
)
73 setHeightBaseValue(SVGLength(this, LengthModeHeight
, value
));
74 else if (attr
->name() == SVGNames::resultAttr
)
75 setResultBaseValue(value
);
77 return SVGStyledElement::parseMappedAttribute(attr
);
80 void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(SVGFilterEffect
* filterEffect
) const
86 ASSERT(filterEffect
->filter());
88 float _x
, _y
, _width
, _height
;
90 if (filterEffect
->filter()->effectBoundingBoxMode()) {
91 _x
= x().valueAsPercentage();
92 _y
= y().valueAsPercentage();
93 _width
= width().valueAsPercentage();
94 _height
= height().valueAsPercentage();
96 // We need to resolve any percentages in filter rect space.
97 if (x().unitType() == LengthTypePercentage
) {
98 filterEffect
->setXBoundingBoxMode(true);
99 _x
= x().valueAsPercentage();
101 filterEffect
->setXBoundingBoxMode(false);
105 if (y().unitType() == LengthTypePercentage
) {
106 filterEffect
->setYBoundingBoxMode(true);
107 _y
= y().valueAsPercentage();
109 filterEffect
->setYBoundingBoxMode(false);
113 if (width().unitType() == LengthTypePercentage
) {
114 filterEffect
->setWidthBoundingBoxMode(true);
115 _width
= width().valueAsPercentage();
117 filterEffect
->setWidthBoundingBoxMode(false);
118 _width
= width().value();
121 if (height().unitType() == LengthTypePercentage
) {
122 filterEffect
->setHeightBoundingBoxMode(true);
123 _height
= height().valueAsPercentage();
125 filterEffect
->setHeightBoundingBoxMode(false);
126 _height
= height().value();
130 filterEffect
->setSubRegion(FloatRect(_x
, _y
, _width
, _height
));
131 filterEffect
->setResult(result());
136 #endif // ENABLE(SVG)