[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - sw/qa vcl/source

Luke Deller (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 8 10:53:35 UTC 2019


 sw/qa/extras/ww8export/data/tdf126708_containsemf.odt |binary
 sw/qa/extras/ww8export/ww8export3.cxx                 |   18 ++++++
 vcl/source/filter/graphicfilter2.cxx                  |   48 ++++++++++++++++--
 3 files changed, 62 insertions(+), 4 deletions(-)

New commits:
commit bea53649cb9716c48ab2a5518ef2cea76a2cbe3b
Author:     Luke Deller <luke at deller.id.au>
AuthorDate: Wed Aug 7 00:22:12 2019 +1000
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Aug 8 12:52:54 2019 +0200

    tdf#126708 Fix EMF image size in CLI .doc export
    
    Implement EMF image size detection, to fix this bug where an EMF image
    gets zero size when exported to .doc format from the command line.
    
    Reviewed-on: https://gerrit.libreoffice.org/77031
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    (cherry picked from commit 6369cab9b1e16275c8700692bb717aec3c42d346)
    
    Conflicts:
            sw/qa/extras/ww8export/ww8export3.cxx
    
    Change-Id: If980c5d65d4880150815fd1df9704d9c1b3b93c9
    Reviewed-on: https://gerrit.libreoffice.org/77136
    Tested-by: Jenkins
    Tested-by: Xisco Faulí <xiscofauli at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sw/qa/extras/ww8export/data/tdf126708_containsemf.odt b/sw/qa/extras/ww8export/data/tdf126708_containsemf.odt
new file mode 100644
index 000000000000..31b0fab8d02d
Binary files /dev/null and b/sw/qa/extras/ww8export/data/tdf126708_containsemf.odt differ
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index fcf5fc44379f..9e8d17d86ac5 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -13,6 +13,7 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XIndexAccess.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
 #include <com/sun/star/text/XFormField.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/text/XTextTablesSupplier.hpp>
@@ -259,6 +260,23 @@ DECLARE_WW8EXPORT_TEST(testTdf118375export, "tdf118375_240degClockwise.doc")
     CPPUNIT_ASSERT_DOUBLES_EQUAL(1152.0, static_cast<double>(nPosY), 1.0);
 }
 
+DECLARE_WW8EXPORT_TEST(testTdf126708emf, "tdf126708_containsemf.odt")
+{
+    auto xShape = getShape(1);
+    // First check the size of the EMF graphic contained in the shape.
+    auto xGraphic = getProperty< uno::Reference<graphic::XGraphic> >(
+        xShape, "Graphic");
+    auto xSize = getProperty<awt::Size>(xGraphic, "Size100thMM");
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(8501), xSize.Height);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(18939), xSize.Width);
+
+    // Now check that the shape itself has a decent size.
+    // This size varies slightly when round tripping through doc format.
+    xSize = getProperty<awt::Size>(xShape, "Size");
+    CPPUNIT_ASSERT(abs(xSize.Height - 7629) <= 6);
+    CPPUNIT_ASSERT(abs(xSize.Width - 17000) <= 6);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx
index 27dd780b57c8..8839807aa962 100644
--- a/vcl/source/filter/graphicfilter2.cxx
+++ b/vcl/source/filter/graphicfilter2.cxx
@@ -1044,12 +1044,52 @@ bool GraphicDescriptor::ImpDetectWMF( SvStream&, bool )
     return bRet;
 }
 
-bool GraphicDescriptor::ImpDetectEMF( SvStream&, bool )
+bool GraphicDescriptor::ImpDetectEMF( SvStream& rStm, bool bExtendedInfo )
 {
-    bool bRet = aPathExt.startsWith( "emf" );
-    if (bRet)
-        nFormat = GraphicFileFormat::EMF;
+    sal_uInt32 nRecordType = 0;
+    bool bRet = false;
+
+    sal_Int32 nStmPos = rStm.Tell();
+    rStm.SetEndian( SvStreamEndian::LITTLE );
+    rStm.ReadUInt32( nRecordType );
+
+    if ( nRecordType == 0x00000001 )
+    {
+        sal_uInt32 nHeaderSize = 0;
+        sal_Int32 nBoundLeft = 0, nBoundTop = 0, nBoundRight = 0, nBoundBottom = 0;
+        sal_Int32 nFrameLeft = 0, nFrameTop = 0, nFrameRight = 0, nFrameBottom = 0;
+        sal_uInt32 nSignature = 0;
+
+        rStm.ReadUInt32( nHeaderSize );
+        rStm.ReadInt32( nBoundLeft );
+        rStm.ReadInt32( nBoundTop );
+        rStm.ReadInt32( nBoundRight );
+        rStm.ReadInt32( nBoundBottom );
+        rStm.ReadInt32( nFrameLeft );
+        rStm.ReadInt32( nFrameTop );
+        rStm.ReadInt32( nFrameRight );
+        rStm.ReadInt32( nFrameBottom );
+        rStm.ReadUInt32( nSignature );
+
+        if ( nSignature == 0x464d4520 )
+        {
+            nFormat = GraphicFileFormat::EMF;
+            bRet = true;
 
+            if ( bExtendedInfo )
+            {
+                // size in pixels
+                aPixSize.setWidth( nBoundRight - nBoundLeft + 1 );
+                aPixSize.setHeight( nBoundBottom - nBoundTop + 1 );
+
+                // size in 0.01mm units
+                aLogSize.setWidth( nFrameRight - nFrameLeft + 1 );
+                aLogSize.setHeight( nFrameBottom - nFrameTop + 1 );
+            }
+        }
+    }
+
+    rStm.Seek( nStmPos );
     return bRet;
 }
 


More information about the Libreoffice-commits mailing list