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

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
  • graphics
  • qt
SVGResourceClipperQt.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
3  2004, 2005, 2006 Rob Buis <buis@kde.org>
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 "config.h"
25 #include "wtf/Platform.h"
26 
27 #if ENABLE(SVG)
28 #include "SVGResourceClipper.h"
29 
30 /*#include "GraphicsContext.h"*/
31 
32 #include <QPainter>
33 #include <QPainterPath>
34 
35 #include "FloatRect.h"
36 
37 namespace WebCore {
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  /*context->beginPath();*/
45 
46 
47  QPainterPath newPath;
48 
49  bool heterogenousClipRules = false;
50  WindRule clipRule = m_clipData.clipData()[0].windRule;
51 
52  unsigned int clipDataCount = m_clipData.clipData().size();
53  for (unsigned int x = 0; x < clipDataCount; x++) {
54  ClipData clipData = m_clipData.clipData()[x];
55  if (clipData.windRule != clipRule)
56  heterogenousClipRules = true;
57 
58  QPainterPath path = *(clipData.path.platformPath());
59  if (path.isEmpty())
60  continue;
61 
62  if (!newPath.isEmpty())
63  newPath.closeSubpath();
64 
65  // Respect clipping units...
66  QMatrix transform;
67 
68  if (clipData.bboxUnits) {
69  transform.translate(boundingBox.x(), boundingBox.y());
70  transform.scale(boundingBox.width(), boundingBox.height());
71  }
72 
73  // TODO: support heterogenous clip rules!
74  //clipRule = (clipData.windRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
75 
76  for (int i = 0; i < path.elementCount(); ++i) {
77  const QPainterPath::Element &cur = path.elementAt(i);
78 
79  switch (cur.type) {
80  case QPainterPath::MoveToElement:
81  newPath.moveTo(QPointF(cur.x, cur.y) * transform);
82  break;
83  case QPainterPath::LineToElement:
84  newPath.lineTo(QPointF(cur.x, cur.y) * transform);
85  break;
86  case QPainterPath::CurveToElement:
87  {
88  const QPainterPath::Element &c1 = path.elementAt(i + 1);
89  const QPainterPath::Element &c2 = path.elementAt(i + 2);
90 
91  Q_ASSERT(c1.type == QPainterPath::CurveToDataElement);
92  Q_ASSERT(c2.type == QPainterPath::CurveToDataElement);
93 
94  newPath.cubicTo(QPointF(cur.x, cur.y) * transform,
95  QPointF(c1.x, c1.y) * transform,
96  QPointF(c2.x, c2.y) * transform);
97 
98  i += 2;
99  break;
100  }
101  case QPainterPath::CurveToDataElement:
102  Q_ASSERT(false);
103  break;
104  }
105  }
106  }
107 
108  if (m_clipData.clipData().size()) {
109  // FIXME!
110  // We don't currently allow for heterogenous clip rules.
111  // we would have to detect such, draw to a mask, and then clip
112  // to that mask
113  // if (!CGContextIsPathEmpty(cgContext)) {
114  if (clipRule == RULE_EVENODD)
115  newPath.setFillRule(Qt::OddEvenFill);
116  else
117  newPath.setFillRule(Qt::WindingFill);
118  // }
119  }
120 
121  /*QPainter* painter(context ? context->platformContext() : 0);
122  Q_ASSERT(painter);*/
123 
124  painter->setClipPath(newPath);
125 }
126 
127 } // namespace WebCore
128 
129 #endif
130 
131 // vim:ts=4
FloatRect.h
SVGResourceClipper.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal