summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2019-01-20 20:33:26 +0800
committerMark Hung <marklh9@gmail.com>2019-02-04 01:03:00 +0100
commit8a1321362a0229a25869e4e3d0422a5a51c5b5be (patch)
tree3afb0f5d5469adb70e8a5d6ea246413c7312b2e8
parent04160a24e34beb6802cea356b947ed9d8d382d19 (diff)
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@gmail.com>
-rw-r--r--avmedia/source/framework/mediaitem.cxx25
-rw-r--r--include/avmedia/mediaitem.hxx4
-rw-r--r--oox/source/ppt/soundactioncontext.cxx12
-rw-r--r--oox/source/ppt/timenode.cxx4
-rw-r--r--oox/source/ppt/timenodelistcontext.cxx9
-rw-r--r--oox/source/ppt/timetargetelementcontext.cxx13
-rw-r--r--sd/qa/unit/data/pptx/tdf44223.pptxbin0 -> 63723 bytes
-rw-r--r--sd/qa/unit/import-tests.cxx25
8 files changed, 75 insertions, 17 deletions
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
--- /dev/null
+++ b/sd/qa/unit/data/pptx/tdf44223.pptx
Binary files 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();
}