c045cab987c8ee5c7d8b2188612bdd08a78455ef
[WebKit-https.git] / WebCore / kcanvas / device / qt / KRenderingDeviceQt.cpp
1 /*
2     Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
3                   2004, 2005, 2006 Rob Buis <buis@kde.org>
4
5     This file is part of the KDE project
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 General Public License
18     along with this program; 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 #include "IntRect.h"
26 #include "RenderPath.h"
27 #include "AffineTransform.h"
28 #include "GraphicsContext.h"
29 #include "SVGResourceClipper.h"
30 #include "SVGResourceMarker.h"
31 #include "KRenderingDeviceQt.h"
32 #include "SVGPaintServerSolid.h"
33 #include "SVGPaintServerLinearGradient.h"
34 #include "SVGPaintServerRadialGradient.h"
35 #include "SVGPaintServerPattern.h"
36
37 namespace WebCore {
38
39 KRenderingDeviceContextQt::KRenderingDeviceContextQt(QPainter* painter)
40     : m_painter(painter)
41     , m_path()
42 {
43     Q_ASSERT(m_painter != 0);
44 }
45
46 KRenderingDeviceContextQt::~KRenderingDeviceContextQt()
47 {
48 }
49
50 AffineTransform KRenderingDeviceContextQt::concatCTM(const AffineTransform& worldMatrix)
51 {
52     AffineTransform ret = ctm();
53     m_painter->setMatrix(worldMatrix, true);
54     return ret;
55 }
56
57 AffineTransform KRenderingDeviceContextQt::ctm() const
58 {
59     return AffineTransform(m_painter->matrix());
60 }
61
62 IntRect KRenderingDeviceContextQt::mapFromVisual(const IntRect& rect)
63 {
64     return IntRect();
65 }
66
67 IntRect KRenderingDeviceContextQt::mapToVisual(const IntRect& rect)
68 {
69     return IntRect();
70 }
71
72 void KRenderingDeviceContextQt::clearPath()
73 {
74     m_path = QPainterPath();
75 }
76
77 void KRenderingDeviceContextQt::addPath(const Path& path)
78 {
79     m_path.addPath(*(path.platformPath()));
80 }
81
82 GraphicsContext* KRenderingDeviceContextQt::createGraphicsContext()
83 {
84     return new GraphicsContext(m_painter);
85 }
86
87 QPainter& KRenderingDeviceContextQt::painter()
88 {
89     return *m_painter;
90 }
91
92 QRectF KRenderingDeviceContextQt::pathBBox() const
93 {
94     return m_path.boundingRect();
95 }
96
97 void KRenderingDeviceContextQt::setFillRule(WindRule rule)
98 {
99     m_path.setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
100 }
101
102 void KRenderingDeviceContextQt::fillPath()
103 {
104     m_painter->fillPath(m_path, m_painter->brush());
105 }
106
107 void KRenderingDeviceContextQt::strokePath()
108 {
109     m_painter->strokePath(m_path, m_painter->pen());
110 }
111
112 // KRenderingDeviceQt
113 KRenderingDeviceQt::KRenderingDeviceQt() : KRenderingDevice()
114 {
115 }
116
117 KRenderingDeviceQt::~KRenderingDeviceQt()
118 {
119 }
120
121 KRenderingDeviceContext* KRenderingDeviceQt::popContext()
122 {
123     // Any special things needed?
124     return KRenderingDevice::popContext();
125 }
126
127 void KRenderingDeviceQt::pushContext(KRenderingDeviceContext* context)
128 {
129     // Any special things needed?
130     KRenderingDevice::pushContext(context);
131 }
132
133 // context management.
134 KRenderingDeviceContextQt* KRenderingDeviceQt::qtContext() const
135 {
136     return static_cast<KRenderingDeviceContextQt*>(currentContext());
137 }
138
139 KRenderingDeviceContext* KRenderingDeviceQt::contextForImage(SVGResourceImage* image) const
140 {
141     qDebug("KRenderingDeviceQt::contextForImage() TODO!");
142     return 0;
143 }
144
145 // Resource creation
146 PassRefPtr<SVGResource> KRenderingDeviceQt::createResource(const SVGResourceType& type) const
147 {
148     switch (type)
149     {
150         case ClipperResourceType:
151             return new SVGResourceClipper();
152         case MarkerResourceType:
153             return new SVGResourceMarker(); // Use default implementation...
154         case ImageResourceType:
155             // return new SVGResourceImageQt();
156         case FilterResourceType:
157             // return new KCanvasFilterQt();
158         case MaskerResourceType:
159             // return new KCanvasMaskerQt();
160         default:
161             return 0;
162     }
163 }
164
165 PassRefPtr<SVGPaintServer> KRenderingDeviceQt::createPaintServer(const SVGPaintServerType& type) const
166 {
167     switch (type)
168     {
169         case SolidPaintServer:
170             return new SVGPaintServerSolid();
171         case PatternPaintServer:
172             return new SVGPaintServerPattern();
173         case LinearGradientPaintServer:
174             return new SVGPaintServerLinearGradient();
175         case RadialGradientPaintServer:
176             return new SVGPaintServerRadialGradient();
177         default:
178             return 0;
179     }
180 }
181
182 SVGFilterEffect* KRenderingDeviceQt::createFilterEffect(const SVGFilterEffectType& type) const
183 {
184     qDebug("KRenderingDeviceQt::createFilterEffect() TODO!");
185     return 0;
186 }
187
188 KRenderingDevice* renderingDevice()
189 {
190     static KRenderingDevice *sharedRenderingDevice = new KRenderingDeviceQt();
191     return sharedRenderingDevice;
192 }
193
194 }
195
196 // vim:ts=4:noet