summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-01-21 17:39:26 +0100
committerMichael Stahl <mstahl@redhat.com>2016-01-21 19:42:56 +0100
commit332a796366b7cb91dff41de4b9ffb17843112a3e (patch)
treeb578760ddfffde56cfe9e876b3e86a0916ad79a0 /oox
parenta73e606b8cd714520285b4e40890db9fd27d7ba5 (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')
-rw-r--r--oox/inc/drawingml/textparagraph.hxx13
-rw-r--r--oox/source/core/xmlfilterbase.cxx4
-rw-r--r--oox/source/drawingml/shape.cxx51
-rw-r--r--oox/source/drawingml/textbodycontext.cxx5
-rw-r--r--oox/source/drawingml/textparagraph.cxx10
-rw-r--r--oox/source/mathml/import.cxx92
6 files changed, 173 insertions, 2 deletions
diff --git a/oox/inc/drawingml/textparagraph.hxx b/oox/inc/drawingml/textparagraph.hxx
index f96989cffa8e..43bf51a363fa 100644
--- a/oox/inc/drawingml/textparagraph.hxx
+++ b/oox/inc/drawingml/textparagraph.hxx
@@ -28,6 +28,11 @@
#include <drawingml/textliststyle.hxx>
#include <drawingml/textparagraphproperties.hxx>
+
+namespace oox { namespace formulaimport {
+ class XmlStreamBuilder;
+} }
+
namespace oox { namespace drawingml {
typedef RefVector< TextRun > TextRunVector;
@@ -57,10 +62,18 @@ public:
bool bFirst = false,
float nDefaultCharHeight = 0) const;
+ bool HasMathXml() const
+ {
+ return m_pMathXml != nullptr;
+ }
+ formulaimport::XmlStreamBuilder & GetMathXml();
+
private:
TextParagraphProperties maProperties;
TextCharacterProperties maEndProperties;
TextRunVector maRuns;
+ // temporarily store this here
+ std::unique_ptr<formulaimport::XmlStreamBuilder> m_pMathXml;
};
} }
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index ea1721d46f12..062a600981c6 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -129,11 +129,15 @@ struct NamespaceIds: public rtl::StaticWithInit<
NMSP_mce},
{"http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2",
NMSP_mceTest},
+ {"http://schemas.openxmlformats.org/officeDocument/2006/math",
+ NMSP_officeMath},
{"http://schemas.microsoft.com/office/drawing/2008/diagram",
NMSP_dsp},
{"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
NMSP_xls14Lst},
{"http://schemas.libreoffice.org/", NMSP_loext},
+ {"http://schemas.microsoft.com/office/drawing/2010/main",
+ NMSP_a14},
{"http://schemas.microsoft.com/office/powerpoint/2010/main",
NMSP_p14},
{"http://schemas.microsoft.com/office/powerpoint/2012/main",
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index b744bb142cac..9d12b5035205 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -27,6 +27,7 @@
#include "effectproperties.hxx"
#include "oox/drawingml/shapepropertymap.hxx"
#include "drawingml/textbody.hxx"
+#include <drawingml/textparagraph.hxx>
#include <drawingml/ThemeOverrideFragmentHandler.hxx>
#include "drawingml/table/tableproperties.hxx"
#include "oox/drawingml/chart/chartconverter.hxx"
@@ -40,8 +41,12 @@
#include "oox/helper/graphichelper.hxx"
#include "oox/helper/propertyset.hxx"
#include "oox/helper/modelobjecthelper.hxx"
+#include <oox/mathml/importutils.hxx>
+#include <oox/mathml/import.hxx>
+#include <comphelper/classids.hxx>
#include <tools/gen.hxx>
+#include <tools/globname.hxx>
#include <tools/mapunit.hxx>
#include <editeng/unoprnms.hxx>
#include <com/sun/star/awt/Size.hpp>
@@ -55,6 +60,7 @@
#include <com/sun/star/drawing/HomogenMatrix3.hpp>
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
#include <com/sun/star/drawing/GraphicExportFilter.hpp>
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/table/ShadowFormat.hpp>
@@ -407,6 +413,25 @@ Reference< XShape > Shape::createAndInsert(
bool bIsEmbMedia = false;
SAL_INFO("oox.drawingml", OSL_THIS_FUNC << " id: " << msId);
+ formulaimport::XmlStreamBuilder * pMathXml(nullptr);
+ if (mpTextBody.get())
+ {
+ for (auto const& it : mpTextBody->getParagraphs())
+ {
+ if (it->HasMathXml())
+ {
+ if (!mpTextBody->isEmpty() || pMathXml != nullptr)
+ {
+ SAL_WARN("oox.drawingml", "losing a Math object...");
+ }
+ else
+ {
+ pMathXml = &it->GetMathXml();
+ }
+ }
+ }
+ }
+
// tdf#90403 PowerPoint ignores a:ext cx and cy values of p:xfrm, and uses real table width and height
if ( mpTablePropertiesPtr.get() && rServiceName == "com.sun.star.drawing.TableShape" )
{
@@ -427,7 +452,15 @@ Reference< XShape > Shape::createAndInsert(
awt::Rectangle aShapeRectHmm( maPosition.X / EMU_PER_HMM, maPosition.Y / EMU_PER_HMM, maSize.Width / EMU_PER_HMM, maSize.Height / EMU_PER_HMM );
OUString aServiceName;
- if( rServiceName == "com.sun.star.drawing.GraphicObjectShape" &&
+ if (pMathXml)
+ {
+ // convert this shape to OLE
+ aServiceName = "com.sun.star.drawing.OLE2Shape";
+ msServiceName = aServiceName;
+ meFrameType = FRAMETYPE_GENERIC; // not OLEOBJECT, no stream in package
+ mnSubType = 0;
+ }
+ else if (rServiceName == "com.sun.star.drawing.GraphicObjectShape" &&
mpGraphicPropertiesPtr && !mpGraphicPropertiesPtr->m_sMediaPackageURL.isEmpty())
{
aServiceName = finalizeServiceName( rFilterBase, "com.sun.star.presentation.MediaShape", aShapeRectHmm );
@@ -605,6 +638,22 @@ Reference< XShape > Shape::createAndInsert(
}
}
+ if (pMathXml)
+ {
+ // the "EmbeddedObject" property is read-only, so we have to create
+ // the shape first, and it can be read only after the shape is
+ // inserted into the document, so delay the actual import until here
+ SvGlobalName name(SO3_SM_CLASSID);
+ xSet->setPropertyValue("CLSID", uno::makeAny(name.GetHexName()));
+ uno::Reference<embed::XEmbeddedObject> const xObj(
+ xSet->getPropertyValue("EmbeddedObject"), uno::UNO_QUERY);
+ uno::Reference<uno::XInterface> const xMathModel(xObj->getComponent());
+ oox::FormulaImportBase *const pMagic(
+ dynamic_cast<oox::FormulaImportBase*>(xMathModel.get()));
+ assert(pMagic);
+ pMagic->readFormulaOoxml(*pMathXml);
+ }
+
const GraphicHelper& rGraphicHelper = rFilterBase.getGraphicHelper();
LineProperties aLineProperties;
diff --git a/oox/source/drawingml/textbodycontext.cxx b/oox/source/drawingml/textbodycontext.cxx
index 20d3b2683d2d..84fc7690b331 100644
--- a/oox/source/drawingml/textbodycontext.cxx
+++ b/oox/source/drawingml/textbodycontext.cxx
@@ -26,6 +26,8 @@
#include "drawingml/textfield.hxx"
#include "drawingml/textfieldcontext.hxx"
+#include <oox/mathml/import.hxx>
+
using namespace ::oox::core;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::text;
@@ -90,6 +92,9 @@ ContextHandlerRef TextParagraphContext::onCreateContext( sal_Int32 aElementToken
case W_TOKEN( ins ):
return this;
break;
+ case OOX_TOKEN(a14, m):
+ return CreateLazyMathBufferingContext(*this, mrParagraph);
+ break;
default:
SAL_WARN("oox", "TextParagraphContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
}
diff --git a/oox/source/drawingml/textparagraph.cxx b/oox/source/drawingml/textparagraph.cxx
index 76d299a39d44..5d49659fa5b6 100644
--- a/oox/source/drawingml/textparagraph.cxx
+++ b/oox/source/drawingml/textparagraph.cxx
@@ -22,6 +22,7 @@
#include "drawingml/textcharacterproperties.hxx"
#include <rtl/ustring.hxx>
+#include <oox/mathml/importutils.hxx>
#include "oox/helper/propertyset.hxx"
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/text/XTextCursor.hpp>
@@ -138,6 +139,15 @@ void TextParagraph::insertAt(
}
}
+formulaimport::XmlStreamBuilder & TextParagraph::GetMathXml()
+{
+ if (!m_pMathXml)
+ {
+ m_pMathXml.reset(new formulaimport::XmlStreamBuilder);
+ }
+ return *m_pMathXml;
+}
+
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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: */