sw/qa/extras/ww8import/data/image-lazy-read-0size.doc |binary
 sw/qa/extras/ww8import/ww8import.cxx                  |   16 ++++++++++++++++
 sw/source/core/bastyp/swtypes.cxx                     |    7 +++++++
 3 files changed, 23 insertions(+)

New commits:
commit 56a5e5d9fdbc1542c802d1dcb7ce84e99de85fcb
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jun 8 21:05:07 2020 +0200
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Tue Jun 9 20:56:03 2020 +0200

    tdf#133474 DOC import: fix lazy-loading of images with zero size
    
    DOC typically contains images with a size hint outside the image, but
    this is optional. Make sure that we load the image in case the size is
    not available without loading.
    
    The effect is that once SwWW8ImplReader::MapWrapIntoFlyFormat() calls
    SwGrfNode::GetTwipSize(), we always get a valid size. Ideally without
    loading the graphic.
    
    (cherry picked from commit 369355da5c1e25bad7124dd6e187d9e381759751)
    
    Change-Id: I81536ceb44c6e455e9bf274a5852008443f9d64f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95907
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/qa/extras/ww8import/data/image-lazy-read-0size.doc 
b/sw/qa/extras/ww8import/data/image-lazy-read-0size.doc
new file mode 100644
index 000000000000..80306cb1deda
Binary files /dev/null and 
b/sw/qa/extras/ww8import/data/image-lazy-read-0size.doc differ
diff --git a/sw/qa/extras/ww8import/ww8import.cxx 
b/sw/qa/extras/ww8import/ww8import.cxx
index 468cacfd0967..8d0eb0cc10c9 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -181,6 +181,22 @@ DECLARE_OOXMLIMPORT_TEST(testImageLazyRead, 
"image-lazy-read.doc")
     CPPUNIT_ASSERT(!aGraphic.isAvailable());
 }
 
+DECLARE_OOXMLIMPORT_TEST(testImageLazyRead0size, "image-lazy-read-0size.doc")
+{
+    // Load a document with a single bitmap in it: it's declared as a WMF one, 
but actually a TGA
+    // bitmap.
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwNode* pNode = pDoc->GetNodes()[6];
+    SwGrfNode* pGrfNode = pNode->GetGrfNode();
+    CPPUNIT_ASSERT(pGrfNode);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 7590x10440
+    // - Actual  : 0x0
+    // i.e. the size was 0, even if the actual bitmap had a non-0 size.
+    CPPUNIT_ASSERT_EQUAL(Size(7590, 10440), pGrfNode->GetTwipSize());
+}
+
 DECLARE_WW8IMPORT_TEST(testTdf106799, "tdf106799.doc")
 {
     // Ensure that all text portions are calculated before testing.
diff --git a/sw/source/core/bastyp/swtypes.cxx 
b/sw/source/core/bastyp/swtypes.cxx
index 620f4bab771a..59c01abb55cb 100644
--- a/sw/source/core/bastyp/swtypes.cxx
+++ b/sw/source/core/bastyp/swtypes.cxx
@@ -29,6 +29,13 @@ Size GetGraphicSizeTwip(const Graphic& rGraphic, 
vcl::RenderContext* pOutDev)
 {
     const MapMode aMapTwip(MapUnit::MapTwip);
     Size aSize(rGraphic.GetPrefSize());
+
+    if (!aSize.getWidth() && !aSize.getHeight())
+    {
+        const_cast<Graphic&>(rGraphic).makeAvailable();
+        aSize = rGraphic.GetPrefSize();
+    }
+
     if (MapUnit::MapPixel == rGraphic.GetPrefMapMode().GetMapUnit())
     {
         if (!pOutDev)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to