Commit 5ccc03f1 authored by Oliver Sander's avatar Oliver Sander

[arthur] Set the opacity when filling with axial gradients

parent 9cf9356d
......@@ -767,6 +767,7 @@ bool ArthurOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading,
// Number of color space components
auto nComps = shading->getColorSpace()->getNComps();
auto opacity = state->getFillOpacity();
// Helper function to test two color objects for 'almost-equality'
auto isSameGfxColor = [&nComps,&colorDelta](const GfxColor &colorA, const GfxColor &colorB)
......@@ -807,7 +808,7 @@ bool ArthurOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading,
GfxRGB rgb;
shading->getColorSpace()->getRGB(&color0, &rgb);
QColor qColor(colToByte(rgb.r), colToByte(rgb.g), colToByte(rgb.b));
QColor qColor(colToByte(rgb.r), colToByte(rgb.g), colToByte(rgb.b), dblToByte(opacity));
gradient.setColorAt(0,qColor);
// Look for more relevant parameter values by bisection
......@@ -847,7 +848,7 @@ bool ArthurOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading,
// set the color
shading->getColorSpace()->getRGB(&color1, &rgb);
qColor.setRgb(colToByte(rgb.r), colToByte(rgb.g), colToByte(rgb.b));
qColor.setRgb(colToByte(rgb.r), colToByte(rgb.g), colToByte(rgb.b), dblToByte(opacity));
gradient.setColorAt((ta[j] - tMin)/(tMax - tMin), qColor);
// Move to the next parameter region
......
......@@ -72,6 +72,7 @@ qt5_add_qtest(check_qt5_actualtext check_actualtext.cpp)
qt5_add_qtest(check_qt5_lexer check_lexer.cpp)
qt5_add_qtest(check_qt5_goostring check_goostring.cpp)
qt5_add_qtest(check_qt5_object check_object.cpp)
qt5_add_qtest(check_qt5_stroke_opacity check_stroke_opacity.cpp)
qt5_add_qtest(check_qt5_utf_conversion check_utf_conversion.cpp)
qt5_add_qtest(check_qt5_outline check_outline.cpp)
if (NOT WIN32)
......
#include <memory>
#include <QtTest/QtTest>
#include <QtCore/QDebug>
#include <QImage>
#include <poppler-qt5.h>
// Unit tests for rendering axial shadings without full opacity
class TestStrokeOpacity : public QObject
{
Q_OBJECT
public:
TestStrokeOpacity(QObject *parent = nullptr) : QObject(parent) { }
private slots:
void checkStrokeOpacity_data();
void checkStrokeOpacity();
};
void TestStrokeOpacity::checkStrokeOpacity_data()
{
QTest::addColumn<int>("backendType");
QTest::newRow("splash") << (int)Poppler::Document::SplashBackend;
QTest::newRow("qpainter") << (int)Poppler::Document::ArthurBackend;
}
void TestStrokeOpacity::checkStrokeOpacity()
{
QFETCH(int, backendType);
auto doc = std::unique_ptr<Poppler::Document>(Poppler::Document::load(TESTDATADIR "/unittestcases/stroke-alpha-pattern.pdf"));
QVERIFY(doc!=nullptr);
doc->setRenderBackend((Poppler::Document::RenderBackend)backendType);
// BUG: For some reason splash gets the opacity wrong when antialiasing is switched off
if (backendType== (int)Poppler::Document::SplashBackend) {
doc->setRenderHint(Poppler::Document::Antialiasing, true);
}
const auto page = std::unique_ptr<Poppler::Page>(doc->page(0));
QVERIFY(page!=nullptr);
// Render (at low resolution and with cropped marging)
QImage image = page->renderToImage(36,36,40,50,200,230);
// 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;
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;
};
// At the lower left of the test document is a square with an axial shading,
// which should be rendered with opacity 0.25.
// Check that with a sample pixel
auto pixel = image.pixel(70,160);
QVERIFY(approximatelyEqual(pixel, QColor(253,233,196,255)));
}
QTEST_GUILESS_MAIN(TestStrokeOpacity)
#include "check_stroke_opacity.moc"
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