2 Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org>
4 This file is part of the KDE project
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.
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.
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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
25 #include "SVGPaintServer.h"
27 #include "KCanvasRenderingStyle.h"
28 #include "KRenderingDeviceQt.h"
29 #include "RenderPath.h"
36 void SVGPaintServer::setPenProperties(const RenderObject* object, const RenderStyle* style, QPen& pen) const
38 pen.setWidthF(KSVGPainterFactory::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));
40 if (style->svgStyle()->capStyle() == ButtCap)
41 pen.setCapStyle(Qt::FlatCap);
42 else if (style->svgStyle()->capStyle() == RoundCap)
43 pen.setCapStyle(Qt::RoundCap);
45 if (style->svgStyle()->joinStyle() == MiterJoin) {
46 pen.setJoinStyle(Qt::MiterJoin);
47 pen.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());
48 } else if(style->svgStyle()->joinStyle() == RoundJoin)
49 pen.setJoinStyle(Qt::RoundJoin);
51 const KCDashArray& dashes = KSVGPainterFactory::dashArrayFromRenderingStyle(style);
52 double dashOffset = KSVGPainterFactory::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);
54 unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;
56 QVector<qreal> pattern;
57 unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
59 for(unsigned int i = 0; i < count; i++)
60 pattern.append(dashes[i % dashLength] / (float)pen.widthF());
62 pen.setDashPattern(pattern);
65 // TODO: dash-offset, does/will qt4 API allow it? (Rob)
69 void SVGPaintServer::draw(KRenderingDeviceContext* context, const RenderPath* path, SVGPaintTargetType type) const
71 if (!setup(context, path, type))
74 renderPath(context, path, type);
75 teardown(context, path, type);
78 void SVGPaintServer::teardown(KRenderingDeviceContext*, const RenderObject*, SVGPaintTargetType) const
83 void SVGPaintServer::renderPath(KRenderingDeviceContext* context, const RenderPath* path, SVGPaintTargetType type) const
85 RenderStyle* renderStyle = path->style();
86 KRenderingDeviceContextQt* qtContext = static_cast<KRenderingDeviceContextQt*>(context);
88 if ((type & APPLY_TO_FILL) && renderStyle->svgStyle()->hasFill())
89 qtContext->fillPath();
91 if ((type & APPLY_TO_STROKE) && renderStyle->svgStyle()->hasStroke())
92 qtContext->strokePath();
95 } // namespace WebCore