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-20 21:35:52 +0100
commit427973bc2958b34464cfb5b38b3b06c422a919df (patch)
treec38c46c77d0b63aac4f167b9214de7e9652ae7d3 /vcl
parent65d1f709d06bbb51d23962dfe6c13ade04476592 (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> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/83288 Reviewed-by: Michael Stahl <michael.stahl@cib.de>
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 c9593434674b..2b1bfda8a919 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -19,6 +19,7 @@
#include <vcl/graphicfilter.hxx>
#include <tools/stream.hxx>
#include <vcl/pngwrite.hxx>
+#include <unotest/directories.hxx>
using namespace css;
@@ -30,12 +31,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();
};
@@ -80,6 +83,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
@@ -195,6 +200,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 e15644c9fdc2..8616e08e1c9d 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1556,10 +1556,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);
}