Kaydet (Commit) 8a132136 authored tarafından Mark Hung's avatar Mark Hung

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: 's avatarMark Hung <marklh9@gmail.com>
üst 04160a24
...@@ -415,14 +415,10 @@ CreateStream(uno::Reference<embed::XStorage> const& xStorage, ...@@ -415,14 +415,10 @@ CreateStream(uno::Reference<embed::XStorage> const& xStorage,
bool EmbedMedia(uno::Reference<frame::XModel> const& xModel, 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 try
{ {
::ucbhelper::Content sourceContent(rSourceURL,
uno::Reference<ucb::XCommandEnvironment>(),
comphelper::getProcessComponentContext());
uno::Reference<document::XStorageBasedDocument> const xSBD(xModel, uno::Reference<document::XStorageBasedDocument> const xSBD(xModel,
uno::UNO_QUERY_THROW); uno::UNO_QUERY_THROW);
uno::Reference<embed::XStorage> const xStorage( uno::Reference<embed::XStorage> const xStorage(
...@@ -439,10 +435,22 @@ bool EmbedMedia(uno::Reference<frame::XModel> const& xModel, ...@@ -439,10 +435,22 @@ bool EmbedMedia(uno::Reference<frame::XModel> const& xModel,
uno::Reference<io::XOutputStream> const xOutStream( uno::Reference<io::XOutputStream> const xOutStream(
xStream->getOutputStream(), uno::UNO_SET_THROW); xStream->getOutputStream(), uno::UNO_SET_THROW);
if (!sourceContent.openStream(xOutStream)) // copy file to storage if (xInputStream.is())
{ {
SAL_INFO("avmedia", "openStream to storage failed"); // Throw Exception if failed.
return false; ::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( uno::Reference<embed::XTransactedObject> const xSubTransaction(
...@@ -467,7 +475,6 @@ bool EmbedMedia(uno::Reference<frame::XModel> const& xModel, ...@@ -467,7 +475,6 @@ bool EmbedMedia(uno::Reference<frame::XModel> const& xModel,
return false; return false;
} }
} // namespace avmedia } // namespace avmedia
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -127,7 +127,9 @@ typedef ::avmedia::MediaItem avmedia_MediaItem; ...@@ -127,7 +127,9 @@ typedef ::avmedia::MediaItem avmedia_MediaItem;
bool AVMEDIA_DLLPUBLIC EmbedMedia( bool AVMEDIA_DLLPUBLIC EmbedMedia(
const ::css::uno::Reference< ::css::frame::XModel>& xModel, const ::css::uno::Reference< ::css::frame::XModel>& xModel,
const OUString& rSourceURL, 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); OUString GetFilename(OUString const& rSourceURL);
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <oox/token/namespaces.hxx> #include <oox/token/namespaces.hxx>
#include <oox/token/properties.hxx> #include <oox/token/properties.hxx>
#include <oox/token/tokens.hxx> #include <oox/token/tokens.hxx>
#include <oox/core/xmlfilterbase.hxx>
#include <avmedia/mediaitem.hxx>
using namespace ::oox::core; using namespace ::oox::core;
using namespace ::com::sun::star::xml::sax; using namespace ::com::sun::star::xml::sax;
...@@ -54,11 +56,15 @@ namespace oox { namespace ppt { ...@@ -54,11 +56,15 @@ namespace oox { namespace ppt {
if( mbHasStartSound ) if( mbHasStartSound )
{ {
OUString url; OUString url;
// TODO this is very wrong
if ( !msSndName.isEmpty() ) if ( !msSndName.isEmpty() )
{ {
// try the builtIn version Reference<css::io::XInputStream>
url = msSndName; xInputStream = getFilter().openInputStream(msSndName);
if (xInputStream.is())
{
::avmedia::EmbedMedia(getFilter().getModel(), msSndName, url, xInputStream);
xInputStream->closeInput();
}
} }
if ( !url.isEmpty() ) if ( !url.isEmpty() )
{ {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <com/sun/star/animations/XAnimateMotion.hpp> #include <com/sun/star/animations/XAnimateMotion.hpp>
#include <com/sun/star/animations/XAnimateTransform.hpp> #include <com/sun/star/animations/XAnimateTransform.hpp>
#include <com/sun/star/animations/XCommand.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/XIterateContainer.hpp>
#include <com/sun/star/animations/XTimeContainer.hpp> #include <com/sun/star/animations/XTimeContainer.hpp>
#include <com/sun/star/animations/XTransitionFilter.hpp> #include <com/sun/star/animations/XTransitionFilter.hpp>
...@@ -294,6 +295,7 @@ namespace oox { namespace ppt { ...@@ -294,6 +295,7 @@ namespace oox { namespace ppt {
Reference< XAnimateMotion > xAnimateMotion( xNode, UNO_QUERY ); Reference< XAnimateMotion > xAnimateMotion( xNode, UNO_QUERY );
Reference< XAnimateTransform > xAnimateTransform( xNode, UNO_QUERY ); Reference< XAnimateTransform > xAnimateTransform( xNode, UNO_QUERY );
Reference< XCommand > xCommand( xNode, UNO_QUERY ); Reference< XCommand > xCommand( xNode, UNO_QUERY );
Reference< XAudio > xAudio( xNode, UNO_QUERY );
Reference< XIterateContainer > xIterateContainer( xNode, UNO_QUERY ); Reference< XIterateContainer > xIterateContainer( xNode, UNO_QUERY );
sal_Int16 nInt16 = 0; sal_Int16 nInt16 = 0;
bool bBool = false; bool bBool = false;
...@@ -334,6 +336,8 @@ namespace oox { namespace ppt { ...@@ -334,6 +336,8 @@ namespace oox { namespace ppt {
xAnimate->setTarget(aValue); xAnimate->setTarget(aValue);
if (xCommand.is()) if (xCommand.is())
xCommand->setTarget(aValue); xCommand->setTarget(aValue);
if (xAudio.is())
xAudio->setSource(aValue);
} }
break; break;
case NP_SUBITEM: case NP_SUBITEM:
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "commontimenodecontext.hxx" #include "commontimenodecontext.hxx"
#include "timeanimvaluecontext.hxx" #include "timeanimvaluecontext.hxx"
#include "animationtypes.hxx" #include "animationtypes.hxx"
#include "timetargetelementcontext.hxx"
using namespace ::oox::core; using namespace ::oox::core;
using namespace ::oox::drawingml; using namespace ::oox::drawingml;
...@@ -179,12 +180,14 @@ namespace oox { namespace ppt { ...@@ -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 ) switch ( aElementToken )
{ {
case PPT_TOKEN( cBhvr ): case PPT_TOKEN( cTn ):
return new CommonBehaviorContext ( *this, mpNode ); return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
case PPT_TOKEN( tgtEl ):
return new TimeTargetElementContext( *this, mpNode->getTarget() );
default: default:
break; break;
} }
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#include <drawingml/embeddedwavaudiofile.hxx> #include <drawingml/embeddedwavaudiofile.hxx>
#include <oox/token/namespaces.hxx> #include <oox/token/namespaces.hxx>
#include <oox/token/tokens.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::uno;
using namespace ::com::sun::star::xml::sax; using namespace ::com::sun::star::xml::sax;
...@@ -122,8 +125,16 @@ namespace oox { namespace ppt { ...@@ -122,8 +125,16 @@ namespace oox { namespace ppt {
return this; return this;
case PPT_TOKEN( sndTgt ): case PPT_TOKEN( sndTgt ):
{ {
OUString srcFile = drawingml::getEmbeddedWAVAudioFile(getRelations(), rAttribs);
mpTarget->mnType = XML_sndTgt; 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; break;
} }
case PPT_TOKEN( spTgt ): case PPT_TOKEN( spTgt ):
......
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/document/XEventsSupplier.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/ClickAction.hpp>
#include <com/sun/star/presentation/XPresentationPage.hpp> #include <com/sun/star/presentation/XPresentationPage.hpp>
#include <com/sun/star/drawing/GraphicExportFilter.hpp> #include <com/sun/star/drawing/GraphicExportFilter.hpp>
...@@ -191,6 +193,7 @@ public: ...@@ -191,6 +193,7 @@ public:
void testTdf120028(); void testTdf120028();
void testTdf120028b(); void testTdf120028b();
void testTdf94238(); void testTdf94238();
void testTdf44223();
CPPUNIT_TEST_SUITE(SdImportTest); CPPUNIT_TEST_SUITE(SdImportTest);
...@@ -275,6 +278,7 @@ public: ...@@ -275,6 +278,7 @@ public:
CPPUNIT_TEST(testTdf120028); CPPUNIT_TEST(testTdf120028);
CPPUNIT_TEST(testTdf120028b); CPPUNIT_TEST(testTdf120028b);
CPPUNIT_TEST(testTdf94238); CPPUNIT_TEST(testTdf94238);
CPPUNIT_TEST(testTdf44223);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -2621,6 +2625,27 @@ void SdImportTest::testTdf94238() ...@@ -2621,6 +2625,27 @@ void SdImportTest::testTdf94238()
CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RADIAL, aGradient.Style); 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>(100), aGradient.YOffset);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(39), aGradient.Border); 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(); xDocShRef->DoClose();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment