[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 31 21:48:22 UTC 2018


 sw/source/core/unocore/unoframe.cxx |   28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

New commits:
commit d6e31132de073ecb91334f3f4b7c5eecae090f1b
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Wed Oct 31 22:24:57 2018 +0100
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Wed Oct 31 22:41:28 2018 +0100

    sw: fix import of OLE object preview bitmaps
    
    xmloff sets these using package URLs (on this branch, LO >= 6.1 got rid of
    URLs for setting graphics), but SwXFrame::setPropertyValue() only
    expects graphic object URLs, so the preview is lost on import.
    
    Normally this is not noticeable as a fresh preview will be created, but
    in the situation described by commit
    13162d054d628380bf488acd7971170212af005e (svtools: fix lost replacement
    grpahic when updating it via OLE fails, 2018-10-30) this leads for the
    loss of preview on export (e.g. HTML).
    
    Fix the problem by explicitly looking up the graphic stream (of the OLE
    object) in the embedded object container, so the preview from the input
    (ODT) file is kept during conversion.
    
    Change-Id: I91fd23e4db9e39be6153748207b3c0bfb9f58901

diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 35641d6762cd..64c0a7c443ca 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -122,6 +122,8 @@
 #include <calbck.hxx>
 #include <comphelper/servicehelper.hxx>
 #include <cppuhelper/supportsservice.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <vcl/graphicfilter.hxx>
 
 #include <svx/unobrushitemhelper.hxx>
 #include <svx/xbtmpit.hxx>
@@ -1651,6 +1653,8 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any&
         {
             bool bURL = FN_UNO_REPLACEMENT_GRAPHIC_URL == pEntry->nWID;
             bool bApply = false;
+            // If this is a package URL.
+            bool bPackage = false;
             Graphic aGraphic;
             if( bURL )
             {
@@ -1670,6 +1674,8 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any&
                     aGraphic = pGrfObj->GetGraphic();
                     bApply = true;
                 }
+                else if (aGrfUrl.startsWith(sPackageProtocol))
+                    bPackage = true;
             }
             else
             {
@@ -1682,7 +1688,7 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any&
                 }
             }
 
-            if ( bApply )
+            if ( bApply || bPackage )
             {
                 const ::SwFormatContent* pCnt = &pFormat->GetContent();
                 if ( pCnt->GetContentIdx() && pDoc->GetNodes()[ pCnt->GetContentIdx()->GetIndex() + 1 ] )
@@ -1693,6 +1699,26 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any&
                     {
                         svt::EmbeddedObjectRef &rObj = pOleNode->GetOLEObj().GetObject();
 
+                        if (bPackage)
+                        {
+                            // Package URL case: look up the stream of the
+                            // graphic in the object container and initialize
+                            // aGraphic from that stream.
+                            comphelper::EmbeddedObjectContainer* pContainer = rObj.GetContainer();
+                            uno::Reference<embed::XEmbeddedObject> xObj = rObj.GetObject();
+                            if (pContainer)
+                            {
+                                OUString aMediaType;
+                                uno::Reference <io::XInputStream> xStream = pContainer->GetGraphicStream(xObj, &aMediaType);
+                                if (xStream.is())
+                                {
+                                    std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xStream));
+                                    GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
+                                    rGF.ImportGraphic(aGraphic, OUString(), *pStream);
+                                }
+                            }
+                        }
+
                         OUString aMediaType;
                         rObj.SetGraphic( aGraphic, aMediaType );
                     }


More information about the Libreoffice-commits mailing list