comphelper/source/container/embeddedobjectcontainer.cxx |   45 ++++++++++------
 xmloff/source/draw/shapeexport.cxx                      |   22 ++++---
 2 files changed, 42 insertions(+), 25 deletions(-)

New commits:
commit 2aa310cfe0bc10e7bf079147d379f6eb7d061b74
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri May 3 08:14:16 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri May 3 11:19:04 2024 +0200

    tdf#160915: make own OLE objects obey AddReplacementImages setting
    
    Change-Id: I25ce3c920dc8ba25d0ac14310ff9cba8a4c23c6a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167026
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx 
b/comphelper/source/container/embeddedobjectcontainer.cxx
index 1bbf7b847fe4..0f831db3d6c5 100644
--- a/comphelper/source/container/embeddedobjectcontainer.cxx
+++ b/comphelper/source/container/embeddedobjectcontainer.cxx
@@ -36,6 +36,8 @@
 #include <com/sun/star/embed/Aspects.hpp>
 #include <com/sun/star/embed/EmbedMisc.hpp>
 
+#include <comphelper/classids.hxx>
+#include <comphelper/mimeconfighelper.hxx>
 #include <comphelper/seqstream.hxx>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/storagehelper.hxx>
@@ -1158,6 +1160,15 @@ namespace {
 
 }
 
+static bool AlwaysStoreReplacementImages(const 
uno::Reference<embed::XEmbeddedObject>& xObj)
+{
+    const auto clsid = xObj->getClassID();
+    if (clsid == MimeConfigurationHelper::GetSequenceClassID(SO3_SCH_CLASSID)
+        || clsid == 
MimeConfigurationHelper::GetSequenceClassID(SO3_SM_CLASSID))
+        return false;
+    return true;
+}
+
 bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool 
_bCreateEmbedded, bool _bAutoSaveEvent,
                                               const uno::Reference < 
embed::XStorage >& _xStorage)
 {
@@ -1176,26 +1187,28 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool 
_bOasisFormat,bool _bCreateEm
 
                 uno::Reference < io::XInputStream > xStream;
                 OUString aMediaType;
-
-                sal_Int32 nCurState = xObj->getCurrentState();
-                if ( nCurState == embed::EmbedStates::LOADED || nCurState == 
embed::EmbedStates::RUNNING )
+                if 
(officecfg::Office::Common::Save::Graphic::AddReplacementImages::get()
+                    || AlwaysStoreReplacementImages(xObj))
                 {
-                    // means that the object is not active
-                    // copy replacement image from old to new container
-                    xStream = GetGraphicStream( xObj, &aMediaType );
-                }
+                    sal_Int32 nCurState = xObj->getCurrentState();
+                    if (nCurState == embed::EmbedStates::LOADED
+                        || nCurState == embed::EmbedStates::RUNNING)
+                    {
+                        // means that the object is not active
+                        // copy replacement image from old to new container
+                        xStream = GetGraphicStream(xObj, &aMediaType);
+                    }
 
-                if ( !xStream.is() && getUserAllowsLinkUpdate() )
-                {
-                    // the image must be regenerated
-                    // TODO/LATER: another aspect could be used
-                    if ( xObj->getCurrentState() == embed::EmbedStates::LOADED 
)
+                    if (!xStream.is() && getUserAllowsLinkUpdate())
+                    {
+                        // the image must be regenerated
+                        // TODO/LATER: another aspect could be used
+                        if (xObj->getCurrentState() == 
embed::EmbedStates::LOADED)
                             bSwitchBackToLoaded = true;
 
-                    xStream = GetGraphicReplacementStream(
-                                                            
embed::Aspects::MSOLE_CONTENT,
-                                                            xObj,
-                                                            &aMediaType );
+                        xStream = 
GetGraphicReplacementStream(embed::Aspects::MSOLE_CONTENT, xObj,
+                                                              &aMediaType);
+                    }
                 }
 
                 if ( _bOasisFormat || (xLink.is() && xLink->isLink()) )
diff --git a/xmloff/source/draw/shapeexport.cxx 
b/xmloff/source/draw/shapeexport.cxx
index a701fff5dd12..0f150c847cd2 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -2526,8 +2526,8 @@ void XMLShapeExport::ImpExportGraphicObjectShape(
 
         //Resolves: fdo#62461 put preferred image first above, followed by
         //fallback here
-        const bool bAddReplacementImages = 
officecfg::Office::Common::Save::Graphic::AddReplacementImages::get();
-        if( !bIsEmptyPresObj && bAddReplacementImages)
+        if (!bIsEmptyPresObj
+            && 
officecfg::Office::Common::Save::Graphic::AddReplacementImages::get())
         {
             uno::Reference<graphic::XGraphic> xReplacementGraphic;
             xPropSet->getPropertyValue("ReplacementGraphic") >>= 
xReplacementGraphic;
@@ -3574,13 +3574,16 @@ void XMLShapeExport::ImpExportMediaShape(
 
     pPluginOBJ.reset();
 
-    uno::Reference<graphic::XGraphic> xGraphic;
-    xPropSet->getPropertyValue("Graphic") >>= xGraphic;
-    Graphic aGraphic(xGraphic);
-    if (!aGraphic.IsNone())
+    if (officecfg::Office::Common::Save::Graphic::AddReplacementImages::get())
     {
-        // The media has a preview, export it.
-        ExportGraphicPreview(xGraphic, mrExport, u"MediaPreview", u".png", 
"image/png");
+        uno::Reference<graphic::XGraphic> xGraphic;
+        xPropSet->getPropertyValue("Graphic") >>= xGraphic;
+        Graphic aGraphic(xGraphic);
+        if (!aGraphic.IsNone())
+        {
+            // The media has a preview, export it.
+            ExportGraphicPreview(xGraphic, mrExport, u"MediaPreview", u".png", 
"image/png");
+        }
     }
 
     ImpExportDescription(xShape);
@@ -5170,7 +5173,8 @@ void XMLShapeExport::ImpExportTableShape( const 
uno::Reference< drawing::XShape
             }
         }
 
-        if( !bIsEmptyPresObj )
+        if (!bIsEmptyPresObj
+            && 
officecfg::Office::Common::Save::Graphic::AddReplacementImages::get())
         {
             uno::Reference< graphic::XGraphic > xGraphic( 
xPropSet->getPropertyValue("ReplacementGraphic"), uno::UNO_QUERY );
             ExportGraphicPreview(xGraphic, mrExport, u"TablePreview", u".svm", 
"image/x-vclgraphic");

Reply via email to