Commit 87755870 authored by Oliver Sander's avatar Oliver Sander

[arthur] Implement the clipToStrokePath method

parent 6c824224
......@@ -882,6 +882,24 @@ void ArthurOutputDev::eoClip(GfxState *state)
m_painter.top()->setClipPath(convertPath( state, state->getPath(), Qt::OddEvenFill ), Qt::IntersectClip );
}
void ArthurOutputDev::clipToStrokePath(GfxState *state)
{
QPainterPath clipPath = convertPath( state, state->getPath(), Qt::WindingFill );
// Get the outline of 'clipPath' as a separate path
QPainterPathStroker stroker;
stroker.setWidth( state->getLineWidth() );
stroker.setCapStyle( m_currentPen.capStyle() );
stroker.setJoinStyle( m_currentPen.joinStyle() );
stroker.setMiterLimit( state->getMiterLimit() );
stroker.setDashPattern( m_currentPen.dashPattern() );
stroker.setDashOffset( m_currentPen.dashOffset() );
QPainterPath clipPathOutline = stroker.createStroke ( clipPath );
// The interior of the outline is the desired clipping region
m_painter.top()->setClipPath(clipPathOutline, Qt::IntersectClip );
}
void ArthurOutputDev::drawChar(GfxState *state, double x, double y,
double dx, double dy,
double originX, double originY,
......
......@@ -125,6 +125,7 @@ public:
//----- path clipping
void clip(GfxState *state) override;
void eoClip(GfxState *state) override;
void clipToStrokePath(GfxState *state) override;
//----- text drawing
// virtual void drawString(GfxState *state, GooString *s);
......
......@@ -47,16 +47,14 @@ void TestStrokeOpacity::checkStrokeOpacity()
// The actual tests start here
// Splash and QPainter backends implement shadings slightly differently,
// hence we cannot expect to get precisely the same colors.
// Allow a tolerance up to '3' per channel.
int tolerance = 3;
// Allow a tolerance.
int tolerance;
auto approximatelyEqual = [&tolerance](QRgb c0, const QColor& c1)
{
return std::abs(qAlpha(c0) - c1.alpha() ) < tolerance
&& std::abs(qRed(c0) - c1.red() ) < tolerance
&& std::abs(qGreen(c0) - c1.green() ) < tolerance
&& std::abs(qBlue(c0) - c1.blue() ) < tolerance;
return std::abs(qAlpha(c0) - c1.alpha() ) <= tolerance
&& std::abs(qRed(c0) - c1.red() ) <= tolerance
&& std::abs(qGreen(c0) - c1.green() ) <= tolerance
&& std::abs(qBlue(c0) - c1.blue() ) <= tolerance;
};
// At the lower left of the test document is a square with an axial shading,
......@@ -64,7 +62,19 @@ void TestStrokeOpacity::checkStrokeOpacity()
// Check that with a sample pixel
auto pixel = image.pixel(70,160);
// Splash and QPainter backends implement shadings slightly differently,
// hence we cannot expect to get precisely the same colors.
tolerance = 2;
QVERIFY(approximatelyEqual(pixel, QColor(253,233,196,255)));
// At the upper left of the test document is a stroked square with an axial shading.
// This is implemented by filling a clip region defined by a stroke outline.
// Check whether the backend really only renders the stroke, not the region
// surrounded by the stroke.
auto pixelUpperLeftInterior = image.pixel(70,70);
tolerance = 0;
QVERIFY(approximatelyEqual(pixelUpperLeftInterior, Qt::white));
}
QTEST_GUILESS_MAIN(TestStrokeOpacity)
......
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