filter/source/pdf/pdfexport.cxx                           |   12 +++++-
 sd/source/ui/unoidl/unomodel.cxx                          |    8 ----
 vcl/qa/cppunit/pdfexport/data/link-wrong-page-partial.odg |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx                    |   28 ++++++++++++++
 4 files changed, 39 insertions(+), 9 deletions(-)

New commits:
commit 51f5e5fcb64c150f5dd8233b52686e54cdeac399
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Jan 20 10:03:20 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Jan 21 13:11:37 2022 +0100

    tdf#141340 PDF export: fix hyperlinks on the wrong page with page num range
    
    Regression from commit 01dbb38680aa39a4d3bc7afd05d44a4b2c9bc6ab
    (tdf#61274 sd PDF export: fix links ending up on wrong pages with hidden
    slides, 2020-03-10), the problem was that the sd/ code that mapped page
    numbers between the model and the PDF output only handled hidden slides,
    but not partial exports.
    
    Fix this by revisiting the decision to handle hidden slides in sd/, the
    filter/ code at the end does have enough information to correctly do
    this mapping at the end, and this way both tdf#61274 and tdf#141340 can
    work at the same time.
    
    (cherry picked from commit 31bbaf478783e3a2c21bd3ea94ddf39299a63d1e)
    
    Change-Id: I5679743ca67fab562e14c73e32f1a06ead8e7a31
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128647
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit 3d60ad8c67e347f56400e3be05a3f1641f77c719)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128545

diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index 2932d2e52ac9..a0328465900d 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -218,6 +218,7 @@ bool PDFExport::ExportSelection( vcl::PDFWriter& rPDFWriter,
                     aMtf.Stop();
                     aMtf.WindStart();
 
+                    bool bEmptyPage = false;
                     if( aMtf.GetActionSize() &&
                              ( !mbSkipEmptyPages || aPageSize.Width || 
aPageSize.Height ) )
                     {
@@ -242,6 +243,10 @@ bool PDFExport::ExportSelection( vcl::PDFWriter& 
rPDFWriter,
                         ImplExportPage(rPDFWriter, rPDFExtOutDevData, aMtf);
                         bRet = true;
                     }
+                    else
+                    {
+                        bEmptyPage = true;
+                    }
 
                     pOut->Pop();
 
@@ -251,7 +256,12 @@ bool PDFExport::ExportSelection( vcl::PDFWriter& 
rPDFWriter,
                         *pFirstPage <<= false;
 
                     ++mnProgressValue;
-                    ++nCurrentPage;
+                    if (!bEmptyPage)
+                    {
+                        // Calculate the page number in the PDF output, which 
may be smaller than the page number in
+                        // case of hidden slides or a partial export.
+                        ++nCurrentPage;
+                    }
                 }
             }
             else
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 006a9cad3347..4fdae7e3cfbe 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -1882,14 +1882,6 @@ void SAL_CALL SdXImpressDocument::render( sal_Int32 
nRenderer, const uno::Any& r
         !(pPDFExtOutDevData && pPDFExtOutDevData->GetIsExportHiddenSlides()) )
         return;
 
-    if (pPDFExtOutDevData)
-    {
-        // Calculate the page number in the PDF output, which may be smaller 
than the page number in
-        // case of hidden slides.
-        sal_Int32 nOutputPageNum = CalcOutputPageNum(pPDFExtOutDevData, mpDoc, 
nPageNumber);
-        pPDFExtOutDevData->SetCurrentPageNumber(nOutputPageNum);
-    }
-
     ::sd::ClientView aView( mpDocShell, pOut );
     ::tools::Rectangle aVisArea( Point(), mpDoc->GetSdPage( 
static_cast<sal_uInt16>(nPageNumber) - 1, ePageKind )->GetSize() );
     vcl::Region                       aRegion( aVisArea );
diff --git a/vcl/qa/cppunit/pdfexport/data/link-wrong-page-partial.odg 
b/vcl/qa/cppunit/pdfexport/data/link-wrong-page-partial.odg
new file mode 100644
index 000000000000..1fad913e0493
Binary files /dev/null and 
b/vcl/qa/cppunit/pdfexport/data/link-wrong-page-partial.odg differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index ad19395c5669..b9290b1be633 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -42,6 +42,7 @@
 #include <unotools/streamwrap.hxx>
 
 #include <vcl/filter/PDFiumLibrary.hxx>
+#include <comphelper/propertyvalue.hxx>
 
 using namespace ::com::sun::star;
 
@@ -2067,6 +2068,33 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testLinkWrongPage)
     CPPUNIT_ASSERT(!pPdfPage2->hasLinks());
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testLinkWrongPagePartial)
+{
+    // Given a Draw document with 3 pages, a link on the 2nd page:
+    // When exporting that the 2nd and 3rd page to pdf:
+    uno::Sequence<beans::PropertyValue> aFilterData = {
+        comphelper::makePropertyValue("PageRange", OUString("2-3")),
+    };
+
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"link-wrong-page-partial.odg";
+    utl::MediaDescriptor aMediaDescriptor;
+    aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
+    aMediaDescriptor["FilterData"] <<= aFilterData;
+
+    // Then make sure the we have a link on the 1st page, but not on the 2nd 
one:
+    std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = 
exportAndParse(aURL, aMediaDescriptor);
+    CPPUNIT_ASSERT(pPdfDocument);
+    CPPUNIT_ASSERT_EQUAL(2, pPdfDocument->getPageCount());
+    std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+    CPPUNIT_ASSERT(pPdfPage);
+    // Without the accompanying fix in place, this test would have failed, as 
the link was on the
+    // 2nd page instead.
+    CPPUNIT_ASSERT(pPdfPage->hasLinks());
+    std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage2 = 
pPdfDocument->openPage(/*nIndex=*/1);
+    CPPUNIT_ASSERT(pPdfPage2);
+    CPPUNIT_ASSERT(!pPdfPage2->hasLinks());
+}
+
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testLargePage)
 {
     // Import the bugdoc and export as PDF.

Reply via email to