diff options
-rw-r--r-- | include/oox/mathml/import.hxx | 11 | ||||
-rw-r--r-- | oox/inc/drawingml/textparagraph.hxx | 13 | ||||
-rw-r--r-- | oox/source/core/xmlfilterbase.cxx | 4 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 51 | ||||
-rw-r--r-- | oox/source/drawingml/textbodycontext.cxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/textparagraph.cxx | 10 | ||||
-rw-r--r-- | oox/source/mathml/import.cxx | 92 | ||||
-rw-r--r-- | sd/qa/unit/export-tests.cxx | 25 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 1 |
9 files changed, 207 insertions, 5 deletions
diff --git a/include/oox/mathml/import.hxx b/include/oox/mathml/import.hxx index 2617ff53e67c..b2ed99b55053 100644 --- a/include/oox/mathml/import.hxx +++ b/include/oox/mathml/import.hxx @@ -9,10 +9,11 @@ #ifndef INCLUDED_OOX_MATHML_IMPORT_HXX #define INCLUDED_OOX_MATHML_IMPORT_HXX -#include <com/sun/star/embed/XEmbeddedObject.hpp> +#include <oox/dllapi.h> + #include <tools/gen.hxx> -#include <oox/dllapi.h> +#include <rtl/ref.hxx> namespace oox { @@ -39,6 +40,12 @@ protected: ~FormulaImportBase() {} }; +namespace core { class ContextHandler; } +namespace drawingml { class TextParagraph; } + +::rtl::Reference<core::ContextHandler> CreateLazyMathBufferingContext( + core::ContextHandler const& rParent, drawingml::TextParagraph & rPara); + } // namespace #endif 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: */ diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index 818ea21afb80..2f9550afda5e 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -1173,7 +1173,30 @@ void SdExportTest::testMathObject() "/p:sld/p:cSld/p:spTree/mc:AlternateContent/mc:Choice/p:sp/p:txBody/a:p/a14:m/m:oMath/m:r[1]/m:t", "a"); - // TODO can't import yet + const SdrPage *pPage = GetPage(1, xDocShRef); + const SdrObject* pObj = dynamic_cast<SdrObject*>(pPage->GetObj(0)); + CPPUNIT_ASSERT_MESSAGE("no object", pObj != nullptr); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(OBJ_OLE2), pObj->GetObjIdentifier()); + } + + utl::TempFile tempFile2; + xDocShRef = saveAndReload( xDocShRef, PPTX, &tempFile2 ); + + // Export an MS specific ole object (imported from a PPTX document) + { + xmlDocPtr pXmlDocContent = parseExport(tempFile1, "ppt/slides/slide1.xml"); + assertXPath(pXmlDocContent, + "/p:sld/p:cSld/p:spTree/mc:AlternateContent/mc:Choice", + "Requires", + "a14"); + assertXPathContent(pXmlDocContent, + "/p:sld/p:cSld/p:spTree/mc:AlternateContent/mc:Choice/p:sp/p:txBody/a:p/a14:m/m:oMath/m:r[1]/m:t", + "a"); + + const SdrPage *pPage = GetPage(1, xDocShRef); + const SdrObject* pObj = dynamic_cast<SdrObject*>(pPage->GetObj(0)); + CPPUNIT_ASSERT_MESSAGE("no object", pObj != nullptr); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(OBJ_OLE2), pObj->GetObjIdentifier()); } xDocShRef->DoClose(); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 4cdd7c052ca8..eeb11a06d73c 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/document/PrinterIndependentLayout.hpp> #include <com/sun/star/document/IndexedPropertyValues.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/embed/XEmbeddedObject.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/style/LineNumberPosition.hpp> |