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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Feb 4 00:03:21 UTC 2019


 avmedia/source/framework/mediaitem.cxx      |   25 ++++++++++++++++---------
 include/avmedia/mediaitem.hxx               |    4 +++-
 oox/source/ppt/soundactioncontext.cxx       |   12 +++++++++---
 oox/source/ppt/timenode.cxx                 |    4 ++++
 oox/source/ppt/timenodelistcontext.cxx      |    9 ++++++---
 oox/source/ppt/timetargetelementcontext.cxx |   13 ++++++++++++-
 sd/qa/unit/data/pptx/tdf44223.pptx          |binary
 sd/qa/unit/import-tests.cxx                 |   25 +++++++++++++++++++++++++
 8 files changed, 75 insertions(+), 17 deletions(-)

New commits:
commit 8a1321362a0229a25869e4e3d0422a5a51c5b5be
Author:     Mark Hung <marklh9 at gmail.com>
AuthorDate: Sun Jan 20 20:33:26 2019 +0800
Commit:     Mark Hung <marklh9 at gmail.com>
CommitDate: Mon Feb 4 01:03:00 2019 +0100

    tdf#44223 oox: import embedded media stream.
    
    - Handle cTn and tgtEl of MediaNodeContext.
    - Setting the audio source of XAudio.
    - Embed the media in TimeNodeTargetElementContext.
    - Embed the media in SoundActionContext.
    - Allow avmedia::EmbedMedia to embed media from a XInputStream.
    
    Change-Id: I164ac50f97f2036db4bfa2f99adedff0bba382e2
    Reviewed-on: https://gerrit.libreoffice.org/67208
    Tested-by: Jenkins
    Reviewed-by: Mark Hung <marklh9 at gmail.com>

diff --git a/avmedia/source/framework/mediaitem.cxx b/avmedia/source/framework/mediaitem.cxx
index 851e501e18cb..6f960f49f3bc 100644
--- a/avmedia/source/framework/mediaitem.cxx
+++ b/avmedia/source/framework/mediaitem.cxx
@@ -415,14 +415,10 @@ CreateStream(uno::Reference<embed::XStorage> const& xStorage,
 
 
 bool EmbedMedia(uno::Reference<frame::XModel> const& xModel,
-        OUString const& rSourceURL, OUString & o_rEmbeddedURL)
+        OUString const& rSourceURL, OUString & o_rEmbeddedURL, uno::Reference<io::XInputStream> const& xInputStream)
 {
     try
     {
-        ::ucbhelper::Content sourceContent(rSourceURL,
-                uno::Reference<ucb::XCommandEnvironment>(),
-                comphelper::getProcessComponentContext());
-
         uno::Reference<document::XStorageBasedDocument> const xSBD(xModel,
                 uno::UNO_QUERY_THROW);
         uno::Reference<embed::XStorage> const xStorage(
@@ -439,10 +435,22 @@ bool EmbedMedia(uno::Reference<frame::XModel> const& xModel,
         uno::Reference<io::XOutputStream> const xOutStream(
             xStream->getOutputStream(), uno::UNO_SET_THROW);
 
-        if (!sourceContent.openStream(xOutStream)) // copy file to storage
+        if (xInputStream.is())
         {
-            SAL_INFO("avmedia", "openStream to storage failed");
-            return false;
+            // Throw Exception if failed.
+            ::comphelper::OStorageHelper::CopyInputToOutput(xInputStream, xOutStream);
+        }
+        else
+        {
+            ::ucbhelper::Content sourceContent(rSourceURL,
+                uno::Reference<ucb::XCommandEnvironment>(),
+                comphelper::getProcessComponentContext());
+
+            if (!sourceContent.openStream(xOutStream)) // copy file to storage
+            {
+                SAL_INFO("avmedia", "openStream to storage failed");
+                return false;
+            }
         }
 
         uno::Reference<embed::XTransactedObject> const xSubTransaction(
@@ -467,7 +475,6 @@ bool EmbedMedia(uno::Reference<frame::XModel> const& xModel,
     return false;
 }
 
-
 } // namespace avmedia
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/avmedia/mediaitem.hxx b/include/avmedia/mediaitem.hxx
index 1f92d0b0d7b6..b2b624bee4db 100644
--- a/include/avmedia/mediaitem.hxx
+++ b/include/avmedia/mediaitem.hxx
@@ -127,7 +127,9 @@ typedef ::avmedia::MediaItem avmedia_MediaItem;
 bool AVMEDIA_DLLPUBLIC EmbedMedia(
         const ::css::uno::Reference< ::css::frame::XModel>& xModel,
         const OUString& rSourceURL,
-        OUString & o_rEmbeddedURL);
+        OUString & o_rEmbeddedURL,
+        ::css::uno::Reference<::css::io::XInputStream> const& xInputStream =
+            ::css::uno::Reference<::css::io::XInputStream>());
 
 OUString GetFilename(OUString const& rSourceURL);
 
diff --git a/oox/source/ppt/soundactioncontext.cxx b/oox/source/ppt/soundactioncontext.cxx
index 775ebf688767..51b2c771867c 100644
--- a/oox/source/ppt/soundactioncontext.cxx
+++ b/oox/source/ppt/soundactioncontext.cxx
@@ -27,6 +27,8 @@
 #include <oox/token/namespaces.hxx>
 #include <oox/token/properties.hxx>
 #include <oox/token/tokens.hxx>
+#include <oox/core/xmlfilterbase.hxx>
+#include <avmedia/mediaitem.hxx>
 
 using namespace ::oox::core;
 using namespace ::com::sun::star::xml::sax;
@@ -54,11 +56,15 @@ namespace oox { namespace ppt {
             if( mbHasStartSound )
             {
                 OUString url;
-                // TODO this is very wrong
                 if ( !msSndName.isEmpty() )
                 {
-                    // try the builtIn version
-                    url = msSndName;
+                    Reference<css::io::XInputStream>
+                        xInputStream = getFilter().openInputStream(msSndName);
+                    if (xInputStream.is())
+                    {
+                        ::avmedia::EmbedMedia(getFilter().getModel(), msSndName, url, xInputStream);
+                        xInputStream->closeInput();
+                    }
                 }
                 if ( !url.isEmpty() )
                 {
diff --git a/oox/source/ppt/timenode.cxx b/oox/source/ppt/timenode.cxx
index 9b77001aaff1..198d0391f3eb 100644
--- a/oox/source/ppt/timenode.cxx
+++ b/oox/source/ppt/timenode.cxx
@@ -27,6 +27,7 @@
 #include <com/sun/star/animations/XAnimateMotion.hpp>
 #include <com/sun/star/animations/XAnimateTransform.hpp>
 #include <com/sun/star/animations/XCommand.hpp>
+#include <com/sun/star/animations/XAudio.hpp>
 #include <com/sun/star/animations/XIterateContainer.hpp>
 #include <com/sun/star/animations/XTimeContainer.hpp>
 #include <com/sun/star/animations/XTransitionFilter.hpp>
@@ -294,6 +295,7 @@ namespace oox { namespace ppt {
             Reference< XAnimateMotion > xAnimateMotion( xNode, UNO_QUERY );
             Reference< XAnimateTransform > xAnimateTransform( xNode, UNO_QUERY );
             Reference< XCommand > xCommand( xNode, UNO_QUERY );
+            Reference< XAudio > xAudio( xNode, UNO_QUERY );
             Reference< XIterateContainer > xIterateContainer( xNode, UNO_QUERY );
             sal_Int16 nInt16 = 0;
             bool bBool = false;
@@ -334,6 +336,8 @@ namespace oox { namespace ppt {
                                 xAnimate->setTarget(aValue);
                             if (xCommand.is())
                                 xCommand->setTarget(aValue);
+                            if (xAudio.is())
+                                xAudio->setSource(aValue);
                         }
                         break;
                     case NP_SUBITEM:
diff --git a/oox/source/ppt/timenodelistcontext.cxx b/oox/source/ppt/timenodelistcontext.cxx
index cb95e38777e7..455c008dc16e 100644
--- a/oox/source/ppt/timenodelistcontext.cxx
+++ b/oox/source/ppt/timenodelistcontext.cxx
@@ -46,6 +46,7 @@
 #include "commontimenodecontext.hxx"
 #include "timeanimvaluecontext.hxx"
 #include "animationtypes.hxx"
+#include "timetargetelementcontext.hxx"
 
 using namespace ::oox::core;
 using namespace ::oox::drawingml;
@@ -179,12 +180,14 @@ namespace oox { namespace ppt {
                 }
             }
 
-        virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& /*rAttribs*/ ) override
+        virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs) override
             {
                 switch ( aElementToken )
                 {
-                case PPT_TOKEN( cBhvr ):
-                    return new CommonBehaviorContext ( *this, mpNode );
+                case PPT_TOKEN( cTn ):
+                    return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
+                case PPT_TOKEN( tgtEl ):
+                    return new TimeTargetElementContext( *this, mpNode->getTarget() );
                 default:
                     break;
                 }
diff --git a/oox/source/ppt/timetargetelementcontext.cxx b/oox/source/ppt/timetargetelementcontext.cxx
index 60ad3af407c1..0f17e4bf5be5 100644
--- a/oox/source/ppt/timetargetelementcontext.cxx
+++ b/oox/source/ppt/timetargetelementcontext.cxx
@@ -27,6 +27,9 @@
 #include <drawingml/embeddedwavaudiofile.hxx>
 #include <oox/token/namespaces.hxx>
 #include <oox/token/tokens.hxx>
+#include <oox/core/xmlfilterbase.hxx>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <avmedia/mediaitem.hxx>
 
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::xml::sax;
@@ -122,8 +125,16 @@ namespace oox { namespace ppt {
             return this;
         case PPT_TOKEN( sndTgt ):
         {
+            OUString srcFile = drawingml::getEmbeddedWAVAudioFile(getRelations(), rAttribs);
             mpTarget->mnType = XML_sndTgt;
-            mpTarget->msValue = drawingml::getEmbeddedWAVAudioFile( getRelations(), rAttribs );
+            Reference<css::io::XInputStream>
+                xInputStream = getFilter().openInputStream(srcFile);
+
+            if (xInputStream.is())
+            {
+                ::avmedia::EmbedMedia(getFilter().getModel(), srcFile, mpTarget->msValue, xInputStream);
+                xInputStream->closeInput();
+            }
             break;
         }
         case PPT_TOKEN( spTgt ):
diff --git a/sd/qa/unit/data/pptx/tdf44223.pptx b/sd/qa/unit/data/pptx/tdf44223.pptx
new file mode 100644
index 000000000000..6f0af688c206
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf44223.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index a068fad4481d..4a60ca586719 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -44,6 +44,8 @@
 
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/document/XEventsSupplier.hpp>
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
 #include <com/sun/star/presentation/ClickAction.hpp>
 #include <com/sun/star/presentation/XPresentationPage.hpp>
 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
@@ -191,6 +193,7 @@ public:
     void testTdf120028();
     void testTdf120028b();
     void testTdf94238();
+    void testTdf44223();
 
     CPPUNIT_TEST_SUITE(SdImportTest);
 
@@ -275,6 +278,7 @@ public:
     CPPUNIT_TEST(testTdf120028);
     CPPUNIT_TEST(testTdf120028b);
     CPPUNIT_TEST(testTdf94238);
+    CPPUNIT_TEST(testTdf44223);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -2621,6 +2625,27 @@ void SdImportTest::testTdf94238()
     CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RADIAL, aGradient.Style);
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(100), aGradient.YOffset);
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(39), aGradient.Border);
+}
+
+void SdImportTest::testTdf44223()
+{
+    ::sd::DrawDocShellRef xDocShRef
+        = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf44223.pptx"), PPTX);
+    uno::Reference<document::XStorageBasedDocument> xSBD(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xSBD.is());
+
+    uno::Reference<embed::XStorage> xStorage = xSBD->getDocumentStorage();
+    CPPUNIT_ASSERT(xStorage.is());
+
+    uno::Reference<container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xNameAccess.is());
+
+    uno::Reference<embed::XStorage> xStorage_2(xNameAccess->getByName("Media"), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xStorage_2.is());
+    uno::Reference< container::XNameAccess > xNameAccess_2(xStorage_2, uno::UNO_QUERY);
+
+    CPPUNIT_ASSERT(xNameAccess_2->hasByName("audio1.wav"));
+    CPPUNIT_ASSERT(xNameAccess_2->hasByName("audio2.wav"));
 
     xDocShRef->DoClose();
 }


More information about the Libreoffice-commits mailing list