Kaydet (Commit) 4acae16f authored tarafından Mike Kaganski's avatar Mike Kaganski

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/70723Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 1123a47c
...@@ -331,6 +331,16 @@ DECLARE_OOXMLIMPORT_TEST(testTdf121440, "tdf121440.docx") ...@@ -331,6 +331,16 @@ DECLARE_OOXMLIMPORT_TEST(testTdf121440, "tdf121440.docx")
getProperty<sal_Int32>(getRun(getParagraph(1), 1), "CharEscapement")); 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 // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -146,6 +146,13 @@ void SAL_CALL OOXMLFastContextHandler::startFastElement ...@@ -146,6 +146,13 @@ void SAL_CALL OOXMLFastContextHandler::startFastElement
(sal_Int32 Element, (sal_Int32 Element,
const uno::Reference< xml::sax::XFastAttributeList > & Attribs) 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) if (oox::getNamespace(Element) == NMSP_mce)
m_bDiscardChildren = prepareMceContext(Element, Attribs); m_bDiscardChildren = prepareMceContext(Element, Attribs);
...@@ -883,6 +890,8 @@ bool OOXMLFastContextHandler::IsPreserveSpace() const ...@@ -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, // 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 // unless overridden with another instance of the xml:space attribute
if (mbPreserveSpaceSet)
return mbPreserveSpace;
if (mpParent) if (mpParent)
return mpParent->IsPreserveSpace(); return mpParent->IsPreserveSpace();
return false; // default value return false; // default value
...@@ -895,9 +904,7 @@ bool OOXMLFastContextHandler::IsPreserveSpace() const ...@@ -895,9 +904,7 @@ bool OOXMLFastContextHandler::IsPreserveSpace() const
OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream
(OOXMLFastContextHandler * pContext) (OOXMLFastContextHandler * pContext)
: OOXMLFastContextHandler(pContext), : OOXMLFastContextHandler(pContext),
mpPropertySetAttrs(new OOXMLPropertySet), mpPropertySetAttrs(new OOXMLPropertySet)
mbPreserveSpace(false),
mbPreserveSpaceSet(false)
{ {
} }
...@@ -908,14 +915,7 @@ OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream() ...@@ -908,14 +915,7 @@ OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream()
void OOXMLFastContextHandlerStream::newProperty(Id nId, void OOXMLFastContextHandlerStream::newProperty(Id nId,
const OOXMLValue::Pointer_t& pVal) const OOXMLValue::Pointer_t& pVal)
{ {
if (nId == NS_ooxml::LN_CT_Text_space) if (nId != 0x0)
{
// 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)
{ {
mpPropertySetAttrs->add(nId, pVal, OOXMLProperty::ATTRIBUTE); mpPropertySetAttrs->add(nId, pVal, OOXMLProperty::ATTRIBUTE);
} }
...@@ -945,15 +945,6 @@ void OOXMLFastContextHandlerStream::handleHyperlink() ...@@ -945,15 +945,6 @@ void OOXMLFastContextHandlerStream::handleHyperlink()
aHyperlinkHandler.writetext(); 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 class OOXMLFastContextHandlerProperties
*/ */
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
virtual ~OOXMLFastContextHandler() override; virtual ~OOXMLFastContextHandler() override;
// css::xml::sax::XFastContextHandler: // 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; 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: ...@@ -224,9 +224,6 @@ protected:
void startAction(); void startAction();
void endAction(); void endAction();
// 2.10 of XML 1.0 specification
virtual bool IsPreserveSpace() const;
const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() { return m_xContext;} const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() { return m_xContext;}
bool inPositionV; bool inPositionV;
...@@ -237,9 +234,14 @@ private: ...@@ -237,9 +234,14 @@ private:
/// Handles AlternateContent. Returns true, if children of the current element should be ignored. /// 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); 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; css::uno::Reference< css::uno::XComponentContext > m_xContext;
bool m_bDiscardChildren; bool m_bDiscardChildren;
bool m_bTookChoice; ///< Did we take the Choice or want Fallback instead? bool m_bTookChoice; ///< Did we take the Choice or want Fallback instead?
bool mbPreserveSpace = false;
bool mbPreserveSpaceSet = false;
}; };
...@@ -259,13 +261,8 @@ public: ...@@ -259,13 +261,8 @@ public:
void handleHyperlink(); void handleHyperlink();
protected:
virtual bool IsPreserveSpace() const override;
private: private:
mutable OOXMLPropertySet::Pointer_t mpPropertySetAttrs; mutable OOXMLPropertySet::Pointer_t mpPropertySetAttrs;
bool mbPreserveSpace : 1;
bool mbPreserveSpaceSet : 1;
}; };
class OOXMLFastContextHandlerProperties : public OOXMLFastContextHandler class OOXMLFastContextHandlerProperties : public OOXMLFastContextHandler
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment