summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-04-14 00:46:15 +0300
committerMichael Stahl <Michael.Stahl@cib.de>2019-04-15 11:00:56 +0200
commit7b6c9c2f52ef80876d494ef966a3ee088c81bcd5 (patch)
tree3ac5ca02c472ccd7500d7f88e119cc586c276b22 /writerfilter
parent64381dad01132f74e513c347db87f304d0e704ff (diff)
tdf#124670: xml:space attribute may be specified for w:document root element
Treat xml:space specially in OOXMLFastContextHandler::startFastElement, to allow this attribute to be handled for any element. Change-Id: I81bd1e0642940ffdfc03d6c65d0ce9f421206c5e Reviewed-on: https://gerrit.libreoffice.org/70723 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/70725 Tested-by: Jenkins Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx31
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.hxx15
2 files changed, 17 insertions, 29 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index ff3da8a3ba5a..be825d2f01d3 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -144,6 +144,13 @@ void SAL_CALL OOXMLFastContextHandler::startFastElement
(Token_t Element,
const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
{
+ // Set xml:space value early, to allow child contexts use it when dealing with strings.
+ if (Attribs && Attribs->hasAttribute(oox::NMSP_xml | oox::XML_space))
+ {
+ mbPreserveSpace = Attribs->getValue(oox::NMSP_xml | oox::XML_space) == "preserve";
+ mbPreserveSpaceSet = true;
+ }
+
if (oox::getNamespace(Element) == NMSP_mce)
m_bDiscardChildren = prepareMceContext(Element, Attribs);
@@ -881,6 +888,8 @@ 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 (mbPreserveSpaceSet)
+ return mbPreserveSpace;
if (mpParent)
return mpParent->IsPreserveSpace();
return false; // default value
@@ -893,9 +902,7 @@ bool OOXMLFastContextHandler::IsPreserveSpace() const
OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream
(OOXMLFastContextHandler * pContext)
: OOXMLFastContextHandler(pContext),
- mpPropertySetAttrs(new OOXMLPropertySet),
- mbPreserveSpace(false),
- mbPreserveSpaceSet(false)
+ mpPropertySetAttrs(new OOXMLPropertySet)
{
}
@@ -906,14 +913,7 @@ OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream()
void OOXMLFastContextHandlerStream::newProperty(Id nId,
const OOXMLValue::Pointer_t& pVal)
{
- 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)
+ if (nId != 0x0)
{
mpPropertySetAttrs->add(nId, pVal, OOXMLProperty::ATTRIBUTE);
}
@@ -943,15 +943,6 @@ void OOXMLFastContextHandlerStream::handleHyperlink()
aHyperlinkHandler.writetext();
}
-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 29842cc5071f..097214b8e049 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -51,7 +51,7 @@ public:
virtual ~OOXMLFastContextHandler() override;
// css::xml::sax::XFastContextHandler:
- virtual void SAL_CALL startFastElement (Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs) override;
+ virtual void SAL_CALL startFastElement (Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs) override final;
virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override;
@@ -224,9 +224,6 @@ protected:
void startAction();
void endAction();
- // 2.10 of XML 1.0 specification
- virtual bool IsPreserveSpace() const;
-
const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() { return m_xContext;}
bool inPositionV;
@@ -237,9 +234,14 @@ private:
/// Handles AlternateContent. Returns true, if children of the current element should be ignored.
bool prepareMceContext(Token_t nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs);
+ // 2.10 of XML 1.0 specification
+ bool IsPreserveSpace() const;
+
css::uno::Reference< css::uno::XComponentContext > m_xContext;
bool m_bDiscardChildren;
bool m_bTookChoice; ///< Did we take the Choice or want Fallback instead?
+ bool mbPreserveSpace = false;
+ bool mbPreserveSpaceSet = false;
};
@@ -259,13 +261,8 @@ 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