tdf#156593 FILEOPEN OOXML: image shown in full instead of cropped

Revert "Revert "tdf#118133 DOCX import: disable lazy-loading of tiff images""

This reverts commit c6bf16909db054ec5467ebdc0ea0c9dc07307048.

Lazy-loading doesn't work with cropped TIFF images, because in case of Lazy-load TIFF images
we are using MapUnit::MapPixel, but in case of cropped images we are using MapUnit::Map100thMM
and the crop values are relative to original bitmap size.

Change-Id: I2dbf6caf08d7899ec2eae683996d997809d62b89
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158509
Tested-by: Jenkins
Reviewed-by: Balazs Varga <balazs.varga.extern@allotropia.de>
diff --git a/include/oox/helper/graphichelper.hxx b/include/oox/helper/graphichelper.hxx
index 32e699e..0d0b692 100644
--- a/include/oox/helper/graphichelper.hxx
+++ b/include/oox/helper/graphichelper.hxx
@@ -121,7 +121,8 @@ public:
    css::uno::Reference< css::graphic::XGraphic >
                        importGraphic(
                            const css::uno::Reference< css::io::XInputStream >& rxInStrm,
                            const WmfExternal* pExtHeader = nullptr ) const;
                            const WmfExternal* pExtHeader = nullptr,
                            const bool bLazyLoad = true ) const;

    /** Imports a graphic from the passed binary memory block. */
    css::uno::Reference< css::graphic::XGraphic >
diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx
index d197b34..830f013 100644
--- a/oox/source/helper/graphichelper.cxx
+++ b/oox/source/helper/graphichelper.cxx
@@ -229,13 +229,13 @@ awt::Size GraphicHelper::convertHmmToAppFont( const awt::Size& rHmm ) const
// Graphics and graphic objects  ----------------------------------------------

Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStream >& rxInStrm,
        const WmfExternal* pExtHeader ) const
        const WmfExternal* pExtHeader, const bool bLazyLoad ) const
{
    Reference< XGraphic > xGraphic;
    if( rxInStrm.is() && mxGraphicProvider.is() ) try
    {
        Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("InputStream", rxInStrm),
                                         comphelper::makePropertyValue("LazyRead", true) };
                                         comphelper::makePropertyValue("LazyRead", bLazyLoad) };

        if ( pExtHeader && pExtHeader->mapMode > 0 )
        {
@@ -283,8 +283,11 @@ Reference< XGraphic > GraphicHelper::importEmbeddedGraphic( const OUString& rStr
        xGraphic = mxGraphicMapper->findGraphic(rStreamName);
        if (!xGraphic.is())
        {
            // Lazy-loading doesn't work with cropped TIFF images, because in case of Lazy-load TIFF images
            // we are using MapUnit::MapPixel, but in case of cropped images we are using MapUnit::Map100thMM
            // and the crop values are relative to original bitmap size.
            auto xStream = mxStorage->openInputStream(rStreamName);
            xGraphic = importGraphic(xStream, pExtHeader);
            xGraphic = importGraphic(xStream, pExtHeader, !rStreamName.endsWith(".tiff"));
            if (xGraphic.is())
                mxGraphicMapper->putGraphic(rStreamName, xGraphic);
        }