1 /*
2 Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
4 2005 Eric Seidel <eric@webkit.org>
5 2009 Dirk Schulze <krit@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
FEOffset(FilterEffect * in,const float & dx,const float & dy)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
create(FilterEffect * in,const float & dx,const float & dy)42 PassRefPtr<FEOffset> FEOffset::create(FilterEffect* in, const float& dx, const float& dy)
43 {
44 return adoptRef(new FEOffset(in, dx, dy));
45 }
46
dx() const47 float FEOffset::dx() const
48 {
49 return m_dx;
50 }
51
setDx(float dx)52 void FEOffset::setDx(float dx)
53 {
54 m_dx = dx;
55 }
56
dy() const57 float FEOffset::dy() const
58 {
59 return m_dy;
60 }
61
setDy(float dy)62 void FEOffset::setDy(float dy)
63 {
64 m_dy = dy;
65 }
66
apply(Filter * filter)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 if (filter->effectBoundingBoxMode()) {
78 setDx(dx() * filter->sourceImageRect().width());
79 setDy(dy() * filter->sourceImageRect().height());
80 }
81
82 FloatRect dstRect = FloatRect(dx() + m_in->subRegion().x() - subRegion().x(),
83 dy() + m_in->subRegion().y() - subRegion().y(),
84 m_in->subRegion().width(),
85 m_in->subRegion().height());
86
87 filterContext->drawImage(m_in->resultImage()->image(), dstRect);
88 }
89
dump()90 void FEOffset::dump()
91 {
92 }
93
externalRepresentation(TextStream & ts) const94 TextStream& FEOffset::externalRepresentation(TextStream& ts) const
95 {
96 ts << "[type=OFFSET] ";
97 FilterEffect::externalRepresentation(ts);
98 ts << " [dx=" << dx() << " dy=" << dy() << "]";
99 return ts;
100 }
101
102 } // namespace WebCore
103
104 #endif // ENABLE(SVG) && ENABLE(FILTERS)
105