Commit cb6516b8 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix artifacts when rendering shapes with miter join set

1) Miter limit in Qt should be normalized by line width.
2) When transforming the insets we should just take maximum
   of insets, not bounding rect. Miters can extend into any
   direction, so not only +-45deg.
parent 0240a770
......@@ -563,11 +563,9 @@ QRectF KoPathShape::boundingRect() const
QPointF center = transform.map(QPointF());
QPointF tl = transform.map(QPointF(-inset.left,-inset.top)) - center;
QPointF br = transform.map(QPointF(inset.right,inset.bottom)) -center;
qreal left = qMin(tl.x(),br.x());
qreal right = qMax(tl.x(),br.x());
qreal top = qMin(tl.y(),br.y());
qreal bottom = qMax(tl.y(),br.y());
bb.adjust(left, top, right, bottom);
const qreal growOffset = std::max({tl.x(), tl.y(), br.x(), br.y()});
bb = kisGrowRect(bb, growOffset);
// TODO: take care about transformations!
// take care about markers!
......
......@@ -224,26 +224,25 @@ void KoShapeStroke::fillStyle(KoGenStyle &style, KoShapeSavingContext &context)
void KoShapeStroke::strokeInsets(const KoShape *shape, KoInsets &insets) const
{
Q_UNUSED(shape);
qreal lineWidth = d->pen.widthF();
if (lineWidth < 0) {
lineWidth = 1;
}
lineWidth *= 0.5; // since we draw a line half inside, and half outside the object.
// '0.5' --- since we draw a line half inside, and half outside the object.
qreal extent = 0.5 * (d->pen.widthF() >= 0 ? d->pen.widthF() : 1.0);
// if we have square cap, we need a little more space
// -> sqrt((0.5*penWidth)^2 + (0.5*penWidth)^2)
if (capStyle() == Qt::SquareCap) {
lineWidth *= M_SQRT2;
extent *= M_SQRT2;
}
if (joinStyle() == Qt::MiterJoin) {
lineWidth = qMax(lineWidth, miterLimit());
// miter limit in Qt is normalized by the line width (and not half-width)
extent = qMax(extent, d->pen.widthF() * miterLimit());
}
insets.top = lineWidth;
insets.bottom = lineWidth;
insets.left = lineWidth;
insets.right = lineWidth;
insets.top = extent;
insets.bottom = extent;
insets.left = extent;
insets.right = extent;
}
qreal KoShapeStroke::strokeMaxMarkersInset(const KoShape *shape) const
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment