include/vcl/pdfwriter.hxx | 2 - sw/qa/core/text/text.cxx | 49 +++++++++++++++++++++++++++++---------- sw/qa/inc/swmodeltestbase.hxx | 2 + sw/qa/unit/swmodeltestbase.cxx | 8 ++++++ sw/source/core/text/itrform2.cxx | 11 ++++++++ 5 files changed, 59 insertions(+), 13 deletions(-)
New commits: commit e58fcd3d60420c42554d0526c88a43ac3b0e6516 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Sep 14 08:35:28 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Sep 15 08:11:11 2022 +0200 sw content controls, dropdown: add PDF export Map this to vcl::PDFWriter::ListBoxWidget, which uses the /FT/Ch widget, i.e. a (dropdown) choice widget. Also extract a SwModelTestBase::StoreToTempFile() from the various test cases that export to a tempfile just by specifying the filter name. (cherry picked from commit 6b2433f3b66c1f118dabcd40924122deb2d4f204) Conflicts: sw/qa/inc/swmodeltestbase.hxx sw/qa/unit/swmodeltestbase.cxx Change-Id: If9ad52ae2553d7199e28188cfdf455353e202ccd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139940 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx index 56181deb5c3a..1a59a66c66f1 100644 --- a/include/vcl/pdfwriter.hxx +++ b/include/vcl/pdfwriter.hxx @@ -394,7 +394,7 @@ public: } }; - struct ListBoxWidget final : public AnyWidget + struct VCL_DLLPUBLIC ListBoxWidget final : public AnyWidget { bool DropDown; bool MultiSelect; diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 282456d491a7..9e0d3cc81579 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -116,10 +116,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testBibliographyUrlPdfExport) xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); // When exporting to PDF: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - utl::MediaDescriptor aMediaDescriptor; - aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); - xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + StoreToTempFile("writer_pdf_Export"); // Then make sure the field links the source. SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); @@ -543,10 +540,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF) pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT); // When exporting to PDF: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - utl::MediaDescriptor aMediaDescriptor; - aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); - xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + StoreToTempFile("writer_pdf_Export"); // Then make sure that a fillable form widget is emitted: SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); @@ -575,10 +569,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testCheckboxContentControlPDF) pWrtShell->InsertContentControl(SwContentControlType::CHECKBOX); // When exporting to PDF: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - utl::MediaDescriptor aMediaDescriptor; - aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); - xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + StoreToTempFile("writer_pdf_Export"); // Then make sure that a checkbox form widget is emitted: SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); @@ -604,6 +595,40 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testCheckboxContentControlPDF) pAnnotation->getFormFieldType(pPdfDocument.get())); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDropdownContentControlPDF) +{ + // Given a file with a dropdown content control: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST); + + // When exporting to PDF: + StoreToTempFile("writer_pdf_Export"); + + // Then make sure that a dropdown form widget is emitted: + SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. the dropdown content control was just exported as normal text. + CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount()); + std::unique_ptr<vcl::pdf::PDFiumAnnotation> pAnnotation = pPage->getAnnotation(0); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Widget, pAnnotation->getSubType()); + // Also check the form widget type (our dropdown is called combo in PDF terms): + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFFormFieldType::ComboBox, + pAnnotation->getFormFieldType(pPdfDocument.get())); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx index f1e8444c4c52..75bee223fbd2 100644 --- a/sw/qa/inc/swmodeltestbase.hxx +++ b/sw/qa/inc/swmodeltestbase.hxx @@ -401,6 +401,8 @@ protected: */ SwDoc* createSwWebDoc( std::u16string_view rDataDirectory = std::u16string_view(), const char* pName = nullptr); + + void StoreToTempFile(const OUString& rFilterName); }; /** diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx index fdf25ca3bc11..cc8edcb2a213 100644 --- a/sw/qa/unit/swmodeltestbase.cxx +++ b/sw/qa/unit/swmodeltestbase.cxx @@ -766,4 +766,12 @@ SwDoc* SwModelTestBase::createSwWebDoc(std::u16string_view rDataDirectory, const return pTextDoc->GetDocShell()->GetDoc(); } +void SwModelTestBase::StoreToTempFile(const OUString& rFilterName) +{ + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= rFilterName; + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 1d05e5cf605e..6db3fe4a39c8 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -941,6 +941,17 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co pCheckBoxWidget->OffValue = pContentControl->GetUncheckedState(); break; } + case SwContentControlType::DROP_DOWN_LIST: + { + pDescriptor = std::make_unique<vcl::PDFWriter::ListBoxWidget>(); + auto pListWidget = static_cast<vcl::PDFWriter::ListBoxWidget*>(pDescriptor.get()); + pListWidget->DropDown = true; + for (const auto& rItem : pContentControl->GetListItems()) + { + pListWidget->Entries.push_back(rItem.m_aDisplayText); + } + break; + } default: break; }