diff options
-rw-r--r-- | vcl/CppunitTest_vcl_graphic_test.mk | 2 | ||||
-rw-r--r-- | vcl/qa/cppunit/GraphicTest.cxx | 27 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 8 |
3 files changed, 37 insertions, 0 deletions
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; |