avmedia/source/framework/mediaitem.cxx |   13 +++++++++++++
 include/avmedia/mediaitem.hxx          |    8 ++++++--
 sd/qa/unit/export-tests-ooxml1.cxx     |   23 +++++++++++++++++++++++
 svx/source/svdraw/svdomedia.cxx        |    5 +++++
 svx/source/unodraw/unoprov.cxx         |    1 +
 svx/source/unodraw/unoshap4.cxx        |   31 +++++++++++++++++++++++++++++--
 6 files changed, 77 insertions(+), 4 deletions(-)

New commits:
commit e2d46da076f43a7c0d56fc486b9f15339243f7c9
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Jan 21 15:08:13 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Jan 21 21:40:20 2021 +0100

    avmedia: add doc model for bitmap fill of slide narrations
    
    This allows specifying a custom bitmap for a media shape. It's mostly
    useful for audio-only streams where the additional bitmap may be e.g. a
    speaker icon to indicate this a narration.
    
    Change-Id: I21c1b492ac09b631cf6e3ec8120be8b82c01c26d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109763
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/avmedia/source/framework/mediaitem.cxx 
b/avmedia/source/framework/mediaitem.cxx
index f42065e8e81e..54db2e3bc6bf 100644
--- a/avmedia/source/framework/mediaitem.cxx
+++ b/avmedia/source/framework/mediaitem.cxx
@@ -40,6 +40,7 @@
 #include <mediamisc.hxx>
 #include <osl/file.hxx>
 #include <tools/diagnose_ex.h>
+#include <vcl/graph.hxx>
 
 using namespace ::com::sun::star;
 
@@ -62,6 +63,7 @@ struct MediaItem::Impl
     bool                    m_bLoop;
     bool                    m_bMute;
     css::media::ZoomLevel m_eZoom;
+    Graphic m_aGraphic;
 
     explicit Impl(AVMediaSetMask nMaskSet)
         : m_nMaskSet( nMaskSet )
@@ -104,6 +106,7 @@ bool MediaItem::operator==( const SfxPoolItem& rItem ) const
         && m_pImpl->m_URL == rOther.m_pImpl->m_URL
         && m_pImpl->m_Referer == rOther.m_pImpl->m_Referer
         && m_pImpl->m_sMimeType == rOther.m_pImpl->m_sMimeType
+        && m_pImpl->m_aGraphic == rOther.m_pImpl->m_aGraphic
         && m_pImpl->m_eState == rOther.m_pImpl->m_eState
         && m_pImpl->m_fDuration == rOther.m_pImpl->m_fDuration
         && m_pImpl->m_fTime == rOther.m_pImpl->m_fTime
@@ -188,6 +191,9 @@ void MediaItem::merge( const MediaItem& rMediaItem )
     if( AVMediaSetMask::MIME_TYPE & nMaskSet )
         setMimeType( rMediaItem.getMimeType() );
 
+    if (nMaskSet & AVMediaSetMask::GRAPHIC)
+        setGraphic(rMediaItem.getGraphic());
+
     if( AVMediaSetMask::STATE & nMaskSet )
         setState( rMediaItem.getState() );
 
@@ -256,6 +262,13 @@ OUString MediaItem::getMimeType() const
     return !m_pImpl->m_sMimeType.isEmpty() ? m_pImpl->m_sMimeType : 
AVMEDIA_MIMETYPE_COMMON;
 }
 
+void MediaItem::setGraphic(const Graphic& rGraphic)
+{
+    m_pImpl->m_nMaskSet |= AVMediaSetMask::GRAPHIC;
+    m_pImpl->m_aGraphic = rGraphic;
+}
+
+Graphic MediaItem::getGraphic() const { return m_pImpl->m_aGraphic; }
 
 void MediaItem::setState( MediaState eState )
 {
diff --git a/include/avmedia/mediaitem.hxx b/include/avmedia/mediaitem.hxx
index 7246c9e7e2a1..9e3fb4cd4530 100644
--- a/include/avmedia/mediaitem.hxx
+++ b/include/avmedia/mediaitem.hxx
@@ -32,6 +32,7 @@ namespace com::sun::star::embed { class XStorage; }
 namespace com::sun::star::frame { class XModel; }
 namespace com::sun::star::io { class XInputStream; }
 namespace com::sun::star::io { class XStream; }
+class Graphic;
 
 enum class AVMediaSetMask
 {
@@ -45,11 +46,12 @@ enum class AVMediaSetMask
     ZOOM        = 0x040,
     URL         = 0x080,
     MIME_TYPE   = 0x100,
-    ALL         = 0x1ff,
+    GRAPHIC     = 0x200,
+    ALL         = 0x3ff,
 };
 namespace o3tl
 {
-    template<> struct typed_flags<AVMediaSetMask> : 
is_typed_flags<AVMediaSetMask, 0x1ff> {};
+    template<> struct typed_flags<AVMediaSetMask> : 
is_typed_flags<AVMediaSetMask, 0x3ff> {};
 }
 
 
@@ -115,6 +117,8 @@ public:
 
     void                    setMimeType( const OUString& rMimeType );
     OUString                getMimeType() const;
+    void setGraphic(const Graphic& rGraphic);
+    Graphic getGraphic() const;
     const OUString&         getTempURL() const;
 
     const OUString&         getReferer() const;
diff --git a/sd/qa/unit/export-tests-ooxml1.cxx 
b/sd/qa/unit/export-tests-ooxml1.cxx
index 5784d00d112d..91ce68e20a50 100644
--- a/sd/qa/unit/export-tests-ooxml1.cxx
+++ b/sd/qa/unit/export-tests-ooxml1.cxx
@@ -53,6 +53,8 @@
 
 #include <svx/svdotable.hxx>
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
+#include <rtl/uri.hxx>
+#include <vcl/pngread.hxx>
 
 using namespace css;
 
@@ -1313,6 +1315,27 @@ void SdOOXMLExportTest1::testNarrationMimeType()
     assertXPath(pXmlDoc,
                 
"/ContentType:Types/ContentType:Override[@PartName='/ppt/media/media1.m4a']",
                 "ContentType", "audio/mp4");
+
+    // Check if the bitmap of the media shape is exported correctly.
+    xmlDocUniquePtr pSlideDoc = parseExport(aTempFile, 
"ppt/slides/slide1.xml");
+    OUString aImageId = getXPath(pSlideDoc, 
"/p:sld/p:cSld/p:spTree/p:pic/p:blipFill/a:blip", "embed");
+    xmlDocUniquePtr pRelsDoc = parseExport(aTempFile, 
"ppt/slides/_rels/slide1.xml.rels");
+    OUString aImagePath = "/rels:Relationships/rels:Relationship[@Id='" + 
aImageId + "']";
+    // Something like ../media/image2.png.
+    OUString aImageStreamName = getXPath(pRelsDoc, aImagePath.toUtf8(), 
"Target");
+    OUString aImageAbsName = rtl::Uri::convertRelToAbs("file:///ppt/slides/", 
aImageStreamName);
+    // Something like ppt/media/image2.png.
+    OUString aImageRelName;
+    CPPUNIT_ASSERT(aImageAbsName.startsWith("file:///", &aImageRelName));
+    std::unique_ptr<SvStream> pImageStream = parseExportStream(aTempFile, 
aImageRelName);
+    vcl::PNGReader aReader(*pImageStream);
+    BitmapEx aBitmapEx = aReader.Read();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 256
+    // - Actual  : 120
+    // i.e. the bitmap of the narration was lost, some default placeholder was 
exported instead.
+    CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(256), 
aBitmapEx.GetSizePixel().Height());
+
     xDocShRef->DoClose();
 }
 
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index 47e30a1049ac..923be7d451ba 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -330,6 +330,11 @@ void SdrMediaObj::mediaPropertiesChanged( const 
::avmedia::MediaItem& rNewProper
     if( AVMediaSetMask::MIME_TYPE & nMaskSet )
         m_xImpl->m_MediaProperties.setMimeType( rNewProperties.getMimeType() );
 
+    if (nMaskSet & AVMediaSetMask::GRAPHIC)
+    {
+        m_xImpl->m_MediaProperties.setGraphic(rNewProperties.getGraphic());
+    }
+
     if( ( AVMediaSetMask::URL & nMaskSet ) &&
         ( rNewProperties.getURL() != getURL() ))
     {
diff --git a/svx/source/unodraw/unoprov.cxx b/svx/source/unodraw/unoprov.cxx
index 0531cff10bb9..865380d2a0c8 100644
--- a/svx/source/unodraw/unoprov.cxx
+++ b/svx/source/unodraw/unoprov.cxx
@@ -729,6 +729,7 @@ static SfxItemPropertyMapEntry const * 
ImplGetSvxMediaShapePropertyMap()
         {u"PrivateTempFileURL", OWN_ATTR_MEDIA_TEMPFILEURL, 
cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY, 0},
         { u"MediaMimeType", OWN_ATTR_MEDIA_MIMETYPE, 
cppu::UnoType<OUString>::get(), 0, 0},
         { u"FallbackGraphic", OWN_ATTR_FALLBACK_GRAPHIC, 
cppu::UnoType<css::graphic::XGraphic>::get(), 
css::beans::PropertyAttribute::READONLY, 0},
+        { u"" UNO_NAME_GRAPHOBJ_GRAPHIC,   OWN_ATTR_VALUE_GRAPHIC     , 
cppu::UnoType<css::graphic::XGraphic>::get(), 0, 0},
         { u"", 0, css::uno::Type(), 0, 0 }
     };
 
diff --git a/svx/source/unodraw/unoshap4.cxx b/svx/source/unodraw/unoshap4.cxx
index 658cb2c8fd6c..17daf3f5a1ed 100644
--- a/svx/source/unodraw/unoshap4.cxx
+++ b/svx/source/unodraw/unoshap4.cxx
@@ -779,7 +779,8 @@ bool SvxMediaShape::setPropertyValueImpl( const OUString& 
rName, const SfxItemPr
 {
     if( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= 
OWN_ATTR_MEDIA_ZOOM))
         || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
-        || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE) )
+        || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
+        || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC))
     {
         SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
         ::avmedia::MediaItem aItem;
@@ -869,6 +870,19 @@ bool SvxMediaShape::setPropertyValueImpl( const OUString& 
rName, const SfxItemPr
 #endif
         break;
 
+        case OWN_ATTR_VALUE_GRAPHIC:
+#if HAVE_FEATURE_AVMEDIA
+        {
+            uno::Reference<graphic::XGraphic> xGraphic(rValue, uno::UNO_QUERY);
+            if (xGraphic.is())
+            {
+                bOk = true;
+                aItem.setGraphic(Graphic(xGraphic));
+            }
+        }
+#endif
+        break;
+
         case OWN_ATTR_MEDIA_STREAM:
 #if HAVE_FEATURE_AVMEDIA
             try
@@ -924,7 +938,8 @@ bool SvxMediaShape::getPropertyValueImpl( const OUString& 
rName, const SfxItemPr
         || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
         || (pProperty->nWID == OWN_ATTR_MEDIA_TEMPFILEURL)
         || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
-        || (pProperty->nWID == OWN_ATTR_FALLBACK_GRAPHIC))
+        || (pProperty->nWID == OWN_ATTR_FALLBACK_GRAPHIC)
+        || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC))
     {
         SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
         const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );
@@ -995,6 +1010,18 @@ bool SvxMediaShape::getPropertyValueImpl( const OUString& 
rName, const SfxItemPr
 #endif
                 break;
 
+            case OWN_ATTR_VALUE_GRAPHIC:
+#if HAVE_FEATURE_AVMEDIA
+            {
+                Graphic aGraphic = aItem.getGraphic();
+                if (!aGraphic.IsNone())
+                {
+                    rValue <<= aGraphic.GetXGraphic();
+                }
+            }
+#endif
+            break;
+
             case OWN_ATTR_FALLBACK_GRAPHIC:
                 rValue <<= pMedia->getSnapshot();
                 break;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to