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 + +#include +#include +#include + +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 xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference 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(3928), aCrop.Top); + CPPUNIT_ASSERT_EQUAL(static_cast(6660), aCrop.Bottom); + CPPUNIT_ASSERT_EQUAL(static_cast(1732), aCrop.Left); + CPPUNIT_ASSERT_EQUAL(static_cast(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); }