2006-10-05 Nikolas Zimmermann <zimmermann@kde.org>
[WebKit-https.git] / WebCore / kcanvas / device / qt / KRenderingPaintServerPatternQt.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 <qrect.h>
26 #include <qimage.h>
27
28 #include <math.h>
29 #include <QPointF>
30 #include <QPainterPath>
31
32 #include "RenderStyle.h"
33 #include "KRenderingDeviceQt.h"
34 #include "KCanvasRenderingStyle.h"
35 #include "KRenderingFillPainter.h"
36 #include "KRenderingStrokePainter.h"
37 #include "KRenderingPaintServerPatternQt.h"
38 #include "KCanvasImage.h"
39
40 namespace WebCore {
41
42 // KRenderingPaintServerPatternQt
43 KRenderingPaintServerPatternQt::KRenderingPaintServerPatternQt()
44     : KRenderingPaintServerPattern()
45     , KRenderingPaintServerQt()
46 {
47 }
48
49 KRenderingPaintServerPatternQt::~KRenderingPaintServerPatternQt()
50 {
51 }
52
53 void KRenderingPaintServerPatternQt::renderPath(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
54 {
55     RenderStyle* renderStyle = path->style();
56     KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
57
58     if ((type & APPLY_TO_FILL) && renderStyle->svgStyle()->hasFill())
59         qtContext->fillPath();
60
61     if ((type & APPLY_TO_STROKE) && renderStyle->svgStyle()->hasStroke())
62         qtContext->strokePath();
63 }
64
65 bool KRenderingPaintServerPatternQt::setup(KRenderingDeviceContext* context, const RenderObject* object, KCPaintTargetType type) const
66 {
67 /*
68     KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
69     Q_ASSERT(qtContext != 0);
70
71     QPainterPath* _path = static_cast<QPainterPath*>(qtContext->path());
72     Q_ASSERT(_path != 0);
73  
74     if (listener()) {
75         listener()->resourceNotification();
76     }
77
78     RenderStyle* renderStyle = object->style();
79
80     qtContext->painter().setPen(Qt::NoPen);
81     qtContext->painter().setBrush(Qt::NoBrush);
82     QImage* patternimage = new QImage(tile()->bits(), tile()->width(), tile()->height(), QImage::Format_ARGB32_Premultiplied);
83     patternimage->setAlphaBuffer(true);
84     if (type & APPLY_TO_FILL) {
85         //QColor c = color();
86         //c.setAlphaF(style->fillPainter()->opacity() * style->opacity() * opacity());
87         KRenderingFillPainter fillPainter = KSVGPainterFactory::fillPainter(renderStyle, object);
88         QBrush brush(QPixmap::fromImage(*patternimage));
89         _path->setFillRule(fillPainter.fillRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
90         qtContext->painter().setBrush(brush);
91     }
92     if (type & APPLY_TO_STROKE) {
93         //QColor c = color();
94         //c.setAlphaF(style->strokePainter()->opacity() * style->opacity() * opacity());
95         KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(renderStyle, object);
96
97         QPen pen;
98         QBrush brush(QPixmap::fromImage(*patternimage));
99
100         setPenProperties(strokePainter, pen);
101         pen.setBrush(brush);
102         qtContext->painter().setPen(pen);
103     }
104
105     qtContext->painter().drawPath(*_path);
106
107     delete patternimage;
108 */
109
110     return true;
111 }
112
113 void KRenderingPaintServerPatternQt::teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const
114 {
115 }
116
117 void KRenderingPaintServerPatternQt::draw(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
118 {
119     if (!setup(context, path, type))
120         return;
121
122     renderPath(context, path, type);
123     teardown(context, path, type);
124 }
125
126 }
127
128 // vim:ts=4:noet
129