2 Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 2005 Eric Seidel <eric.seidel@kdemail.net>
6 This file is part of the KDE project
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.
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.
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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
25 #include "RenderPath.h"
26 #include "KCanvasRenderingStyle.h"
27 #include "KRenderingStrokePainter.h"
30 #include <QPainterPathStroker>
34 bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const
39 if (requiresStroke && !KSVGPainterFactory::strokePaintServer(style(), this))
45 static QPainterPath getPathStroke(const QPainterPath &path, const KRenderingStrokePainter &strokePainter)
47 QPainterPathStroker s;
48 s.setWidth(strokePainter.strokeWidth());
49 if(strokePainter.strokeCapStyle() == CAP_BUTT)
50 s.setCapStyle(Qt::FlatCap);
51 else if(strokePainter.strokeCapStyle() == CAP_ROUND)
52 s.setCapStyle(Qt::RoundCap);
54 if(strokePainter.strokeJoinStyle() == JOIN_MITER) {
55 s.setJoinStyle(Qt::MiterJoin);
56 s.setMiterLimit((qreal)strokePainter.strokeMiterLimit());
57 } else if(strokePainter.strokeJoinStyle() == JOIN_ROUND)
58 s.setJoinStyle(Qt::RoundJoin);
60 KCDashArray dashes = strokePainter.dashArray();
61 unsigned int dashLength = !dashes.isEmpty() ? dashes.count() : 0;
63 QVector<qreal> pattern;
64 unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
66 for(unsigned int i = 0; i < count; i++)
67 pattern.append(dashes[i % dashLength] / (float)s.width());
69 s.setDashPattern(pattern);
70 // TODO: dash-offset, does/will qt4 API allow it? (Rob)
73 return s.createStroke(path);
76 FloatRect RenderPath::strokeBBox() const
78 KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(style(), this);
79 QPainterPath outline = getPathStroke(*(path().platformPath()), strokePainter);
80 return outline.boundingRect();