[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 9 16:05:59 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 162d1babb958502ee98486d2b98cfd8a45b53ba1
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 18:05:28 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

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 250a32832752..1ea8fb0cc222 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -193,6 +193,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