Home | History | Annotate | Download | only in filters
      1 /*
      2     Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3                   2004, 2005 Rob Buis <buis (at) kde.org>
      4                   2005 Eric Seidel <eric (at) webkit.org>
      5                   2009 Dirk Schulze <krit (at) webkit.org>
      6 
      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.
     11 
     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.
     16 
     17     You should have received a copy of the GNU Library General Public License
     18     aint 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.
     21 */
     22 
     23 #include "config.h"
     24 
     25 #if ENABLE(SVG) && ENABLE(FILTERS)
     26 #include "SVGFEOffset.h"
     27 
     28 #include "Filter.h"
     29 #include "GraphicsContext.h"
     30 #include "SVGRenderTreeAsText.h"
     31 
     32 namespace WebCore {
     33 
     34 FEOffset::FEOffset(FilterEffect* in, const float& dx, const float& dy)
     35     : FilterEffect()
     36     , m_in(in)
     37     , m_dx(dx)
     38     , m_dy(dy)
     39 {
     40 }
     41 
     42 PassRefPtr<FEOffset> FEOffset::create(FilterEffect* in, const float& dx, const float& dy)
     43 {
     44     return adoptRef(new FEOffset(in, dx, dy));
     45 }
     46 
     47 float FEOffset::dx() const
     48 {
     49     return m_dx;
     50 }
     51 
     52 void FEOffset::setDx(float dx)
     53 {
     54     m_dx = dx;
     55 }
     56 
     57 float FEOffset::dy() const
     58 {
     59     return m_dy;
     60 }
     61 
     62 void FEOffset::setDy(float dy)
     63 {
     64     m_dy = dy;
     65 }
     66 
     67 void FEOffset::apply(Filter* filter)
     68 {
     69     m_in->apply(filter);
     70     if (!m_in->resultImage())
     71         return;
     72 
     73     GraphicsContext* filterContext = getEffectContext();
     74     if (!filterContext)
     75         return;
     76 
     77     setIsAlphaImage(m_in->isAlphaImage());
     78 
     79     FloatRect sourceImageRect = filter->sourceImageRect();
     80     sourceImageRect.scale(filter->filterResolution().width(), filter->filterResolution().height());
     81 
     82     if (filter->effectBoundingBoxMode()) {
     83         m_dx *= sourceImageRect.width();
     84         m_dy *= sourceImageRect.height();
     85     }
     86     m_dx *= filter->filterResolution().width();
     87     m_dy *= filter->filterResolution().height();
     88 
     89     FloatRect dstRect = FloatRect(m_dx + m_in->scaledSubRegion().x() - scaledSubRegion().x(),
     90                                   m_dy + m_in->scaledSubRegion().y() - scaledSubRegion().y(),
     91                                   m_in->scaledSubRegion().width(),
     92                                   m_in->scaledSubRegion().height());
     93 
     94     filterContext->drawImage(m_in->resultImage()->image(), DeviceColorSpace, dstRect);
     95 }
     96 
     97 void FEOffset::dump()
     98 {
     99 }
    100 
    101 TextStream& FEOffset::externalRepresentation(TextStream& ts) const
    102 {
    103     ts << "[type=OFFSET] ";
    104     FilterEffect::externalRepresentation(ts);
    105     ts << " [dx=" << dx() << " dy=" << dy() << "]";
    106     return ts;
    107 }
    108 
    109 } // namespace WebCore
    110 
    111 #endif // ENABLE(SVG) && ENABLE(FILTERS)
    112