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,
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: */
......@@ -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);
......
......@@ -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() )
{
......
......@@ -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:
......
......@@ -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;
}
......
......@@ -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 ):
......
......@@ -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();
}
......
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