From 12273af6f18edade1bdda828fe270fa37960e14f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 30 Sep 2019 21:36:56 +0200 Subject: tdf#127446 vcl image lazy-load: fix custom size handling of metafiles This is a regression from commit acb803b730f2c6bd82e39beab58949ec14f85eb0 (tdf#125591 DOC import: lazy-load metafiles with explicit size, 2019-06-11), which assumed that once maSwapInfo.maPrefSize stores the preferred size, it'll be set on the Graphic when it's loaded later. It seems there was no support for that, it was just an accident that the guessed size of the metafile was about right. Handle this explicitly in ImpGraphic::loadPrepared(), so that the bugdoc (which has a custom preferred size) aspect ratio is correct. Change-Id: Ic7c4009ad6723a2e16129d27600c904311ff3daf Reviewed-on: https://gerrit.libreoffice.org/79899 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- vcl/CppunitTest_vcl_graphic_test.mk | 2 ++ vcl/qa/cppunit/GraphicTest.cxx | 27 +++++++++++++++++++++++++++ vcl/source/gdi/impgraph.cxx | 8 ++++++++ 3 files changed, 37 insertions(+) (limited to 'vcl') diff --git a/vcl/CppunitTest_vcl_graphic_test.mk b/vcl/CppunitTest_vcl_graphic_test.mk index d339cd22a5cb..fd5c7aeb039b 100644 --- a/vcl/CppunitTest_vcl_graphic_test.mk +++ b/vcl/CppunitTest_vcl_graphic_test.mk @@ -48,6 +48,8 @@ $(eval $(call gb_CppunitTest_use_components,vcl_graphic_test,\ i18npool/util/i18npool \ ucb/source/core/ucb1 \ unotools/util/utl \ + emfio/emfio \ + drawinglayer/drawinglayer \ )) $(eval $(call gb_CppunitTest_use_configuration,vcl_graphic_test)) diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx index 5bff94a9e9de..f5f5bd3ce292 100644 --- a/vcl/qa/cppunit/GraphicTest.cxx +++ b/vcl/qa/cppunit/GraphicTest.cxx @@ -27,10 +27,12 @@ class GraphicTest : public CppUnit::TestFixture { void testUnloadedGraphic(); void testUnloadedGraphicLoading(); + void testUnloadedGraphicWmf(); CPPUNIT_TEST_SUITE(GraphicTest); CPPUNIT_TEST(testUnloadedGraphic); CPPUNIT_TEST(testUnloadedGraphicLoading); + CPPUNIT_TEST(testUnloadedGraphicWmf); CPPUNIT_TEST_SUITE_END(); }; @@ -130,6 +132,31 @@ void GraphicTest::testUnloadedGraphicLoading() } } +void GraphicTest::testUnloadedGraphicWmf() +{ + // Create some in-memory WMF data, set its own preferred size to 99x99. + BitmapEx aBitmapEx = createBitmap(); + SvMemoryStream aStream; + GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); + sal_uInt16 nFilterFormat = rGraphicFilter.GetExportFormatNumberForShortName("wmf"); + Graphic aGraphic(aBitmapEx); + aGraphic.SetPrefSize(Size(99, 99)); + aGraphic.SetPrefMapMode(MapMode(MapUnit::Map100thMM)); + rGraphicFilter.ExportGraphic(aGraphic, "none", aStream, nFilterFormat); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + + // Now lazy-load this WMF data, with a custom preferred size of 42x42. + Size aMtfSize100(42, 42); + aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, &aMtfSize100); + aGraphic.makeAvailable(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 42x42 + // - Actual : 99x99 + // i.e. we the custom preferred size was lost after lazy-load. + CPPUNIT_ASSERT_EQUAL(Size(42, 42), aGraphic.GetPrefSize()); +} + } // namespace CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest); diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 372b93bec360..0a215fede7b0 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1562,7 +1562,15 @@ bool ImpGraphic::loadPrepared() if (mpGfxLink->LoadNative(aGraphic)) { GraphicExternalLink aLink = maGraphicExternalLink; + + Size aPrefSize = maSwapInfo.maPrefSize; *this = *aGraphic.ImplGetImpGraphic(); + if (aPrefSize.getWidth() && aPrefSize.getHeight()) + { + // Use custom preferred size if it was set when the graphic was still unloaded. + ImplSetPrefSize(aPrefSize); + } + maGraphicExternalLink = aLink; return true; -- cgit