[Libreoffice-commits] core.git: include/oox oox/CppunitTest_oox_tokenmap.mk oox/Library_oox.mk oox/source sd/source

Jan Holesovsky kendy at collabora.com
Thu Sep 7 05:01:34 UTC 2017


 include/oox/export/drawingml.hxx         |    4 ++
 include/oox/token/relationship.hxx       |    1 
 oox/CppunitTest_oox_tokenmap.mk          |    1 
 oox/Library_oox.mk                       |    3 +
 oox/source/export/drawingml.cxx          |   54 ++++++++++++++++++++++++++++
 oox/source/export/shapes.cxx             |   58 +++++++++++++++++++++++++++----
 oox/source/token/relationship.inc        |    1 
 sd/source/filter/eppt/pptx-epptooxml.cxx |    2 +
 8 files changed, 117 insertions(+), 7 deletions(-)

New commits:
commit cbcffbaee204e9dfbdc2125dda73e36d77e9b844
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Sep 5 16:53:14 2017 +0200

    tdf#106867: Export videos in PPTX.
    
    Change-Id: I7f4f389a72aa7ecef65d87f07bb69ba8f3374a14
    Reviewed-on: https://gerrit.libreoffice.org/41979
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 866689fa5e21..0e497f91a4a5 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -135,6 +135,10 @@ protected:
 
     /// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship
     OUString WriteImage( const OUString& rURL, bool bRelPathToMedia = false);
+
+    /// Copy a video from vnd.sun.star.Package: to the output and return RelId.
+    OUString WriteMedia(const css::uno::Reference<css::drawing::XShape>& xShape, bool bRelPathToMedia = false);
+
     void WriteStyleProperties( sal_Int32 nTokenId, const css::uno::Sequence< css::beans::PropertyValue >& aProperties );
 
     const char* GetComponentDir();
diff --git a/include/oox/token/relationship.hxx b/include/oox/token/relationship.hxx
index d00552e02560..329fe7407df1 100644
--- a/include/oox/token/relationship.hxx
+++ b/include/oox/token/relationship.hxx
@@ -53,6 +53,7 @@ enum class Relationship
     STYLES,
     THEME,
     VBAPROJECT,
+    VIDEO,
     VMLDRAWING,
     WORDVBADATA,
     WORKSHEET
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"}
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx
index 28c1d2870ed4..b00aa125b129 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -323,6 +323,8 @@ ShapeExport& PowerPointShapeExport::WriteUnknownShape(const Reference< XShape >&
         if (!WritePlaceholder(xShape, Subtitle, mbMaster))
             ShapeExport::WriteTextShape(xShape);
     }
+    else
+        SAL_WARN("sd.eppt", "unknown shape not handled: " << USS(sShapeType));
 
     return *this;
 }


More information about the Libreoffice-commits mailing list