sd/source/ui/unoidl/unomodel.cxx | 8 +++++ vcl/qa/cppunit/pdfexport/data/link-wrong-page.odp |binary vcl/qa/cppunit/pdfexport/pdfexport.cxx | 34 ++++++++++++++++++++++ 3 files changed, 42 insertions(+)
New commits: commit 01dbb38680aa39a4d3bc7afd05d44a4b2c9bc6ab Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Mar 10 18:10:07 2020 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Mar 10 20:40:38 2020 +0100 tdf#61274 sd PDF export: fix links ending up on wrong pages with hidden slides SdPage::IsExcluded() decides if a slide is hidden, SdXImpressDocument::render() checks for this and returns early if needed. In that case PDFExport::ExportSelection() detects that the produced metafile has no actions and avoids creating a PDF page. Then Impress links are created using the vcl::PDFExtOutDevData::CreateLink() call in drawinglayer::processor2d::VclMetafileProcessor2D::processTextHierarchyFieldPrimitive2D(), not specifying the PDF page number explicitly. This means the link is created on the "current" page number, set in vcl::PDFExtOutDevData::SetCurrentPageNumber(), called by PDFExport::ExportSelection(), but that filter/ code can't know about hidden slides in sd/. Fix the problem by setting the page number again in SdXImpressDocument::render(), that way the link created by drawinglayer will end on the correct page. Change-Id: Ic29e345d45bc7c944d65e6e450f1d742dd0e9f8c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90299 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 67660e4919ac..b06e341a6879 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -1893,6 +1893,14 @@ 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); + } + std::unique_ptr<::sd::ClientView> pView( new ::sd::ClientView( 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.odp b/vcl/qa/cppunit/pdfexport/data/link-wrong-page.odp new file mode 100644 index 000000000000..b6787aff6684 Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/link-wrong-page.odp differ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 706c4cac3fda..a3ea246ed612 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -142,6 +142,7 @@ public: void testPdfImageResourceInlineXObjectRef(); void testReduceSmallImage(); void testReduceImage(); + void testLinkWrongPage(); CPPUNIT_TEST_SUITE(PdfExportTest); CPPUNIT_TEST(testTdf106059); @@ -181,6 +182,7 @@ public: CPPUNIT_TEST(testPdfImageResourceInlineXObjectRef); CPPUNIT_TEST(testReduceSmallImage); CPPUNIT_TEST(testReduceImage); + CPPUNIT_TEST(testLinkWrongPage); CPPUNIT_TEST_SUITE_END(); }; @@ -1962,6 +1964,38 @@ void PdfExportTest::testReduceImage() CPPUNIT_ASSERT_EQUAL(160, nHeight); } +bool HasLinksOnPage(PageHolder& pPdfPage) +{ + int nStartPos = 0; + FPDF_LINK pLinkAnnot = nullptr; + return FPDFLink_Enumerate(pPdfPage.get(), &nStartPos, &pLinkAnnot); +} + +void PdfExportTest::testLinkWrongPage() +{ + // Import the bugdoc and export as PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "link-wrong-page.odp"; + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("impress_pdf_Export"); + DocumentHolder pPdfDocument = exportAndParse(aURL, aMediaDescriptor); + + // The document has 2 pages. + CPPUNIT_ASSERT_EQUAL(2, FPDF_GetPageCount(pPdfDocument.get())); + + // First page should have 1 link (2nd slide, 1st was hidden). + PageHolder pPdfPage(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/0)); + CPPUNIT_ASSERT(pPdfPage.get()); + + // 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)); + + // Second page should have no links (3rd slide). + PageHolder pPdfPage2(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/1)); + CPPUNIT_ASSERT(pPdfPage2.get()); + CPPUNIT_ASSERT(!HasLinksOnPage(pPdfPage2)); +} + void PdfExportTest::testPdfImageResourceInlineXObjectRef() { // Create an empty document. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits