[poppler] qt5/src qt5/tests
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Apr 16 21:17:11 UTC 2020
qt5/src/ArthurOutputDev.cc | 5 +-
qt5/tests/CMakeLists.txt | 1
qt5/tests/check_stroke_opacity.cpp | 73 +++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 2 deletions(-)
New commits:
commit 5ccc03f13b22c11d38f349b95c6d50dcfbaedb4b
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Wed Apr 15 15:40:38 2020 +0200
[arthur] Set the opacity when filling with axial gradients
diff --git a/qt5/src/ArthurOutputDev.cc b/qt5/src/ArthurOutputDev.cc
index 9469f82e..d535a8fa 100644
--- a/qt5/src/ArthurOutputDev.cc
+++ b/qt5/src/ArthurOutputDev.cc
@@ -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
diff --git a/qt5/tests/CMakeLists.txt b/qt5/tests/CMakeLists.txt
index 5abcbc45..b01d0835 100644
--- a/qt5/tests/CMakeLists.txt
+++ b/qt5/tests/CMakeLists.txt
@@ -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)
diff --git a/qt5/tests/check_stroke_opacity.cpp b/qt5/tests/check_stroke_opacity.cpp
new file mode 100644
index 00000000..e278c16e
--- /dev/null
+++ b/qt5/tests/check_stroke_opacity.cpp
@@ -0,0 +1,73 @@
+#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"
+
More information about the poppler
mailing list