include/vcl/pdfextoutdevdata.hxx | 2 - sc/qa/extras/scpdfexport.cxx | 32 ++++++++++++++++++++ sc/qa/extras/testdocuments/tdf162955_comment.ods |binary sc/source/ui/view/output.cxx | 20 +++++++++++- sd/source/ui/unoidl/unomodel.cxx | 6 +++ vcl/qa/cppunit/pdfexport/data/tdf162955_comment.odp |binary vcl/qa/cppunit/pdfexport/pdfexport.cxx | 26 ++++++++++++++++ 7 files changed, 82 insertions(+), 4 deletions(-)
New commits: commit bff514dea53e0c8c02663fda1b7f1ee469e2c536 Author: Tibor Nagy <tibor.nagy.ext...@allotropia.de> AuthorDate: Wed Sep 18 01:49:39 2024 +0200 Commit: Nagy Tibor <tibor.nagy.ext...@allotropia.de> CommitDate: Thu Sep 19 08:59:16 2024 +0200 tdf#162955 PDF export: avoid the popup rectangle with zero size Change-Id: I9a3cdda4d1dfa0b23a3ea6dd99341cb17ca47490 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173580 Tested-by: Jenkins Reviewed-by: Nagy Tibor <tibor.nagy.ext...@allotropia.de> diff --git a/include/vcl/pdfextoutdevdata.hxx b/include/vcl/pdfextoutdevdata.hxx index 6ffd88ddce15..44ac3646f184 100644 --- a/include/vcl/pdfextoutdevdata.hxx +++ b/include/vcl/pdfextoutdevdata.hxx @@ -349,7 +349,7 @@ public: number of page the note is on (as returned by NewPage) or -1 in which case the current page is used */ - sal_Int32 CreateNote(const tools::Rectangle& rRect, const vcl::pdf::PDFNote& rNote, const tools::Rectangle& rPopupRect = tools::Rectangle(), sal_Int32 nPageNr = -1); + sal_Int32 CreateNote(const tools::Rectangle& rRect, const vcl::pdf::PDFNote& rNote, const tools::Rectangle& rPopupRect, sal_Int32 nPageNr = -1); /** begin a new logical structure element diff --git a/sc/qa/extras/scpdfexport.cxx b/sc/qa/extras/scpdfexport.cxx index 43ed70bd55c1..ec763d59b289 100644 --- a/sc/qa/extras/scpdfexport.cxx +++ b/sc/qa/extras/scpdfexport.cxx @@ -57,6 +57,7 @@ private: // unit tests public: + void testPopupRectangleSize_Tdf162955(); void testMediaShapeScreen_Tdf159094(); void testExportRange_Tdf120161(); void testExportFitToPage_Tdf103516(); @@ -74,6 +75,7 @@ public: void testForcepoint97(); CPPUNIT_TEST_SUITE(ScPDFExportTest); + CPPUNIT_TEST(testPopupRectangleSize_Tdf162955); CPPUNIT_TEST(testMediaShapeScreen_Tdf159094); CPPUNIT_TEST(testExportRange_Tdf120161); CPPUNIT_TEST(testExportFitToPage_Tdf103516); @@ -223,6 +225,36 @@ void ScPDFExportTest::testMediaShapeScreen_Tdf159094() exportToPDF(xModel, aRange); } +void ScPDFExportTest::testPopupRectangleSize_Tdf162955() +{ + loadFromFile(u"tdf162955_comment.ods"); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + + // A1 + ScRange aRange(0, 0, 0, 0, 0, 0); + exportToPDF(xModel, aRange); + + // Parse the export result with pdfium. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + // Get the first page + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(0); + CPPUNIT_ASSERT(pPdfPage); + + // Popup annotation + { + auto pAnnotation = pPdfPage->getAnnotation(1); + CPPUNIT_ASSERT(pAnnotation); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, pAnnotation->getSubType()); + CPPUNIT_ASSERT(!pAnnotation->getRectangle().isEmpty()); + double nWidth = pAnnotation->getRectangle().getWidth(); + double nHeight = pAnnotation->getRectangle().getHeight(); + CPPUNIT_ASSERT(nWidth > 0); + CPPUNIT_ASSERT(nHeight > 0); + } +} + // Selection was not taken into account during export into PDF void ScPDFExportTest::testExportRange_Tdf120161() { diff --git a/sc/qa/extras/testdocuments/tdf162955_comment.ods b/sc/qa/extras/testdocuments/tdf162955_comment.ods new file mode 100644 index 000000000000..e9b1cc21d86b Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf162955_comment.ods differ diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx index 9c545e588bed..89ca5150b9cb 100644 --- a/sc/source/ui/view/output.cxx +++ b/sc/source/ui/view/output.cxx @@ -21,6 +21,7 @@ #include <editeng/brushitem.hxx> #include <svtools/colorcfg.hxx> #include <svx/rotmodit.hxx> +#include <svx/svdocapt.hxx> #include <editeng/shaditem.hxx> #include <editeng/svxfont.hxx> #include <tools/poly.hxx> @@ -2647,7 +2648,7 @@ void ScOutputData::AddPDFNotes() // use origin's pCell for NotePtr test below } - const ScPostIt* pNote = mpDoc->GetNote(nMergeX, nMergeY, nTab); + ScPostIt* pNote = mpDoc->GetNote(nMergeX, nMergeY, nTab); if ( pNote && ( bIsMerged || ( !pInfo->bHOverlapped && !pInfo->bVOverlapped ) ) ) { @@ -2679,7 +2680,22 @@ void ScOutputData::AddPDFNotes() OUString aContent = pNote->GetText(); aNote.maContents = aContent.replaceAll(" ", " "); - pPDFData->CreateNote( aNoteRect, aNote ); + // If the caption is hidden, we need to show it to get its rectangle, + // then hide it again because it is also hidden in the file. + bool bShowCaption = pNote->IsCaptionShown(); + if (!bShowCaption) + pNote->ShowCaption(aAddress, true); + + SdrCaptionObj* pCaption = pNote->GetCaption(); + tools::Rectangle aCaptionRect(pCaption->GetLogicRect()); + Point aPoint(aCaptionRect.getX() + nScrX, aCaptionRect.getY() + nScrY); + Size aSize(aCaptionRect.GetWidth(), aCaptionRect.GetHeight()); + tools::Rectangle aPopupRect(aPoint, aSize); + + if (!bShowCaption) + pNote->ShowCaption(aAddress, false); + + pPDFData->CreateNote(aNoteRect, aNote, aPopupRect); } } diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 6351b3356fcd..539148a3a78c 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -1761,6 +1761,9 @@ static void ImplPDFExportComments( const uno::Reference< drawing::XDrawPage >& x Point aPoint(aRealPoint2D.X * 100.0, aRealPoint2D.Y * 100.0); Size aSize(aRealSize2D.Width * 100.0, aRealSize2D.Height * 100.0); + Point aPopupPoint(aPoint.X(), aPoint.Y()); + Size aPopupSize(aSize.Width() * 10.0, aSize.Height() * 10.0); + uno::Reference<text::XText> xText(xAnnotation->getTextRange()); vcl::pdf::PDFNote aNote; @@ -1798,7 +1801,8 @@ static void ImplPDFExportComments( const uno::Reference< drawing::XDrawPage >& x } } - rPDFExtOutDevData.CreateNote(::tools::Rectangle(aPoint, aSize), aNote); + rPDFExtOutDevData.CreateNote(::tools::Rectangle(aPoint, aSize), aNote, + ::tools::Rectangle(aPopupPoint, aPopupSize)); } } catch (const uno::Exception&) diff --git a/vcl/qa/cppunit/pdfexport/data/tdf162955_comment.odp b/vcl/qa/cppunit/pdfexport/data/tdf162955_comment.odp new file mode 100644 index 000000000000..ac37fbd01606 Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf162955_comment.odp differ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index ddb228351228..e030115497c2 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -64,6 +64,32 @@ void PdfExportTest::load(std::u16string_view rFile, vcl::filter::PDFDocument& rD CPPUNIT_ASSERT(rDocument.Read(aStream)); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testPopupRectangleSize) +{ + // Enable Comment as PDF annotations + uno::Sequence<beans::PropertyValue> aFilterData( + comphelper::InitPropertySequence({ { "ExportNotes", uno::Any(true) } })); + aMediaDescriptor[u"FilterData"_ustr] <<= aFilterData; + saveAsPDF(u"tdf162955_comment.odp"); + + // Parse the export result with pdfium. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(0); + CPPUNIT_ASSERT(pPdfPage); + + // Popup annotation + { + auto pAnnotation = pPdfPage->getAnnotation(1); + CPPUNIT_ASSERT(pAnnotation); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, pAnnotation->getSubType()); + CPPUNIT_ASSERT(!pAnnotation->getRectangle().isEmpty()); + double nWidth = pAnnotation->getRectangle().getWidth(); + double nHeight = pAnnotation->getRectangle().getHeight(); + CPPUNIT_ASSERT(nWidth > 0); + CPPUNIT_ASSERT(nHeight > 0); + } +} + CPPUNIT_TEST_FIXTURE(PdfExportTest, testCommentAnnotation) { // Enable PDF/UA and Comment as PDF annotations