KHTML
SVGResourceFilter.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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())
00102 ts << " [bounding box mode=" << filterBoundingBoxMode() << "]";
00103 if (effectBoundingBoxMode())
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 }
00122
00123 #endif // ENABLE(SVG)