include/vcl/filter/PDFiumLibrary.hxx |    1 +
 sw/qa/core/text/text.cxx             |   26 ++++++++++++++++++++++++++
 sw/source/core/text/itrform2.cxx     |   10 ++++++++++
 vcl/source/pdf/PDFiumLibrary.cxx     |    7 +++++++
 4 files changed, 44 insertions(+)

New commits:
commit 4f312a7e017d2fa6843f98b638982399e7e10819
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Sep 23 11:34:28 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Sep 26 08:19:38 2022 +0200

    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.
    
    (cherry picked from commit 82b9ff35649cd67ca16296676d2ad1e4eff15493)
    
    Change-Id: Ifb99625c2ab8792b756ad52a3f6d599507c5773f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140519
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/vcl/filter/PDFiumLibrary.hxx 
b/include/vcl/filter/PDFiumLibrary.hxx
index 1dc1382643d0..6927da3d7b20 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 201dead90bfa..b5b9476cd236 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -662,6 +662,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 aa987fa9b7fb..35548fe00217 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -953,6 +953,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 1fc22cc50223..8df65a71f990 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -251,6 +251,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
@@ -1136,6 +1137,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);

Reply via email to