diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-09-23 11:34:28 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-09-23 13:15:30 +0200 |
commit | 82b9ff35649cd67ca16296676d2ad1e4eff15493 (patch) | |
tree | 01ee7cd8972dd305316e1eb4a5ca36523847bd29 | |
parent | 1cfa1e7a0976dce86a8b4168119c9c6f015ff5ce (diff) |
sw content controls, combo box: add PDF export
Map it to vcl::PDFWriter::ComboBoxWidget, which knows that this has list
items + allows free-form user input as well.
PDF 32000-1:2008 Table 230 documents those field flag bits.
Change-Id: Ifb99625c2ab8792b756ad52a3f6d599507c5773f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140480
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | include/vcl/filter/PDFiumLibrary.hxx | 1 | ||||
-rw-r--r-- | sw/qa/core/text/text.cxx | 26 | ||||
-rw-r--r-- | sw/source/core/text/itrform2.cxx | 10 | ||||
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 7 |
4 files changed, 44 insertions, 0 deletions
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 8140864171eb..1541fcb689e4 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -104,6 +104,7 @@ public: virtual PDFFormFieldType getFormFieldType(PDFiumDocument* pDoc) = 0; virtual float getFormFontSize(PDFiumDocument* pDoc) = 0; virtual OUString getFormFieldAlternateName(PDFiumDocument* pDoc) = 0; + virtual int getFormFieldFlags(PDFiumDocument* pDoc) = 0; }; class PDFiumTextPage; diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 245f8c230ca6..0084ac52bae2 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -751,6 +751,32 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDFFont) CPPUNIT_ASSERT_EQUAL(24.0f, pAnnotation->getFormFontSize(pPdfDocument.get())); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testComboContentControlPDF) +{ + // Given a file with a combo box content control: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::COMBO_BOX); + + // When exporting to PDF: + StoreToTempFile("writer_pdf_Export"); + + // Then make sure that a combo box form widget is emitted: + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile(); + 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 combo box content control was exported as plain 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()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFFormFieldType::ComboBox, + pAnnotation->getFormFieldType(pPdfDocument.get())); + // 19th bit: combo box, not dropdown. + CPPUNIT_ASSERT(pAnnotation->getFormFieldFlags(pPdfDocument.get()) & 0x00040000); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index f07ea0bc1de7..20855df95956 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -959,6 +959,16 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co } break; } + case SwContentControlType::COMBO_BOX: + { + pDescriptor = std::make_unique<vcl::PDFWriter::ComboBoxWidget>(); + auto pComboWidget = static_cast<vcl::PDFWriter::ComboBoxWidget*>(pDescriptor.get()); + for (const auto& rItem : pContentControl->GetListItems()) + { + pComboWidget->Entries.push_back(rItem.m_aDisplayText); + } + break; + } case SwContentControlType::DATE: { pDescriptor = std::make_unique<vcl::PDFWriter::EditWidget>(); diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index e64aa2f5e3e5..68bae2d78d80 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -252,6 +252,7 @@ public: PDFFormFieldType getFormFieldType(PDFiumDocument* pDoc) override; float getFormFontSize(PDFiumDocument* pDoc) override; OUString getFormFieldAlternateName(PDFiumDocument* pDoc) override; + int getFormFieldFlags(PDFiumDocument* pDoc) override; }; class PDFiumPageObjectImpl final : public PDFiumPageObject @@ -1137,6 +1138,12 @@ PDFFormFieldType PDFiumAnnotationImpl::getFormFieldType(PDFiumDocument* pDoc) FPDFAnnot_GetFormFieldType(pDocImpl->getFormHandlePointer(), mpAnnotation)); } +int PDFiumAnnotationImpl::getFormFieldFlags(PDFiumDocument* pDoc) +{ + auto pDocImpl = static_cast<PDFiumDocumentImpl*>(pDoc); + return FPDFAnnot_GetFormFieldFlags(pDocImpl->getFormHandlePointer(), mpAnnotation); +} + float PDFiumAnnotationImpl::getFormFontSize(PDFiumDocument* pDoc) { auto pDocImpl = static_cast<PDFiumDocumentImpl*>(pDoc); |