[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - vcl/CppunitTest_vcl_graphic_test.mk vcl/Module_vcl.mk vcl/qa vcl/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Fri Nov 27 12:08:34 UTC 2020
vcl/CppunitTest_vcl_graphic_test.mk | 48 +++++++++++++++++++
vcl/Module_vcl.mk | 1
vcl/qa/cppunit/GraphicTest.cxx | 90 ++++++++++++++++++++++++++++++++++++
vcl/qa/cppunit/data/roundtrip.wmf |binary
vcl/source/filter/graphicfilter.cxx | 31 ++++++++++--
5 files changed, 165 insertions(+), 5 deletions(-)
New commits:
commit 66db3307b75ce21767328a00371a8683207ddc99
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Nov 25 18:01:08 2020 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Nov 27 13:07:40 2020 +0100
WMF export: just write the source data as is for from-WMF graphics
This was already working on master since commit
5868745db74ae930edb0058490076d82aaeafbe9 (emfplus: make VectorFormats
Emf/Wmf/Svg work, 2017-06-12), but a matching testcase was missing.
[ And on this branch, fix the actual problem by picking the small
relevant subset of the above commit. ]
(cherry picked from commit 6bb0e09e2423ae00e06e6b7ae2c5a0af6ca100a1)
Conflicts:
vcl/qa/cppunit/GraphicTest.cxx
Change-Id: I7661cd5e66d13b1750f16c0c423c4b69420577a0
diff --git a/vcl/CppunitTest_vcl_graphic_test.mk b/vcl/CppunitTest_vcl_graphic_test.mk
new file mode 100644
index 000000000000..98eaae8800e7
--- /dev/null
+++ b/vcl/CppunitTest_vcl_graphic_test.mk
@@ -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,vcl_graphic_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_graphic_test, \
+ vcl/qa/cppunit/GraphicTest \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,vcl_graphic_test,\
+ boost_headers \
+ glm_headers \
+))
+
+$(eval $(call gb_CppunitTest_set_include,vcl_graphic_test,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/vcl/inc \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_graphic_test, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ svt \
+ test \
+ tl \
+ unotest \
+ vcl \
+ utl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,vcl_graphic_test))
+$(eval $(call gb_CppunitTest_use_ure,vcl_graphic_test))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_graphic_test))
+$(eval $(call gb_CppunitTest_use_rdb,vcl_graphic_test,services))
+$(eval $(call gb_CppunitTest_use_configuration,vcl_graphic_test))
+
+# we need to explicitly depend on Library_gie because it's dynamically loaded for .gif
+$(call gb_CppunitTest_get_target,vcl_graphic_test) : $(call gb_Library_get_target,gie)
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index a5e4bf5d68d2..b74bc2e67208 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -154,6 +154,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\
CppunitTest_vcl_svm_test \
CppunitTest_vcl_pdfexport \
CppunitTest_vcl_errorhandler \
+ CppunitTest_vcl_graphic_test \
))
diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
new file mode 100644
index 000000000000..d71a85ebf07b
--- /dev/null
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -0,0 +1,90 @@
+/* -*- 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 <sal/config.h>
+#include <config_oox.h>
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#include <vcl/bitmapaccess.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <tools/stream.hxx>
+#include <unotest/directories.hxx>
+#include <comphelper/hash.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/tempfile.hxx>
+
+using namespace css;
+
+namespace
+{
+class GraphicTest : public CppUnit::TestFixture
+{
+public:
+ ~GraphicTest();
+
+private:
+ void testWMFRoundtrip();
+
+ CPPUNIT_TEST_SUITE(GraphicTest);
+ CPPUNIT_TEST(testWMFRoundtrip);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+GraphicTest::~GraphicTest()
+{
+}
+
+void GraphicTest::testWMFRoundtrip()
+{
+ // Load a WMF file.
+ test::Directories aDirectories;
+ OUString aURL = aDirectories.getURLFromSrc("vcl/qa/cppunit/data/roundtrip.wmf");
+ SvFileStream aStream(aURL, StreamMode::READ);
+ sal_uInt64 nPos = aStream.Tell();
+ aStream.Seek(STREAM_SEEK_TO_END);
+ sal_uInt64 nExpectedSize = aStream.Tell();
+ aStream.Seek(nPos);
+ GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+ Graphic aGraphic;
+ rGraphicFilter.ImportGraphic(aGraphic, OUString(), aStream);
+
+ // Save as WMF.
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ sal_uInt16 nFormat = rGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
+ SvStream& rOutStream = *aTempFile.GetStream(StreamMode::READWRITE);
+ rGraphicFilter.ExportGraphic(aGraphic, OUString(), rOutStream, nFormat);
+
+ // Check if we preserved the WMF data perfectly.
+ nPos = rOutStream.Tell();
+ rOutStream.Seek(STREAM_SEEK_TO_END);
+ sal_uInt64 nActualSize = rOutStream.Tell();
+ rOutStream.Seek(nPos);
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected less or equal than: 10
+ // - Actual : 3637
+ // i.e. we lost most of the WMF data on roundtrip. Still allow loosing some padding bytes at the
+ // very end, that's harmless.
+ CPPUNIT_ASSERT_LESSEQUAL(static_cast<sal_uInt64>(10), nExpectedSize - nActualSize);
+}
+
+} // namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/data/roundtrip.wmf b/vcl/qa/cppunit/data/roundtrip.wmf
new file mode 100644
index 000000000000..83210546c373
Binary files /dev/null and b/vcl/qa/cppunit/data/roundtrip.wmf differ
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 1638ae023eb9..5b0e24c2ce86 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1939,12 +1939,33 @@ sal_uInt16 GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString
}
else if ( aFilterName.equalsIgnoreAsciiCase( EXP_WMF ) )
{
- // #i119735# just use GetGDIMetaFile, it will create a bufferd version of contained bitmap now automatically
- if ( !ConvertGDIMetaFileToWMF( aGraphic.GetGDIMetaFile(), rOStm, &aConfigItem ) )
- nStatus = GRFILTER_FORMATERROR;
+ bool bDone = false;
- if( rOStm.GetError() )
- nStatus = GRFILTER_IOERROR;
+ const GfxLink& rLink = aGraphic.GetLink();
+ if (rLink.GetDataSize() && rLink.GetType() == GfxLinkType::NativeWmf)
+ {
+ // The source is already in WMF, no need to convert anything.
+ rOStm.WriteBytes(rLink.GetData(), rLink.GetDataSize());
+
+ if (rOStm.GetError())
+ {
+ nStatus = GRFILTER_IOERROR;
+ }
+ else
+ {
+ bDone = true;
+ }
+ }
+
+ if (!bDone)
+ {
+ // #i119735# just use GetGDIMetaFile, it will create a bufferd version of contained bitmap now automatically
+ if ( !ConvertGDIMetaFileToWMF( aGraphic.GetGDIMetaFile(), rOStm, &aConfigItem ) )
+ nStatus = GRFILTER_FORMATERROR;
+
+ if( rOStm.GetError() )
+ nStatus = GRFILTER_IOERROR;
+ }
}
else if ( aFilterName.equalsIgnoreAsciiCase( EXP_EMF ) )
{
More information about the Libreoffice-commits
mailing list