KHTML
SVGResourceFilter.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 00003 2004, 2005 Rob Buis <buis@kde.org> 00004 2005 Eric Seidel <eric@webkit.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 aint with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "config.h" 00023 00024 #if ENABLE(SVG) && ENABLE(SVG_FILTERS) 00025 #include "SVGResourceFilter.h" 00026 00027 #include "SVGRenderTreeAsText.h" 00028 #include "SVGFilterEffect.h" 00029 00030 namespace WebCore { 00031 00032 SVGResourceFilter::SVGResourceFilter() 00033 : m_platformData(createPlatformData()) 00034 , m_filterBBoxMode(false) 00035 , m_effectBBoxMode(false) 00036 , m_xBBoxMode(false) 00037 , m_yBBoxMode(false) 00038 { 00039 } 00040 00041 void SVGResourceFilter::clearEffects() 00042 { 00043 m_effects.clear(); 00044 } 00045 00046 void SVGResourceFilter::addFilterEffect(SVGFilterEffect* effect) 00047 { 00048 ASSERT(effect); 00049 00050 if (effect) { 00051 ASSERT(effect->filter() == this); 00052 m_effects.append(effect); 00053 } 00054 } 00055 00056 FloatRect SVGResourceFilter::filterBBoxForItemBBox(const FloatRect& itemBBox) const 00057 { 00058 FloatRect filterBBox = filterRect(); 00059 00060 float xOffset = 0.0f; 00061 float yOffset = 0.0f; 00062 00063 if (!effectBoundingBoxMode()) { 00064 xOffset = itemBBox.x(); 00065 yOffset = itemBBox.y(); 00066 } 00067 00068 if (filterBoundingBoxMode()) { 00069 filterBBox = FloatRect(xOffset + filterBBox.x() * itemBBox.width(), 00070 yOffset + filterBBox.y() * itemBBox.height(), 00071 filterBBox.width() * itemBBox.width(), 00072 filterBBox.height() * itemBBox.height()); 00073 } else { 00074 if (xBoundingBoxMode()) 00075 filterBBox.setX(xOffset + filterBBox.x()); 00076 00077 if (yBoundingBoxMode()) 00078 filterBBox.setY(yOffset + filterBBox.y()); 00079 } 00080 00081 return filterBBox; 00082 } 00083 00084 TextStream& SVGResourceFilter::externalRepresentation(TextStream& ts) const 00085 { 00086 ts << "[type=FILTER] "; 00087 00088 FloatRect bbox = filterRect(); 00089 static FloatRect defaultFilterRect(0, 0, 1, 1); 00090 00091 if (!filterBoundingBoxMode() || bbox != defaultFilterRect) { 00092 ts << " [bounding box="; 00093 if (filterBoundingBoxMode()) { 00094 bbox.scale(100.f); 00095 ts << "at (" << bbox.x() << "%," << bbox.y() << "%) size " << bbox.width() << "%x" << bbox.height() << "%"; 00096 } else 00097 ts << filterRect(); 00098 ts << "]"; 00099 } 00100 00101 if (!filterBoundingBoxMode()) // default is true 00102 ts << " [bounding box mode=" << filterBoundingBoxMode() << "]"; 00103 if (effectBoundingBoxMode()) // default is false 00104 ts << " [effect bounding box mode=" << effectBoundingBoxMode() << "]"; 00105 if (m_effects.size() > 0) 00106 ts << " [effects=" << m_effects << "]"; 00107 00108 return ts; 00109 } 00110 00111 SVGResourceFilter* getFilterById(Document* document, const AtomicString& id) 00112 { 00113 SVGResource* resource = getResourceById(document, id); 00114 if (resource && resource->isFilter()) 00115 return static_cast<SVGResourceFilter*>(resource); 00116 00117 return 0; 00118 } 00119 00120 00121 } // namespace WebCore 00122 00123 #endif // ENABLE(SVG)
KDE 4.6 API Reference