[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Apr 23 13:24:26 UTC 2018


 sw/qa/extras/htmlimport/data/image-lazy-read.html |   11 +++++++++++
 sw/qa/extras/htmlimport/htmlimport.cxx            |    8 ++++++++
 sw/source/filter/html/htmlgrin.cxx                |   21 +++++++++++++++++++--
 3 files changed, 38 insertions(+), 2 deletions(-)

New commits:
commit a0f5c5e6d16ef9e3db140a922912ff2a49a224b7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Apr 23 14:10:10 2018 +0200

    sw HTML import: lazy-read inline images
    
    Also prefer Graphic::GetPrefSize() over Graphic::GetSizePixel(), since the
    previous does not swap in the image.
    
    Change-Id: I100da14716448e72b687ce8ad1800326f0b3735e
    Reviewed-on: https://gerrit.libreoffice.org/53322
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sw/qa/extras/htmlimport/data/image-lazy-read.html b/sw/qa/extras/htmlimport/data/image-lazy-read.html
new file mode 100644
index 000000000000..afc19a7a62d0
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/image-lazy-read.html
@@ -0,0 +1,11 @@
+<html>
+<p>
+aaa
+</p>
+<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
+bbb
+</p>
+<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
+<img src="data:image/png;base64,/9j/4AAQSkZJRgABAQEAWQBZAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/wgALCAGQAMgBAREA/8QAHQABAAMBAAMBAQAAAAAAAAAAAAEICQQCBgcFA//aAAgBAQAAAAG1H86QfEnigJ/pdr7pXGnkQfcLv/0jlz19DmIBL6PfurFZXge/aFdU8ee3vH0tEA9Mr5db2eg/J4Hv2hPW5M97I/f0gj83PX9e+tLPisQ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VW4pINbj47S/0pU2txHkm/ZGMrLyPMnZCQh5h7EndoFtr1zCCkklVwNxqEvURcyPLNxqVm5oBoBoBoBoBoBoBoBoBoBJWm43BvCVAN/ooYiTiHJV/vmGnrshoRRPM
 clq2r4x6iTKiQYpyZKTblGfsazc1m5rNzWbms3NZuazc1m5rNzWbms3NZuUP+hT/AOxIJbjY4Y/1jzDhjgzMSvmD0YuwmoFoJG3H4NFNXY5mJXBRV8aSglCHkiJqFTmQ1P4JX4QlAlCP/9k=">
+</p>
+</html>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 5829cdcd4d31..fecd3c53b5b6 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -224,6 +224,14 @@ DECLARE_HTMLIMPORT_TEST(testImageWidthAuto, "image-width-auto.html")
     CPPUNIT_ASSERT_EQUAL(Size(1835, 560), rSize.GetSize());
 }
 
+DECLARE_HTMLIMPORT_TEST(testImageLazyRead, "image-lazy-read.html")
+{
+    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_HTMLIMPORT_TEST(testChangedby, "meta-changedby.html")
 {
     SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index 869d92c3c435..cb25a316277f 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -480,8 +480,25 @@ IMAGE_SETEVENT:
         std::unique_ptr<SvMemoryStream> const pStream(aGraphicURL.getData());
         if (pStream)
         {
-            if (ERRCODE_NONE == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *pStream))
+            GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+            aGraphic = rFilter.ImportUnloadedGraphic(*pStream);
+            if (aGraphic)
+            {
                 sGrfNm.clear();
+
+                if (!bHeightProvided || !bWidthProvided)
+                {
+                    Size aPrefSize = aGraphic.GetPrefSize();
+                    nWidth = aPrefSize.getWidth();
+                    nHeight = aPrefSize.getHeight();
+                }
+            }
+
+            if (!sGrfNm.isEmpty())
+            {
+                if (ERRCODE_NONE == rFilter.ImportGraphic(aGraphic, "", *pStream))
+                    sGrfNm.clear();
+            }
         }
     }
     else if (m_sBaseURL.isEmpty() || !aGraphicData.isEmpty())
@@ -497,7 +514,7 @@ IMAGE_SETEVENT:
         aGraphic.SetDefaultType();
     }
 
-    if (!bHeightProvided || !bWidthProvided)
+    if (!nHeight || !nWidth)
     {
         Size aPixelSize = aGraphic.GetSizePixel(Application::GetDefaultDevice());
         if (!bWidthProvided)


More information about the Libreoffice-commits mailing list