summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-10-31 13:41:20 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-10-31 18:14:33 +0100
commitd40c2be38aaf56116f4dc7be9e78f4e9695407fc (patch)
tree3f45ea21d6d8d84b6829cbf22367b61bf6e3db2c /writerfilter
parent94890fdc3402d1b62a22824235e557d191332bd9 (diff)
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@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx23
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx11
2 files changed, 34 insertions, 0 deletions
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