[Libreoffice-commits] core.git: filter/source oox/source sw/CppunitTest_sw_ww8import.mk sw/qa vcl/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Apr 20 19:13:40 UTC 2018


 filter/source/msfilter/msdffimp.cxx             |    9 ++++++++-
 oox/source/helper/graphichelper.cxx             |    7 +------
 sw/CppunitTest_sw_ww8import.mk                  |    1 +
 sw/qa/extras/ww8import/data/image-lazy-read.doc |binary
 sw/qa/extras/ww8import/ww8import.cxx            |    8 ++++++++
 vcl/source/filter/graphicfilter.cxx             |    1 +
 vcl/source/graphic/UnoGraphicProvider.cxx       |    6 +++---
 7 files changed, 22 insertions(+), 10 deletions(-)

New commits:
commit b11188835d3b87cd9d2a8cdb3da204cfda5d3e6e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Apr 20 17:58:09 2018 +0200

    DOC import: lazy-read images
    
    At least JPEG files are now only loaded when the user scrolls to the
    relevant page.
    
    Also fix the root cause of the EMF lazy-read problem and remove the
    previous workarounds.
    
    Change-Id: I9699927282b99bcb71a0d271a20bbfd56a361ee8
    Reviewed-on: https://gerrit.libreoffice.org/53219
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index f2fbc026c16d..3e80858d9275 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -6545,7 +6545,14 @@ bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, tool
         else
         {   // and unleash our filter
             GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
-            nRes = rGF.ImportGraphic( rData, "", *pGrStream );
+            Graphic aGraphic = rGF.ImportUnloadedGraphic(*pGrStream);
+            if (aGraphic)
+            {
+                rData = aGraphic;
+                nRes = ERRCODE_NONE;
+            }
+            else
+                nRes = rGF.ImportGraphic( rData, "", *pGrStream );
 
             // SJ: I40472, sometimes the aspect ratio (aMtfSize100) does not match and we get scaling problems,
             // then it is better to use the prefsize that is stored within the metafile. Bug #72846# for what the
diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx
index 002d54b946b5..073cfe6d694f 100644
--- a/oox/source/helper/graphichelper.cxx
+++ b/oox/source/helper/graphichelper.cxx
@@ -244,7 +244,7 @@ Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStrea
         aArgs[ 1 ].Name = "LazyRead";
         aArgs[ 1 ].Value <<= true;
 
-        if ( pExtHeader )
+        if ( pExtHeader && pExtHeader->mapMode > 0 )
         {
             aArgs.realloc( aArgs.getLength() + 1 );
             Sequence< PropertyValue > aFilterData( 3 );
@@ -341,11 +341,6 @@ Reference< XGraphic > GraphicHelper::importEmbeddedGraphic( const OUString& rStr
         EmbeddedGraphicMap::const_iterator aIt = maEmbeddedGraphics.find( rStreamName );
         if( aIt == maEmbeddedGraphics.end() )
         {
-            // TODO make lazy-load work for EMF as well.
-            WmfExternal aHeader;
-            if (rStreamName.endsWith(".emf") && !pExtHeader)
-                pExtHeader = &aHeader;
-
             xGraphic = importGraphic(mxStorage->openInputStream(rStreamName), pExtHeader);
             if( xGraphic.is() )
                 maEmbeddedGraphics[ rStreamName ] = xGraphic;
diff --git a/sw/CppunitTest_sw_ww8import.mk b/sw/CppunitTest_sw_ww8import.mk
index 7e40c058e722..b7102196a27f 100644
--- a/sw/CppunitTest_sw_ww8import.mk
+++ b/sw/CppunitTest_sw_ww8import.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_ww8import, \
     sal \
     test \
     unotest \
+    vcl \
     sfx \
     sw \
 	utl \
diff --git a/sw/qa/extras/ww8import/data/image-lazy-read.doc b/sw/qa/extras/ww8import/data/image-lazy-read.doc
new file mode 100644
index 000000000000..95017d2ac80e
Binary files /dev/null and b/sw/qa/extras/ww8import/data/image-lazy-read.doc differ
diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx
index 907fe47ebcff..de16cfe253e6 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -116,6 +116,14 @@ DECLARE_WW8IMPORT_TEST( testTdf105570, "tdf105570.doc" )
     CPPUNIT_ASSERT_EQUAL( sal_uInt16(0), pTableNd->GetTable().GetRowsToRepeat() );
 }
 
+DECLARE_OOXMLIMPORT_TEST(testImageLazyRead, "image-lazy-read.doc")
+{
+    auto xGraphic = getProperty<uno::Reference<graphic::XGraphic>>(getShape(1), "Graphic");
+    Graphic aGraphic(xGraphic);
+    // This failed, import loaded the graphic, it wasn't lazy-read.
+    CPPUNIT_ASSERT(!aGraphic.isAvailable());
+}
+
 DECLARE_WW8IMPORT_TEST(testTdf106799, "tdf106799.doc")
 {
     sal_Int32 const nCellWidths[3][4] = { { 9530, 0, 0, 0 },{ 2382, 2382, 2382, 2384 },{ 2382, 2382, 2382, 2384 } };
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 023c07ecb9a2..43feef35e5e2 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1572,6 +1572,7 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream)
             nGraphicContentSize = nStreamLength;
             pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
 
+            rIStream.Seek(nStreamBegin);
             rIStream.ReadBytes(pGraphicContent.get(), nStreamLength);
 
             if (!rIStream.GetError())
diff --git a/vcl/source/graphic/UnoGraphicProvider.cxx b/vcl/source/graphic/UnoGraphicProvider.cxx
index 8b9ccb93bf94..7adb183f5aa8 100644
--- a/vcl/source/graphic/UnoGraphicProvider.cxx
+++ b/vcl/source/graphic/UnoGraphicProvider.cxx
@@ -355,9 +355,6 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
         }
     }
 
-    if (bLazyRead && aFilterData.hasElements())
-        bLazyRead = false;
-
     SolarMutexGuard g;
 
     if( xIStm.is() )
@@ -396,7 +393,10 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
             aExtHeader.mapMode = nExtMapMode;
             WmfExternal *pExtHeader = nullptr;
             if ( nExtMapMode > 0 )
+            {
                 pExtHeader = &aExtHeader;
+                bLazyRead = false;
+            }
 
             ErrCode error = ERRCODE_NONE;
             if (bLazyRead)


More information about the Libreoffice-commits mailing list