diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2017-07-07 11:33:34 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2017-07-07 12:54:05 +0200 |
commit | 6a3960044c609b682170f7a34612761e62746c98 (patch) | |
tree | 63ace6152ee8b775a6fe79e2786471be8479e2ab /writerfilter | |
parent | 919b6958dbb1c17c060ba9a58fe245b825b271c2 (diff) |
tdf#108995: take xml:space attribute into account
See paragraph 2.10 of XML 1.0 specification and 17.3.3.31 of ECMA-376-1:2016
Change-Id: I7f19d3b9cf2ccce88a5fa03022beeb99facc04fe
Reviewed-on: https://gerrit.libreoffice.org/39682
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit 7c1a51516aaf2767e43b393259a1ad21570df5fb)
Reviewed-on: https://gerrit.libreoffice.org/39688
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 37 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.hxx | 8 |
2 files changed, 43 insertions, 2 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 84d2a65ad6e0..bb59ed9bebdc 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -627,6 +627,12 @@ void OOXMLFastContextHandler::text(const OUString & sText) // tdf#108806: CRLFs in XML were converted to \n before this point. // These must be converted to spaces before further processing. OUString sNormalizedText = sText.replaceAll("\n", " "); + // tdf#108995: by default, leading and trailing white space is ignored; + // tabs are converted to spaces + if (!IsPreserveSpace()) + { + sNormalizedText = sNormalizedText.trim().replaceAll("\t", " "); + } mpStream->utext(reinterpret_cast < const sal_uInt8 * > (sNormalizedText.getStr()), sNormalizedText.getLength()); @@ -889,6 +895,15 @@ void OOXMLFastContextHandler::sendPropertiesToParent() } } +bool OOXMLFastContextHandler::IsPreserveSpace() const +{ + // xml:space attribute applies to all elements within the content of the element where it is specified, + // unless overridden with another instance of the xml:space attribute + if (mpParent) + return mpParent->IsPreserveSpace(); + return false; // default value +} + /* class OOXMLFastContextHandlerStream */ @@ -896,7 +911,9 @@ void OOXMLFastContextHandler::sendPropertiesToParent() OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream (OOXMLFastContextHandler * pContext) : OOXMLFastContextHandler(pContext), - mpPropertySetAttrs(new OOXMLPropertySet) + mpPropertySetAttrs(new OOXMLPropertySet), + mbPreserveSpace(false), + mbPreserveSpaceSet(false) { } @@ -907,7 +924,14 @@ OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream() void OOXMLFastContextHandlerStream::newProperty(Id nId, const OOXMLValue::Pointer_t& pVal) { - if (nId != 0x0) + if (nId == NS_ooxml::LN_CT_Text_space) + { + // Set <xml:space> value early, to allow + // child contexts use it when dealing with strings + mbPreserveSpace = pVal->getString() == "preserve"; + mbPreserveSpaceSet = true; + } + else if (nId != 0x0) { OOXMLProperty::Pointer_t pProperty(new OOXMLProperty(nId, pVal, OOXMLProperty::ATTRIBUTE)); @@ -938,6 +962,15 @@ void OOXMLFastContextHandlerStream::handleHyperlink() getPropertySetAttrs()->resolve(aHyperlinkHandler); } +bool OOXMLFastContextHandlerStream::IsPreserveSpace() const +{ + // xml:space attribute applies to all elements within the content of the element where it is specified, + // unless overridden with another instance of the xml:space attribute + if (mbPreserveSpaceSet) + return mbPreserveSpace; + return OOXMLFastContextHandler::IsPreserveSpace(); +} + /* class OOXMLFastContextHandlerProperties */ diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx index e4e3e563fad5..eaf40e27f47b 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx @@ -224,6 +224,9 @@ protected: void startAction(Token_t Element); void endAction(Token_t Element); + // 2.10 of XML 1.0 specification + virtual bool IsPreserveSpace() const; + const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() { return m_xContext;} bool inPositionV; @@ -258,8 +261,13 @@ public: void handleHyperlink(); +protected: + virtual bool IsPreserveSpace() const override; + private: mutable OOXMLPropertySet::Pointer_t mpPropertySetAttrs; + bool mbPreserveSpace : 1; + bool mbPreserveSpaceSet : 1; }; class OOXMLFastContextHandlerProperties : public OOXMLFastContextHandler |