[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - vcl/qa vcl/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon Dec 7 16:42:29 UTC 2020


 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 24deea41f820399593210c8806edd68940f77c20
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Dec 7 17:10:56 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Dec 7 17:41:41 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

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 7f60343e17c7..4c082a10d21c 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>
@@ -50,6 +52,7 @@ private:
     void testSwapping();
     void testSwappingVectorGraphic();
     void testWMFRoundtrip();
+    void testEmfToWmfConversion();
 
     CPPUNIT_TEST_SUITE(GraphicTest);
     CPPUNIT_TEST(testUnloadedGraphic);
@@ -60,6 +63,7 @@ private:
     CPPUNIT_TEST(testSwapping);
     CPPUNIT_TEST(testSwappingVectorGraphic);
     CPPUNIT_TEST(testWMFRoundtrip);
+    CPPUNIT_TEST(testEmfToWmfConversion);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -298,6 +302,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 9593847dd276..b4763831105b 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1926,9 +1926,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());
 


More information about the Libreoffice-commits mailing list