summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-03-09 13:36:27 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-03-09 15:53:35 +0100
commit2e1e7d8b99ce03dfa585ba4287fa8392e2f6b4d5 (patch)
tree83d66b5f46170020ea901f7fb9f010eee099c350
parentef47b4c2aa50b74d1f337f764428bfb1a537faa8 (diff)
PDF export of PDF images: don't preserve annotations in general
Regression from 33c9bc0225a92f26770f9ef20b252af47853e7b9 (PDF export of PDF images: preserve hyperlinks, 2022-01-07), the problem was that we want to preserve hyperlinks, but annotations are added by the PDF export explicitly, so it isn't a good idea to "preserve" them as well. Fix the problem by going back to the old behavior, except when the annotation sub-type is /Link. This keeps hyperlinks working but doesn't lead to duplicated comments when re-exporting an image + adding comments explicitly. Conflicts: vcl/qa/cppunit/pdfexport/pdfexport.cxx Change-Id: I910990da59bdc1150cc346f1a5471cb6da55dd2c
-rw-r--r--vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odgbin0 -> 29714 bytes
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport.cxx19
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx16
3 files changed, 33 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
new file mode 100644
index 000000000000..6dee0145c536
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 7312078b1896..f9046d8c3e97 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2963,6 +2963,25 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageHyperlink)
#endif
}
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageAnnots)
+{
+ // Given a document with a PDF image that has 2 comments (popup, text) and a hyperlink:
+ aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
+
+ // When saving to PDF:
+ saveAsPDF(u"pdf-image-annots.odg");
+
+ // Then make sure only the hyperlink is kept, since Draw itself has its own comments:
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parseExport();
+ CPPUNIT_ASSERT(pPdfDocument);
+ 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());
+}
} // end anonymous namespace
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index b5e94882a0fb..6f10c891330d 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8434,7 +8434,7 @@ void PDFWriterImpl::writeReferenceXObject(const 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")))
{
@@ -8452,7 +8452,19 @@ void PDFWriterImpl::writeReferenceXObject(const 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);
}
}