KHtml

SVGPaintServerQt.cpp
1 /*
2  Copyright (C) 2006 Nikolas Zimmermann <[email protected]>
3 
4  This file is part of the KDE project
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  aint with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "wtf/Platform.h"
23 
24 #if ENABLE(SVG)
25 #include "SVGPaintServer.h"
26 
27 /*#include "GraphicsContext.h"*/
28 #include "SVGRenderStyle.h"
29 #include "RenderObject.h"
30 #include "RenderPath.h"
31 
32 #include <QPainter>
33 #include <QVector>
34 
35 namespace WebCore
36 {
37 
38 void SVGPaintServer::setPenProperties(const RenderObject *object, const RenderStyle *style, QPen &pen) const
39 {
40  pen.setWidthF(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));
41 
42  /*if (style->svgStyle()->capStyle() == ButtCap)
43  pen.setCapStyle(Qt::FlatCap);
44  else if (style->svgStyle()->capStyle() == RoundCap)
45  pen.setCapStyle(Qt::RoundCap);
46 
47  if (style->svgStyle()->joinStyle() == MiterJoin) {
48  pen.setJoinStyle(Qt::MiterJoin);
49  pen.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());
50  } else if(style->svgStyle()->joinStyle() == RoundJoin)
51  pen.setJoinStyle(Qt::RoundJoin);*/
52 
53  /*const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style);
54  double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);
55 
56  unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;
57  if(dashLength) {
58  QVector<qreal> pattern;
59  unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
60 
61  for(unsigned int i = 0; i < count; i++)
62  pattern.append(dashes[i % dashLength] / (float)pen.widthF());
63 
64  pen.setDashPattern(pattern);
65 
66  Q_UNUSED(dashOffset);
67  // TODO: dash-offset, does/will qt4 API allow it? (Rob)
68  }*/
69 }
70 
71 void SVGPaintServer::draw(QPainter *painter, QPainterPath *painterPath, const RenderObject *path, SVGPaintTargetType type) const
72 {
73  if (!setup(painter, painterPath, path, type)) {
74  return;
75  }
76 
77  renderPath(painter, painterPath, path, type);
78  teardown(painter, painterPath, path, type);
79 }
80 
81 void SVGPaintServer::teardown(QPainter *painter, QPainterPath *painterPath, const RenderObject *, SVGPaintTargetType, bool isPaintingText) const
82 {
83  Q_UNUSED(painter);
84  Q_UNUSED(painterPath);
85  Q_UNUSED(isPaintingText);
86  // no-op
87 }
88 
89 void SVGPaintServer::renderPath(QPainter *painter, QPainterPath *painterPath, const RenderObject *path, SVGPaintTargetType type) const
90 {
91  RenderStyle *renderStyle = path->style();
92 
93  //QPainter* painter(context ? context->platformContext() : 0);
94  //Q_ASSERT(painter);
95 
96  //QPainterPath* painterPath(context ? context->currentPath() : 0);
97  //Q_ASSERT(painterPath);
98 
99  if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) {
100  painter->fillPath(*painterPath, painter->brush());
101  }
102 
103  if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) {
104  painter->strokePath(*painterPath, painter->pen());
105  }
106 }
107 
108 } // namespace WebCore
109 
110 #endif
111 
void strokePath(const QPainterPath &path, const QPen &pen)
void fillPath(const QPainterPath &path, const QBrush &brush)
void setWidthF(qreal width)
const QBrush & brush() const const
const QPen & pen() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.