vcl/qa/cppunit/GraphicTest.cxx      |   36 ++++++++++++++++++++++++++++++++++++
 vcl/qa/cppunit/data/to-wmf.emf      |binary
 vcl/source/filter/graphicfilter.cxx |    8 +++++++-
 3 files changed, 43 insertions(+), 1 deletion(-)

New commits:
commit c06abb40f7155e92c56026ce3ea0526ceb3a0f27
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Dec 7 17:10:56 2020 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Dec 7 18:22:24 2020 +0100

    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 <vmik...@collabora.com>
    Tested-by: Jenkins

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
Binary files /dev/null and b/vcl/qa/cppunit/data/to-wmf.emf 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());
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to