[Libreoffice-commits] core.git: sw/qa writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 31 17:15:19 UTC 2019


 sw/qa/extras/ooxmlexport/ooxmlexport14.cxx        |    8 ++++++-
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   23 ++++++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |   11 ++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

New commits:
commit d40c2be38aaf56116f4dc7be9e78f4e9695407fc
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Oct 31 13:41:20 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Oct 31 18:14:33 2019 +0100

    tdf#125038 DOCX import: better support for linebreaks in IF fields
    
    IF fields can't contain linebreaks, so instead of just calling
    finishParagraph() and hoping it does something sane, explicitly handle
    them: remember the properties and perform the call only once the field
    is closed.
    
    Change-Id: I676aa2c83f12cb600829177a0eb25558822b1d94
    Reviewed-on: https://gerrit.libreoffice.org/81847
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 2c2d94821acf..27317edd1615 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -56,7 +56,13 @@ DECLARE_OOXMLIMPORT_TEST(testTdf125038b, "tdf125038b.docx")
     uno::Reference<container::XEnumerationAccess> xParagraphAccess(xTextDocument->getText(), uno::UNO_QUERY);
     uno::Reference<container::XEnumeration> xParagraphs = xParagraphAccess->createEnumeration();
     CPPUNIT_ASSERT(xParagraphs->hasMoreElements());
-    xParagraphs->nextElement();
+    uno::Reference<text::XTextRange> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY);
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: phone: 1234
+    // - Actual  :
+    // i.e. the the first paragraph was empty and the second paragraph had the content.
+    CPPUNIT_ASSERT_EQUAL(OUString("phone: 1234"), xParagraph->getString());
     CPPUNIT_ASSERT(xParagraphs->hasMoreElements());
     xParagraphs->nextElement();
 
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index cae12ac298f0..48505401b876 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1309,6 +1309,17 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
                 return;
             }
         }
+
+        if (pFieldContext && pFieldContext->IsCommandCompleted())
+        {
+            if (pFieldContext->GetFieldId() == FIELD_IF)
+            {
+                // Conditional text fields can't contain newlines, finish the paragraph later.
+                FieldParagraph aFinish{pPropertyMap, bRemove};
+                pFieldContext->GetParagraphsToFinish().push_back(aFinish);
+                return;
+            }
+        }
     }
 
 #ifdef DBG_UTIL
@@ -5661,10 +5672,22 @@ void DomainMapper_Impl::PopFieldContext()
         }
 
         //TOCs have to include all the imported content
+    }
 
+    std::vector<FieldParagraph> aParagraphsToFinish;
+    if (pContext)
+    {
+        aParagraphsToFinish = pContext->GetParagraphsToFinish();
     }
+
     //remove the field context
     m_aFieldStack.pop_back();
+
+    // Finish the paragraph(s) now that the field is closed.
+    for (const auto& rFinish : aParagraphsToFinish)
+    {
+        finishParagraph(rFinish.m_pPropertyMap, rFinish.m_bRemove);
+    }
 }
 
 
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 7dbd7032c4fa..27c606a3f681 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -129,6 +129,13 @@ public:
     bool getTextInserted() const;
 };
 
+/// Information about a paragraph to be finished after a field end.
+struct FieldParagraph
+{
+    PropertyMapPtr m_pPropertyMap;
+    bool m_bRemove = false;
+};
+
 /// field stack element
 class FieldContext : public virtual SvRefBase
 {
@@ -155,6 +162,8 @@ class FieldContext : public virtual SvRefBase
     /// (Character) properties of the field itself.
     PropertyMapPtr m_pProperties;
 
+    std::vector<FieldParagraph> m_aParagraphsToFinish;
+
 public:
     explicit FieldContext(css::uno::Reference<css::text::XTextRange> const& xStart);
     ~FieldContext() override;
@@ -202,6 +211,8 @@ public:
     const PropertyMapPtr& getProperties() const { return m_pProperties; }
 
     ::std::vector<OUString> GetCommandParts() const;
+
+    std::vector<FieldParagraph>& GetParagraphsToFinish() { return m_aParagraphsToFinish; }
 };
 
 struct TextAppendContext


More information about the Libreoffice-commits mailing list