Reviewed by Eric. Landed by rwlbuis.
authorrwlbuis <rwlbuis@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Aug 2006 19:11:41 +0000 (19:11 +0000)
committerrwlbuis <rwlbuis@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Aug 2006 19:11:41 +0000 (19:11 +0000)
         Fixes: http://bugzilla.opendarwin.org/show_bug.cgi?id=10470
         The Qt platform needs a KCanvas device.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@15938 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
WebCore/ChangeLog
WebCore/kcanvas/device/qt/KCanvasClipperQt.cpp [new file with mode: 0644]
WebCore/kcanvas/device/qt/KCanvasClipperQt.h [new file with mode: 0644]
WebCore/kcanvas/device/qt/KCanvasPathQt.cpp [new file with mode: 0644]
WebCore/kcanvas/device/qt/KCanvasPathQt.h [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingDeviceQt.cpp [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingDeviceQt.h [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingPaintServerGradientQt.cpp [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingPaintServerGradientQt.h [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingPaintServerPatternQt.cpp [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingPaintServerPatternQt.h [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingPaintServerQt.cpp [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingPaintServerQt.h [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingPaintServerSolidQt.cpp [new file with mode: 0644]
WebCore/kcanvas/device/qt/KRenderingPaintServerSolidQt.h [new file with mode: 0644]
WebCore/kcanvas/device/qt/RenderPathQt.cpp [new file with mode: 0644]
WebCore/kcanvas/device/qt/RenderPathQt.h [new file with mode: 0644]

index bae73eb..1a67ee1 100644 (file)
@@ -1,3 +1,54 @@
+ 2006-08-18  Nikolas Zimmermann  <zimmermann@kde.org>
+         Reviewed by Eric. Landed by rwlbuis.
+         Fixes: http://bugzilla.opendarwin.org/show_bug.cgi?id=10470
+         The Qt platform needs a KCanvas device.
+         * kcanvas/device/qt/KCanvasClipperQt.cpp: Added.
+         (WebCore::KCanvasClipperQt::applyClip):
+         * kcanvas/device/qt/KCanvasClipperQt.h: Added.
+         (WebCore::KCanvasClipperQt::KCanvasClipperQt):
+         * kcanvas/device/qt/KCanvasPathQt.cpp: Added.
+         (WebCore::KCanvasPathQt::KCanvasPathQt):
+         (WebCore::KCanvasPathQt::~KCanvasPathQt):
+         (WebCore::KCanvasPathQt::isEmpty):
+         (WebCore::KCanvasPathQt::moveTo):
+         (WebCore::KCanvasPathQt::lineTo):
+         (WebCore::KCanvasPathQt::curveTo):
+         (WebCore::KCanvasPathQt::closeSubpath):
+         (WebCore::KCanvasPathQt::boundingBox):
+         (WebCore::KCanvasPathQt::strokeBoundingBox):
+         (WebCore::KCanvasPathQt::strokeContainsPoint):
+         (WebCore::KCanvasPathQt::containsPoint):
+         * kcanvas/device/qt/KCanvasPathQt.h: Added.
+         (WebCore::KCanvasPathQt::qtPath):
+         * kcanvas/device/qt/KRenderingDeviceQt.cpp: Added.
+         (WebCore::KRenderingDeviceContextQt::KRenderingDeviceContextQt):
+         (WebCore::KRenderingDeviceContextQt::~KRenderingDeviceContextQt):
+         (WebCore::KRenderingDeviceContextQt::concatCTM):
+         (WebCore::KRenderingDeviceContextQt::ctm):
+         (WebCore::KRenderingDeviceContextQt::mapFromVisual):
+         (WebCore::KRenderingDeviceContextQt::mapToVisual):
+         (WebCore::KRenderingDeviceContextQt::clearPath):
+         (WebCore::KRenderingDeviceContextQt::addPath):
+         (WebCore::KRenderingDeviceContextQt::createGraphicsContext):
+         (WebCore::KRenderingDeviceContextQt::painter):
+         (WebCore::KRenderingDeviceContextQt::pathBBox):
+         (WebCore::KRenderingDeviceContextQt::setFillRule):
+         (WebCore::KRenderingDeviceContextQt::fillPath):
+         (WebCore::KRenderingDeviceContextQt::strokePath):
+         (WebCore::KRenderingDeviceQt::KRenderingDeviceQt):
+         (WebCore::KRenderingDeviceQt::~KRenderingDeviceQt):
+         (WebCore::KRenderingDeviceQt::popContext):
+         (WebCore::KRenderingDeviceQt::pushContext):
+         (WebCore::KRenderingDeviceQt::qtContext):
+         (WebCore::KRenderingDeviceQt::contextForImage):
+         (WebCore::KRenderingDeviceQt::stringForPath):
+         (WebCore::KRenderingDeviceQt::createResource):
+         (WebCore::KRenderingDeviceQt::createPaintServer):
+         (WebCore::KRenderingDeviceQt::createFilterEffect):
+
 2006-08-17  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Eric. Landed by rwlbuis.
diff --git a/WebCore/kcanvas/device/qt/KCanvasClipperQt.cpp b/WebCore/kcanvas/device/qt/KCanvasClipperQt.cpp
new file mode 100644 (file)
index 0000000..35f2324
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+                  2005 Apple Computer, Inc.
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    aint with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.
+*/
+
+#include "config.h"
+
+#include "KCanvasPathQt.h"
+#include "KCanvasClipperQt.h"
+#include "KRenderingDeviceQt.h"
+
+namespace WebCore {
+
+void KCanvasClipperQt::applyClip(const FloatRect& boundingBox) const
+{
+    KRenderingDeviceContext *context = renderingDevice()->currentContext();
+    KRenderingDeviceContextQt *qtContext = static_cast<KRenderingDeviceContextQt *>(context);
+    if (m_clipData.count() < 1)
+        return;
+
+    context->clearPath();
+
+    QPainterPath newPath;
+
+    bool heterogenousClipRules = false;
+    KCWindRule clipRule = m_clipData[0].windRule();
+
+    for (unsigned int x = 0; x < m_clipData.count(); x++) {
+        KCClipData clipData = m_clipData[x];
+        if (clipData.windRule() != clipRule)
+            heterogenousClipRules = true;
+       
+        QPainterPath path = static_cast<KCanvasPathQt *>(clipData.path.get())->qtPath(); 
+        if (path.isEmpty())
+            continue;
+
+        if (!newPath.isEmpty())
+            newPath.closeSubpath();
+
+        // Respect clipping units...
+        QMatrix transform;
+
+        if (clipData.bboxUnits) {
+            transform.translate(boundingBox.x(), boundingBox.y());
+            transform.scale(boundingBox.width(), boundingBox.height());
+        }
+
+        // TODO: support heterogenous clip rules!
+        //clipRule = (clipData.windRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
+
+        for (int i = 0; i < path.elementCount(); ++i) {
+            const QPainterPath::Element &cur = path.elementAt(i);
+
+            switch (cur.type) {
+                case QPainterPath::MoveToElement:
+                    newPath.moveTo(QPointF(cur.x, cur.y) * transform);
+                    break;
+                case QPainterPath::LineToElement:
+                    newPath.lineTo(QPointF(cur.x, cur.y) * transform);
+                    break;
+                case QPainterPath::CurveToElement:
+                {
+                    const QPainterPath::Element &c1 = path.elementAt(i + 1);
+                    const QPainterPath::Element &c2 = path.elementAt(i + 2);
+
+                    Q_ASSERT(c1.type == QPainterPath::CurveToDataElement);
+                    Q_ASSERT(c2.type == QPainterPath::CurveToDataElement);
+
+                    newPath.cubicTo(QPointF(cur.x, cur.y) * transform,
+                                    QPointF(c1.x, c1.y) * transform,
+                                    QPointF(c2.x, c2.y) * transform);
+
+                    i += 2;
+                    break;
+                }
+                case QPainterPath::CurveToDataElement:
+                    Q_ASSERT(false);
+                    break;
+            }
+        }
+    }
+
+    if (m_clipData.count()) {
+        // FIXME!
+        // We don't currently allow for heterogenous clip rules.
+        // we would have to detect such, draw to a mask, and then clip
+        // to that mask
+        // if (!CGContextIsPathEmpty(cgContext)) {
+            if (clipRule == RULE_EVENODD) {
+                newPath.setFillRule(Qt::OddEvenFill);
+            } else {
+                newPath.setFillRule(Qt::WindingFill);
+            }
+        // }
+    }
+
+    qtContext->painter().setClipPath(newPath);
+}
+
+}
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KCanvasClipperQt.h b/WebCore/kcanvas/device/qt/KCanvasClipperQt.h
new file mode 100644 (file)
index 0000000..d1be620
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+                  2005 Apple Computer, Inc.
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    aint with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCanvasClipperQt_h
+#define KCanvasClipperQt_h
+
+#include "KCanvasResources.h"
+
+namespace WebCore {
+
+class KCanvasClipperQt : public KCanvasClipper {
+public:
+    KCanvasClipperQt()
+    {
+    }
+    
+    virtual void applyClip(const FloatRect& boundingBox) const;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KCanvasPathQt.cpp b/WebCore/kcanvas/device/qt/KCanvasPathQt.cpp
new file mode 100644 (file)
index 0000000..57ca60b
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+                  2005 Apple Computer, Inc.
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    aint with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.
+*/
+
+#include "config.h"
+#include "KCanvasPathQt.h"
+
+namespace WebCore {
+
+KCanvasPathQt::KCanvasPathQt()
+{
+}
+
+KCanvasPathQt::~KCanvasPathQt()
+{
+}
+
+bool KCanvasPathQt::isEmpty() const
+{
+    return m_path.isEmpty();
+}
+
+void KCanvasPathQt::moveTo(float x, float y)
+{
+    m_path.moveTo(x, y);
+}
+
+void KCanvasPathQt::lineTo(float x, float y)
+{
+    m_path.lineTo(x, y);
+}
+
+void KCanvasPathQt::curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
+{
+    m_path.cubicTo(x1, y1, x2, y2, x3, y3);
+}
+
+void KCanvasPathQt::closeSubpath()
+{
+    m_path.closeSubpath();
+}
+
+FloatRect KCanvasPathQt::boundingBox()
+{
+    return FloatRect(m_path.boundingRect());
+}
+
+FloatRect KCanvasPathQt::strokeBoundingBox(const KRenderingStrokePainter& strokePainter)
+{
+    qDebug("KCanvasPathQt::strokeBoundingBox() TODO!");
+    return boundingBox();
+}
+
+bool KCanvasPathQt::strokeContainsPoint(const FloatPoint& point)
+{
+    qDebug("KCanvasPathQt::strokeContainsPoint() TODO!");    
+    return containsPoint(point, RULE_EVENODD);
+}
+
+bool KCanvasPathQt::containsPoint(const FloatPoint& point, KCWindRule rule)
+{
+    Qt::FillRule savedRule = m_path.fillRule();
+    m_path.setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
+
+    bool contains = m_path.contains(point);
+
+    m_path.setFillRule(savedRule);
+    return contains;
+}
+
+}
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KCanvasPathQt.h b/WebCore/kcanvas/device/qt/KCanvasPathQt.h
new file mode 100644 (file)
index 0000000..20022d4
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+                  2005 Apple Computer, Inc.
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    aint with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCanvasPathQt_H
+#define KCanvasPathQt_H
+
+#include <QPainterPath>
+
+#include "KCanvasPath.h"
+
+namespace WebCore {
+
+class KCanvasPathQt : public KCanvasPath
+{
+public:
+    KCanvasPathQt();
+    virtual ~KCanvasPathQt();
+
+    virtual bool isEmpty() const;
+
+    virtual void moveTo(float x, float y);
+    virtual void lineTo(float x, float y);
+    virtual void curveTo(float x1, float y1, float x2, float y2, float x3, float y3);
+    virtual void closeSubpath();
+
+    virtual FloatRect boundingBox();
+    virtual FloatRect strokeBoundingBox(const KRenderingStrokePainter&);
+    virtual bool strokeContainsPoint(const FloatPoint&);
+    virtual bool containsPoint(const FloatPoint&, KCWindRule);
+
+    // Qt specific stuff
+    const QPainterPath &qtPath() const { return m_path; }
+
+private:
+    QPainterPath m_path;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingDeviceQt.cpp b/WebCore/kcanvas/device/qt/KRenderingDeviceQt.cpp
new file mode 100644 (file)
index 0000000..6a52684
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#include "IntRect.h"
+#include "RenderPathQt.h"
+#include "KCanvasMatrix.h"
+#include "KCanvasPathQt.h"
+#include "KCanvasClipperQt.h"
+#include "GraphicsContext.h"
+#include "KRenderingDeviceQt.h"
+#include "KRenderingPaintServerSolidQt.h"
+#include "KRenderingPaintServerGradientQt.h"
+#include "KRenderingPaintServerPatternQt.h"
+
+namespace WebCore {
+
+KRenderingDeviceContextQt::KRenderingDeviceContextQt(QPainter* painter)
+    : m_painter(painter)
+      , m_path()
+{
+    Q_ASSERT(m_painter != 0);
+}
+
+KRenderingDeviceContextQt::~KRenderingDeviceContextQt()
+{
+}
+
+KCanvasMatrix KRenderingDeviceContextQt::concatCTM(const KCanvasMatrix& worldMatrix)
+{
+    KCanvasMatrix ret = ctm();
+    m_painter->setMatrix(worldMatrix.matrix(), true);
+    return ret;
+}
+
+KCanvasMatrix KRenderingDeviceContextQt::ctm() const
+{
+    return KCanvasMatrix(m_painter->matrix());
+}
+
+IntRect KRenderingDeviceContextQt::mapFromVisual(const IntRect& rect)
+{
+    return IntRect();
+}
+
+IntRect KRenderingDeviceContextQt::mapToVisual(const IntRect& rect)
+{
+    return IntRect();
+}
+
+void KRenderingDeviceContextQt::clearPath()
+{
+    m_path = QPainterPath();
+}
+
+void KRenderingDeviceContextQt::addPath(const KCanvasPath* path)
+{
+    m_path.addPath(static_cast<const KCanvasPathQt*>(path)->qtPath());
+}
+
+GraphicsContext* KRenderingDeviceContextQt::createGraphicsContext()
+{
+    return new GraphicsContext(m_painter);
+}
+
+QPainter& KRenderingDeviceContextQt::painter()
+{
+    return *m_painter;
+}
+
+QRectF KRenderingDeviceContextQt::pathBBox() const
+{
+    return m_path.boundingRect();
+}
+
+void KRenderingDeviceContextQt::setFillRule(KCWindRule rule)
+{
+    m_path.setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
+}
+
+void KRenderingDeviceContextQt::fillPath()
+{
+    m_painter->fillPath(m_path, m_painter->brush());
+}
+
+void KRenderingDeviceContextQt::strokePath()
+{
+    m_painter->strokePath(m_path, m_painter->pen());
+}
+
+// KRenderingDeviceQt
+KRenderingDeviceQt::KRenderingDeviceQt() : KRenderingDevice()
+{
+}
+
+KRenderingDeviceQt::~KRenderingDeviceQt()
+{
+}
+
+KRenderingDeviceContext* KRenderingDeviceQt::popContext()
+{
+    // Any special things needed?
+    return KRenderingDevice::popContext();
+}
+
+void KRenderingDeviceQt::pushContext(KRenderingDeviceContext* context)
+{
+    // Any special things needed?
+    KRenderingDevice::pushContext(context);
+}
+
+// context management.
+KRenderingDeviceContextQt* KRenderingDeviceQt::qtContext() const
+{
+    return static_cast<KRenderingDeviceContextQt*>(currentContext());
+}
+
+KRenderingDeviceContext* KRenderingDeviceQt::contextForImage(KCanvasImage* image) const
+{
+    qDebug("KRenderingDeviceQt::contextForImage() TODO!");
+    return 0;
+}
+
+DeprecatedString KRenderingDeviceQt::stringForPath(const KCanvasPath* path)
+{
+    qDebug("KRenderingDeviceQt::stringForPath() TODO!");
+    return 0;
+}
+
+// Resource creation
+KCanvasResource* KRenderingDeviceQt::createResource(const KCResourceType& type) const
+{
+    switch (type)
+    {
+        case RS_CLIPPER:
+            return new KCanvasClipperQt();
+        case RS_MARKER:
+            return new KCanvasMarker(); // Use default implementation...
+        case RS_IMAGE:
+            // return new KCanvasImageQt();
+        case RS_FILTER:
+            // return new KCanvasFilterQt();
+        case RS_MASKER:
+            // return new KCanvasMaskerQt();
+        default:
+            return 0;
+    }
+}
+
+KRenderingPaintServer* KRenderingDeviceQt::createPaintServer(const KCPaintServerType& type) const
+{
+    switch (type)
+    {
+        case PS_SOLID:
+            return new KRenderingPaintServerSolidQt();
+        case PS_PATTERN:
+            return new KRenderingPaintServerPatternQt();
+        case PS_LINEAR_GRADIENT:
+            return new KRenderingPaintServerLinearGradientQt();
+        case PS_RADIAL_GRADIENT:
+            return new KRenderingPaintServerRadialGradientQt();
+        default:
+            return 0;
+    }
+}
+
+KCanvasFilterEffect* KRenderingDeviceQt::createFilterEffect(const KCFilterEffectType& type) const
+{
+    qDebug("KRenderingDeviceQt::createFilterEffect() TODO!");
+    return 0;
+}
+
+KCanvasPath* KRenderingDeviceQt::createPath() const
+{
+    return new KCanvasPathQt();
+}
+
+// item creation
+RenderPath* KRenderingDeviceQt::createItem(RenderArena* arena, RenderStyle* style, SVGStyledElement* node, KCanvasPath* path) const
+{
+    RenderPath* item = new (arena) RenderPathQt(style, node);
+    item->setPath(path);
+    return item;
+}
+
+KRenderingDevice* renderingDevice()
+{
+    static KRenderingDevice *sharedRenderingDevice = new KRenderingDeviceQt();
+    return sharedRenderingDevice;
+}
+
+}
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingDeviceQt.h b/WebCore/kcanvas/device/qt/KRenderingDeviceQt.h
new file mode 100644 (file)
index 0000000..fcfe3b0
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRenderingDeviceQt_H
+#define KRenderingDeviceQt_H
+
+#include <QPainter>
+#include <QPainterPath>
+
+#include "KRenderingDevice.h"
+
+namespace WebCore {
+
+class KRenderingDeviceContextQt : public KRenderingDeviceContext
+{
+public:
+    KRenderingDeviceContextQt(QPainter*);
+    virtual ~KRenderingDeviceContextQt();
+
+    virtual KCanvasMatrix concatCTM(const KCanvasMatrix&);
+    virtual KCanvasMatrix ctm() const;
+
+    virtual IntRect mapFromVisual(const IntRect&);
+    virtual IntRect mapToVisual(const IntRect&);
+
+    virtual void clearPath();
+    virtual void addPath(const KCanvasPath*);
+
+    virtual GraphicsContext* createGraphicsContext();
+    
+    // Qt specific stuff
+    QPainter& painter();
+    QRectF pathBBox() const;
+
+    void setFillRule(KCWindRule);
+
+    void fillPath();
+    void strokePath();
+
+private:
+    QPainter* m_painter;
+    QPainterPath m_path;
+};
+
+class KRenderingDeviceQt : public KRenderingDevice
+{
+public:
+    KRenderingDeviceQt();
+    virtual ~KRenderingDeviceQt();
+
+    virtual bool isBuffered() const { return false; }
+
+    virtual KRenderingDeviceContext* popContext();
+    virtual void pushContext(KRenderingDeviceContext*);
+
+    // context management.
+    KRenderingDeviceContextQt* qtContext() const;
+    virtual KRenderingDeviceContext* contextForImage(KCanvasImage*) const;
+
+    virtual DeprecatedString stringForPath(const KCanvasPath*);
+
+    // Resource creation
+    virtual KCanvasResource* createResource(const KCResourceType&) const;
+    virtual KRenderingPaintServer* createPaintServer(const KCPaintServerType&) const;
+    virtual KCanvasFilterEffect* createFilterEffect(const KCFilterEffectType&) const;
+    virtual KCanvasPath* createPath() const;
+
+    // item creation
+    virtual RenderPath* createItem(RenderArena*, RenderStyle*, SVGStyledElement*, KCanvasPath*) const;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingPaintServerGradientQt.cpp b/WebCore/kcanvas/device/qt/KRenderingPaintServerGradientQt.cpp
new file mode 100644 (file)
index 0000000..23e8e10
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#include <math.h>
+#include <QPointF>
+
+#include "RenderStyle.h"
+#include "KCanvasMatrix.h"
+#include "KRenderingDeviceQt.h"
+#include "KCanvasRenderingStyle.h"
+#include "KRenderingFillPainter.h"
+#include "KRenderingStrokePainter.h"
+#include "KRenderingPaintServerGradientQt.h"
+
+namespace WebCore {
+
+void fill_color_array(QGradient& gradient, const Vector<KCGradientStop>& stops, float opacity)
+{
+    for (unsigned i = 0; i < stops.size(); ++i) {
+        float offset = stops[i].first;
+        Color color = stops[i].second;
+        
+        QColor c(color.red(), color.green(), color.blue());
+        c.setAlpha(int(color.alpha() * opacity));
+
+        gradient.setColorAt(offset, c);
+    }
+}
+
+// KRenderingPaintServerLinearGradientQt
+KRenderingPaintServerLinearGradientQt::KRenderingPaintServerLinearGradientQt()
+    : KRenderingPaintServerLinearGradient()
+      , KRenderingPaintServerQt()
+{
+}
+
+void KRenderingPaintServerLinearGradientQt::renderPath(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
+{
+    RenderStyle* renderStyle = path->style();
+    KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
+
+    if ((type & APPLY_TO_FILL) && KSVGPainterFactory::isFilled(renderStyle))
+        qtContext->fillPath();
+
+    if ((type & APPLY_TO_STROKE) && KSVGPainterFactory::isStroked(renderStyle))
+        qtContext->strokePath();
+}
+
+bool KRenderingPaintServerLinearGradientQt::setup(KRenderingDeviceContext* context, const RenderObject* object, KCPaintTargetType type) const
+{
+    KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
+    Q_ASSERT(qtContext != 0);
+
+    if (listener())
+        listener()->resourceNotification();
+
+    RenderStyle* renderStyle = object->style();
+
+    double x1, x2, y1, y2;
+    if (boundingBoxMode()) {
+        QRectF bbox = qtContext->pathBBox();
+        x1 = double(bbox.left()) + (double(gradientStart().x() / 100.0) * double(bbox.width()));
+        y1 = double(bbox.top()) + (double(gradientStart().y() / 100.0) * double(bbox.height()));
+        x2 = double(bbox.left()) + (double(gradientEnd().x() / 100.0)  * double(bbox.width()));
+        y2 = double(bbox.top()) + (double(gradientEnd().y() / 100.0) * double(bbox.height()));
+    } else {
+        x1 = gradientStart().x();
+        y1 = gradientStart().y();
+        x2 = gradientEnd().x();
+        y2 = gradientEnd().y();
+    }
+
+    qtContext->painter().setPen(Qt::NoPen);
+    qtContext->painter().setBrush(Qt::NoBrush);
+
+    QLinearGradient gradient(QPointF(x1, y1), QPointF(x2, y2));
+    if (spreadMethod() == SPREADMETHOD_REPEAT) {
+        gradient.setSpread(QGradient::RepeatSpread);
+    } else if (spreadMethod() == SPREADMETHOD_REFLECT) {
+        gradient.setSpread(QGradient::ReflectSpread);
+    } else {
+        gradient.setSpread(QGradient::PadSpread);
+    }
+
+    double opacity = 1.0;
+
+    // TODO: Gradient transform + opacity fixes! 
+
+    if ((type & APPLY_TO_FILL) && KSVGPainterFactory::isFilled(renderStyle)) {
+        KRenderingFillPainter fillPainter = KSVGPainterFactory::fillPainter(renderStyle, object);
+        fill_color_array(gradient, gradientStops(), opacity);
+
+        QBrush brush(gradient);
+
+        qtContext->painter().setBrush(brush);
+        qtContext->setFillRule(fillPainter.fillRule());
+    }
+
+    if ((type & APPLY_TO_STROKE) && KSVGPainterFactory::isStroked(renderStyle)) {
+        KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(renderStyle, object);
+        fill_color_array(gradient, gradientStops(), opacity);
+
+        QPen pen;
+        QBrush brush(gradient);
+
+        setPenProperties(strokePainter, pen);
+        pen.setBrush(brush);
+
+        qtContext->painter().setPen(pen);
+    }
+
+    return true;
+}
+
+void KRenderingPaintServerLinearGradientQt::teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const
+{
+}
+
+void KRenderingPaintServerLinearGradientQt::draw(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
+{
+    if (!setup(context, path, type))
+        return;
+
+    renderPath(context, path, type);
+    teardown(context, path, type);
+}
+
+// KRenderingPaintServerRadialGradientQt
+KRenderingPaintServerRadialGradientQt::KRenderingPaintServerRadialGradientQt()
+    : KRenderingPaintServerRadialGradient()
+{
+}
+
+bool KRenderingPaintServerRadialGradientQt::setup(KRenderingDeviceContext* context, const RenderObject* object, KCPaintTargetType type) const
+{
+    KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
+    Q_ASSERT(qtContext != 0);
+
+    if (listener())
+        listener()->resourceNotification();
+
+    RenderStyle* renderStyle = object->style();
+
+    qtContext->painter().setPen(Qt::NoPen);
+    qtContext->painter().setBrush(Qt::NoBrush);
+    QMatrix mat = qtContext->ctm().matrix();
+
+    double cx, fx, cy, fy, r;
+    if (boundingBoxMode()) {
+        QRectF bbox = qtContext->pathBBox();
+        cx = double(bbox.left()) + (double(gradientCenter().x() / 100.0) * double(bbox.width()));
+        cy = double(bbox.top()) + (double(gradientCenter().y() / 100.0) * double(bbox.height()));
+        fx = double(bbox.left()) + (double(gradientFocal().x() / 100.0) * double(bbox.width())) - cx;
+        fy = double(bbox.top()) + (double(gradientFocal().y() / 100.0) * double(bbox.height())) - cy;
+        r = double(gradientRadius() / 100.0) * (sqrt(pow(bbox.width(), 2) + pow(bbox.height(), 2)));
+
+        float width = bbox.width();
+        float height = bbox.height();
+
+        int diff = int(width - height); // allow slight tolerance
+        if (!(diff > -2 && diff < 2)) {
+            // make elliptical or circular depending on bbox aspect ratio
+            float ratioX = (width / height);
+            float ratioY = (height / width);
+            mat.scale((width > height) ? 1 : ratioX, (width > height) ? ratioY : 1);
+        }
+    } else {
+        cx = gradientCenter().x();
+        cy = gradientCenter().y();
+
+        fx = gradientFocal().x();
+        fy = gradientFocal().y();
+
+        fx -= cx;
+        fy -= cy;
+
+        r = gradientRadius();
+    }
+
+    if (sqrt(fx * fx + fy * fy) > r) {
+        // Spec: If (fx, fy) lies outside the circle defined by (cx, cy) and r, set (fx, fy)
+        // to the point of intersection of the line through (fx, fy) and the circle.
+        double angle = atan2(fy, fx);
+        fx = int(cos(angle) * r) - 1;
+        fy = int(sin(angle) * r) - 1;
+    }
+
+    QRadialGradient gradient(QPointF(cx, cy), gradientRadius(), QPointF(fx + cx, fy + cy));
+    if (spreadMethod() == SPREADMETHOD_REPEAT) {
+        gradient.setSpread(QGradient::RepeatSpread);
+    } else if (spreadMethod() == SPREADMETHOD_REFLECT) {
+        gradient.setSpread(QGradient::ReflectSpread);
+    } else {
+        gradient.setSpread(QGradient::PadSpread);
+    }
+
+    double opacity = 1.0;
+
+    // TODO: Gradient transform + opacity fixes! 
+
+    // KCanvasMatrix gradientTrans = gradientTransform();
+    // gradientTrans.qmatrix().map(cx, cy, &cx, &cy);
+    // qtContext->painter().setMatrix(mat);
+
+    if ((type & APPLY_TO_FILL) && KSVGPainterFactory::isFilled(renderStyle)) {
+        KRenderingFillPainter fillPainter = KSVGPainterFactory::fillPainter(renderStyle, object);
+        fill_color_array(gradient, gradientStops(), opacity);
+
+        QBrush brush(gradient);
+
+        qtContext->painter().setBrush(brush);
+        qtContext->setFillRule(fillPainter.fillRule());
+    }
+
+    if ((type & APPLY_TO_STROKE) && KSVGPainterFactory::isStroked(renderStyle)) {
+        KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(renderStyle, object);
+        fill_color_array(gradient, gradientStops(), opacity);
+
+        QPen pen;
+        QBrush brush(gradient);
+
+        setPenProperties(strokePainter, pen);
+        pen.setBrush(brush);
+
+        qtContext->painter().setPen(pen);
+    }
+
+    return true;
+}
+
+void KRenderingPaintServerRadialGradientQt::draw(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
+{
+    if (!setup(context, path, type))
+        return;
+
+    renderPath(context, path, type);
+    teardown(context, path, type);
+}
+
+void KRenderingPaintServerRadialGradientQt::teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const
+{
+}
+
+void KRenderingPaintServerRadialGradientQt::renderPath(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
+{
+    RenderStyle* renderStyle = path->style();
+    KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
+
+    if ((type & APPLY_TO_FILL) && KSVGPainterFactory::isFilled(renderStyle))
+        qtContext->fillPath();
+
+    if ((type & APPLY_TO_STROKE) && KSVGPainterFactory::isStroked(renderStyle))
+        qtContext->strokePath();
+}
+
+}
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingPaintServerGradientQt.h b/WebCore/kcanvas/device/qt/KRenderingPaintServerGradientQt.h
new file mode 100644 (file)
index 0000000..a6898c9
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRenderingPaintServerGradientQt_H
+#define KRenderingPaintServerGradientQt_H
+
+#include "KRenderingPaintServerQt.h"
+#include "KRenderingPaintServerGradient.h"
+
+namespace WebCore {
+
+class KRenderingPaintServerLinearGradientQt : public KRenderingPaintServerLinearGradient,
+                                              public KRenderingPaintServerQt
+{
+public:
+    KRenderingPaintServerLinearGradientQt();
+
+    virtual void draw(KRenderingDeviceContext*, const RenderPath*, KCPaintTargetType) const;
+    virtual bool setup(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const;
+    virtual void teardown(KRenderingDeviceContext* , const RenderObject*, KCPaintTargetType) const;
+
+protected:
+    virtual void renderPath(KRenderingDeviceContext*, const RenderPath*, KCPaintTargetType) const;
+};
+
+class KRenderingPaintServerRadialGradientQt : public KRenderingPaintServerRadialGradient,
+                                              public KRenderingPaintServerQt
+{
+public:
+    KRenderingPaintServerRadialGradientQt();
+
+    virtual void draw(KRenderingDeviceContext*, const RenderPath*, KCPaintTargetType) const;
+    virtual bool setup(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const;
+    virtual void teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const;
+
+protected:
+    virtual void renderPath(KRenderingDeviceContext*, const RenderPath*, KCPaintTargetType) const;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingPaintServerPatternQt.cpp b/WebCore/kcanvas/device/qt/KRenderingPaintServerPatternQt.cpp
new file mode 100644 (file)
index 0000000..3833e03
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#include <qrect.h>
+#include <qimage.h>
+
+#include <math.h>
+#include <QPointF>
+#include <QPainterPath>
+
+#include "RenderStyle.h"
+#include "KRenderingDeviceQt.h"
+#include "KCanvasRenderingStyle.h"
+#include "KRenderingFillPainter.h"
+#include "KRenderingStrokePainter.h"
+#include "KRenderingPaintServerPatternQt.h"
+#include "KCanvasImage.h"
+
+namespace WebCore {
+
+// KRenderingPaintServerPatternQt
+KRenderingPaintServerPatternQt::KRenderingPaintServerPatternQt()
+    : KRenderingPaintServerPattern()
+      , KRenderingPaintServerQt()
+{
+}
+
+KRenderingPaintServerPatternQt::~KRenderingPaintServerPatternQt()
+{
+}
+
+void KRenderingPaintServerPatternQt::renderPath(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
+{
+    RenderStyle* renderStyle = path->style();
+    KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
+
+    if ((type & APPLY_TO_FILL) && KSVGPainterFactory::isFilled(renderStyle))
+        qtContext->fillPath();
+
+    if ((type & APPLY_TO_STROKE) && KSVGPainterFactory::isStroked(renderStyle))
+        qtContext->strokePath();
+}
+
+bool KRenderingPaintServerPatternQt::setup(KRenderingDeviceContext* context, const RenderObject* object, KCPaintTargetType type) const
+{
+/*
+    KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
+    Q_ASSERT(qtContext != 0);
+
+    QPainterPath* _path = static_cast<QPainterPath*>(qtContext->path());
+    Q_ASSERT(_path != 0);
+    if (listener()) {
+        listener()->resourceNotification();
+    }
+
+    RenderStyle* renderStyle = object->style();
+
+    qtContext->painter().setPen(Qt::NoPen);
+    qtContext->painter().setBrush(Qt::NoBrush);
+    QImage* patternimage = new QImage(tile()->bits(), tile()->width(), tile()->height(), QImage::Format_ARGB32_Premultiplied);
+    patternimage->setAlphaBuffer(true);
+    if (type & APPLY_TO_FILL) {
+        //QColor c = color();
+        //c.setAlphaF(style->fillPainter()->opacity() * style->opacity() * opacity());
+        KRenderingFillPainter fillPainter = KSVGPainterFactory::fillPainter(renderStyle, object);
+        QBrush brush(QPixmap::fromImage(*patternimage));
+        _path->setFillRule(fillPainter.fillRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
+        qtContext->painter().setBrush(brush);
+    }
+    if (type & APPLY_TO_STROKE) {
+        //QColor c = color();
+        //c.setAlphaF(style->strokePainter()->opacity() * style->opacity() * opacity());
+        KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(renderStyle, object);
+
+        QPen pen;
+        QBrush brush(QPixmap::fromImage(*patternimage));
+
+        setPenProperties(strokePainter, pen);
+        pen.setBrush(brush);
+        qtContext->painter().setPen(pen);
+    }
+
+    qtContext->painter().drawPath(*_path);
+
+    delete patternimage;
+*/
+
+    return true;
+}
+
+void KRenderingPaintServerPatternQt::teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const
+{
+}
+
+void KRenderingPaintServerPatternQt::draw(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
+{
+    if (!setup(context, path, type))
+        return;
+
+    renderPath(context, path, type);
+    teardown(context, path, type);
+}
+
+}
+
+// vim:ts=4:noet
+
diff --git a/WebCore/kcanvas/device/qt/KRenderingPaintServerPatternQt.h b/WebCore/kcanvas/device/qt/KRenderingPaintServerPatternQt.h
new file mode 100644 (file)
index 0000000..570d259
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRenderingPaintServerPatternQt_H
+#define KRenderingPaintServerPatternQt_H
+
+#include "KRenderingPaintServerQt.h"
+#include "KRenderingPaintServerPattern.h"
+
+namespace WebCore {
+
+class KRenderingPaintServerPatternQt : public KRenderingPaintServerPattern,
+                                       public KRenderingPaintServerQt
+{
+public:
+    KRenderingPaintServerPatternQt();
+    virtual ~KRenderingPaintServerPatternQt();
+
+    virtual void draw(KRenderingDeviceContext*, const RenderPath*, KCPaintTargetType) const;
+    virtual bool setup(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const;
+    virtual void teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const;
+
+protected:
+    virtual void renderPath(KRenderingDeviceContext*, const RenderPath*, KCPaintTargetType) const;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingPaintServerQt.cpp b/WebCore/kcanvas/device/qt/KRenderingPaintServerQt.cpp
new file mode 100644 (file)
index 0000000..7b5bbd4
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#include <QPen>
+#include <QVector>
+
+#include "KRenderingStrokePainter.h"
+#include "KRenderingPaintServerQt.h"
+
+namespace WebCore {
+
+KRenderingPaintServerQt::KRenderingPaintServerQt()
+{
+}
+
+KRenderingPaintServerQt::~KRenderingPaintServerQt()
+{
+}
+
+void KRenderingPaintServerQt::setPenProperties(const KRenderingStrokePainter& strokePainter, QPen& pen) const
+{
+    pen.setWidthF(strokePainter.strokeWidth());
+    if (strokePainter.strokeCapStyle() == CAP_BUTT) {
+        pen.setCapStyle(Qt::FlatCap);
+    } else if (strokePainter.strokeCapStyle() == CAP_ROUND) {
+        pen.setCapStyle(Qt::RoundCap);
+    }
+
+    if(strokePainter.strokeJoinStyle() == JOIN_MITER) {
+        pen.setJoinStyle(Qt::MiterJoin);
+        pen.setMiterLimit((qreal)strokePainter.strokeMiterLimit());
+    } else if(strokePainter.strokeJoinStyle() == JOIN_ROUND) {
+        pen.setJoinStyle(Qt::RoundJoin);
+    }
+
+    KCDashArray dashes = strokePainter.dashArray();
+    unsigned int dashLength = !dashes.isEmpty() ? dashes.count() : 0;
+    if(dashLength) {
+        QVector<qreal> pattern;
+        unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
+
+        for(unsigned int i = 0; i < count; i++)
+            pattern.append(dashes[i % dashLength] / (float)pen.widthF());
+
+        pen.setDashPattern(pattern);
+        // TODO: dash-offset, does/will qt4 API allow it? (Rob)
+    }
+}
+
+}
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingPaintServerQt.h b/WebCore/kcanvas/device/qt/KRenderingPaintServerQt.h
new file mode 100644 (file)
index 0000000..ac767ef
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRenderingPaintServerQt_H
+#define KRenderingPaintServerQt_H
+
+#include "KRenderingPaintServer.h"
+
+class QPen;
+
+namespace WebCore {
+
+class KRenderingStrokePainter;
+
+// This class is designed as an extension to
+// KRenderingPaintServer, it won't inherit from it.
+class KRenderingPaintServerQt
+{
+public:
+    KRenderingPaintServerQt();
+    ~KRenderingPaintServerQt();
+
+    void setPenProperties(const KRenderingStrokePainter&, QPen&) const;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingPaintServerSolidQt.cpp b/WebCore/kcanvas/device/qt/KRenderingPaintServerSolidQt.cpp
new file mode 100644 (file)
index 0000000..ba4e18b
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#include <QPen>
+#include <QBrush>
+#include <QPainter>
+
+#include "RenderStyle.h"
+#include "KRenderingDeviceQt.h"
+#include "KCanvasRenderingStyle.h"
+#include "KRenderingFillPainter.h"
+#include "KRenderingStrokePainter.h"
+#include "KRenderingPaintServerSolidQt.h"
+
+namespace WebCore {
+
+KRenderingPaintServerSolidQt::KRenderingPaintServerSolidQt()
+    : KRenderingPaintServerSolid()
+      , KRenderingPaintServerQt()
+{
+}
+
+KRenderingPaintServerSolidQt::~KRenderingPaintServerSolidQt()
+{
+}
+
+// 'Solid' interface
+void KRenderingPaintServerSolidQt::draw(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
+{
+    if (!setup(context, path, type))
+        return;
+
+    renderPath(context, path, type);
+    teardown(context, path, type);
+}
+
+bool KRenderingPaintServerSolidQt::setup(KRenderingDeviceContext* context, const RenderObject* object, KCPaintTargetType type) const
+{
+    KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
+
+    RenderStyle* renderStyle = object->style();
+    // TODO? qtContext->painter().setOpacity(renderStyle->opacity());
+
+    QColor c = color();
+
+    if ((type & APPLY_TO_FILL) && KSVGPainterFactory::isFilled(renderStyle)) {
+        KRenderingFillPainter fillPainter = KSVGPainterFactory::fillPainter(renderStyle, object);
+        c.setAlphaF(fillPainter.opacity());
+
+        QBrush brush(c);
+        qtContext->painter().setBrush(brush);
+        qtContext->setFillRule(fillPainter.fillRule());
+
+        /* if(isPaintingText()) ... */
+    }
+
+    if((type & APPLY_TO_STROKE) && KSVGPainterFactory::isStroked(renderStyle)) {
+        KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(renderStyle, object);
+        c.setAlphaF(strokePainter.opacity());
+
+        QPen pen(c);
+        setPenProperties(strokePainter, pen);
+        qtContext->painter().setPen(pen);
+
+        /* if(isPaintingText()) ... */
+    }
+
+    return true;
+}
+
+void KRenderingPaintServerSolidQt::teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const
+{
+}
+
+void KRenderingPaintServerSolidQt::renderPath(KRenderingDeviceContext* context, const RenderPath* path, KCPaintTargetType type) const
+{
+    RenderStyle* renderStyle = path->style();
+    KRenderingDeviceContextQt *qtContext = static_cast<KRenderingDeviceContextQt*>(context);
+
+    if ((type & APPLY_TO_FILL) && KSVGPainterFactory::isFilled(renderStyle))
+        qtContext->fillPath();
+
+    if ((type & APPLY_TO_STROKE) && KSVGPainterFactory::isStroked(renderStyle))
+        qtContext->strokePath();
+}
+
+}
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/KRenderingPaintServerSolidQt.h b/WebCore/kcanvas/device/qt/KRenderingPaintServerSolidQt.h
new file mode 100644 (file)
index 0000000..ae72f7e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; see the file COPYING.LIB. If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRenderingPaintServerSolidQt_H
+#define KRenderingPaintServerSolidQt_H
+
+#include "KRenderingPaintServerQt.h"
+#include "KRenderingPaintServerSolid.h"
+
+namespace WebCore {
+    
+class KRenderingPaintServerSolidQt : public KRenderingPaintServerSolid,
+                                     public KRenderingPaintServerQt
+{
+public:
+    KRenderingPaintServerSolidQt();
+    virtual ~KRenderingPaintServerSolidQt();
+
+    virtual void draw(KRenderingDeviceContext*, const RenderPath*, KCPaintTargetType) const;
+    virtual bool setup(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const;
+    virtual void teardown(KRenderingDeviceContext*, const RenderObject*, KCPaintTargetType) const;
+
+protected:
+    virtual void renderPath(KRenderingDeviceContext*, const RenderPath*, KCPaintTargetType) const;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/RenderPathQt.cpp b/WebCore/kcanvas/device/qt/RenderPathQt.cpp
new file mode 100644 (file)
index 0000000..7b1d864
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+                  2005 Eric Seidel <eric.seidel@kdemail.net>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    aint with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.
+*/
+
+#include <QDebug>
+
+#include "config.h"
+#include "RenderPathQt.h"
+
+namespace WebCore {
+    
+RenderPathQt::RenderPathQt(RenderStyle* style, SVGStyledElement* node)
+    : RenderPath(style, node)
+{
+}
+
+void RenderPathQt::drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const KCanvasPath*) const
+{
+    qDebug("RenderPathQt::drawMarkersIfNeeded() TODO!");
+}
+
+}
+
+// vim:ts=4:noet
diff --git a/WebCore/kcanvas/device/qt/RenderPathQt.h b/WebCore/kcanvas/device/qt/RenderPathQt.h
new file mode 100644 (file)
index 0000000..f2f360f
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
+                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+                  2005 Eric Seidel <eric.seidel@kdemail.net>
+
+    This file is part of the KDE project
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    aint with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.
+*/
+
+#ifndef RenderPathQt_H
+#define RenderPathQt_H
+
+#include "RenderPath.h"
+
+namespace WebCore {
+
+class RenderPathQt : public RenderPath
+{
+public:
+    RenderPathQt(RenderStyle*, SVGStyledElement*);
+
+protected:
+    virtual void drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const KCanvasPath *) const;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet