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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Dec 9 10:18:05 UTC 2020


 vcl/qa/cppunit/GraphicTest.cxx      |   36 ++++++++++++++++++++++++++++++++++++
 vcl/qa/cppunit/data/to-wmf.emf      |binary
 vcl/source/filter/graphicfilter.cxx |    6 +++++-
 vcl/source/filter/wmf/enhwmf.cxx    |    5 ++++-
 4 files changed, 45 insertions(+), 2 deletions(-)

New commits:
commit f38c84f1dd1f78763bc72496ff251216bc1209a0
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Dec 8 15:15:47 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Dec 9 11:15:31 2020 +0100

    emfio: allow disabling EMF+ via a bootstrap variable
    
    Bootstrap variables have multiple sources, so the environment variable
    way continues to work. This also allows disabling EMF+ using the
    -env:EMF_PLUS_DISABLE=1 cmdline parameter, which is useful when soffice
    is not started in a shell.
    
    (cherry picked from commit 71a1ea29b8793a8db012dd3452ef0dd87f1be36a)
    
    Conflicts:
            emfio/source/reader/emfreader.cxx
    
    Change-Id: I76e82b77d70910ba4843db6ab998b0b1ea4a31f5

diff --git a/vcl/source/filter/wmf/enhwmf.cxx b/vcl/source/filter/wmf/enhwmf.cxx
index 0a22ab3762fd..b10c61a14766 100644
--- a/vcl/source/filter/wmf/enhwmf.cxx
+++ b/vcl/source/filter/wmf/enhwmf.cxx
@@ -21,6 +21,7 @@
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <vcl/dibtools.hxx>
 #include <o3tl/make_unique.hxx>
+#include <rtl/bootstrap.hxx>
 
 #include "winmtf.hxx"
 
@@ -648,7 +649,9 @@ bool EnhWMFReader::ReadEnhWMF()
     bool    bStatus = ReadHeader();
     bool    bHaveDC = false;
 
-    static bool bEnableEMFPlus = ( getenv( "EMF_PLUS_DISABLE" ) == nullptr );
+    OUString aEMFPlusDisable;
+    rtl::Bootstrap::get("EMF_PLUS_DISABLE", aEMFPlusDisable);
+    bool bEnableEMFPlus = aEMFPlusDisable.isEmpty();
 
     while( bStatus && nRecordCount-- && pWMF->good())
     {
commit 61809810c13778607f4cd3eaff6e490c3c6dd50d
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Dec 7 17:10:56 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Dec 9 10:19:38 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.
    
    (cherry picked from commit 24deea41f820399593210c8806edd68940f77c20)
    
    Conflicts:
            vcl/qa/cppunit/GraphicTest.cxx
            vcl/source/filter/graphicfilter.cxx
    
    Change-Id: Iad40aee79df5ae367ae37c2fb3d5f4dfad8a40fc

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index d71a85ebf07b..5012ae723bb5 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -24,6 +24,7 @@
 #include <comphelper/hash.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <unotools/tempfile.hxx>
+#include <vcl/cvtgrf.hxx>
 
 using namespace css;
 
@@ -36,9 +37,11 @@ public:
 
 private:
     void testWMFRoundtrip();
+    void testEmfToWmfConversion();
 
     CPPUNIT_TEST_SUITE(GraphicTest);
     CPPUNIT_TEST(testWMFRoundtrip);
+    CPPUNIT_TEST(testEmfToWmfConversion);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -46,6 +49,8 @@ GraphicTest::~GraphicTest()
 {
 }
 
+char const DATA_DIRECTORY[] = "/vcl/qa/cppunit/data/";
+
 void GraphicTest::testWMFRoundtrip()
 {
     // Load a WMF file.
@@ -81,6 +86,37 @@ void GraphicTest::testWMFRoundtrip()
     CPPUNIT_ASSERT_LESSEQUAL(static_cast<sal_uInt64>(10), nExpectedSize - nActualSize);
 }
 
+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(static_cast<sal_uInt16>(ERRCODE_NONE),
+                         aGraphicFilter.ImportGraphic(aGraphic, OUString(), aStream, nFormat));
+
+    // Save as WMF.
+    sal_uInt16 nFilterType = aGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
+    SvMemoryStream aGraphicStream;
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(ERRCODE_NONE),
+                         aGraphicFilter.ExportGraphic(aGraphic, OUString(),
+                                                      aGraphicStream,
+                                                      nFilterType));
+    aGraphicStream.Seek(0);
+    sal_uInt32 nHeader = 0;
+    aGraphicStream.ReadUInt32(nHeader);
+    // 0xd7cdc69a in the spec.
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 0x9ac6cdd7
+    // - Actual  : 1
+    // i.e. EMF data was requested to be converted to WMF, but the output was still EMF.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0x9ac6cdd7), nHeader);
+}
+
 } // namespace
 
 CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);
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 5b0e24c2ce86..cc287b0b896c 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1942,7 +1942,11 @@ sal_uInt16 GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString
                 bool bDone = false;
 
                 const GfxLink& rLink = aGraphic.GetLink();
-                if (rLink.GetDataSize() && rLink.GetType() == GfxLinkType::NativeWmf)
+                bool bIsEMF = rLink.IsEMF();
+
+                // VectorGraphicDataType::Wmf means WMF or EMF, allow direct write in the WMF case
+                // only.
+                if (rLink.GetDataSize() && rLink.GetType() == GfxLinkType::NativeWmf && !bIsEMF)
                 {
                     // The source is already in WMF, no need to convert anything.
                     rOStm.WriteBytes(rLink.GetData(), rLink.GetDataSize());


More information about the Libreoffice-commits mailing list