25 #include "wtf/Platform.h"
33 #include <QPainterPath>
39 void SVGResourceClipper::applyClip(QPainter* painter,
const FloatRect& boundingBox)
const
41 if (m_clipData.clipData().size() < 1)
49 bool heterogenousClipRules =
false;
50 WindRule clipRule = m_clipData.clipData()[0].windRule;
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;
58 QPainterPath path = *(clipData.path.platformPath());
62 if (!newPath.isEmpty())
63 newPath.closeSubpath();
68 if (clipData.bboxUnits) {
69 transform.translate(boundingBox.x(), boundingBox.y());
70 transform.scale(boundingBox.width(), boundingBox.height());
76 for (
int i = 0; i < path.elementCount(); ++i) {
77 const QPainterPath::Element &cur = path.elementAt(i);
80 case QPainterPath::MoveToElement:
81 newPath.moveTo(QPointF(cur.x, cur.y) * transform);
83 case QPainterPath::LineToElement:
84 newPath.lineTo(QPointF(cur.x, cur.y) * transform);
86 case QPainterPath::CurveToElement:
88 const QPainterPath::Element &c1 = path.elementAt(i + 1);
89 const QPainterPath::Element &c2 = path.elementAt(i + 2);
91 Q_ASSERT(c1.type == QPainterPath::CurveToDataElement);
92 Q_ASSERT(c2.type == QPainterPath::CurveToDataElement);
94 newPath.cubicTo(QPointF(cur.x, cur.y) * transform,
95 QPointF(c1.x, c1.y) * transform,
96 QPointF(c2.x, c2.y) * transform);
101 case QPainterPath::CurveToDataElement:
108 if (m_clipData.clipData().size()) {
114 if (clipRule == RULE_EVENODD)
115 newPath.setFillRule(Qt::OddEvenFill);
117 newPath.setFillRule(Qt::WindingFill);
124 painter->setClipPath(newPath);