oox/CppunitTest_oox_helper.mk | 48 ++++++++++++++++++++++++++++++ oox/Module_oox.mk | 1 oox/qa/unit/data/tif-crop.docx |binary oox/qa/unit/helper.cxx | 56 ++++++++++++++++++++++++++++++++++++ oox/source/helper/graphichelper.cxx | 4 +- 5 files changed, 108 insertions(+), 1 deletion(-)
New commits: commit 8455a8ed5a1bd4808e2c24b9bbd54786066783b1 Author: Miklos Vajna <[email protected]> AuthorDate: Fri Dec 12 08:32:04 2025 +0100 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Dec 15 10:57:10 2025 +0100 tdf#169680 DOCX import: fix unexpected stretched image Open the bugdoc, the music notes picture inside is not readable. This went wrong in commit edda1e5fc8113aa4744e32f97c96a3cc311485ca (DOCX import: lazy-read images without external headers, 2018-04-20), and later commit c3ce373227433f40d686847a22e78651bedbab24 (tdf#156593 FILEOPEN OOXML: image shown in full instead of cropped, 2023-10-27) fixed a similar problem, this bugdoc is still bad. Note how the second commit looks for the .tiff extension, while this bugdoc has a .TIF image. Fix the problem by looking for both extensions, in a case-insensitive way. A future possibility would be to improve OInputCompStream's XPropertySet implementation, so next to its Compressed and Size properties, it would also expose the image/tiff MIME type, and then we would not have to guess content based on the file extension. Change-Id: I81519119bae698bf1cca34792fcf1aa6587b48a8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195510 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> (cherry picked from commit a297035f4b58baf09e35c32480b058305072254c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195632 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Miklos Vajna <[email protected]> diff --git a/oox/CppunitTest_oox_helper.mk b/oox/CppunitTest_oox_helper.mk new file mode 100644 index 000000000000..755f0d6ec4ec --- /dev/null +++ b/oox/CppunitTest_oox_helper.mk @@ -0,0 +1,48 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,oox_helper)) + +$(eval $(call gb_CppunitTest_use_externals,oox_helper,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,oox_helper, \ + oox/qa/unit/helper \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,oox_helper, \ + comphelper \ + cppu \ + cppuhelper \ + oox \ + sal \ + subsequenttest \ + test \ + unotest \ + utl \ + tl \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,oox_helper)) + +$(eval $(call gb_CppunitTest_use_ure,oox_helper)) +$(eval $(call gb_CppunitTest_use_vcl,oox_helper)) + +$(eval $(call gb_CppunitTest_use_rdb,oox_helper,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,oox_helper,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,oox_helper)) + +# vim: set noet sw=4 ts=4: diff --git a/oox/Module_oox.mk b/oox/Module_oox.mk index f1d88c2dee21..07e33ec774d8 100644 --- a/oox/Module_oox.mk +++ b/oox/Module_oox.mk @@ -37,6 +37,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\ CppunitTest_oox_mcgr \ CppunitTest_oox_testscene3d \ CppunitTest_oox_wpc_drawing_canvas \ + CppunitTest_oox_helper \ )) endif diff --git a/oox/qa/unit/data/tif-crop.docx b/oox/qa/unit/data/tif-crop.docx new file mode 100644 index 000000000000..46fd22c972d2 Binary files /dev/null and b/oox/qa/unit/data/tif-crop.docx differ diff --git a/oox/qa/unit/helper.cxx b/oox/qa/unit/helper.cxx new file mode 100644 index 000000000000..d9739e925dc3 --- /dev/null +++ b/oox/qa/unit/helper.cxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/unoapi_test.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/text/GraphicCrop.hpp> + +using namespace ::com::sun::star; + +namespace +{ +/// Covers oox/source/helper/ fixes. +class Test : public UnoApiTest +{ +public: + Test() + : UnoApiTest(u"/oox/qa/unit/data/"_ustr) + { + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testImportTifCrop) +{ + // Given a cropped .TIF file in a document: + // When loading that document: + loadFromFile(u"tif-crop.docx"); + + // Then make sure the result has the correct crop rectangle: + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + text::GraphicCrop aCrop; + xShape->getPropertyValue(u"GraphicCrop"_ustr) >>= aCrop; + // Without the accompanying fix in place, this failed with: + // - Expected: 3928 + // - Actual : 24553 + // i.e. lazy-loading lead to some unexpected crop rectangle, the image was not readable. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3928), aCrop.Top); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6660), aCrop.Bottom); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1732), aCrop.Left); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1145), aCrop.Right); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx index c68ebe7e295c..4a6e42c2e2f0 100644 --- a/oox/source/helper/graphichelper.cxx +++ b/oox/source/helper/graphichelper.cxx @@ -288,7 +288,9 @@ Reference< XGraphic > GraphicHelper::importEmbeddedGraphic( const OUString& rStr // 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, !rStreamName.endsWith(".tiff")); + bool bLazyLoad = !rStreamName.endsWithIgnoreAsciiCase(".tiff") + && !rStreamName.endsWithIgnoreAsciiCase(".tif"); + xGraphic = importGraphic(xStream, pExtHeader, bLazyLoad); if (xGraphic.is()) mxGraphicMapper->putGraphic(rStreamName, xGraphic); }
