summaryrefslogtreecommitdiff
path: root/writerfilter/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2013-11-14 09:37:06 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-11-14 10:04:21 +0100
commit43796f03e97fa1f61c66ba12c69c2ece1d6d3870 (patch)
tree92679c44c89a4e1063f82fff2b5c8cd200bb2634 /writerfilter/source
parente2beb3ee1519ecb790c157853050d3b352d3839c (diff)
writerfilter: improve mc:AlternateContent support
Commit af7d4a5ebf3e6a09cd2079f241dee16aa22e0276 (n#820503: initial MCE support in writerfilter ooxml tokenizer, 2013-07-03) introduced initial support for this, always reading the Fallback branch. Improve this, so an array can contain the list of features we support. Change-Id: I2d6ba2207f6bfc62dc1e15c1a605311ede1d7eeb
Diffstat (limited to 'writerfilter/source')
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx49
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.hxx3
2 files changed, 47 insertions, 5 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 206c885664f9..e6abeecdc320 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -27,6 +27,7 @@
#include <resourcemodel/util.hxx>
#include <ooxml/resourceids.hxx>
#include <doctok/sprmids.hxx>
+#include <oox/token/namespaces.hxx>
#include <ooxml/OOXMLnamespaceids.hxx>
#include <dmapper/DomainMapper.hxx>
#include <dmapper/GraphicHelpers.hxx>
@@ -128,7 +129,8 @@ OOXMLFastContextHandler::OOXMLFastContextHandler
mnRefCount(0),
inPositionV(false),
m_xContext(context),
- m_bDiscardChildren(false)
+ m_bDiscardChildren(false),
+ m_bTookChoice(false)
{
mnInstanceCount++;
aSetContexts.insert(this);
@@ -152,7 +154,8 @@ OOXMLFastContextHandler::OOXMLFastContextHandler
mnRefCount(0),
inPositionV(pContext->inPositionV),
m_xContext(pContext->m_xContext),
- m_bDiscardChildren(pContext->m_bDiscardChildren)
+ m_bDiscardChildren(pContext->m_bDiscardChildren),
+ m_bTookChoice(pContext->m_bTookChoice)
{
if (pContext != NULL)
{
@@ -175,6 +178,42 @@ OOXMLFastContextHandler::~OOXMLFastContextHandler()
aSetContexts.erase(this);
}
+bool OOXMLFastContextHandler::prepareMceContext(Token_t nElement, const uno::Reference<xml::sax::XFastAttributeList>& rAttribs)
+{
+ switch (oox::getBaseToken(nElement))
+ {
+ case OOXML_AlternateContent:
+ break;
+ case OOXML_Choice:
+ {
+ OUString aRequires = rAttribs->getOptionalValue(OOXML_Requires);
+#if 0 // Disabled for now: enabling "wps" would introduce regressions, and SAL_N_ELEMENTS() needs at least one element.
+ static const char* aFeatures[] = {
+ "wps",
+ };
+ for (size_t i = 0; i < SAL_N_ELEMENTS(aFeatures); ++i)
+ {
+ if (aRequires.equalsAscii(aFeatures[i]))
+ {
+ m_bTookChoice = true;
+ return false;
+ }
+ }
+#endif
+ return true;
+ }
+ break;
+ case OOXML_Fallback:
+ // If Choice is already taken, then let's ignore the Fallback.
+ return m_bTookChoice;
+ break;
+ default:
+ SAL_WARN("writerfilter", "OOXMLFastContextHandler::prepareMceContext: unhandled element:" << oox::getBaseToken(nElement));
+ break;
+ }
+ return false;
+}
+
// ::com::sun::star::xml::sax::XFastContextHandler:
void SAL_CALL OOXMLFastContextHandler::startFastElement
(Token_t Element,
@@ -192,8 +231,8 @@ void SAL_CALL OOXMLFastContextHandler::startFastElement
dumpXml( debug_logger );
debug_logger->endElement();
#endif
- if ((Element & 0xffff0000) == NS_mce && (Element & 0xffff) == OOXML_Choice)
- m_bDiscardChildren = true;
+ if (oox::getNamespace(Element) == static_cast<sal_Int32>(NS_mce))
+ m_bDiscardChildren = prepareMceContext(Element, Attribs);
if (!m_bDiscardChildren)
{
@@ -226,7 +265,7 @@ throw (uno::RuntimeException, xml::sax::SAXException)
(void) sToken;
#endif
- if ((Element & 0xffff0000) == NS_mce && (Element & 0xffff) == OOXML_Choice)
+ if (Element == (NS_mce | OOXML_Choice) || Element == (NS_mce | OOXML_Fallback))
m_bDiscardChildren = false;
if (!m_bDiscardChildren)
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index d26dcda7b482..14a49a35d03e 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -287,9 +287,12 @@ protected:
private:
void operator =(OOXMLFastContextHandler &); // not defined
+ /// Handles AlternateContent. Returns true, if children of the current element should be ignored.
+ bool prepareMceContext(Token_t nElement, const uno::Reference<xml::sax::XFastAttributeList>& Attribs);
uno::Reference< uno::XComponentContext > m_xContext;
bool m_bDiscardChildren;
+ bool m_bTookChoice; ///< Did we take the Choice or want Fallback instead?
static sal_uInt32 mnInstanceCount;