|
1 /* |
|
2 Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org> |
|
3 2004, 2005 Rob Buis <buis@kde.org> |
|
4 2005 Eric Seidel <eric.seidel@kdemail.net> |
|
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 aint 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_EXPERIMENTAL_FEATURES) |
|
27 #include "SVGResourceFilter.h" |
|
28 |
|
29 #include "SVGRenderTreeAsText.h" |
|
30 #include "SVGFilterEffect.h" |
|
31 #include "TextStream.h" |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 void SVGResourceFilter::clearEffects() |
|
36 { |
|
37 m_effects.clear(); |
|
38 } |
|
39 |
|
40 void SVGResourceFilter::addFilterEffect(SVGFilterEffect* effect) |
|
41 { |
|
42 ASSERT(effect); |
|
43 |
|
44 if (effect) |
|
45 m_effects.append(effect); |
|
46 } |
|
47 |
|
48 FloatRect SVGResourceFilter::filterBBoxForItemBBox(FloatRect itemBBox) const |
|
49 { |
|
50 FloatRect filterBBox = filterRect(); |
|
51 |
|
52 if (filterBoundingBoxMode()) |
|
53 filterBBox = FloatRect(filterBBox.x() * itemBBox.width(), |
|
54 filterBBox.y() * itemBBox.height(), |
|
55 filterBBox.width() * itemBBox.width(), |
|
56 filterBBox.height() * itemBBox.height()); |
|
57 |
|
58 return filterBBox; |
|
59 } |
|
60 |
|
61 TextStream& SVGResourceFilter::externalRepresentation(TextStream& ts) const |
|
62 { |
|
63 ts << "[type=FILTER] "; |
|
64 |
|
65 FloatRect bbox = filterRect(); |
|
66 static FloatRect defaultFilterRect(0, 0, 1, 1); |
|
67 |
|
68 if (!filterBoundingBoxMode() || bbox != defaultFilterRect) { |
|
69 ts << " [bounding box="; |
|
70 if (filterBoundingBoxMode()) { |
|
71 bbox.scale(100.f); |
|
72 ts << "at (" << bbox.x() << "%," << bbox.y() << "%) size " << bbox.width() << "%x" << bbox.height() << "%"; |
|
73 } else |
|
74 ts << filterRect(); |
|
75 ts << "]"; |
|
76 } |
|
77 |
|
78 if (!filterBoundingBoxMode()) // default is true |
|
79 ts << " [bounding box mode=" << filterBoundingBoxMode() << "]"; |
|
80 if (effectBoundingBoxMode()) // default is false |
|
81 ts << " [effect bounding box mode=" << effectBoundingBoxMode() << "]"; |
|
82 if (m_effects.size() > 0) |
|
83 ts << " [effects=" << m_effects << "]"; |
|
84 |
|
85 return ts; |
|
86 } |
|
87 |
|
88 SVGResourceFilter* getFilterById(Document* document, const AtomicString& id) |
|
89 { |
|
90 SVGResource* resource = getResourceById(document, id); |
|
91 if (resource && resource->isFilter()) |
|
92 return static_cast<SVGResourceFilter*>(resource); |
|
93 |
|
94 return 0; |
|
95 } |
|
96 |
|
97 |
|
98 } // namespace WebCore |
|
99 |
|
100 #endif // ENABLE(SVG) |