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

New commits:
commit 4d26bb9e8fd25edb913ad5fb52bdbc56fad75291
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Wed Apr 6 16:18:29 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Apr 27 10:49:22 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>
    (cherry picked from commit 9564747d2fd5d2c859a359dd7fa6242c6859c0d7)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133410
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index 2b682bcd1b99..e3830618522b 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -954,11 +954,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 dc6498ec614d..0b244bc76233 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -1832,11 +1832,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();
     }
 }
 
commit 24c7741adcb373b4de508b16deef56343119df26
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Apr 26 16:51:01 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Apr 27 10:48:53 2022 +0200

    ofz#47042 previous use of static variable affecting later runs
    
    Change-Id: I64fb184e43fb025798781c85c9a0a8e0354b21b0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133453
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 1bd12242b436..d5a73be7e623 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -71,7 +71,6 @@ constexpr OUStringLiteral sXML_CDATA = u"CDATA";
     rendEl("text:span"); \
     tstart = false
 
-static hchar *field = nullptr;
 static char buf[1024];
 
 namespace
@@ -97,12 +96,13 @@ struct HwpReaderPrivate
         bInHeader = false;
         nPnPos = 0;
         pPn = nullptr;
-
+        pField = nullptr;
     }
     bool bFirstPara;
     bool bInBody;
     bool bInHeader;
     ShowPageNum *pPn;
+    hchar *pField;
     int nPnPos;
 };
 
@@ -2933,7 +2933,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool 
bParaStart)
                 firstspace = 1;
                 if( hbox->type[0] == 4 && hbox->type[1] == 0 )
                 {
-                     field = hbox->str3.get();
+                     d->pField = hbox->str3.get();
                 }
                 else{
                      makeFieldCode(str, hbox);
@@ -2946,7 +2946,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool 
bParaStart)
                 if( hbox->type[0] == 4 && hbox->type[1] == 0 )
                 {
                      makeFieldCode(str, hbox);
-                     field = nullptr;
+                     d->pField = nullptr;
                 }
                 infield = false;
                 str.clear();
@@ -3114,8 +3114,8 @@ void HwpReader::makeFieldCode(hchar_string const & rStr, 
FieldCode const *hbox)
     if( hbox->type[0] == 4 && hbox->type[1] == 0 )
     {
         padd("text:placeholder-type", sXML_CDATA, "text");
-        if( field )
-              padd("text:description", sXML_CDATA, 
fromHcharStringToOUString(hstr2ucsstr(field)));
+        if (d->pField)
+            padd("text:description", sXML_CDATA, 
fromHcharStringToOUString(hstr2ucsstr(d->pField)));
         rstartEl( "text:placeholder", mxList);
         mxList->clear();
         rchars( fromHcharStringToOUString(rStr) );

Reply via email to