KHtml

SVGResourceClipperQt.cpp
1 /*
2  Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006 Rob Buis <[email protected]>
4  2005 Apple Computer, Inc.
5 
6  This file is part of the KDE project
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  aint with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include "wtf/Platform.h"
25 
26 #if ENABLE(SVG)
27 #include "SVGResourceClipper.h"
28 
29 /*#include "GraphicsContext.h"*/
30 
31 #include <QPainter>
32 #include <QPainterPath>
33 
34 #include "FloatRect.h"
35 
36 namespace WebCore
37 {
38 
39 void SVGResourceClipper::applyClip(/*GraphicsContext* context*/QPainter *painter, const FloatRect &boundingBox) const
40 {
41  if (m_clipData.clipData().size() < 1) {
42  return;
43  }
44 
45  /*context->beginPath();*/
46 
47  QPainterPath newPath;
48 
49  WindRule clipRule = m_clipData.clipData()[0].windRule;
50 
51  unsigned int clipDataCount = m_clipData.clipData().size();
52  for (unsigned int x = 0; x < clipDataCount; x++) {
53  ClipData clipData = m_clipData.clipData()[x];
54 
55  QPainterPath path = *(clipData.path.platformPath());
56  if (path.isEmpty()) {
57  continue;
58  }
59 
60  if (!newPath.isEmpty()) {
61  newPath.closeSubpath();
62  }
63 
64  // Respect clipping units...
66 
67  if (clipData.bboxUnits) {
68  transform.translate(boundingBox.x(), boundingBox.y());
69  transform.scale(boundingBox.width(), boundingBox.height());
70  }
71 
72  // TODO: support heterogenous clip rules!
73  //clipRule = (clipData.windRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
74 
75  for (int i = 0; i < path.elementCount(); ++i) {
76  const QPainterPath::Element &cur = path.elementAt(i);
77 
78  switch (cur.type) {
80  newPath.moveTo(QPointF(cur.x, cur.y) * transform);
81  break;
83  newPath.lineTo(QPointF(cur.x, cur.y) * transform);
84  break;
86  const QPainterPath::Element &c1 = path.elementAt(i + 1);
87  const QPainterPath::Element &c2 = path.elementAt(i + 2);
88 
89  Q_ASSERT(c1.type == QPainterPath::CurveToDataElement);
90  Q_ASSERT(c2.type == QPainterPath::CurveToDataElement);
91 
92  newPath.cubicTo(QPointF(cur.x, cur.y) * transform,
93  QPointF(c1.x, c1.y) * transform,
94  QPointF(c2.x, c2.y) * transform);
95 
96  i += 2;
97  break;
98  }
100  Q_ASSERT(false);
101  break;
102  }
103  }
104  }
105 
106  if (m_clipData.clipData().size()) {
107  // FIXME!
108  // We don't currently allow for heterogenous clip rules.
109  // we would have to detect such, draw to a mask, and then clip
110  // to that mask
111  // if (!CGContextIsPathEmpty(cgContext)) {
112  if (clipRule == RULE_EVENODD) {
113  newPath.setFillRule(Qt::OddEvenFill);
114  } else {
115  newPath.setFillRule(Qt::WindingFill);
116  }
117  // }
118  }
119 
120  /*QPainter* painter(context ? context->platformContext() : 0);
121  Q_ASSERT(painter);*/
122 
123  painter->setClipPath(newPath);
124 }
125 
126 } // namespace WebCore
127 
128 #endif
129 
void setClipPath(const QPainterPath &path, Qt::ClipOperation operation)
void closeSubpath()
OddEvenFill
void cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &endPoint)
QPainterPath::Element elementAt(int index) const const
void moveTo(const QPointF &point)
KDOCTOOLS_EXPORT QString transform(const QString &file, const QString &stylesheet, const QVector< const char * > &params=QVector< const char * >())
int elementCount() const const
void setFillRule(Qt::FillRule fillRule)
void lineTo(const QPointF &endPoint)
QMatrix & translate(qreal dx, qreal dy)
bool isEmpty() const const
QMatrix & scale(qreal sx, qreal sy)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.