• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

SVGResourceClipperQt.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
00003                   2004, 2005, 2006 Rob Buis <buis@kde.org>
00004                   2005 Apple Computer, Inc.
00005 
00006     This file is part of the KDE project
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     aint with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "config.h"
00025 #include "wtf/Platform.h"
00026 
00027 #if ENABLE(SVG)
00028 #include "SVGResourceClipper.h"
00029 
00030 /*#include "GraphicsContext.h"*/
00031 
00032 #include <QPainter>
00033 #include <QPainterPath>
00034 
00035 #include "FloatRect.h"
00036 
00037 namespace WebCore {
00038 
00039 void SVGResourceClipper::applyClip(/*GraphicsContext* context*/QPainter* painter, const FloatRect& boundingBox) const
00040 {
00041     if (m_clipData.clipData().size() < 1)
00042         return;
00043 
00044     /*context->beginPath();*/
00045 
00046 
00047     QPainterPath newPath;
00048 
00049     bool heterogenousClipRules = false;
00050     WindRule clipRule = m_clipData.clipData()[0].windRule;
00051 
00052     unsigned int clipDataCount = m_clipData.clipData().size();
00053     for (unsigned int x = 0; x < clipDataCount; x++) {
00054         ClipData clipData = m_clipData.clipData()[x];
00055         if (clipData.windRule != clipRule)
00056             heterogenousClipRules = true;
00057 
00058         QPainterPath path = *(clipData.path.platformPath());
00059         if (path.isEmpty())
00060             continue;
00061 
00062         if (!newPath.isEmpty())
00063             newPath.closeSubpath();
00064 
00065         // Respect clipping units...
00066         QMatrix transform;
00067 
00068         if (clipData.bboxUnits) {
00069             transform.translate(boundingBox.x(), boundingBox.y());
00070             transform.scale(boundingBox.width(), boundingBox.height());
00071         }
00072 
00073         // TODO: support heterogenous clip rules!
00074         //clipRule = (clipData.windRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
00075 
00076         for (int i = 0; i < path.elementCount(); ++i) {
00077             const QPainterPath::Element &cur = path.elementAt(i);
00078 
00079             switch (cur.type) {
00080                 case QPainterPath::MoveToElement:
00081                     newPath.moveTo(QPointF(cur.x, cur.y) * transform);
00082                     break;
00083                 case QPainterPath::LineToElement:
00084                     newPath.lineTo(QPointF(cur.x, cur.y) * transform);
00085                     break;
00086                 case QPainterPath::CurveToElement:
00087                 {
00088                     const QPainterPath::Element &c1 = path.elementAt(i + 1);
00089                     const QPainterPath::Element &c2 = path.elementAt(i + 2);
00090 
00091                     Q_ASSERT(c1.type == QPainterPath::CurveToDataElement);
00092                     Q_ASSERT(c2.type == QPainterPath::CurveToDataElement);
00093 
00094                     newPath.cubicTo(QPointF(cur.x, cur.y) * transform,
00095                                     QPointF(c1.x, c1.y) * transform,
00096                                     QPointF(c2.x, c2.y) * transform);
00097 
00098                     i += 2;
00099                     break;
00100                 }
00101                 case QPainterPath::CurveToDataElement:
00102                     Q_ASSERT(false);
00103                     break;
00104             }
00105         }
00106     }
00107 
00108     if (m_clipData.clipData().size()) {
00109         // FIXME!
00110         // We don't currently allow for heterogenous clip rules.
00111         // we would have to detect such, draw to a mask, and then clip
00112         // to that mask
00113         // if (!CGContextIsPathEmpty(cgContext)) {
00114             if (clipRule == RULE_EVENODD)
00115                 newPath.setFillRule(Qt::OddEvenFill);
00116             else
00117                 newPath.setFillRule(Qt::WindingFill);
00118         // }
00119     }
00120 
00121     /*QPainter* painter(context ? context->platformContext() : 0);
00122     Q_ASSERT(painter);*/
00123 
00124     painter->setClipPath(newPath);
00125 }
00126 
00127 } // namespace WebCore
00128 
00129 #endif
00130 
00131 // vim:ts=4

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal