tdf#169680 DOCX import: fix unexpected stretched image
Open the bugdoc, the music notes picture inside is not readable. This went wrong in commitedda1e5fc8(DOCX import: lazy-read images without external headers, 2018-04-20), and later commitc3ce373227(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/+/195542 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
This commit is contained in:
@@ -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:
|
||||
@@ -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
|
||||
|
||||
|
||||
Binary file not shown.
@@ -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: */
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user