oox/source/drawingml/fillproperties.cxx      |    6 ++---
 oox/source/drawingml/graphicshapecontext.cxx |   32 ++++++++++++++++++++-------
 sd/qa/unit/export-tests-ooxml2.cxx           |   19 +++++++++++++++-
 3 files changed, 45 insertions(+), 12 deletions(-)

New commits:
commit 9564747d2fd5d2c859a359dd7fa6242c6859c0d7
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Wed Apr 6 16:18:29 2022 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Apr 26 17:41:27 2022 +0200

    tdf#53970 PPTX: fix import of linked media files
    
    Linked media files were imported as images in documents
    created with Impress after PPTX export.
    
    Change-Id: If4920c2e40f45fff73eca4a5fa987d524177597e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132635
    Tested-by: Jenkins
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index 9589a7388bd5..5555a6d5250f 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -963,11 +963,11 @@ void GraphicProperties::pushToPropMap( PropertyMap& 
rPropMap, const GraphicHelpe
         rPropMap.setProperty(PROP_AdjustContrast, nContrast);
 
     // Media content
-    assert(m_xMediaStream.is() != m_sMediaPackageURL.isEmpty());
-    if (m_xMediaStream.is() && !m_sMediaPackageURL.isEmpty())
+    if (!m_sMediaPackageURL.isEmpty())
     {
-        rPropMap.setProperty(PROP_PrivateStream, m_xMediaStream);
         rPropMap.setProperty(PROP_MediaURL, m_sMediaPackageURL);
+        if (m_xMediaStream.is())
+            rPropMap.setProperty(PROP_PrivateStream, m_xMediaStream);
     }
 }
 
diff --git a/oox/source/drawingml/graphicshapecontext.cxx 
b/oox/source/drawingml/graphicshapecontext.cxx
index 3ed00edfd28c..d90980a87824 100644
--- a/oox/source/drawingml/graphicshapecontext.cxx
+++ b/oox/source/drawingml/graphicshapecontext.cxx
@@ -84,10 +84,12 @@ ContextHandlerRef GraphicShapeContext::onCreateContext( 
sal_Int32 aElementToken,
     case XML_wavAudioFile:
         {
             OUString const path(getEmbeddedWAVAudioFile(getRelations(), 
rAttribs));
-            mpShapePtr->getGraphicProperties().m_xMediaStream =
-                lcl_GetMediaStream(path, getFilter());
-            mpShapePtr->getGraphicProperties().m_sMediaPackageURL =
-                lcl_GetMediaReference(path);
+            Reference<XInputStream> xMediaStream = lcl_GetMediaStream(path, 
getFilter());
+            if (xMediaStream.is())
+            {
+                mpShapePtr->getGraphicProperties().m_xMediaStream = 
xMediaStream;
+                mpShapePtr->getGraphicProperties().m_sMediaPackageURL = 
lcl_GetMediaReference(path);
+            }
         }
         break;
     case XML_audioFile:
@@ -95,10 +97,24 @@ ContextHandlerRef GraphicShapeContext::onCreateContext( 
sal_Int32 aElementToken,
         {
             OUString rPath = getRelations().getFragmentPathFromRelId(
                     rAttribs.getString(R_TOKEN(link)).get() );
-            mpShapePtr->getGraphicProperties().m_xMediaStream =
-                lcl_GetMediaStream(rPath, getFilter());
-            mpShapePtr->getGraphicProperties().m_sMediaPackageURL =
-                lcl_GetMediaReference(rPath);
+            if (!rPath.isEmpty())
+            {
+                Reference<XInputStream> xMediaStream = 
lcl_GetMediaStream(rPath, getFilter());
+                if (xMediaStream.is()) // embedded media file
+                {
+                    mpShapePtr->getGraphicProperties().m_xMediaStream = 
xMediaStream;
+                    mpShapePtr->getGraphicProperties().m_sMediaPackageURL
+                        = lcl_GetMediaReference(rPath);
+                }
+            }
+            else
+            {
+                rPath = getRelations().getExternalTargetFromRelId(
+                    rAttribs.getString(R_TOKEN(link)).get());
+                if (!rPath.isEmpty()) // linked media file
+                    mpShapePtr->getGraphicProperties().m_sMediaPackageURL
+                        = getFilter().getAbsoluteUrl(rPath);
+            }
         }
         break;
     }
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx 
b/sd/qa/unit/export-tests-ooxml2.cxx
index 8ad1872d2c52..56ff8b067763 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -1823,11 +1823,28 @@ void SdOOXMLExportTest2::testTdf53970()
             
m_directories.getURLFromSrc(u"/sd/qa/unit/data/odp/tdf53970_linked.odp"), ODP);
         utl::TempFile tempFile;
         xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
-        xDocShRef->DoClose();
 
         xmlDocUniquePtr pXmlRels = parseExport(tempFile, 
"ppt/slides/_rels/slide1.xml.rels");
         CPPUNIT_ASSERT(pXmlRels);
         assertXPath(pXmlRels, 
"/rels:Relationships/rels:Relationship[@TargetMode='External']", 2);
+
+        uno::Reference<beans::XPropertySet> xShape(getShape(0, getPage(0, 
xDocShRef)));
+        CPPUNIT_ASSERT(xShape.is());
+        OUString sVideoURL;
+
+        // Without fix in place, the media shape was imported as an image 
after export.
+        try
+        {
+            CPPUNIT_ASSERT_MESSAGE("MediaURL property is not set",
+                                   xShape->getPropertyValue("MediaURL") >>= 
sVideoURL);
+        }
+        catch (const beans::UnknownPropertyException&)
+        {
+            CPPUNIT_FAIL("Error: MediaURL is unknown property");
+        }
+        CPPUNIT_ASSERT_MESSAGE("MediaURL is empty", !sVideoURL.isEmpty());
+
+        xDocShRef->DoClose();
     }
 }
 

Reply via email to