summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-12-07 17:10:56 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-12-07 18:22:24 +0100
commitc06abb40f7155e92c56026ce3ea0526ceb3a0f27 (patch)
tree6c82a43adfe3c7a8a98460ec7278368e92c0cb10
parentb541cd9a8038810ce449f8c49ae179d9d6eaa7e8 (diff)
vcl graphic export: convert EMF to WMF when WMF is requested
Regression from commit 5868745db74ae930edb0058490076d82aaeafbe9 (emfplus: make VectorFormats Emf/Wmf/Svg work, 2017-06-12), we used to export graphic data as-is when the requested format is WMF and the source format is EMF or WMF. Restrict the as-is copying to the WMF source format only. Change-Id: Iad40aee79df5ae367ae37c2fb3d5f4dfad8a40fc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107355 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--vcl/qa/cppunit/GraphicTest.cxx36
-rw-r--r--vcl/qa/cppunit/data/to-wmf.emfbin0 -> 1057 bytes
-rw-r--r--vcl/source/filter/graphicfilter.cxx8
3 files changed, 43 insertions, 1 deletions
diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index df9711b54a35..479a3c91f836 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -25,8 +25,10 @@
#include <comphelper/hash.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <unotools/tempfile.hxx>
+#include <vcl/cvtgrf.hxx>
#include <impgraph.hxx>
+#include <graphic/GraphicFormatDetector.hxx>
#if USE_TLS_NSS
#include <nss.h>
@@ -51,6 +53,7 @@ private:
void testSwappingVectorGraphic();
void testSwappingPageNumber();
void testWMFRoundtrip();
+ void testEmfToWmfConversion();
CPPUNIT_TEST_SUITE(GraphicTest);
CPPUNIT_TEST(testUnloadedGraphic);
@@ -62,6 +65,7 @@ private:
CPPUNIT_TEST(testSwappingVectorGraphic);
CPPUNIT_TEST(testSwappingPageNumber);
CPPUNIT_TEST(testWMFRoundtrip);
+ CPPUNIT_TEST(testEmfToWmfConversion);
CPPUNIT_TEST_SUITE_END();
};
@@ -301,6 +305,38 @@ void GraphicTest::testUnloadedGraphicSizeUnit()
CPPUNIT_ASSERT_EQUAL(Size(400, 363), aGraphic.GetPrefSize());
}
+void GraphicTest::testEmfToWmfConversion()
+{
+ // Load EMF data.
+ GraphicFilter aGraphicFilter;
+ test::Directories aDirectories;
+ OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "to-wmf.emf";
+ SvFileStream aStream(aURL, StreamMode::READ);
+ Graphic aGraphic;
+ // This similar to an application/x-openoffice-wmf mime type in manifest.xml in the ODF case.
+ sal_uInt16 nFormat = aGraphicFilter.GetImportFormatNumberForShortName(u"WMF");
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE,
+ aGraphicFilter.ImportGraphic(aGraphic, OUString(), aStream, nFormat));
+ CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Wmf,
+ aGraphic.getVectorGraphicData()->getVectorGraphicDataType());
+
+ // Save as WMF.
+ sal_uInt16 nFilterType = aGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
+ SvMemoryStream aGraphicStream;
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, aGraphicFilter.ExportGraphic(aGraphic, OUString(),
+ aGraphicStream, nFilterType));
+ aGraphicStream.Seek(0);
+ vcl::GraphicFormatDetector aDetector(aGraphicStream, OUString());
+ CPPUNIT_ASSERT(aDetector.detect());
+ CPPUNIT_ASSERT(aDetector.checkWMForEMF());
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: WMF
+ // - Actual : EMF
+ // i.e. EMF data was requested to be converted to WMF, but the output was still EMF.
+ CPPUNIT_ASSERT_EQUAL(OUString("WMF"), aDetector.msDetectedFormat);
+}
+
void GraphicTest::testSwapping()
{
// Prepare Graphic from a PNG image first
diff --git a/vcl/qa/cppunit/data/to-wmf.emf b/vcl/qa/cppunit/data/to-wmf.emf
new file mode 100644
index 000000000000..e1a7b9f9e517
--- /dev/null
+++ b/vcl/qa/cppunit/data/to-wmf.emf
Binary files differ
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index ad3dabd4494e..4b4fa6c4582d 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1960,9 +1960,15 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& r
// do we have a native Vector Graphic Data RenderGraphic, whose data can be written directly?
auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
+ bool bIsEMF = rGraphic.GetGfxLink().IsEMF();
+
+ // VectorGraphicDataType::Wmf means WMF or EMF, allow direct write in the WMF case
+ // only.
if (rVectorGraphicDataPtr
&& rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()
- && VectorGraphicDataType::Wmf == rVectorGraphicDataPtr->getVectorGraphicDataType())
+ && VectorGraphicDataType::Wmf
+ == rVectorGraphicDataPtr->getVectorGraphicDataType()
+ && !bIsEMF)
{
rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());