KHTML
RenderPathQt.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "config.h"
00025 #include "RenderPath.h"
00026 #include "SVGRenderStyle.h"
00027 #include "SVGPaintServer.h"
00028
00029 #include <QDebug>
00030 #include <QPainterPathStroker>
00031
00032 namespace WebCore {
00033
00034 bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const
00035 {
00036 if (path().isEmpty())
00037 return false;
00038
00039 if (requiresStroke && !SVGPaintServer::strokePaintServer(style(), this))
00040 return false;
00041
00042 return false;
00043 }
00044
00045 static QPainterPath getPathStroke(const QPainterPath &path, const RenderObject* object, const RenderStyle* style)
00046 {
00047 QPainterPathStroker s;
00048 s.setWidth(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));
00049
00050 if (style->svgStyle()->capStyle() == ButtCap)
00051 s.setCapStyle(Qt::FlatCap);
00052 else if (style->svgStyle()->capStyle() == RoundCap)
00053 s.setCapStyle(Qt::RoundCap);
00054
00055 if (style->svgStyle()->joinStyle() == MiterJoin) {
00056 s.setJoinStyle(Qt::MiterJoin);
00057 s.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());
00058 } else if(style->svgStyle()->joinStyle() == RoundJoin)
00059 s.setJoinStyle(Qt::RoundJoin);
00060
00061 const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style);
00062 double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);
00063
00064 unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;
00065 if(dashLength) {
00066 QVector<qreal> pattern;
00067 unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
00068
00069 for(unsigned int i = 0; i < count; i++)
00070 pattern.append(dashes[i % dashLength] / (float)s.width());
00071
00072 s.setDashPattern(pattern);
00073
00074 Q_UNUSED(dashOffset);
00075
00076 }
00077
00078 return s.createStroke(path);
00079 }
00080
00081 FloatRect RenderPath::strokeBBox() const
00082 {
00083 QPainterPath outline = getPathStroke(*(path().platformPath()), this, style());
00084 return outline.boundingRect();
00085 }
00086
00087 }
00088
00089