diff options
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 8 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 23 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 11 |
3 files changed, 41 insertions, 1 deletions
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 |