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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 9 07:02:34 UTC 2020


 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 369355da5c1e25bad7124dd6e187d9e381759751
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Jun 8 21:05:07 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Jun 9 09:02:01 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.
    
    Change-Id: I81536ceb44c6e455e9bf274a5852008443f9d64f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95857
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.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 dfbd496a31df..8a085472ea4a 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -186,6 +186,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)


More information about the Libreoffice-commits mailing list