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.
Change-Id: I5679743ca67fab562e14c73e32f1a06ead8e7a31
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128643
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index 43d2b97..604326b 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -220,6 +220,7 @@ bool PDFExport::ExportSelection( vcl::PDFWriter& rPDFWriter,
aMtf.Stop();
aMtf.WindStart();
bool bEmptyPage = false;
if( aMtf.GetActionSize() &&
( !mbSkipEmptyPages || aPageSize.Width || aPageSize.Height ) )
{
@@ -244,6 +245,10 @@ bool PDFExport::ExportSelection( vcl::PDFWriter& rPDFWriter,
ImplExportPage(rPDFWriter, rPDFExtOutDevData, aMtf);
bRet = true;
}
else
{
bEmptyPage = true;
}
pOut->Pop();
@@ -253,7 +258,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 71137c4..f0b939ac 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -1893,14 +1893,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 0000000..1fad913
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/link-wrong-page-partial.odg
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 386a85ee..88b2a13 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -43,6 +43,7 @@
#include <unotools/streamwrap.hxx>
#include <vcl/filter/PDFiumLibrary.hxx>
#include <comphelper/propertyvalue.hxx>
using namespace ::com::sun::star;
@@ -1980,6 +1981,31 @@ 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")),
};
aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
aMediaDescriptor["FilterData"] <<= aFilterData;
saveAsPDF(u"link-wrong-page-partial.odg");
// 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 = parseExport();
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.