oox/source/export/shapes.cxx       |   64 ++++++++++++++++++++++---------------
 sd/qa/unit/data/odp/linked_ole.odp |binary
 sd/qa/unit/export-tests-ooxml3.cxx |   18 ++++++++++
 3 files changed, 57 insertions(+), 25 deletions(-)

New commits:
commit 34ca1dca73ca03cbec1cfeab79f2e11e36af1280
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Tue Jan 24 15:02:09 2023 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jan 31 11:36:41 2023 +0000

    tdf#153185 PPTX: fix export of linked OLE objects
    
    Linked OLE objects were not exported.
    
    Change-Id: If6e8c6e0d0c9917e8ec476ad14dcaa1602c74b29
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146073
    Tested-by: Jenkins
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit f589d7e769bee4b82826a944fed3cf2382d84fb2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146319
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 4b41f56d79cd..4ef05ba80cab 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -2601,49 +2601,60 @@ ShapeExport& ShapeExport::WriteOLE2Shape( const 
Reference< XShape >& xShape )
     OUString sRelationType;
     OUString sSuffix;
     const char * pProgID(nullptr);
+    OString anotherProgID;
 
     uno::Reference<io::XInputStream> const xInStream =
         oox::GetOLEObjectStream(
             mpFB->getComponentContext(), xObj, progID,
             sMediaType, sRelationType, sSuffix, pProgID);
 
+    OUString sURL;
+    OUString sRelId;
     if (!xInStream.is())
     {
-        return *this;
-    }
+        xPropSet->getPropertyValue("LinkURL") >>= sURL;
+        if (sURL.isEmpty())
+            return *this;
 
-    OString anotherProgID;
-    if (!pProgID && !progID.isEmpty())
-    {
-        anotherProgID = OUStringToOString(progID, RTL_TEXTENCODING_UTF8);
-        pProgID = anotherProgID.getStr();
+        sRelId = mpFB->addRelation(mpFS->getOutputStream(),
+                                   
oox::getRelationship(Relationship::OLEOBJECT), sURL, true);
     }
+    else
+    {
+        if (!pProgID && !progID.isEmpty())
+        {
+            anotherProgID = OUStringToOString(progID, RTL_TEXTENCODING_UTF8);
+            pProgID = anotherProgID.getStr();
+        }
+
+        assert(!sMediaType.isEmpty());
+        assert(!sRelationType.isEmpty());
+        assert(!sSuffix.isEmpty());
 
-    assert(!sMediaType.isEmpty());
-    assert(!sRelationType.isEmpty());
-    assert(!sSuffix.isEmpty());
+        OUString sFileName
+            = "embeddings/oleObject" + OUString::number(++m_nEmbeddedObjects) 
+ "." + sSuffix;
+        uno::Reference<io::XOutputStream> const 
xOutStream(mpFB->openFragmentStream(
+            OUString::createFromAscii(GetComponentDir()) + "/" + sFileName, 
sMediaType));
+        assert(xOutStream.is()); // no reason why that could fail
 
-    OUString sFileName = "embeddings/oleObject" + 
OUString::number(++m_nEmbeddedObjects) + "." + sSuffix;
-    uno::Reference<io::XOutputStream> const xOutStream(
-        mpFB->openFragmentStream(
-            OUString::createFromAscii(GetComponentDir()) + "/" + sFileName,
-            sMediaType));
-    assert(xOutStream.is()); // no reason why that could fail
+        try
+        {
+            ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, 
xOutStream);
+        }
+        catch (uno::Exception const&)
+        {
+            TOOLS_WARN_EXCEPTION("oox.shape", "ShapeExport::WriteOLEObject");
+        }
 
-    try {
-        ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream);
-    } catch (uno::Exception const&) {
-        TOOLS_WARN_EXCEPTION("oox.shape", "ShapeExport::WriteOLEObject");
+        sRelId = mpFB->addRelation(
+            mpFS->getOutputStream(), sRelationType,
+            Concat2View(OUString::createFromAscii(GetRelationCompPrefix()) + 
sFileName));
     }
 
     sal_Int64 nAspect;
     bool bShowAsIcon = (xPropSet->getPropertyValue("Aspect") >>= nAspect)
                        && nAspect == embed::Aspects::MSOLE_ICON;
 
-    OUString const sRelId = mpFB->addRelation(
-        mpFS->getOutputStream(), sRelationType,
-        Concat2View(OUString::createFromAscii(GetRelationCompPrefix()) + 
sFileName));
-
     mpFS->startElementNS(mnXmlNamespace, XML_graphicFrame);
 
     mpFS->startElementNS(mnXmlNamespace, XML_nvGraphicFramePr);
@@ -2681,7 +2692,10 @@ ShapeExport& ShapeExport::WriteOLE2Shape( const 
Reference< XShape >& xShape )
                           XML_spid, "" );
     }
 
-    mpFS->singleElementNS( mnXmlNamespace, XML_embed );
+    if (sURL.isEmpty())
+        mpFS->singleElementNS(mnXmlNamespace, XML_embed);
+    else
+        mpFS->singleElementNS(mnXmlNamespace, XML_link, XML_updateAutomatic, 
"1");
 
     // pic element
     SdrObject* pSdrOLE2(SdrObject::getSdrObjectFromXShape(xShape));
diff --git a/sd/qa/unit/data/odp/linked_ole.odp 
b/sd/qa/unit/data/odp/linked_ole.odp
new file mode 100644
index 000000000000..13fb0a845a13
Binary files /dev/null and b/sd/qa/unit/data/odp/linked_ole.odp differ
diff --git a/sd/qa/unit/export-tests-ooxml3.cxx 
b/sd/qa/unit/export-tests-ooxml3.cxx
index db023bef2592..287f35cc3637 100644
--- a/sd/qa/unit/export-tests-ooxml3.cxx
+++ b/sd/qa/unit/export-tests-ooxml3.cxx
@@ -131,6 +131,7 @@ public:
     void testAutofittedTextboxIndent();
     void testTdf151622_oleIcon();
     void testTdf152436();
+    void testLinkedOLE();
 
     CPPUNIT_TEST_SUITE(SdOOXMLExportTest3);
 
@@ -223,6 +224,7 @@ public:
     CPPUNIT_TEST(testAutofittedTextboxIndent);
     CPPUNIT_TEST(testTdf151622_oleIcon);
     CPPUNIT_TEST(testTdf152436);
+    CPPUNIT_TEST(testLinkedOLE);
     CPPUNIT_TEST_SUITE_END();
 
     virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override
@@ -2117,6 +2119,22 @@ void SdOOXMLExportTest3::testTdf152436()
     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getPage(0)->getCount());
 }
 
+void SdOOXMLExportTest3::testLinkedOLE()
+{
+    createSdImpressDoc("odp/linked_ole.odp");
+
+    save("Impress Office Open XML");
+
+    xmlDocUniquePtr pXml = parseExport("ppt/slides/slide1.xml");
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // - In<>, XPath '//p:oleObj' number of nodes is incorrect
+    // i.e. the linked ole object wasn't exported.
+    assertXPath(pXml, "//p:oleObj", 1);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest3);
 
 CPPUNIT_PLUGIN_IMPLEMENT();

Reply via email to