#include "config.h"
#include "RenderPath.h"
#include "SVGRenderStyle.h"
#include "SVGPaintServer.h"
#include <QDebug>
#include <QPainterPathStroker>
namespace WebCore {
bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const
{
if (path().isEmpty())
return false;
if (requiresStroke && !SVGPaintServer::strokePaintServer(style(), this))
return false;
return false;
}
static QPainterPath getPathStroke(const QPainterPath &path, const RenderObject* object, const RenderStyle* style)
{
QPainterPathStroker s;
s.setWidth(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));
if (style->svgStyle()->capStyle() == ButtCap)
s.setCapStyle(Qt::FlatCap);
else if (style->svgStyle()->capStyle() == RoundCap)
s.setCapStyle(Qt::RoundCap);
if (style->svgStyle()->joinStyle() == MiterJoin) {
s.setJoinStyle(Qt::MiterJoin);
s.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());
} else if(style->svgStyle()->joinStyle() == RoundJoin)
s.setJoinStyle(Qt::RoundJoin);
const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style);
double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);
unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;
if(dashLength) {
QVector<qreal> pattern;
unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
for(unsigned int i = 0; i < count; i++)
pattern.append(dashes[i % dashLength] / (float)s.width());
s.setDashPattern(pattern);
Q_UNUSED(dashOffset);
}
return s.createStroke(path);
}
FloatRect RenderPath::strokeBBox() const
{
QPainterPath outline = getPathStroke(*(path().platformPath()), this, style());
return outline.boundingRect();
}
}