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")
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();
......
......@@ -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
*/
......
......@@ -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
......
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