diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-14 00:46:15 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-14 08:58:53 +0200 |
commit | 4acae16f9252ada89fd530f1ca86edafc046bc07 (patch) | |
tree | 48169dd5320329e55afb644b808a4e48266df700 | |
parent | 1123a47c9771e0f4a680316c034e9878919a85d5 (diff) |
tdf#124670: xml:space attribute may be specified for w:document top-level 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>
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/tdf124670.docx | bin | 0 -> 1434 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 10 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 31 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.hxx | 15 |
4 files changed, 27 insertions, 29 deletions
diff --git a/sw/qa/extras/ooxmlimport/data/tdf124670.docx b/sw/qa/extras/ooxmlimport/data/tdf124670.docx Binary files differnew file mode 100644 index 000000000000..d804efa5a990 --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/tdf124670.docx diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index 213148db627e..2a2efc42da0b 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -331,6 +331,16 @@ DECLARE_OOXMLIMPORT_TEST(testTdf121440, "tdf121440.docx") getProperty<sal_Int32>(getRun(getParagraph(1), 1), "CharEscapement")); } +DECLARE_OOXMLIMPORT_TEST(testTdf124670, "tdf124670.docx") +{ + CPPUNIT_ASSERT_EQUAL(1, getParagraphs()); + // We need to take xml:space attribute into account, even in w:document element + uno::Reference<text::XTextRange> paragraph = getParagraph(1); + CPPUNIT_ASSERT_EQUAL( + OUString("You won't believe, but that's how it was in markup of original bugdoc!"), + paragraph->getString()); +} + // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index abe565112a6c..4b9b8896f139 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -146,6 +146,13 @@ void SAL_CALL OOXMLFastContextHandler::startFastElement (sal_Int32 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); @@ -883,6 +890,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 @@ -895,9 +904,7 @@ bool OOXMLFastContextHandler::IsPreserveSpace() const OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream (OOXMLFastContextHandler * pContext) : OOXMLFastContextHandler(pContext), - mpPropertySetAttrs(new OOXMLPropertySet), - mbPreserveSpace(false), - mbPreserveSpaceSet(false) + mpPropertySetAttrs(new OOXMLPropertySet) { } @@ -908,14 +915,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); } @@ -945,15 +945,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 38653bf29b1b..978e8e5afc22 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 (sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs) override; + virtual void SAL_CALL startFastElement (sal_Int32 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 |