[Libreoffice-commits] core.git: include/vcl vcl/qa vcl/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Dec 18 08:09:04 UTC 2020


 include/vcl/filter/PDFiumLibrary.hxx   |    2 ++
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   22 +++++-----------------
 vcl/source/pdf/PDFiumLibrary.cxx       |    9 +++++++++
 3 files changed, 16 insertions(+), 17 deletions(-)

New commits:
commit e987a050260ad4c8f6c3487e57bec1c8b680c65e
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Dec 17 21:07:41 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Dec 18 09:08:19 2020 +0100

    pdfium: add PDFiumPage::hasLinks() wrapper
    
    Reduces the amount of raw pdfium includes in CppunitTest_vcl_pdfexport.
    
    Change-Id: I61bcc7ef11932cc5129be8123dba0e8b06e8f324
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107925
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index cc6d65c15362..5dc8ea46fede 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -220,6 +220,8 @@ public:
     double getHeight();
 
     bool hasTransparency();
+
+    bool hasLinks();
 };
 
 /// Represents one digital signature, as exposed by PDFium.
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 69b7d17711a2..61debc5ed5ec 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -35,9 +35,6 @@
 #include <unotools/tempfile.hxx>
 #include <vcl/filter/pdfdocument.hxx>
 #include <tools/zcodec.hxx>
-#include <fpdf_edit.h>
-#include <fpdf_text.h>
-#include <fpdf_doc.h>
 #include <fpdf_annot.h>
 #include <fpdfview.h>
 #include <vcl/graphicfilter.hxx>
@@ -1803,11 +1800,9 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTocLink)
     CPPUNIT_ASSERT(pPdfPage);
 
     // Ensure there is a link on the first page (in the ToC).
-    int nStartPos = 0;
-    FPDF_LINK pLinkAnnot = nullptr;
-    // Without the accompanying fix in place, this test would have failed, as FPDFLink_Enumerate()
-    // returned false, as the page contained no links.
-    CPPUNIT_ASSERT(FPDFLink_Enumerate(pPdfPage->getPointer(), &nStartPos, &pLinkAnnot));
+    // Without the accompanying fix in place, this test would have failed, as the page contained no
+    // links.
+    CPPUNIT_ASSERT(pPdfPage->hasLinks());
 }
 
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testReduceSmallImage)
@@ -1904,13 +1899,6 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testReduceImage)
     CPPUNIT_ASSERT_EQUAL(160, nHeight);
 }
 
-bool HasLinksOnPage(std::unique_ptr<vcl::pdf::PDFiumPage>& pPdfPage)
-{
-    int nStartPos = 0;
-    FPDF_LINK pLinkAnnot = nullptr;
-    return FPDFLink_Enumerate(pPdfPage->getPointer(), &nStartPos, &pLinkAnnot);
-}
-
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testLinkWrongPage)
 {
     // Import the bugdoc and export as PDF.
@@ -1928,12 +1916,12 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testLinkWrongPage)
 
     // Without the accompanying fix in place, this test would have failed, as the link of the first
     // page went to the second page due to the hidden first slide.
-    CPPUNIT_ASSERT(HasLinksOnPage(pPdfPage));
+    CPPUNIT_ASSERT(pPdfPage->hasLinks());
 
     // Second page should have no links (3rd slide).
     std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage2 = pPdfDocument->openPage(/*nIndex=*/1);
     CPPUNIT_ASSERT(pPdfPage2);
-    CPPUNIT_ASSERT(!HasLinksOnPage(pPdfPage2));
+    CPPUNIT_ASSERT(!pPdfPage2->hasLinks());
 }
 
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testLargePage)
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index 01b1acf1bd1a..78abdc433fa6 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -458,6 +458,15 @@ std::unique_ptr<PDFiumTextPage> PDFiumPage::getTextPage()
     return pPDFiumTextPage;
 }
 
+bool PDFiumPage::hasLinks()
+{
+    // This could be a full iterator, but at the moment we just determine if the list is empty or
+    // not.
+    int nStartPos = 0;
+    FPDF_LINK pLinkAnnot = nullptr;
+    return FPDFLink_Enumerate(mpPage, &nStartPos, &pLinkAnnot);
+}
+
 PDFiumPageObject::PDFiumPageObject(FPDF_PAGEOBJECT pPageObject)
     : mpPageObject(pPageObject)
 {


More information about the Libreoffice-commits mailing list