[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - sw/qa writerfilter/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Mon Apr 15 09:01:37 UTC 2019
sw/qa/extras/ooxmlimport/data/tdf124670.docx |binary
sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 10 +++++
writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 31 ++++++------------
writerfilter/source/ooxml/OOXMLFastContextHandler.hxx | 15 +++-----
4 files changed, 27 insertions(+), 29 deletions(-)
New commits:
commit 7b6c9c2f52ef80876d494ef966a3ee088c81bcd5
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Apr 14 00:46:15 2019 +0300
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Mon Apr 15 11:00:56 2019 +0200
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 at collabora.com>
Tested-by: Mike Kaganski <mike.kaganski at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/70725
Tested-by: Jenkins
Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
diff --git a/sw/qa/extras/ooxmlimport/data/tdf124670.docx b/sw/qa/extras/ooxmlimport/data/tdf124670.docx
new file mode 100644
index 000000000000..d804efa5a990
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf124670.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 991573fd40af..a74501cd708c 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -330,6 +330,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 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
More information about the Libreoffice-commits
mailing list