[Libreoffice-commits] .: 2 commits - cppcanvas/source svtools/source

Radek Doulík rodo at kemper.freedesktop.org
Wed Mar 7 08:12:51 PST 2012


 cppcanvas/source/inc/implrenderer.hxx    |    2 +-
 cppcanvas/source/mtfrenderer/emfplus.cxx |   18 ++++++++++++------
 svtools/source/filter/wmf/winwmf.cxx     |    8 ++++++--
 3 files changed, 19 insertions(+), 9 deletions(-)

New commits:
commit 0d396171b6345e6077dd85dc7ff6d9f9fdcd523d
Author: Radek Doulik <rodo at novell.com>
Date:   Wed Mar 7 16:58:37 2012 +0100

    workaround for buggy metafile images

diff --git a/cppcanvas/source/inc/implrenderer.hxx b/cppcanvas/source/inc/implrenderer.hxx
index c93c83c..d41d504 100644
--- a/cppcanvas/source/inc/implrenderer.hxx
+++ b/cppcanvas/source/inc/implrenderer.hxx
@@ -271,7 +271,7 @@ static float GetSwapFloat( SvStream& rSt )
                                    ActionVector::const_iterator& o_rRangeBegin,
                                    ActionVector::const_iterator& o_rRangeEnd ) const;
 
-            void processObjectRecord(SvMemoryStream& rObjectStream, sal_uInt16 flags);
+            void processObjectRecord(SvMemoryStream& rObjectStream, sal_uInt16 flags, sal_Bool bUseWholeStream = sal_False);
             void processEMFPlus( MetaCommentAction* pAct, const ActionFactoryParameters& rFactoryParms, OutDevState& rState, const CanvasSharedPtr& rCanvas );
             void EMFPPlusFillPolygon (::basegfx::B2DPolyPolygon& polygon, const ActionFactoryParameters& rParms, OutDevState& rState, const CanvasSharedPtr& rCanvas, bool isColor, sal_uInt32 brushIndexOrColor);
 
diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx
index 8ccb75b..953a0c8 100644
--- a/cppcanvas/source/mtfrenderer/emfplus.cxx
+++ b/cppcanvas/source/mtfrenderer/emfplus.cxx
@@ -717,7 +717,7 @@ namespace cppcanvas
             Graphic graphic;
 
 
-            void Read (SvMemoryStream &s)
+            void Read (SvMemoryStream &s, sal_Bool bUseWholeStream)
             {
                 sal_uInt32 header, unknown;
 
@@ -742,13 +742,19 @@ namespace cppcanvas
                     EMFP_DEBUG (printf ("EMF+\tmetafile type: %d dataSize: %d\n", mfType, mfSize));
 
                     GraphicFilter filter;
-                    SvMemoryStream mfStream (((char *)s.GetData()) + s.Tell(), mfSize, STREAM_READ);
+                    // workaround buggy metafiles, which have wrong mfSize set (n#705956 for example)
+                    SvMemoryStream mfStream (((char *)s.GetData()) + s.Tell(), bUseWholeStream ? s.remainingSize() : mfSize, STREAM_READ);
 
                     filter.ImportGraphic (graphic, String (), mfStream);
 
                     // debug code - write the stream to debug file /tmp/emf-stream.emf
                     EMFP_DEBUG(mfStream.Seek(0);
-                               SvFileStream file( UniString::CreateFromAscii( "/tmp/emf-embedded-stream.emf" ), STREAM_WRITE | STREAM_TRUNC );
+                               static int emfp_debug_stream_numnber = 0;
+                               UniString emfp_debug_filename = UniString::CreateFromAscii( "/tmp/emf-embedded-stream" );
+                               emfp_debug_filename.Append( UniString::CreateFromInt32( emfp_debug_stream_numnber++ ));
+                               emfp_debug_filename.Append( UniString::CreateFromAscii( ".emf" ));
+
+                               SvFileStream file( emfp_debug_filename, STREAM_WRITE | STREAM_TRUNC );
 
                                mfStream >> file;
                                file.Flush();
@@ -1087,7 +1093,7 @@ namespace cppcanvas
             }
         }
 
-        void ImplRenderer::processObjectRecord(SvMemoryStream& rObjectStream, sal_uInt16 flags)
+        void ImplRenderer::processObjectRecord(SvMemoryStream& rObjectStream, sal_uInt16 flags, sal_Bool bUseWholeStream)
         {
             sal_uInt32 index;
 
@@ -1142,7 +1148,7 @@ namespace cppcanvas
                 {
                     EMFPImage *image;
                     aObjects [index] = image = new EMFPImage ();
-                    image->Read (rObjectStream);
+                    image->Read (rObjectStream, bUseWholeStream);
 
                     break;
                 }
@@ -1193,7 +1199,7 @@ namespace cppcanvas
                     if (mbMultipart) {
                         EMFP_DEBUG (printf ("EMF+ multipart record flags: %04hx\n", mMFlags));
                         mMStream.Seek (0);
-                        processObjectRecord (mMStream, mMFlags);
+                        processObjectRecord (mMStream, mMFlags, sal_True);
                     }
                     mbMultipart = false;
                 }
commit d86d122a986292d76fe0a57c6285667356ee5170
Author: Radek Doulik <rodo at novell.com>
Date:   Wed Mar 7 16:52:22 2012 +0100

    allow wmf header to be placed on position aligned to 4 bytes
    
     - because there are such buggy emf files flying around (n#705956)

diff --git a/svtools/source/filter/wmf/winwmf.cxx b/svtools/source/filter/wmf/winwmf.cxx
index 43cf34b..13f8fee 100644
--- a/svtools/source/filter/wmf/winwmf.cxx
+++ b/svtools/source/filter/wmf/winwmf.cxx
@@ -1099,8 +1099,12 @@ sal_Bool WMFReader::ReadHeader()
         return false;
     if (nMetaKey != 0x00090001)
     {
-        pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR );
-        return false;
+        sal_uInt16 aNextWord;
+        *pWMF >> aNextWord;
+        if (aNextWord != 0x09) {
+            pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR );
+            return false;
+        }
     }
 
     pWMF->SeekRel( 2 ); // Version (von Windows)


More information about the Libreoffice-commits mailing list