summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-11-18 21:18:24 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-11-19 10:20:12 +0100
commitc1e207afd82c587c977d3497c466a82b2628cb7b (patch)
tree03985153cc59e0ec587b468a7a45ab37af38861d /vcl
parentbced052ae28a3cafbe4cd0538cefc9a37f80094f (diff)
tdf#128632 vcl image lazy-load: take unit into account when setting size
It makes no sense to set the size of an image based on the swap info when the swap info unit and the actually loaded image's unit doesn't match. Converting the size would be also an option, but let's wait for the first case when a custom size is actually needed for mismatching units. (cherry picked from commit 0098563895f6a4024b400582d1bf93cb4435ceed) Change-Id: I96b5c237f0be5587bb2f938faf3c69fa0e1d4a5c Reviewed-on: https://gerrit.libreoffice.org/83160 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/GraphicTest.cxx22
-rw-r--r--vcl/qa/cppunit/data/inch-size.emfbin0 -> 28322 bytes
-rw-r--r--vcl/source/gdi/impgraph.cxx4
3 files changed, 25 insertions, 1 deletions
diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 56e05c8bf3de..e67ba6ff7ee7 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -18,6 +18,7 @@
#include <vcl/graph.hxx>
#include <vcl/graphicfilter.hxx>
#include <tools/stream.hxx>
+#include <unotest/directories.hxx>
using namespace css;
@@ -29,12 +30,14 @@ class GraphicTest : public CppUnit::TestFixture
void testUnloadedGraphicLoading();
void testUnloadedGraphicWmf();
void testUnloadedGraphicAlpha();
+ void testUnloadedGraphicSizeUnit();
CPPUNIT_TEST_SUITE(GraphicTest);
CPPUNIT_TEST(testUnloadedGraphic);
CPPUNIT_TEST(testUnloadedGraphicLoading);
CPPUNIT_TEST(testUnloadedGraphicWmf);
CPPUNIT_TEST(testUnloadedGraphicAlpha);
+ CPPUNIT_TEST(testUnloadedGraphicSizeUnit);
CPPUNIT_TEST_SUITE_END();
};
@@ -79,6 +82,8 @@ Graphic makeUnloadedGraphic(OUString const& sType, bool alpha = false)
return rGraphicFilter.ImportUnloadedGraphic(aStream);
}
+char const DATA_DIRECTORY[] = "/vcl/qa/cppunit/data/";
+
void GraphicTest::testUnloadedGraphic()
{
// make unloaded test graphic
@@ -194,6 +199,23 @@ void GraphicTest::testUnloadedGraphicAlpha()
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
}
+void GraphicTest::testUnloadedGraphicSizeUnit()
+{
+ GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+ test::Directories aDirectories;
+ OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "inch-size.emf";
+ Size aMtfSize100(42, 42);
+ SvFileStream aStream(aURL, StreamMode::READ);
+ Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, &aMtfSize100);
+ aGraphic.makeAvailable();
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 400x363
+ // - Actual : 42x42
+ // i.e. a mm100 size was used as a hint and the inch size was set for a non-matching unit.
+ CPPUNIT_ASSERT_EQUAL(Size(400, 363), aGraphic.GetPrefSize());
+}
+
} // namespace
CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);
diff --git a/vcl/qa/cppunit/data/inch-size.emf b/vcl/qa/cppunit/data/inch-size.emf
new file mode 100644
index 000000000000..ac5a1b805cf2
--- /dev/null
+++ b/vcl/qa/cppunit/data/inch-size.emf
Binary files differ
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 824caae1698f..280ad3c2f1cd 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1570,10 +1570,12 @@ bool ImpGraphic::loadPrepared()
GraphicExternalLink aLink = maGraphicExternalLink;
Size aPrefSize = maSwapInfo.maPrefSize;
+ MapMode aPrefMapMode = maSwapInfo.maPrefMapMode;
*this = *aGraphic.ImplGetImpGraphic();
- if (aPrefSize.getWidth() && aPrefSize.getHeight())
+ if (aPrefSize.getWidth() && aPrefSize.getHeight() && aPrefMapMode == ImplGetPrefMapMode())
{
// Use custom preferred size if it was set when the graphic was still unloaded.
+ // Only set the size in case the unloaded and loaded unit matches.
ImplSetPrefSize(aPrefSize);
}