[Libreoffice-commits] core.git: 2 commits - include/oox oox/source sd/qa

Michael Stahl mstahl at redhat.com
Fri Jan 15 07:48:50 PST 2016


 include/oox/export/shapes.hxx |    1 
 oox/source/export/shapes.cxx  |   90 +++++++++++++++++++++++++++++++++++++-----
 sd/qa/unit/export-tests.cxx   |   28 +++++++++++++
 3 files changed, 109 insertions(+), 10 deletions(-)

New commits:
commit a951d70609fa125def231c3d7579e72c381334f5
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Jan 11 17:16:24 2016 +0100

    oox: getEntryName() could throw a WrongStateException
    
    let's guard against that.
    
    Change-Id: I970fb801a642592d9c23390572867f0e21f03132

diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 0facbf1..b4e7b13 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -1678,15 +1678,24 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
         return *this;
     }
 
-    uno::Reference<beans::XPropertySet> const xParent(
-        uno::Reference<container::XChild>(xObj, uno::UNO_QUERY)->getParent(),
-        uno::UNO_QUERY);
-
     uno::Sequence<beans::PropertyValue> grabBag;
-    xParent->getPropertyValue("InteropGrabBag") >>= grabBag;
+    OUString entryName;
+    try
+    {
+        uno::Reference<beans::XPropertySet> const xParent(
+            uno::Reference<container::XChild>(xObj, uno::UNO_QUERY_THROW)->getParent(),
+            uno::UNO_QUERY_THROW);
+
+        xParent->getPropertyValue("InteropGrabBag") >>= grabBag;
+
+        entryName = uno::Reference<embed::XEmbedPersist>(xObj, uno::UNO_QUERY)->getEntryName();
+    }
+    catch (uno::Exception const& e)
+    {
+        SAL_WARN("oox", "ShapeExport::WriteOLE2Shape: exception: " << e.Message);
+        return *this;
+    }
 
-    OUString const entryName(
-        uno::Reference<embed::XEmbedPersist>(xObj, uno::UNO_QUERY)->getEntryName());
     OUString progID;
 
     for (auto const& it : grabBag)
commit cb890ae43bacd2be24bc74fad2e2e5cce8910995
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Jan 15 15:26:43 2016 +0100

    oox: export Math objects to PPTX files
    
    These hit the assert in lcl_StoreOwnAsOOXML now so better implement some
    export.
    
    Change-Id: I10c005a547e8a85f2a82198a49f9a03fc46a61d7

diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx
index 29f597f..ab67def 100644
--- a/include/oox/export/shapes.hxx
+++ b/include/oox/export/shapes.hxx
@@ -180,6 +180,7 @@ public:
                         WriteTextShape( css::uno::Reference< css::drawing::XShape > xShape );
     ShapeExport&
                         WriteTableShape( css::uno::Reference< css::drawing::XShape > xShape );
+    void                WriteMathShape(css::uno::Reference<css::drawing::XShape> const& xShape);
     ShapeExport&
                         WriteOLE2Shape( css::uno::Reference< css::drawing::XShape > xShape );
     virtual ShapeExport&
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 8320aad..0facbf1 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -93,6 +93,7 @@
 #include <editeng/svxenum.hxx>
 #include <svx/unoapi.hxx>
 #include <oox/export/chartexport.hxx>
+#include <oox/mathml/export.hxx>
 
 using namespace ::css;
 using namespace ::css::beans;
@@ -1578,13 +1579,64 @@ ShapeExport& ShapeExport::WriteTextShape( Reference< XShape > xShape )
     return *this;
 }
 
+void ShapeExport::WriteMathShape(Reference<XShape> const& xShape)
+{
+    Reference<XPropertySet> const xPropSet(xShape, UNO_QUERY);
+    assert(xPropSet.is());
+    Reference<XModel> xMathModel;
+    xPropSet->getPropertyValue("Model") >>= xMathModel;
+    assert(xMathModel.is());
+    assert(GetDocumentType() != DOCUMENT_DOCX); // should be written in DocxAttributeOutput
+    SAL_WARN_IF(GetDocumentType() == DOCUMENT_XLSX, "oox", "Math export to XLSX isn't tested, should it happen here?");
+
+    // ECMA standard does not actually allow oMath outside of
+    // WordProcessingML so write a MCE like PPT 2010 does
+    mpFS->startElementNS(XML_mc, XML_AlternateContent, FSEND);
+    mpFS->startElementNS(XML_mc, XML_Choice,
+        FSNS(XML_xmlns, XML_a14), "http://schemas.microsoft.com/office/drawing/2010/main",
+        XML_Requires, "a14",
+        FSEND);
+    mpFS->startElementNS(mnXmlNamespace, XML_sp, FSEND);
+    mpFS->startElementNS(mnXmlNamespace, XML_nvSpPr, FSEND);
+    mpFS->singleElementNS(mnXmlNamespace, XML_cNvPr,
+         XML_id, OString::number(GetNewShapeID(xShape)).getStr(),
+         XML_name, OString("Formula " + OString::number(mnShapeIdMax++)).getStr(),
+         FSEND);
+    mpFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr, XML_txBox, "1", FSEND);
+    mpFS->singleElementNS(mnXmlNamespace, XML_nvPr, FSEND);
+    mpFS->endElementNS(mnXmlNamespace, XML_nvSpPr);
+    mpFS->startElementNS(mnXmlNamespace, XML_spPr, FSEND);
+    WriteShapeTransformation(xShape, XML_a);
+    WritePresetShape("rect");
+    mpFS->endElementNS(mnXmlNamespace, XML_spPr);
+    mpFS->startElementNS(mnXmlNamespace, XML_txBody, FSEND);
+    mpFS->startElementNS(XML_a, XML_bodyPr, FSEND);
+    mpFS->endElementNS(XML_a, XML_bodyPr);
+    mpFS->startElementNS(XML_a, XML_p, FSEND);
+    mpFS->startElementNS(XML_a14, XML_m, FSEND);
+
+    oox::FormulaExportBase *const pMagic(dynamic_cast<oox::FormulaExportBase*>(xMathModel.get()));
+    assert(pMagic);
+    pMagic->writeFormulaOoxml(GetFS(), GetFB()->getVersion(), GetDocumentType());
+
+    mpFS->endElementNS(XML_a14, XML_m);
+    mpFS->endElementNS(XML_a, XML_p);
+    mpFS->endElementNS(mnXmlNamespace, XML_txBody);
+    mpFS->endElementNS(mnXmlNamespace, XML_sp);
+    mpFS->endElementNS(XML_mc, XML_Choice);
+    mpFS->startElementNS(XML_mc, XML_Fallback, FSEND);
+    // TODO: export bitmap shape as fallback
+    mpFS->endElementNS(XML_mc, XML_Fallback);
+    mpFS->endElementNS(XML_mc, XML_AlternateContent);
+}
+
 ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
 {
     Reference< XPropertySet > xPropSet( xShape, UNO_QUERY );
     if (!xPropSet.is())
         return *this;
 
-    bool bIsChart(false);
+    enum { CHART, MATH, OTHER } eType(OTHER);
     OUString clsid;
     xPropSet->getPropertyValue("CLSID") >>= clsid;
     if (!clsid.isEmpty())
@@ -1592,10 +1644,13 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
         SvGlobalName aClassID;
         bool const isValid = aClassID.MakeId(clsid);
         assert(isValid); (void)isValid;
-        bIsChart = SotExchange::IsChart(aClassID);
+        if (SotExchange::IsChart(aClassID))
+            eType = CHART;
+        else if (SotExchange::IsMath(aClassID))
+            eType = MATH;
     }
 
-    if (bIsChart)
+    if (CHART == eType)
     {
         Reference< XChartDocument > xChartDoc;
         xPropSet->getPropertyValue("Model") >>= xChartDoc;
@@ -1608,6 +1663,12 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
         return *this;
     }
 
+    if (MATH == eType)
+    {
+        WriteMathShape(xShape);
+        return *this;
+    }
+
     uno::Reference<embed::XEmbeddedObject> const xObj(
         xPropSet->getPropertyValue("EmbeddedObject"), uno::UNO_QUERY);
 
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index 102a3f4..818ea21 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -141,6 +141,7 @@ public:
     void testFdo90607();
     void testTdf91378();
     void testBnc822341();
+    void testMathObject();
     void testTdf80224();
     void testTdf92527();
 
@@ -180,6 +181,7 @@ public:
     CPPUNIT_TEST(testTdf91378);
 
     CPPUNIT_TEST(testBnc822341);
+    CPPUNIT_TEST(testMathObject);
     CPPUNIT_TEST(testTdf80224);
 
     CPPUNIT_TEST(testExportTransitionsPPTX);
@@ -208,10 +210,12 @@ public:
             { "v", "urn:schemas-microsoft-com:vml" },
             { "a", "http://schemas.openxmlformats.org/drawingml/2006/main" },
             { "c", "http://schemas.openxmlformats.org/drawingml/2006/chart" },
+            { "m", "http://schemas.openxmlformats.org/officeDocument/2006/math" },
             { "pic", "http://schemas.openxmlformats.org/drawingml/2006/picture" },
             { "wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" },
             { "p", "http://schemas.openxmlformats.org/presentationml/2006/main" },
             { "w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main" },
+            { "a14", "http://schemas.microsoft.com/office/drawing/2010/main" },
             { "wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape" },
             { "wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" },
         };
@@ -1151,6 +1155,30 @@ void SdExportTest::testBnc822341()
     xDocShRef->DoClose();
 }
 
+void SdExportTest::testMathObject()
+{
+    // Check import / export of math object
+    ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("sd/qa/unit/data/odp/math.odp"), ODP);
+    utl::TempFile tempFile1;
+    xDocShRef = saveAndReload(xDocShRef, PPTX, &tempFile1);
+
+    // Export an LO specific ole object (imported from an ODP 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");
+
+        // TODO can't import yet
+    }
+
+    xDocShRef->DoClose();
+}
+
 void SdExportTest::testBulletMarginAndIndentation()
 {
     ::sd::DrawDocShellRef xDocShRef = loadURL( getURLFromSrc("/sd/qa/unit/data/pptx/bulletMarginAndIndent.pptx"), PPTX );


More information about the Libreoffice-commits mailing list