summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2017-09-05 16:53:14 +0200
committerJan Holesovsky <kendy@collabora.com>2017-09-07 07:01:09 +0200
commitcbcffbaee204e9dfbdc2125dda73e36d77e9b844 (patch)
tree1e0cc588b1514afd8727fda78f27e6139aa3569d /oox
parentf2c29539d52095ea7b914b20ef7f564469d2aa96 (diff)
tdf#106867: Export videos in PPTX.
Change-Id: I7f4f389a72aa7ecef65d87f07bb69ba8f3374a14 Reviewed-on: https://gerrit.libreoffice.org/41979 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/CppunitTest_oox_tokenmap.mk1
-rw-r--r--oox/Library_oox.mk3
-rw-r--r--oox/source/export/drawingml.cxx54
-rw-r--r--oox/source/export/shapes.cxx58
-rw-r--r--oox/source/token/relationship.inc1
5 files changed, 110 insertions, 7 deletions
diff --git a/oox/CppunitTest_oox_tokenmap.mk b/oox/CppunitTest_oox_tokenmap.mk
index 1ef9d85bc625..8019da7a2301 100644
--- a/oox/CppunitTest_oox_tokenmap.mk
+++ b/oox/CppunitTest_oox_tokenmap.mk
@@ -35,6 +35,7 @@ endif
endif
$(eval $(call gb_CppunitTest_use_libraries,oox_tokenmap,\
+ avmedia \
basegfx \
comphelper \
cppu \
diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk
index db6e9b2d16f7..ecf760f0350c 100644
--- a/oox/Library_oox.mk
+++ b/oox/Library_oox.mk
@@ -38,6 +38,7 @@ $(eval $(call gb_Library_use_api,oox,\
))
$(eval $(call gb_Library_use_libraries,oox,\
+ avmedia \
basegfx \
comphelper \
cppu \
@@ -47,7 +48,7 @@ $(eval $(call gb_Library_use_libraries,oox,\
drawinglayer \
msfilter \
sal \
- i18nlangtag \
+ i18nlangtag \
sax \
sfx \
svl \
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 94dcd54ed063..32e971fa4995 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -43,6 +43,7 @@
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <com/sun/star/drawing/BitmapMode.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
@@ -58,6 +59,7 @@
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
@@ -70,6 +72,8 @@
#include <com/sun/star/text/XTextField.hpp>
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/style/CaseMap.hpp>
+
+#include <comphelper/storagehelper.hxx>
#include <o3tl/any.hxx>
#include <tools/stream.hxx>
#include <unotools/fontdefs.hxx>
@@ -88,6 +92,7 @@
#include <editeng/flditem.hxx>
#include <svx/sdtfsitm.hxx>
#include <svx/svdoashp.hxx>
+#include <svx/svdomedia.hxx>
#include <svx/unoapi.hxx>
#include <svx/unoshape.hxx>
#include <android/compatibility.hxx>
@@ -946,6 +951,55 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia )
return sRelId;
}
+OUString DrawingML::WriteMedia(const css::uno::Reference<css::drawing::XShape>& xShape, bool bRelPathToMedia)
+{
+ SdrMediaObj* pMediaObj = dynamic_cast<SdrMediaObj*>(GetSdrObjectFromXShape(xShape));
+ if (!pMediaObj)
+ return OUString();
+
+ // extension
+ OUString aExtension;
+ const OUString& rURL(pMediaObj->getURL());
+ int nLastDot = rURL.lastIndexOf('.');
+ if (nLastDot >= 0)
+ aExtension = rURL.copy(nLastDot);
+
+ // mime type
+ // TODO add more types explicitly based on the extension (?)
+ OUString aMimeType;
+ if (aExtension.equalsIgnoreAsciiCase(".wmv"))
+ aMimeType = "video/x-ms-wmv";
+ else
+ aMimeType = pMediaObj->getMediaProperties().getMimeType();
+
+ Reference<XOutputStream> xOutStream = mpFB->openFragmentStream(OUStringBuffer()
+ .appendAscii(GetComponentDir())
+ .append("/media/media")
+ .append((sal_Int32) mnImageCounter)
+ .append(aExtension)
+ .makeStringAndClear(),
+ aMimeType);
+
+ uno::Reference<io::XInputStream> xInputStream(pMediaObj->GetInputStream());
+ comphelper::OStorageHelper::CopyInputToOutput(xInputStream, xOutStream);
+
+ xOutStream->closeOutput();
+
+ // create the relation
+ OString sRelPathToMedia = "media/media";
+ if (bRelPathToMedia)
+ sRelPathToMedia = "../" + sRelPathToMedia;
+
+ return mpFB->addRelation(mpFS->getOutputStream(),
+ oox::getRelationship(Relationship::VIDEO),
+ OUStringBuffer()
+ .appendAscii(GetRelationCompPrefix())
+ .appendAscii(sRelPathToMedia.getStr())
+ .append((sal_Int32) mnImageCounter++)
+ .append(aExtension)
+ .makeStringAndClear());
+}
+
OUString DrawingML::WriteBlip( const Reference< XPropertySet >& rXPropSet, const OUString& rURL, bool bRelPathToMedia, const Graphic *pGraphic )
{
OUString sRelId;
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 7d2584da3641..88794f3b01e1 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -60,6 +60,7 @@
#include <com/sun/star/embed/XEmbeddedObject.hpp>
#include <com/sun/star/embed/XEmbedPersist.hpp>
#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
@@ -80,6 +81,7 @@
#include <tools/globname.hxx>
#include <comphelper/classids.hxx>
#include <comphelper/propertysequence.hxx>
+#include <comphelper/sequence.hxx>
#include <comphelper/storagehelper.hxx>
#include <sot/exchange.hxx>
#include <utility>
@@ -1096,10 +1098,22 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape
SAL_INFO("oox.shape", "graphicObject without text");
OUString sGraphicURL;
+ OUString sMediaURL;
Reference< XPropertySet > xShapeProps( xShape, UNO_QUERY );
- if( !pGraphic && ( !xShapeProps.is() || !( xShapeProps->getPropertyValue( "GraphicURL" ) >>= sGraphicURL ) ) )
+
+ bool bHasGraphicURL = xShapeProps.is() && xShapeProps->getPropertySetInfo()->hasPropertyByName("GraphicURL") && (xShapeProps->getPropertyValue("GraphicURL") >>= sGraphicURL);
+ bool bHasMediaURL = xShapeProps.is() && xShapeProps->getPropertySetInfo()->hasPropertyByName("MediaURL") && (xShapeProps->getPropertyValue("MediaURL") >>= sMediaURL);
+
+ if (!pGraphic && !bHasGraphicURL && !bHasMediaURL)
+ {
+ SAL_INFO("oox.shape", "no graphic or media URL found");
+ return;
+ }
+
+ // TODO FIXME currently we support only embedded video
+ if (bHasMediaURL && !sMediaURL.startsWith("vnd.sun.star.Package:"))
{
- SAL_INFO("oox.shape", "no graphic URL found");
+ SAL_INFO("oox.shape", "external media URL not exported");
return;
}
@@ -1123,26 +1137,57 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape
if ( ( bHaveDesc = GetProperty( xShapeProps, "Description" ) ) )
mAny >>= sDescr;
- pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
+ pFS->startElementNS( mnXmlNamespace, XML_cNvPr,
XML_id, I32S( GetNewShapeID( xShape ) ),
XML_name, bHaveName ? USS( sName ) : OString( "Picture " + OString::number( mnPictureIdMax++ )).getStr(),
XML_descr, bHaveDesc ? USS( sDescr ) : nullptr,
FSEND );
+
// OOXTODO: //cNvPr children: XML_extLst, XML_hlinkClick, XML_hlinkHover
+ if (bHasMediaURL)
+ pFS->singleElementNS(XML_a, XML_hlinkClick,
+ FSNS(XML_r, XML_id), "",
+ XML_action, "ppaction://media",
+ FSEND);
+
+ pFS->endElementNS(mnXmlNamespace, XML_cNvPr);
pFS->singleElementNS( mnXmlNamespace, XML_cNvPicPr,
// OOXTODO: XML_preferRelativeSize
FSEND );
- WriteNonVisualProperties( xShape );
+ if (bHasMediaURL)
+ {
+ GetFS()->startElementNS(XML_p, XML_nvPr, FSEND);
+
+ OUString sRelId = WriteMedia(xShape, false);
+ GetFS()->singleElementNS(XML_a, XML_videoFile,
+ FSNS(XML_r, XML_link), USS(sRelId),
+ FSEND);
+
+ GetFS()->endElementNS(XML_p, XML_nvPr);
+ }
+ else
+ WriteNonVisualProperties( xShape );
pFS->endElementNS( mnXmlNamespace, XML_nvPicPr );
pFS->startElementNS( mnXmlNamespace, XML_blipFill, FSEND );
- WriteBlip( xShapeProps, sGraphicURL, false, pGraphic );
+ if (pGraphic || bHasGraphicURL)
+ WriteBlip(xShapeProps, sGraphicURL, false, pGraphic);
+ else if (bHasMediaURL)
+ {
+ Reference<graphic::XGraphic> rGraphic;
+ if (xShapeProps->getPropertySetInfo()->hasPropertyByName("FallbackGraphic"))
+ xShapeProps->getPropertyValue("FallbackGraphic") >>= rGraphic;
+
+ Graphic aGraphic(rGraphic);
+ WriteBlip(xShapeProps, sMediaURL, false, &aGraphic);
+ }
- WriteSrcRect( xShapeProps, sGraphicURL );
+ if (bHasGraphicURL)
+ WriteSrcRect(xShapeProps, sGraphicURL);
// now we stretch always when we get pGraphic (when changing that
// behavior, test n#780830 for regression, where the OLE sheet might get tiled
@@ -1418,6 +1463,7 @@ static const NameToConvertMapType& lcl_GetConverters()
shape_converters[ "com.sun.star.drawing.GroupShape" ] = &ShapeExport::WriteGroupShape;
shape_converters[ "com.sun.star.presentation.GraphicObjectShape" ] = &ShapeExport::WriteGraphicObjectShape;
+ shape_converters[ "com.sun.star.presentation.MediaShape" ] = &ShapeExport::WriteGraphicObjectShape;
shape_converters[ "com.sun.star.presentation.OLE2Shape" ] = &ShapeExport::WriteOLE2Shape;
shape_converters[ "com.sun.star.presentation.TableShape" ] = &ShapeExport::WriteTableShape;
shape_converters[ "com.sun.star.presentation.TextShape" ] = &ShapeExport::WriteTextShape;
diff --git a/oox/source/token/relationship.inc b/oox/source/token/relationship.inc
index 85a459d49697..2bdf6eab7e68 100644
--- a/oox/source/token/relationship.inc
+++ b/oox/source/token/relationship.inc
@@ -36,6 +36,7 @@
{Relationship::STYLES, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"},
{Relationship::THEME, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"},
{Relationship::VBAPROJECT, "http://schemas.microsoft.com/office/2006/relationships/vbaProject"},
+{Relationship::VIDEO, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/video"},
{Relationship::VMLDRAWING, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"},
{Relationship::WORDVBADATA, "http://schemas.microsoft.com/office/2006/relationships/wordVbaData"},
{Relationship::WORKSHEET, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"}