[poppler] qt5/src qt5/tests qt6/src qt6/tests

2023-06-26 Thread GitLab Mirror
 qt5/src/poppler-page.cc   |8 
 qt5/tests/CMakeLists.txt  |1 +
 qt5/tests/check_overprint.cpp |   41 +
 qt6/src/poppler-page.cc   |8 
 qt6/tests/CMakeLists.txt  |1 +
 qt6/tests/check_overprint.cpp |   38 ++
 6 files changed, 89 insertions(+), 8 deletions(-)

New commits:
commit 6ebe45e8dceae11d02c74df47c34f4490a45a15e
Author: Kevin Ottens 
Date:   Wed Jun 21 15:10:48 2023 +0200

Don't crash when overprint preview is enabled with the Qt bindings

When overprint preview is enabled, the image data row size changes
during conversion to XBGR. The Qt bindings were assuming this row
size was constant which led to badly broken QImages at conversion
time (generating garbage if displayed or even crashing).

This commit simply add regression tests for the case and gets the
row size after bitmap conversion.

diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index b2cea93b..43c7d9fd 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -129,10 +129,6 @@ public:
 {
 SplashBitmap *b = getBitmap();
 
-const int bw = b->getWidth();
-const int bh = b->getHeight();
-const int brs = b->getRowSize();
-
 // If we use DeviceN8, convert to XBGR8.
 // If requested, also transfer Splash's internal alpha channel.
 const SplashBitmap::ConversionMode mode = ignorePaperColor ? 
SplashBitmap::conversionAlphaPremultiplied : SplashBitmap::conversionOpaque;
@@ -140,6 +136,10 @@ public:
 const QImage::Format format = ignorePaperColor ? 
QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
 
 if (b->convertToXBGR(mode)) {
+const int bw = b->getWidth();
+const int bh = b->getHeight();
+const int brs = b->getRowSize();
+
 SplashColorPtr data = takeImageData ? b->takeData() : 
b->getDataPtr();
 
 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
diff --git a/qt5/tests/CMakeLists.txt b/qt5/tests/CMakeLists.txt
index 9de870ee..e610413a 100644
--- a/qt5/tests/CMakeLists.txt
+++ b/qt5/tests/CMakeLists.txt
@@ -74,6 +74,7 @@ qt5_add_qtest(check_qt5_signature_basics 
check_signature_basics.cpp)
 qt5_add_qtest(check_qt5_utf8document check_utf8document.cpp)
 qt5_add_qtest(check_qt5_distinguished_name_parser 
check_distinguished_name_parser.cpp)
 qt5_add_qtest(check_qt5_cidfontswidthsbuilder check_cidfontswidthsbuilder.cpp)
+qt5_add_qtest(check_qt5_overprint check_overprint.cpp)
 if (NOT WIN32)
   qt5_add_qtest(check_qt5_pagelabelinfo check_pagelabelinfo.cpp)
   qt5_add_qtest(check_qt5_strings check_strings.cpp)
diff --git a/qt5/tests/check_overprint.cpp b/qt5/tests/check_overprint.cpp
new file mode 100644
index ..3035c652
--- /dev/null
+++ b/qt5/tests/check_overprint.cpp
@@ -0,0 +1,41 @@
+#include 
+
+#include 
+
+#include 
+
+class TestOverprint : public QObject
+{
+Q_OBJECT
+public:
+explicit TestOverprint(QObject *parent = nullptr) : QObject(parent) { }
+private slots:
+void checkOverprintImageRendering();
+};
+
+void TestOverprint::checkOverprintImageRendering()
+{
+Poppler::Document *doc = Poppler::Document::load(TESTDATADIR 
"/tests/mask-seams.pdf");
+QVERIFY(doc);
+
+doc->setRenderHint(Poppler::Document::OverprintPreview, true);
+
+Poppler::Page *page = doc->page(0);
+QVERIFY(page);
+
+constexpr int width = 600;
+constexpr int height = 400;
+
+QImage img = page->renderToImage(300.0, 300.0, 0, 0, width, height);
+QCOMPARE(img.format(), QImage::Format_RGB32);
+QCOMPARE(img.width(), width);
+QCOMPARE(img.height(), height);
+QCOMPARE(img.bytesPerLine(), width * 4);
+QCOMPARE(img.sizeInBytes(), width * height * 4);
+
+delete page;
+delete doc;
+}
+
+QTEST_GUILESS_MAIN(TestOverprint)
+#include "check_overprint.moc"
diff --git a/qt6/src/poppler-page.cc b/qt6/src/poppler-page.cc
index dd1cb0e5..40062e81 100644
--- a/qt6/src/poppler-page.cc
+++ b/qt6/src/poppler-page.cc
@@ -128,10 +128,6 @@ public:
 {
 SplashBitmap *b = getBitmap();
 
-const int bw = b->getWidth();
-const int bh = b->getHeight();
-const int brs = b->getRowSize();
-
 // If we use DeviceN8, convert to XBGR8.
 // If requested, also transfer Splash's internal alpha channel.
 const SplashBitmap::ConversionMode mode = ignorePaperColor ? 
SplashBitmap::conversionAlphaPremultiplied : SplashBitmap::conversionOpaque;
@@ -139,6 +135,10 @@ public:
 const QImage::Format format = ignorePaperColor ? 
QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
 
 if (b->convertToXBGR(mode)) {
+const int bw = b->getWidth();
+const int bh = b->getHeight();
+const int brs = b->getRowSize();
+
 SplashColorPtr data = takeImageData ? b->takeData() : 
b->getDataPtr();
 
 

[poppler] qt5/src qt5/tests qt6/src qt6/tests

2021-07-14 Thread GitLab Mirror
 qt5/src/poppler-document.cc  |5 +
 qt5/src/poppler-qt5.h|   20 +++-
 qt5/tests/check_metadata.cpp |7 +++
 qt5/tests/stress-poppler-dir.cpp |7 +--
 qt5/tests/stress-poppler-qt5.cpp |4 ++--
 qt5/tests/test-password-qt5.cpp  |5 ++---
 qt5/tests/test-poppler-qt5.cpp   |5 ++---
 qt6/src/poppler-document.cc  |7 ++-
 qt6/src/poppler-qt6.h|   14 +-
 qt6/tests/check_metadata.cpp |7 +++
 qt6/tests/stress-poppler-dir.cpp |4 ++--
 qt6/tests/stress-poppler-qt6.cpp |4 ++--
 qt6/tests/test-password-qt6.cpp  |5 ++---
 qt6/tests/test-poppler-qt6.cpp   |5 ++---
 14 files changed, 60 insertions(+), 39 deletions(-)

New commits:
commit 13c95f251bf47068a3c083bf038cab86fea7f570
Author: Oliver Sander 
Date:   Fri Jul 9 11:55:24 2021 +0200

Make getPdfVersion return a dedicated version object

That's a bit more modern than the old way where pointers to two
integers had to be passed to the method.

With the new method you can write

  auto pdfVersion = doc->getPdfVersion();
  // access numbers as pdfVersion.major and pdfVersion.minor

instead of

  int major, minor;
  doc->getPdfVersion(, );

With C++17 you can even write

  auto [major, minor] = doc->getPdfVersion();

The new method is put alongside the old one in the Qt5 interface.
It replaces the old one in the Qt6 interface.

diff --git a/qt5/src/poppler-document.cc b/qt5/src/poppler-document.cc
index 6118ccdd..25835f35 100644
--- a/qt5/src/poppler-document.cc
+++ b/qt5/src/poppler-document.cc
@@ -556,6 +556,11 @@ void Document::getPdfVersion(int *major, int *minor) const
 *minor = m_doc->doc->getPDFMinorVersion();
 }
 
+Document::PdfVersion Document::getPdfVersion() const
+{
+return PdfVersion { m_doc->doc->getPDFMajorVersion(), 
m_doc->doc->getPDFMinorVersion() };
+}
+
 Page *Document::page(const QString ) const
 {
 GooString label_g(label.toLatin1().data());
diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h
index d6dbd461..dacda011 100644
--- a/qt5/src/poppler-qt5.h
+++ b/qt5/src/poppler-qt5.h
@@ -1648,9 +1648,27 @@ QString subject = m_doc->info("Subject");
\param minor an optional pointer to a variable where store the
"minor" number of the version
 
+   \deprecated Will be removed in the Qt6 interface.  Use the method
+   returning a PdfVersion object instead!
+
\since 0.12
 */
-void getPdfVersion(int *major, int *minor) const;
+Q_DECL_DEPRECATED void getPdfVersion(int *major, int *minor) const;
+
+/** \brief The version specification of a pdf file */
+struct PdfVersion
+{
+int major;
+int minor;
+};
+
+/**
+   The version of the PDF specification that the document
+   conforms to
+
+   \since 21.08
+*/
+PdfVersion getPdfVersion() const;
 
 /**
The fonts within the PDF document.
diff --git a/qt5/tests/check_metadata.cpp b/qt5/tests/check_metadata.cpp
index 6167d9c3..90ebba04 100644
--- a/qt5/tests/check_metadata.cpp
+++ b/qt5/tests/check_metadata.cpp
@@ -226,10 +226,9 @@ void TestMetaData::checkVersion()
 doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
 QVERIFY(doc);
 
-int major = 0, minor = 0;
-doc->getPdfVersion(, );
-QCOMPARE(major, 1);
-QCOMPARE(minor, 6);
+auto pdfVersion = doc->getPdfVersion();
+QCOMPARE(pdfVersion.major, 1);
+QCOMPARE(pdfVersion.minor, 6);
 
 delete doc;
 }
diff --git a/qt5/tests/stress-poppler-dir.cpp b/qt5/tests/stress-poppler-dir.cpp
index 6db57129..8cac185b 100644
--- a/qt5/tests/stress-poppler-dir.cpp
+++ b/qt5/tests/stress-poppler-dir.cpp
@@ -28,8 +28,11 @@ int main(int argc, char **argv)
 delete doc;
 }
 } else {
-int major = 0, minor = 0;
-doc->getPdfVersion(, );
+auto pdfVersion = doc->getPdfVersion();
+if (pdfVersion.major != 1) {
+qWarning() << "pdf major version is not '1'";
+}
+
 doc->info(QStringLiteral("Title"));
 doc->info(QStringLiteral("Subject"));
 doc->info(QStringLiteral("Author"));
diff --git a/qt5/tests/stress-poppler-qt5.cpp b/qt5/tests/stress-poppler-qt5.cpp
index 07f8cdf2..31795f96 100644
--- a/qt5/tests/stress-poppler-qt5.cpp
+++ b/qt5/tests/stress-poppler-qt5.cpp
@@ -36,8 +36,8 @@ int main(int argc, char **argv)
 if (!doc) {
 qWarning() << "doc not loaded";
 } else {
-int major = 0, minor = 0;
-doc->getPdfVersion(, );
+auto pdfVersion = doc->getPdfVersion();
+Q_UNUSED(pdfVersion);
 doc->info(QStringLiteral("Title"));
 doc->info(QStringLiteral("Subject"));
 

[poppler] qt5/src qt5/tests qt6/src qt6/tests

2021-04-14 Thread GitLab Mirror
 qt5/src/poppler-private.cc  |4 
 qt5/tests/check_strings.cpp |   12 +---
 qt6/src/poppler-private.cc  |4 
 qt6/tests/check_strings.cpp |   12 +---
 4 files changed, 26 insertions(+), 6 deletions(-)

New commits:
commit b770a55a47278f4104fc410034577cc4ea0434a6
Author: Albert Astals Cid 
Date:   Tue Apr 13 17:59:34 2021 +0200

qt: QStringToUnicodeGooString don't produce a "fake empty" string

if the input string is empty, just return an empty GooString, not a
GooString with only the unicode marker

diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc
index 5b30f19c..695b9b8c 100644
--- a/qt5/src/poppler-private.cc
+++ b/qt5/src/poppler-private.cc
@@ -9,6 +9,7 @@
  * Copyright (C) 2018-2020 Adam Reichold 
  * Copyright (C) 2019, 2020 Oliver Sander 
  * Copyright (C) 2019 João Netto 
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, 

  * Inspired on code by
  * Copyright (C) 2004 by Albert Astals Cid 
  * Copyright (C) 2004 by Enrico Ros 
@@ -115,6 +116,9 @@ QString UnicodeParsedString(const std::string )
 
 GooString *QStringToUnicodeGooString(const QString )
 {
+if (s.isEmpty()) {
+return new GooString();
+}
 int len = s.length() * 2 + 2;
 char *cstring = (char *)gmallocn(len, sizeof(char));
 cstring[0] = (char)0xfe;
diff --git a/qt5/tests/check_strings.cpp b/qt5/tests/check_strings.cpp
index 4c996c4f..14d22740 100644
--- a/qt5/tests/check_strings.cpp
+++ b/qt5/tests/check_strings.cpp
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010, 2011, Pino Toscano 
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, 

  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -189,9 +190,14 @@ void TestStrings::check_QStringToUnicodeGooString()
 QFETCH(QByteArray, result);
 
 GooString *goo = Poppler::QStringToUnicodeGooString(string);
-QVERIFY(goo->hasUnicodeMarker());
-QCOMPARE(goo->getLength(), string.length() * 2 + 2);
-QCOMPARE(result, QByteArray::fromRawData(goo->c_str() + 2, 
goo->getLength() - 2));
+if (string.isEmpty()) {
+QVERIFY(goo->toStr().empty());
+QCOMPARE(goo->getLength(), 0);
+} else {
+QVERIFY(goo->hasUnicodeMarker());
+QCOMPARE(goo->getLength(), string.length() * 2 + 2);
+QCOMPARE(result, QByteArray::fromRawData(goo->c_str() + 2, 
goo->getLength() - 2));
+}
 
 delete goo;
 }
diff --git a/qt6/src/poppler-private.cc b/qt6/src/poppler-private.cc
index c60876da..a2971adc 100644
--- a/qt6/src/poppler-private.cc
+++ b/qt6/src/poppler-private.cc
@@ -9,6 +9,7 @@
  * Copyright (C) 2018-2020 Adam Reichold 
  * Copyright (C) 2019, 2020 Oliver Sander 
  * Copyright (C) 2019 João Netto 
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, 

  * Inspired on code by
  * Copyright (C) 2004 by Albert Astals Cid 
  * Copyright (C) 2004 by Enrico Ros 
@@ -115,6 +116,9 @@ QString UnicodeParsedString(const std::string )
 
 GooString *QStringToUnicodeGooString(const QString )
 {
+if (s.isEmpty()) {
+return new GooString();
+}
 int len = s.length() * 2 + 2;
 char *cstring = (char *)gmallocn(len, sizeof(char));
 cstring[0] = (char)0xfe;
diff --git a/qt6/tests/check_strings.cpp b/qt6/tests/check_strings.cpp
index c887105c..fdd2f703 100644
--- a/qt6/tests/check_strings.cpp
+++ b/qt6/tests/check_strings.cpp
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010, 2011, Pino Toscano 
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, 

  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -189,9 +190,14 @@ void TestStrings::check_QStringToUnicodeGooString()
 QFETCH(QByteArray, result);
 
 GooString *goo = Poppler::QStringToUnicodeGooString(string);
-QVERIFY(goo->hasUnicodeMarker());
-QCOMPARE(goo->getLength(), string.length() * 2 + 2);
-QCOMPARE(result, QByteArray::fromRawData(goo->c_str() + 2, 
goo->getLength() - 2));
+if (string.isEmpty()) {
+QVERIFY(goo->toStr().empty());
+QCOMPARE(goo->getLength(), 0);
+} else {
+QVERIFY(goo->hasUnicodeMarker());
+QCOMPARE(goo->getLength(), string.length() * 2 + 2);
+QCOMPARE(result, QByteArray::fromRawData(goo->c_str() + 2, 
goo->getLength() - 2));
+}
 
 delete goo;
 }
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


[poppler] qt5/src qt5/tests qt6/src qt6/tests

2020-08-25 Thread GitLab Mirror
 qt5/src/poppler-private.cc  |4 ++--
 qt5/tests/check_strings.cpp |9 +
 qt6/src/poppler-private.cc  |4 ++--
 qt6/tests/check_strings.cpp |9 +
 4 files changed, 22 insertions(+), 4 deletions(-)

New commits:
commit 2b8692a5a52a8cd997e70f7912ad7cedeb34891b
Author: Albert Astals Cid 
Date:   Tue Aug 25 23:05:51 2020 +0200

qt: Clean as many null characters from the end as possible

Not only one

Fixes KDE bug #425791

diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc
index 827a6345..84cc8c56 100644
--- a/qt5/src/poppler-private.cc
+++ b/qt5/src/poppler-private.cc
@@ -77,8 +77,8 @@ QString unicodeToQString(const Unicode *u, int len)
 {
 const UnicodeMap *utf8Map = globalParams->getUtf8Map();
 
-// ignore the last character if it is 0x0
-if ((len > 0) && (u[len - 1] == 0)) {
+// ignore the last characters if they are 0x0
+while ((len > 0) && (u[len - 1] == 0)) {
 --len;
 }
 
diff --git a/qt5/tests/check_strings.cpp b/qt5/tests/check_strings.cpp
index 948171f6..4c996c4f 100644
--- a/qt5/tests/check_strings.cpp
+++ b/qt5/tests/check_strings.cpp
@@ -114,6 +114,15 @@ void TestStrings::check_unicodeToQString_data()
 u[2] = 0x0;
 QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + 0") << u << l << 
QStringLiteral("封面");
 }
+{
+const int l = 4;
+Unicode *u = new Unicode[l];
+u[0] = 0x5c01;
+u[1] = 0x9762;
+u[2] = 0x0;
+u[3] = 0x0;
+QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + two 0") << u << l << 
QStringLiteral("封面");
+}
 }
 
 void TestStrings::check_unicodeToQString()
diff --git a/qt6/src/poppler-private.cc b/qt6/src/poppler-private.cc
index 44a9a6dc..e7566500 100644
--- a/qt6/src/poppler-private.cc
+++ b/qt6/src/poppler-private.cc
@@ -77,8 +77,8 @@ QString unicodeToQString(const Unicode *u, int len)
 {
 const UnicodeMap *utf8Map = globalParams->getUtf8Map();
 
-// ignore the last character if it is 0x0
-if ((len > 0) && (u[len - 1] == 0)) {
+// ignore the last characters if they are 0x0
+while ((len > 0) && (u[len - 1] == 0)) {
 --len;
 }
 
diff --git a/qt6/tests/check_strings.cpp b/qt6/tests/check_strings.cpp
index fa7c6bab..c887105c 100644
--- a/qt6/tests/check_strings.cpp
+++ b/qt6/tests/check_strings.cpp
@@ -114,6 +114,15 @@ void TestStrings::check_unicodeToQString_data()
 u[2] = 0x0;
 QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + 0") << u << l << 
QStringLiteral("封面");
 }
+{
+const int l = 4;
+Unicode *u = new Unicode[l];
+u[0] = 0x5c01;
+u[1] = 0x9762;
+u[2] = 0x0;
+u[3] = 0x0;
+QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + two 0") << u << l << 
QStringLiteral("封面");
+}
 }
 
 void TestStrings::check_unicodeToQString()
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


[poppler] qt5/src qt5/tests

2020-04-16 Thread GitLab Mirror
 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 
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 = [,](const GfxColor , const 
GfxColor )
@@ -807,7 +808,7 @@ bool ArthurOutputDev::axialShadedFill(GfxState *state, 
GfxAxialShading *shading,
 
   GfxRGB rgb;
   shading->getColorSpace()->getRGB(, );
-  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(, );
-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 ..e278c16e
--- /dev/null
+++ b/qt5/tests/check_stroke_opacity.cpp
@@ -0,0 +1,73 @@
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+
+// 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("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::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(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 = [](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"
+
___
poppler mailing list

[poppler] qt5/src qt5/tests

2020-01-05 Thread GitLab Mirror
 qt5/src/poppler-form.cc   |2 +-
 qt5/tests/check_forms.cpp |   18 ++
 2 files changed, 19 insertions(+), 1 deletion(-)

New commits:
commit dd0ea681efc1e0a476803be1260f7a7691c26534
Author: David García Garzón 
Date:   Sun Jan 5 23:35:51 2020 +

qt5: Fix FormField::name encoding

Also add a test for it

diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc
index 26b583ba..cab25af6 100644
--- a/qt5/src/poppler-form.cc
+++ b/qt5/src/poppler-form.cc
@@ -147,7 +147,7 @@ QString FormField::name() const
   QString name;
   if (const GooString *goo = m_formData->fm->getPartialName())
   {
-name = QString::fromLatin1(goo->c_str());
+name = UnicodeParsedString(goo);
   }
   return name;
 }
diff --git a/qt5/tests/check_forms.cpp b/qt5/tests/check_forms.cpp
index ac60fdc4..fb7c3baf 100644
--- a/qt5/tests/check_forms.cpp
+++ b/qt5/tests/check_forms.cpp
@@ -16,6 +16,7 @@ private slots:
 void testSetIcon();// Test that setIcon will always be valid.
 void testSetPrintable();
 void testSetAppearanceText();
+void testUnicodeFieldAttributes();
 };
 
 void TestForms::testCheckbox()
@@ -208,5 +209,22 @@ void TestForms::testSetAppearanceText()
 QCOMPARE( nTextForms, 5 );
 }
 
+void TestForms::testUnicodeFieldAttributes()
+{
+QScopedPointer< Poppler::Document > 
document(Poppler::Document::load(TESTDATADIR 
"/unittestcases/fieldWithUtf16Names.pdf"));
+QVERIFY( document );
+
+QScopedPointer< Poppler::Page > page(document->page(0));
+QVERIFY( page );
+
+QList forms = page->formFields();
+
+   Poppler::FormField * field = forms.first();
+
+   QCOMPARE(field->name(), QStringLiteral("Tex"));
+   QCOMPARE(field->uiName(), QStringLiteral("Texto de ayuda"));
+}
+
+
 QTEST_GUILESS_MAIN(TestForms)
 #include "check_forms.moc"
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


[poppler] qt5/src qt5/tests

2019-07-09 Thread GitLab Mirror
 qt5/src/poppler-form.cc   |   16 
 qt5/src/poppler-form.h|   12 
 qt5/tests/check_forms.cpp |   20 
 3 files changed, 48 insertions(+)

New commits:
commit 04e8309d18fa2f90ed93930e7eb689e523c7eb44
Author: João Netto 
Date:   Mon Jul 8 20:43:19 2019 -0300

Added option to set the form available to print

diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc
index fa9c3312..111d5b09 100644
--- a/qt5/src/poppler-form.cc
+++ b/qt5/src/poppler-form.cc
@@ -207,6 +207,22 @@ void FormField::setVisible(bool value)
   m_formData->fm->getWidgetAnnotation()->setFlags(flags);
 }
 
+bool FormField::isPrintable() const
+{
+  return (m_formData->fm->getWidgetAnnotation()->getFlags() & 
Annot::flagPrint);
+}
+
+void FormField::setPrintable(bool value)
+{
+  unsigned int flags = m_formData->fm->getWidgetAnnotation()->getFlags();
+  if (value) {
+flags |= Annot::flagPrint;
+  } else {
+flags &= ~Annot::flagPrint;
+  }
+  m_formData->fm->getWidgetAnnotation()->setFlags(flags);
+}
+
 Link* FormField::activationAction() const
 {
   Link* action = nullptr;
diff --git a/qt5/src/poppler-form.h b/qt5/src/poppler-form.h
index f4c64589..ac00da26 100644
--- a/qt5/src/poppler-form.h
+++ b/qt5/src/poppler-form.h
@@ -155,6 +155,18 @@ namespace Poppler {
void setVisible(bool value);
 
/**
+ Whether this field is printable.
+ \since 0.79
+*/ 
+   bool isPrintable() const;
+
+   /**
+ Set whether this field is printable.
+ \since 0.79
+*/
+   void setPrintable(bool value);
+
+   /**
  The activation action of this form field.
 
  \note It may be null.
diff --git a/qt5/tests/check_forms.cpp b/qt5/tests/check_forms.cpp
index ec48ce91..f139ed1f 100644
--- a/qt5/tests/check_forms.cpp
+++ b/qt5/tests/check_forms.cpp
@@ -14,6 +14,7 @@ private slots:
 void testCheckbox();// Test for issue #655
 void testCheckboxIssue159();// Test for issue #159
 void testSetIcon();// Test that setIcon will always be valid.
+void testSetPrintable();
 };
 
 void TestForms::testCheckbox()
@@ -148,5 +149,24 @@ void TestForms::testSetIcon()
 QVERIFY( Poppler::FormFieldIconData::getData( anmIcon )->icon );
 }
 
+void TestForms::testSetPrintable()
+{
+QScopedPointer< Poppler::Document > 
document(Poppler::Document::load(TESTDATADIR 
"/unittestcases/form_set_icon.pdf"));
+QVERIFY( document );
+
+QScopedPointer< Poppler::Page > page(document->page(0));
+QVERIFY( page );
+
+QList forms = page->formFields();
+
+Q_FOREACH (Poppler::FormField *field, forms) {
+field->setPrintable( true );
+QCOMPARE( field->isPrintable(), true );
+
+field->setPrintable( false );
+QCOMPARE( field->isPrintable(), false );
+}
+}
+
 QTEST_GUILESS_MAIN(TestForms)
 #include "check_forms.moc"
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler

[poppler] qt5/src qt5/tests

2019-04-28 Thread GitLab Mirror
 qt5/src/poppler-annotation.cc   |2 +-
 qt5/tests/check_annotations.cpp |   18 ++
 2 files changed, 19 insertions(+), 1 deletion(-)

New commits:
commit 0d0630cd6f10d0586172b740290056620fe56b21
Author: Albert Astals Cid 
Date:   Sun Apr 28 19:25:08 2019 +0200

qt5: Fix regression in annotation handling

diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc
index 207d6ca4..c2798408 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -412,7 +412,7 @@ QList 
AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD
 if (!markupann)
 {
 // Assume it's a root annotation, and skip if user didn't request 
it
-if (parentID != 0)
+if (parentID != -1)
 continue;
 }
 else if (markupann->getInReplyToID() != parentID)
diff --git a/qt5/tests/check_annotations.cpp b/qt5/tests/check_annotations.cpp
index 1145ceec..20b33f21 100644
--- a/qt5/tests/check_annotations.cpp
+++ b/qt5/tests/check_annotations.cpp
@@ -20,6 +20,7 @@ private slots:
   void checkFontSizeAndColor();
   void checkHighlightFromAndToQuads();
   void checkUTF16LEAnnot();
+  void checkNonMarkupAnnotations();
 };
 
 /* Is .5f sufficient for 16 bit color channel roundtrip trough save and load 
on all architectures? */
@@ -155,6 +156,23 @@ void TestAnnotations::checkUTF16LEAnnot()
 QCOMPARE(annot->contents(), QString::fromUtf8("Únîcödé豰")); 
//clazy:exclude=qstring-allocations
 }
 
+void TestAnnotations::checkNonMarkupAnnotations()
+{
+std::unique_ptr doc{
+  Poppler::Document::load(TESTDATADIR 
"/unittestcases/checkbox_issue_159.pdf")
+};
+QVERIFY(doc.get());
+
+std::unique_ptr page{
+  doc->page(0)
+};
+QVERIFY(page.get());
+
+auto annots = page->annotations();
+QCOMPARE(annots.size(), 17);
+}
+
+
 QTEST_GUILESS_MAIN(TestAnnotations)
 
 #include "check_annotations.moc"
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler

[poppler] qt5/src qt5/tests

2019-03-28 Thread GitLab Mirror
 qt5/src/poppler-private.cc  |   15 ---
 qt5/tests/check_strings.cpp |2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)

New commits:
commit 623d073030259042921d34034cdcf701dae7c96b
Author: Albert Astals Cid 
Date:   Thu Mar 28 12:47:22 2019 +0100

qt: UnicodeParsedString support UTF16-LE strings

They are not part of the standard but Adobe seems to support them and
there's files out there like that so better to support them than not

diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc
index 5f673973..b284a744 100644
--- a/qt5/src/poppler-private.cc
+++ b/qt5/src/poppler-private.cc
@@ -1,6 +1,6 @@
 /* poppler-private.cc: qt interface to poppler
  * Copyright (C) 2005, Net Integration Technologies, Inc.
- * Copyright (C) 2006, 2011, 2015, 2017, 2018 by Albert Astals Cid 

+ * Copyright (C) 2006, 2011, 2015, 2017-2019 by Albert Astals Cid 

  * Copyright (C) 2008, 2010, 2011, 2014 by Pino Toscano 
  * Copyright (C) 2013 by Thomas Freitag 
  * Copyright (C) 2013 Adrian Johnson 
@@ -108,12 +108,20 @@ namespace Debug {
 const char *cString;
 int stringLength;
 bool deleteCString;
-if ( ( s1->getChar(0) & 0xff ) == 0xfe && ( s1->getLength() > 1 && ( 
s1->getChar(1) & 0xff ) == 0xff ) )
+bool isLE = false;
+if ( s1->hasUnicodeMarker() )
 {
 cString = s1->c_str();
 stringLength = s1->getLength();
 deleteCString = false;
 }
+else if ( s1->hasUnicodeMarkerLE() )
+{
+isLE = true;
+cString = s1->c_str();
+stringLength = s1->getLength();
+deleteCString = false;
+}
 else
 {
 cString = pdfDocEncodingToUTF16(s1, );
@@ -124,7 +132,8 @@ namespace Debug {
 // i = 2 to skip the unicode marker
 for ( int i = 2; i < stringLength; i += 2 )
 {
-const Unicode u = ( ( cString[i] & 0xff ) << 8 ) | ( cString[i+1] 
& 0xff );
+const Unicode u = isLE ? ( ( cString[i+1] & 0xff ) << 8 ) | ( 
cString[i] & 0xff )
+   : ( ( cString[i] & 0xff ) << 8 ) | ( 
cString[i+1] & 0xff );
 result += QChar( u );
 }
 if (deleteCString)
diff --git a/qt5/tests/check_strings.cpp b/qt5/tests/check_strings.cpp
index 583617aa..e7b3f990 100644
--- a/qt5/tests/check_strings.cpp
+++ b/qt5/tests/check_strings.cpp
@@ -163,6 +163,8 @@ void TestStrings::check_UnicodeParsedString_data()
 << QStringLiteral("ša");
 QTest::newRow("test string") << newGooString("\xFE\xFF\0t\0e\0s\0t\0 
\0s\0t\0r\0i\0n\0g", 24)
  << QStringLiteral("test string");
+QTest::newRow("UTF16-LE") << 
newGooString("\xFF\xFE\xDA\x00\x6E\x00\xEE\x00\x63\x00\xF6\x00\x64\x00\xE9\x00\x51\x75",
 18)
+ << QStringLiteral("Únîcödé畑");
 }
 
 void TestStrings::check_UnicodeParsedString()
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler