diff options
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg | bin | 0 -> 29714 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 30 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 16 |
3 files changed, 44 insertions, 2 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg b/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg Binary files differnew file mode 100644 index 000000000000..6dee0145c536 --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 8c1c81162ace..2206bd25d58a 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -2645,6 +2645,36 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageHyperlink) CPPUNIT_ASSERT_EQUAL(0.0012626264, rtl::math::round(aScale.getY(), 10)); #endif } + +CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageAnnots) +{ + // Given a document with a PDF image that has 2 comments (popup, text) and a hyperlink: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "pdf-image-annots.odg"; + mxComponent = loadFromDesktop(aURL); + CPPUNIT_ASSERT(mxComponent.is()); + + // When saving to PDF: + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export"); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Then make sure only the hyperlink is kept, since Draw itself has its own comments: + SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); + maMemory.WriteStream(aFile); + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument + = pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize()); + CPPUNIT_ASSERT(pPdfDocument); + CPPUNIT_ASSERT_EQUAL(1, 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 with: + // - Expected: 1 + // - Actual : 3 + // i.e. not only the hyperlink but also the 2 comments were exported, leading to duplication. + CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getAnnotationCount()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 6aefaf2edabe..3e934a19825d 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -8511,7 +8511,7 @@ void PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit) return; } - // Merge page annotations (links, etc) from pPage to our page. + // Merge link annotations from pPage to our page. std::vector<filter::PDFObjectElement*> aAnnots; if (auto pArray = dynamic_cast<filter::PDFArrayElement*>(pPage->Lookup("Annots"))) { @@ -8529,7 +8529,19 @@ void PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit) continue; } - // Annotation refers to an object, remember it. + auto pType = dynamic_cast<filter::PDFNameElement*>(pObject->Lookup("Type")); + if (!pType || pType->GetValue() != "Annot") + { + continue; + } + + auto pSubtype = dynamic_cast<filter::PDFNameElement*>(pObject->Lookup("Subtype")); + if (!pSubtype || pSubtype->GetValue() != "Link") + { + continue; + } + + // Reference to a link annotation object, remember it. aAnnots.push_back(pObject); } } |