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/+/95897
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@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 0000000..80306cb
--- /dev/null
+++ b/sw/qa/extras/ww8import/data/image-lazy-read-0size.doc
Binary files differ
diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx
index dfbd496..8a08547 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 620f4ba..59c01ab 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)