Home | History | Annotate | Download | only in filters
      1 /*
      2  *  Copyright (C) 2009 Dirk Schulze <krit (at) webkit.org>
      3  *
      4  *   This library is free software; you can redistribute it and/or
      5  *  modify it under the terms of the GNU Library General Public
      6  *  License as published by the Free Software Foundation; either
      7  *  version 2 of the License, or (at your option) any later version.
      8  *
      9  *  This library is distributed in the hope that it will be useful,
     10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  *  Library General Public License for more details.
     13  *
     14  *  You should have received a copy of the GNU Library General Public License
     15  *  aint with this library; see the file COPYING.LIB.  If not, write to
     16  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  *  Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #include "config.h"
     21 
     22 #if ENABLE(SVG) && ENABLE(FILTERS)
     23 #include "SVGFilter.h"
     24 
     25 namespace WebCore {
     26 
     27 SVGFilter::SVGFilter(const FloatRect& itemBox, const FloatRect& filterRect, bool effectBBoxMode)
     28     : Filter()
     29     , m_itemBox(itemBox)
     30     , m_filterRect(filterRect)
     31     , m_effectBBoxMode(effectBBoxMode)
     32 {
     33 }
     34 
     35 void SVGFilter::calculateEffectSubRegion(FilterEffect* effect)
     36 {
     37     FloatRect subRegionBBox = effect->effectBoundaries();
     38     FloatRect useBBox = effect->unionOfChildEffectSubregions();
     39     FloatRect newSubRegion = subRegionBBox;
     40 
     41     if (m_effectBBoxMode) {
     42         newSubRegion = useBBox;
     43 
     44         if (effect->hasX())
     45             newSubRegion.setX(m_itemBox.x() + subRegionBBox.x() * m_itemBox.width());
     46 
     47         if (effect->hasY())
     48             newSubRegion.setY(m_itemBox.y() + subRegionBBox.y() * m_itemBox.height());
     49 
     50         if (effect->hasWidth())
     51             newSubRegion.setWidth(subRegionBBox.width() * m_itemBox.width());
     52 
     53         if (effect->hasHeight())
     54             newSubRegion.setHeight(subRegionBBox.height() * m_itemBox.height());
     55     } else {
     56         if (!effect->hasX())
     57             newSubRegion.setX(useBBox.x());
     58 
     59         if (!effect->hasY())
     60             newSubRegion.setY(useBBox.y());
     61 
     62         if (!effect->hasWidth())
     63             newSubRegion.setWidth(useBBox.width());
     64 
     65         if (!effect->hasHeight())
     66             newSubRegion.setHeight(useBBox.height());
     67     }
     68 
     69     // clip every filter effect to the filter region
     70     newSubRegion.intersect(m_filterRect);
     71 
     72     effect->setSubRegion(newSubRegion);
     73     newSubRegion.scale(filterResolution().width(), filterResolution().height());
     74     effect->setScaledSubRegion(newSubRegion);
     75     m_maxImageSize = m_maxImageSize.expandedTo(newSubRegion.size());
     76 }
     77 
     78 PassRefPtr<SVGFilter> SVGFilter::create(const FloatRect& itemBox, const FloatRect& filterRect, bool effectBBoxMode)
     79 {
     80     return adoptRef(new SVGFilter(itemBox, filterRect, effectBBoxMode));
     81 }
     82 
     83 } // namespace WebCore
     84 
     85 #endif // ENABLE(SVG) && ENABLE(FILTERS)
     86