filter/source/config/fragments/types/emf_MS_Windows_Metafile.xcu |    2 
 filter/source/config/fragments/types/wmf_MS_Windows_Metafile.xcu |    2 
 include/tools/zcodec.hxx                                         |    6 
 tools/source/zcodec/zcodec.cxx                                   |   23 ++-
 vcl/inc/graphic/GraphicFormatDetector.hxx                        |   13 +
 vcl/qa/cppunit/GraphicFormatDetectorTest.cxx                     |   51 +++++++
 vcl/qa/cppunit/data/TypeDetectionExample.emf                     |binary
 vcl/qa/cppunit/data/TypeDetectionExample.emz                     |binary
 vcl/qa/cppunit/data/TypeDetectionExample.wmz                     |binary
 vcl/source/filter/GraphicFormatDetector.cxx                      |   68 
++++++----
 vcl/source/filter/graphicfilter.cxx                              |   44 +++++-
 vcl/source/filter/graphicfilter2.cxx                             |   50 -------
 12 files changed, 170 insertions(+), 89 deletions(-)

New commits:
commit e9c50fbbc3b07ef927d133da9cf2395c55611e0f
Author:     offtkp <[email protected]>
AuthorDate: Sat Apr 2 15:49:32 2022 +0300
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Fri May 6 04:02:05 2022 +0200

    tdf#103954: Z compressed graphic formats support for EMF/WMF
    
    - Added .emz and .wmz file opening support
    - Added a function to check for Z compression that
    all z comp. formats can use
    - Added 3 unit tests for emf/emz/wmz files
    and the example files have been checked with
    a different tool (File Viewer 4)
    - emf/emz file detection changed from magic byte checking
    to extension checking, like wmf/wmz does
    
    Change-Id: I3e433fd23d18482648a51cd04b8f467368e97b62
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132456
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/filter/source/config/fragments/types/emf_MS_Windows_Metafile.xcu 
b/filter/source/config/fragments/types/emf_MS_Windows_Metafile.xcu
index 6d1564bebd07..2003217aad30 100644
--- a/filter/source/config/fragments/types/emf_MS_Windows_Metafile.xcu
+++ b/filter/source/config/fragments/types/emf_MS_Windows_Metafile.xcu
@@ -18,7 +18,7 @@
     <node oor:name="emf_MS_Windows_Metafile" oor:op="replace" >
         <prop 
oor:name="DetectService"><value>com.sun.star.comp.draw.FormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
-        <prop oor:name="Extensions"><value>emf</value></prop>
+        <prop oor:name="Extensions"><value>emf emz</value></prop>
         <prop oor:name="MediaType"><value>image/x-emf</value></prop>
         <prop oor:name="Preferred"><value>false</value></prop>
         <prop oor:name="PreferredFilter"><value>EMF - MS Windows 
Metafile</value></prop>
diff --git a/filter/source/config/fragments/types/wmf_MS_Windows_Metafile.xcu 
b/filter/source/config/fragments/types/wmf_MS_Windows_Metafile.xcu
index 54c6bf54c33b..7564dd057cf4 100644
--- a/filter/source/config/fragments/types/wmf_MS_Windows_Metafile.xcu
+++ b/filter/source/config/fragments/types/wmf_MS_Windows_Metafile.xcu
@@ -18,7 +18,7 @@
     <node oor:name="wmf_MS_Windows_Metafile" oor:op="replace" >
         <prop 
oor:name="DetectService"><value>com.sun.star.comp.draw.FormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
-        <prop oor:name="Extensions"><value>wmf</value></prop>
+        <prop oor:name="Extensions"><value>wmf wmz</value></prop>
         <prop oor:name="MediaType"><value>image/x-wmf</value></prop>
         <prop oor:name="Preferred"><value>false</value></prop>
         <prop oor:name="PreferredFilter"><value>WMF - MS Windows 
Metafile</value></prop>
diff --git a/include/tools/zcodec.hxx b/include/tools/zcodec.hxx
index c9c71bf752b1..745d44e9199e 100644
--- a/include/tools/zcodec.hxx
+++ b/include/tools/zcodec.hxx
@@ -59,6 +59,12 @@ class SAL_WARN_UNUSED TOOLS_DLLPUBLIC ZCodec
 public:
                     ZCodec( size_t nInBufSize = 32768, size_t nOutBufSize = 
32768 );
                     ~ZCodec();
+    /**
+     * @brief Checks whether a stream is Z compressed
+     *
+     * @param rIStm the stream to check
+     */
+    static bool IsZCompressed( SvStream& rIStm );
 
     void            BeginCompression( int nCompressLevel = 
ZCODEC_DEFAULT_COMPRESSION, bool gzLib = false );
     tools::Long            EndCompression();
diff --git a/tools/source/zcodec/zcodec.cxx b/tools/source/zcodec/zcodec.cxx
index 97a03a463021..80daa1507a19 100644
--- a/tools/source/zcodec/zcodec.cxx
+++ b/tools/source/zcodec/zcodec.cxx
@@ -36,7 +36,7 @@
 #define GZ_COMMENT      0x10 /* bit 4 set: file comment present */
 #define GZ_RESERVED     0xE0 /* bits 5..7: reserved */
 
-const int gz_magic[2] = { 0x1f, 0x8b }; /* gzip magic header */
+constexpr sal_uInt16 GZ_MAGIC_BYTES_LE = 0x8B1F; /* gzip magic bytes, little 
endian */
 
 ZCodec::ZCodec( size_t nInBufSize, size_t nOutBufSize )
     : meState(STATE_INIT)
@@ -58,6 +58,16 @@ ZCodec::~ZCodec()
     delete pStream;
 }
 
+bool ZCodec::IsZCompressed( SvStream& rIStm )
+{
+    sal_uInt64 nCurPos = rIStm.Tell();
+    rIStm.Seek( 0 );
+    sal_uInt16 nFirstTwoBytes = 0;
+    rIStm.ReadUInt16( nFirstTwoBytes );
+    rIStm.Seek( nCurPos );
+    return nFirstTwoBytes == GZ_MAGIC_BYTES_LE;
+}
+
 void ZCodec::BeginCompression( int nCompressLevel, bool gzLib )
 {
     assert(meState == STATE_INIT);
@@ -272,12 +282,11 @@ void ZCodec::InitDecompress(SvStream & inStream)
     if ( mbStatus &&  mbGzLib )
     {
         sal_uInt8 j, nMethod, nFlags;
-        for (int i : gz_magic)   // gz - magic number
-        {
-            inStream.ReadUChar( j );
-            if ( j != i )
-                mbStatus = false;
-        }
+        sal_uInt16 nFirstTwoBytes;
+        inStream.Seek( 0 );
+        inStream.ReadUInt16( nFirstTwoBytes );
+        if ( nFirstTwoBytes != GZ_MAGIC_BYTES_LE )
+            mbStatus = false;
         inStream.ReadUChar( nMethod );
         inStream.ReadUChar( nFlags );
         if ( nMethod != Z_DEFLATED )
diff --git a/vcl/inc/graphic/GraphicFormatDetector.hxx 
b/vcl/inc/graphic/GraphicFormatDetector.hxx
index 34a8b16a2c5d..dc1bbf0b3e08 100644
--- a/vcl/inc/graphic/GraphicFormatDetector.hxx
+++ b/vcl/inc/graphic/GraphicFormatDetector.hxx
@@ -78,6 +78,19 @@ public:
     bool checkMOV();
     bool checkPDF();
     bool checkWEBP();
+
+private:
+    /**
+     * @brief Checks whether mrStream needs to be uncompressed and returns a 
pointer to the
+     * to aUncompressedBuffer or a pointer to maFirstBytes if it doesn't need 
to be uncompressed
+     *
+     * @param aUncompressedBuffer the buffer to hold the uncompressed data
+     * @param nSize the amount of bytes to uncompress
+     * @param nRetSize the amount of bytes actually uncompressed
+     * @return sal_uInt8* a pointer to maFirstBytes or aUncompressed buffer
+     */
+    sal_uInt8* checkAndUncompressBuffer(sal_uInt8* aUncompressedBuffer, 
sal_uInt32 nSize,
+                                        sal_uInt64& nDecompressedSize);
 };
 }
 
diff --git a/vcl/qa/cppunit/GraphicFormatDetectorTest.cxx 
b/vcl/qa/cppunit/GraphicFormatDetectorTest.cxx
index 1061b12fd2df..e142c94ab1be 100644
--- a/vcl/qa/cppunit/GraphicFormatDetectorTest.cxx
+++ b/vcl/qa/cppunit/GraphicFormatDetectorTest.cxx
@@ -35,6 +35,7 @@ class GraphicFormatDetectorTest : public 
test::BootstrapFixtureBase
     void testDetectMET();
     void testDetectBMP();
     void testDetectWMF();
+    void testDetectWMZ();
     void testDetectPCX();
     void testDetectJPG();
     void testDetectPNG();
@@ -49,6 +50,8 @@ class GraphicFormatDetectorTest : public 
test::BootstrapFixtureBase
     void testDetectPDF();
     void testDetectEPS();
     void testDetectWEBP();
+    void testDetectEMF();
+    void testDetectEMZ();
     void testMatchArray();
     void testCheckArrayForMatchingStrings();
 
@@ -56,6 +59,7 @@ class GraphicFormatDetectorTest : public 
test::BootstrapFixtureBase
     CPPUNIT_TEST(testDetectMET);
     CPPUNIT_TEST(testDetectBMP);
     CPPUNIT_TEST(testDetectWMF);
+    CPPUNIT_TEST(testDetectWMZ);
     CPPUNIT_TEST(testDetectPCX);
     CPPUNIT_TEST(testDetectJPG);
     CPPUNIT_TEST(testDetectPNG);
@@ -70,6 +74,8 @@ class GraphicFormatDetectorTest : public 
test::BootstrapFixtureBase
     CPPUNIT_TEST(testDetectPDF);
     CPPUNIT_TEST(testDetectEPS);
     CPPUNIT_TEST(testDetectWEBP);
+    CPPUNIT_TEST(testDetectEMF);
+    CPPUNIT_TEST(testDetectEMZ);
     CPPUNIT_TEST(testMatchArray);
     CPPUNIT_TEST(testCheckArrayForMatchingStrings);
     CPPUNIT_TEST_SUITE_END();
@@ -120,6 +126,21 @@ void GraphicFormatDetectorTest::testDetectWMF()
     CPPUNIT_ASSERT_EQUAL(OUString("WMF"), rFormatExtension);
 }
 
+void GraphicFormatDetectorTest::testDetectWMZ()
+{
+    SvFileStream aFileStream(getFullUrl(u"TypeDetectionExample.wmz"), 
StreamMode::READ);
+    vcl::GraphicFormatDetector aDetector(aFileStream, "WMF");
+
+    CPPUNIT_ASSERT(aDetector.detect());
+    CPPUNIT_ASSERT(aDetector.checkWMForEMF());
+
+    aFileStream.Seek(aDetector.mnStreamPosition);
+
+    OUString rFormatExtension;
+    CPPUNIT_ASSERT(vcl::peekGraphicFormat(aFileStream, rFormatExtension, 
false));
+    CPPUNIT_ASSERT_EQUAL(OUString("WMF"), rFormatExtension);
+}
+
 void GraphicFormatDetectorTest::testDetectPCX()
 {
     SvFileStream aFileStream(getFullUrl(u"TypeDetectionExample.pcx"), 
StreamMode::READ);
@@ -330,6 +351,36 @@ void GraphicFormatDetectorTest::testDetectWEBP()
     CPPUNIT_ASSERT_EQUAL(OUString("WEBP"), rFormatExtension);
 }
 
+void GraphicFormatDetectorTest::testDetectEMF()
+{
+    SvFileStream aFileStream(getFullUrl(u"TypeDetectionExample.emf"), 
StreamMode::READ);
+    vcl::GraphicFormatDetector aDetector(aFileStream, "EMF");
+
+    CPPUNIT_ASSERT(aDetector.detect());
+    CPPUNIT_ASSERT(aDetector.checkWMForEMF());
+
+    aFileStream.Seek(aDetector.mnStreamPosition);
+
+    OUString rFormatExtension;
+    CPPUNIT_ASSERT(vcl::peekGraphicFormat(aFileStream, rFormatExtension, 
false));
+    CPPUNIT_ASSERT_EQUAL(OUString("EMF"), rFormatExtension);
+}
+
+void GraphicFormatDetectorTest::testDetectEMZ()
+{
+    SvFileStream aFileStream(getFullUrl(u"TypeDetectionExample.emz"), 
StreamMode::READ);
+    vcl::GraphicFormatDetector aDetector(aFileStream, "EMF");
+
+    CPPUNIT_ASSERT(aDetector.detect());
+    CPPUNIT_ASSERT(aDetector.checkWMForEMF());
+
+    aFileStream.Seek(aDetector.mnStreamPosition);
+
+    OUString rFormatExtension;
+    CPPUNIT_ASSERT(vcl::peekGraphicFormat(aFileStream, rFormatExtension, 
false));
+    CPPUNIT_ASSERT_EQUAL(OUString("EMF"), rFormatExtension);
+}
+
 void GraphicFormatDetectorTest::testMatchArray()
 {
     std::string aString("<?xml version=\"1.0\" standalone=\"no\"?>\n"
diff --git a/vcl/qa/cppunit/data/TypeDetectionExample.emf 
b/vcl/qa/cppunit/data/TypeDetectionExample.emf
new file mode 100644
index 000000000000..571a25c81bbf
Binary files /dev/null and b/vcl/qa/cppunit/data/TypeDetectionExample.emf differ
diff --git a/vcl/qa/cppunit/data/TypeDetectionExample.emz 
b/vcl/qa/cppunit/data/TypeDetectionExample.emz
new file mode 100644
index 000000000000..dd3b3b2f1fa3
Binary files /dev/null and b/vcl/qa/cppunit/data/TypeDetectionExample.emz differ
diff --git a/vcl/qa/cppunit/data/TypeDetectionExample.wmz 
b/vcl/qa/cppunit/data/TypeDetectionExample.wmz
new file mode 100644
index 000000000000..2435f20baf57
Binary files /dev/null and b/vcl/qa/cppunit/data/TypeDetectionExample.wmz differ
diff --git a/vcl/source/filter/GraphicFormatDetector.cxx 
b/vcl/source/filter/GraphicFormatDetector.cxx
index 2dddcfa0f9ae..6ef3d3015817 100644
--- a/vcl/source/filter/GraphicFormatDetector.cxx
+++ b/vcl/source/filter/GraphicFormatDetector.cxx
@@ -26,6 +26,9 @@
 #include <tools/solar.h>
 #include <tools/zcodec.hxx>
 
+constexpr sal_uInt32 SVG_CHECK_SIZE = 2048;
+constexpr sal_uInt32 WMF_EMF_CHECK_SIZE = 44;
+
 namespace vcl
 {
 bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool 
bTest)
@@ -66,7 +69,8 @@ bool peekGraphicFormat(SvStream& rStream, OUString& 
rFormatExtension, bool bTest
         }
     }
 
-    if (!bTest || rFormatExtension.startsWith("WMF") || 
rFormatExtension.startsWith("EMF"))
+    if (!bTest || rFormatExtension.startsWith("WMF") || 
rFormatExtension.startsWith("EMF")
+        || rFormatExtension.startsWith("WMZ") || 
rFormatExtension.startsWith("EMZ"))
     {
         bSomethingTested = true;
         if (aDetector.checkWMForEMF())
@@ -450,13 +454,19 @@ bool GraphicFormatDetector::checkBMP()
 
 bool GraphicFormatDetector::checkWMForEMF()
 {
+    sal_uInt64 nCheckSize = std::min<sal_uInt64>(mnStreamLength, 256);
+    sal_uInt8 sExtendedOrDecompressedFirstBytes[WMF_EMF_CHECK_SIZE];
+    sal_uInt64 nDecompressedSize = nCheckSize;
+    // check if it is gzipped -> wmz/emz
+    sal_uInt8* pCheckArray = 
checkAndUncompressBuffer(sExtendedOrDecompressedFirstBytes,
+                                                      WMF_EMF_CHECK_SIZE, 
nDecompressedSize);
     if (mnFirstLong == 0xd7cdc69a || mnFirstLong == 0x01000900)
     {
         msDetectedFormat = "WMF";
         return true;
     }
-    else if (mnFirstLong == 0x01000000 && maFirstBytes[40] == 0x20 && 
maFirstBytes[41] == 0x45
-             && maFirstBytes[42] == 0x4d && maFirstBytes[43] == 0x46)
+    else if (mnFirstLong == 0x01000000 && pCheckArray[40] == 0x20 && 
pCheckArray[41] == 0x45
+             && pCheckArray[42] == 0x4d && pCheckArray[43] == 0x46)
     {
         msDetectedFormat = "EMF";
         return true;
@@ -696,34 +706,16 @@ bool GraphicFormatDetector::checkXBM()
 
 bool GraphicFormatDetector::checkSVG()
 {
-    sal_uInt8* pCheckArray = maFirstBytes.data();
     sal_uInt64 nCheckSize = std::min<sal_uInt64>(mnStreamLength, 256);
-
-    sal_uInt8 sExtendedOrDecompressedFirstBytes[2048];
+    sal_uInt8 sExtendedOrDecompressedFirstBytes[SVG_CHECK_SIZE];
     sal_uInt64 nDecompressedSize = nCheckSize;
-
-    bool bIsGZip(false);
-
     // check if it is gzipped -> svgz
-    if (maFirstBytes[0] == 0x1F && maFirstBytes[1] == 0x8B)
-    {
-        ZCodec aCodec;
-        mrStream.Seek(mnStreamPosition);
-        aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/ true);
-        auto nDecompressedOut = aCodec.Read(mrStream, 
sExtendedOrDecompressedFirstBytes, 2048);
-        // ZCodec::Decompress returns -1 on failure
-        nDecompressedSize = nDecompressedOut < 0 ? 0 : nDecompressedOut;
-        nCheckSize = std::min<sal_uInt64>(nDecompressedSize, 256);
-        aCodec.EndCompression();
-        pCheckArray = sExtendedOrDecompressedFirstBytes;
-
-        bIsGZip = true;
-    }
-
+    sal_uInt8* pCheckArray = 
checkAndUncompressBuffer(sExtendedOrDecompressedFirstBytes,
+                                                      SVG_CHECK_SIZE, 
nDecompressedSize);
+    nCheckSize = std::min<sal_uInt64>(nDecompressedSize, 256);
     bool bIsSvg(false);
-
+    bool bIsGZip = (nDecompressedSize > 0);
     const char* pCheckArrayAsCharArray = reinterpret_cast<char*>(pCheckArray);
-
     // check for XML
     // #119176# SVG files which have no xml header at all have shown up this 
is optional
     // check for "xml" then "version" then "DOCTYPE" and "svg" tags
@@ -838,6 +830,30 @@ bool GraphicFormatDetector::checkWEBP()
     return false;
 }
 
+sal_uInt8* GraphicFormatDetector::checkAndUncompressBuffer(sal_uInt8* 
aUncompressedBuffer,
+                                                           sal_uInt32 nSize, 
sal_uInt64& nRetSize)
+{
+    if (ZCodec::IsZCompressed(mrStream))
+    {
+        ZCodec aCodec;
+        mrStream.Seek(mnStreamPosition);
+        aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/ true);
+        auto nDecompressedOut = aCodec.Read(mrStream, aUncompressedBuffer, 
nSize);
+        // ZCodec::Decompress returns -1 on failure
+        nRetSize = nDecompressedOut < 0 ? 0 : nDecompressedOut;
+        aCodec.EndCompression();
+        // Recalculate first/second long
+        for (int i = 0; i < 4; ++i)
+        {
+            mnFirstLong = (mnFirstLong << 8) | 
sal_uInt32(aUncompressedBuffer[i]);
+            mnSecondLong = (mnSecondLong << 8) | 
sal_uInt32(aUncompressedBuffer[i + 4]);
+        }
+        return aUncompressedBuffer;
+    }
+    nRetSize = 0;
+    return maFirstBytes.data();
+}
+
 } // vcl namespace
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/graphicfilter.cxx 
b/vcl/source/filter/graphicfilter.cxx
index 9bc7eea56566..68a2418fed58 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -891,10 +891,29 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& 
rIStream, sal_uInt64 size
         {
             nGraphicContentSize = nStreamLength;
             pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
-
             rIStream.Seek(nStreamBegin);
-            rIStream.ReadBytes(pGraphicContent.get(), nStreamLength);
+            if (ZCodec::IsZCompressed(rIStream))
+            {
+                ZCodec aCodec;
+                SvMemoryStream aMemStream;
+                tools::Long nMemoryLength;
+                aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, 
/*gzLib*/true);
+                nMemoryLength = aCodec.Decompress(rIStream, aMemStream);
+                aCodec.EndCompression();
+
+                if (!rIStream.GetError() && nMemoryLength >= 0)
+                {
+                    nGraphicContentSize = nMemoryLength;
+                    pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
 
+                    aMemStream.Seek(STREAM_SEEK_TO_BEGIN);
+                    aMemStream.ReadBytes(pGraphicContent.get(), 
nGraphicContentSize);
+                }
+            }
+            else
+            {
+                rIStream.ReadBytes(pGraphicContent.get(), nStreamLength);
+            }
             if (!rIStream.GetError())
             {
                 eLinkType = GfxLinkType::NativeWmf;
@@ -1148,15 +1167,22 @@ ErrCode GraphicFilter::readWMF_EMF(SvStream & rStream, 
Graphic & rGraphic, GfxLi
     // use new UNO API service, do not directly import but create a
     // Graphic that contains the original data and decomposes to
     // primitives on demand
-
+    sal_uInt32 nStreamLength(rStream.remainingSize());
+    SvStream* aNewStream = &rStream;
     ErrCode aReturnCode = ERRCODE_GRFILTER_FILTERERROR;
-
-    const sal_uInt32 nStreamLength(rStream.remainingSize());
+    SvMemoryStream aMemStream;
+    if (ZCodec::IsZCompressed(rStream))
+    {
+        ZCodec aCodec;
+        aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/true);
+        nStreamLength = aCodec.Decompress(rStream, aMemStream);
+        aCodec.EndCompression();
+        aNewStream = &aMemStream;
+    }
     VectorGraphicDataArray aNewData(nStreamLength);
-
-    rStream.ReadBytes(aNewData.getArray(), nStreamLength);
-
-    if (!rStream.GetError())
+    aNewStream->Seek(STREAM_SEEK_TO_BEGIN);
+    aNewStream->ReadBytes(aNewData.getArray(), nStreamLength);
+    if (!aNewStream->GetError())
     {
         const VectorGraphicDataType aDataType(eType);
         BinaryDataContainer aDataContainer(reinterpret_cast<const 
sal_uInt8*>(aNewData.getConstArray()), aNewData.getLength());
diff --git a/vcl/source/filter/graphicfilter2.cxx 
b/vcl/source/filter/graphicfilter2.cxx
index 5f73d570d9f6..eaef61b1d1e1 100644
--- a/vcl/source/filter/graphicfilter2.cxx
+++ b/vcl/source/filter/graphicfilter2.cxx
@@ -1079,59 +1079,19 @@ bool GraphicDescriptor::ImpDetectSVM( SvStream& rStm, 
bool bExtendedInfo )
 
 bool GraphicDescriptor::ImpDetectWMF( SvStream&, bool )
 {
-    bool bRet = aPathExt.startsWith( "wmf" );
+    bool bRet = aPathExt.startsWith( "wmf" ) || aPathExt.startsWith( "wmz" );
     if (bRet)
         nFormat = GraphicFileFormat::WMF;
 
     return bRet;
 }
 
-bool GraphicDescriptor::ImpDetectEMF( SvStream& rStm, bool bExtendedInfo )
+bool GraphicDescriptor::ImpDetectEMF( SvStream&, bool )
 {
-    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 );
-            }
-        }
-    }
+    bool bRet = aPathExt.startsWith( "emf" ) || aPathExt.startsWith( "emz" );
+    if (bRet)
+        nFormat = GraphicFileFormat::EMF;
 
-    rStm.Seek( nStmPos );
     return bRet;
 }
 

Reply via email to