sw/source/core/text/itrform2.cxx |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

New commits:
commit 2c813b3745e2da2001d318a60d911107bfefc32c
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Jun 2 20:29:34 2023 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jun 5 09:11:28 2023 +0200

    tdf#153040 sw content controls PDF export: output listbox entry
    
    This fixes a 7.5 regression/wrong implementation.
    
    Prior to 7.5, content controls were just exported as plain text to PDF.
    Now that the content control is exported, the selected entry in
    the list box was not being printed - just a big hole in the text.
    
    Fixed by informing PDF of the selected entry.
    
    TODO: the content control starts too late
    (a somewhat wide space at the front),
    and ends too soon (the last portion of the text is cut off).
    
    The unit test for the TODO will cover this case,
    so skipping that for now since I found no examples to follow.
    
    Change-Id: I1412a57efc070010c6d0d0a37f48d63699b085b1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152567
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index ab31c524ba40..dbf5765ef1b6 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -976,6 +976,13 @@ bool SwContentControlPortion::DescribePDFControl(const 
SwTextPaintInfo& rInf) co
         return true;
     }
 
+    const SwPaM aPam(*pTextNode, nEnd, *pTextNode, nStart);
+    static sal_Unicode const aForbidden[] = {
+        CH_TXTATR_BREAKWORD,
+        0
+    };
+    const OUString aText = comphelper::string::removeAny(aPam.GetText(), 
aForbidden);
+
     std::unique_ptr<vcl::PDFWriter::AnyWidget> pDescriptor;
     switch (pContentControl->GetType())
     {
@@ -999,9 +1006,13 @@ bool SwContentControlPortion::DescribePDFControl(const 
SwTextPaintInfo& rInf) co
             pDescriptor = std::make_unique<vcl::PDFWriter::ListBoxWidget>();
             auto pListWidget = 
static_cast<vcl::PDFWriter::ListBoxWidget*>(pDescriptor.get());
             pListWidget->DropDown = true;
+            sal_Int32 nIndex = 0;
             for (const auto& rItem : pContentControl->GetListItems())
             {
                 pListWidget->Entries.push_back(rItem.m_aDisplayText);
+                if (rItem.m_aDisplayText == aText)
+                    pListWidget->SelectedEntries.push_back(nIndex);
+                ++nIndex;
             }
             break;
         }
@@ -1048,15 +1059,7 @@ bool SwContentControlPortion::DescribePDFControl(const 
SwTextPaintInfo& rInf) co
     }
 
     // Map the text of the content control to the descriptor's text.
-    SwPosition aPoint(*pTextNode, nStart);
-    SwPosition aMark(*pTextNode, nEnd);
-    SwPaM aPam(aMark, aPoint);
-    OUString aText = aPam.GetText();
-    static sal_Unicode const aForbidden[] = {
-        CH_TXTATR_BREAKWORD,
-        0
-    };
-    pDescriptor->Text = comphelper::string::removeAny(aText, aForbidden);
+    pDescriptor->Text = aText;
 
     // Calculate the bounding rectangle of this content control, which can be 
one or more layout
     // portions in one or more lines.

Reply via email to