From 01dbb38680aa39a4d3bc7afd05d44a4b2c9bc6ab Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 10 Mar 2020 18:10:07 +0100 Subject: 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 Tested-by: Jenkins --- vcl/qa/cppunit/pdfexport/data/link-wrong-page.odp | Bin 0 -> 12293 bytes vcl/qa/cppunit/pdfexport/pdfexport.cxx | 34 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 vcl/qa/cppunit/pdfexport/data/link-wrong-page.odp (limited to 'vcl') 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. -- cgit