diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-01-21 17:39:26 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-01-21 19:42:56 +0100 |
commit | 332a796366b7cb91dff41de4b9ffb17843112a3e (patch) | |
tree | b578760ddfffde56cfe9e876b3e86a0916ad79a0 /oox/source/mathml | |
parent | a73e606b8cd714520285b4e40890db9fd27d7ba5 (diff) |
oox: import Math objects from PPTX files
This is quite hacky and limited: in OOXML these are not OLE objects but
occur inside text boxes, and PPT 2010 allows inserting multiple Math
objects into one text box but Impress does not have as-character
anchored objects, so we can't import that properly; for now only import
Math if there is nothing else in the text box.
Also for now only import them as children of TextParagraphContext (a:p);
it's not clear what the possible parent elements could be since the
OOXML standard only lists WordProcessingML parent elements :(
Change-Id: I847f810084c9ddae4b60f93896fb73a742683cc2
Diffstat (limited to 'oox/source/mathml')
-rw-r--r-- | oox/source/mathml/import.cxx | 92 |
1 files changed, 91 insertions, 1 deletions
diff --git a/oox/source/mathml/import.cxx b/oox/source/mathml/import.cxx index bf49de250973..5b80dc4e7b06 100644 --- a/oox/source/mathml/import.cxx +++ b/oox/source/mathml/import.cxx @@ -9,6 +9,14 @@ #include "oox/mathml/import.hxx" +#include <oox/mathml/importutils.hxx> +#include <oox/core/contexthandler.hxx> + +#include <drawingml/textparagraph.hxx> + + +using namespace ::com::sun::star; + namespace oox { @@ -16,6 +24,88 @@ FormulaImportBase::FormulaImportBase() { } -} // namespace +namespace formulaimport { + +class LazyMathBufferingContext : public core::ContextHandler +{ +private: + XmlStreamBuilder & m_rBuilder; + long m_Counter; + +public: + LazyMathBufferingContext(core::ContextHandler const& rParent, + drawingml::TextParagraph & rPara); + + // com.sun.star.xml.sax.XFastContextHandler interface --------------------- + + virtual void SAL_CALL startFastElement(::sal_Int32 Element, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override; + virtual void SAL_CALL endFastElement(::sal_Int32 Element) throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override; + virtual uno::Reference< xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(::sal_Int32 Element, const uno::Reference<xml::sax::XFastAttributeList >& xAttribs) throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override; + virtual void SAL_CALL characters(const OUString& rChars) throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override; + +}; + +LazyMathBufferingContext::LazyMathBufferingContext( + core::ContextHandler const& rParent, drawingml::TextParagraph & rPara) + : core::ContextHandler(rParent) + , m_rBuilder(rPara.GetMathXml()) + , m_Counter(0) +{ +} + +void SAL_CALL LazyMathBufferingContext::startFastElement( + sal_Int32 const nElement, + uno::Reference<xml::sax::XFastAttributeList> const& xAttrs) + throw (xml::sax::SAXException, uno::RuntimeException, std::exception) +{ + if (0 < m_Counter) // ignore a14:m + { // ignore outer oMathPara + if (1 != m_Counter || OOX_TOKEN(officeMath, oMathPara) != nElement) + { + m_rBuilder.appendOpeningTag(nElement, xAttrs); + } + } + ++m_Counter; +} + +void SAL_CALL LazyMathBufferingContext::endFastElement(sal_Int32 const nElement) + throw (xml::sax::SAXException, uno::RuntimeException, std::exception) +{ + --m_Counter; + if (0 < m_Counter) // ignore a14:m + { // ignore outer oMathPara + if (1 != m_Counter || OOX_TOKEN(officeMath, oMathPara) != nElement) + { + m_rBuilder.appendClosingTag(nElement); + } + } +} + +uno::Reference<xml::sax::XFastContextHandler> SAL_CALL +LazyMathBufferingContext::createFastChildContext(sal_Int32 const, + uno::Reference<xml::sax::XFastAttributeList> const&) + throw (xml::sax::SAXException, uno::RuntimeException, std::exception) +{ + return this; +} + +void SAL_CALL LazyMathBufferingContext::characters(OUString const& rChars) + throw (xml::sax::SAXException, uno::RuntimeException, std::exception) +{ + if (0 < m_Counter) // ignore a14:m + { + m_rBuilder.appendCharacters(rChars); + } +} + +} // namespace formulaimport + +core::ContextHandlerRef CreateLazyMathBufferingContext( + core::ContextHandler const& rParent, drawingml::TextParagraph & rPara) +{ + return new formulaimport::LazyMathBufferingContext(rParent, rPara); +} + +} // namespace oox /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |