KHtml

RenderPathQt.cpp
1 /*
2  Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006 Rob Buis <[email protected]>
4  2005 Eric Seidel <[email protected]>
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 "RenderPath.h"
25 #include "SVGRenderStyle.h"
26 #include "SVGPaintServer.h"
27 
28 #include "khtml_debug.h"
29 #include <QPainterPathStroker>
30 
31 namespace WebCore
32 {
33 
34 bool RenderPath::strokeContains(const FloatPoint &point, bool requiresStroke) const
35 {
36  if (path().isEmpty()) {
37  return false;
38  }
39 
40  if (requiresStroke && !SVGPaintServer::strokePaintServer(style(), this)) {
41  return false;
42  }
43 
44  return false;
45 }
46 
47 static QPainterPath getPathStroke(const QPainterPath &path, const RenderObject *object, const RenderStyle *style)
48 {
50  s.setWidth(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));
51 
52  if (style->svgStyle()->capStyle() == ButtCap) {
54  } else if (style->svgStyle()->capStyle() == RoundCap) {
56  }
57 
58  if (style->svgStyle()->joinStyle() == MiterJoin) {
60  s.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());
61  } else if (style->svgStyle()->joinStyle() == RoundJoin) {
63  }
64 
65  const DashArray &dashes = WebCore::dashArrayFromRenderingStyle(style);
66  double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);
67 
68  unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;
69  if (dashLength) {
71  unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
72 
73  for (unsigned int i = 0; i < count; i++) {
74  pattern.append(dashes[i % dashLength] / (float)s.width());
75  }
76 
77  s.setDashPattern(pattern);
78 
79  Q_UNUSED(dashOffset);
80  // TODO: dash-offset, does/will qt4 API allow it? (Rob)
81  }
82 
83  return s.createStroke(path);
84 }
85 
86 FloatRect RenderPath::strokeBBox() const
87 {
88  QPainterPath outline = getPathStroke(*(path().platformPath()), this, style());
89  return outline.boundingRect();
90 }
91 
92 }
93 
QRectF boundingRect() const const
void setWidth(qreal width)
void append(const T &value)
qreal width() const const
QString pattern(Mode mode=Reading)
void setMiterLimit(qreal limit)
QPainterPath createStroke(const QPainterPath &path) const const
void setJoinStyle(Qt::PenJoinStyle style)
MiterJoin
void setCapStyle(Qt::PenCapStyle style)
void setDashPattern(Qt::PenStyle style)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.