[Libreoffice-commits] core.git: vcl/source

Armin Le Grand alg at apache.org
Sun May 12 08:59:52 PDT 2013


 vcl/source/filter/wmf/enhwmf.cxx |   77 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 2 deletions(-)

New commits:
commit 0752c18df9a975ffa182a4a7bc86e0bcadd58aec
Author: Armin Le Grand <alg at apache.org>
Date:   Fri Jul 27 14:01:18 2012 +0000

    Resolves: #i119450# Added EMR_ALPHABLEND case to EnhWMFReader
    
    to correct visualisations
    
    Patch by: Jianyuan Li
    Review by: alg(cherry picked from commit 1ea8c3a924d518043c5d3d1427cd40cf500c8b21)
    
    Conflicts:
    	svtools/source/filter/wmf/enhwmf.cxx
    
    Change-Id: If1436cc58ba48048777571e74511f4fc97d2bef3

diff --git a/vcl/source/filter/wmf/enhwmf.cxx b/vcl/source/filter/wmf/enhwmf.cxx
index e0e69cf..5f346b6 100644
--- a/vcl/source/filter/wmf/enhwmf.cxx
+++ b/vcl/source/filter/wmf/enhwmf.cxx
@@ -163,6 +163,21 @@ static float GetSwapFloat( SvStream& rSt )
 }
 #endif
 
+struct BLENDFUNCTION{
+    unsigned char aBlendOperation;
+    unsigned char aBlendFlags;
+    unsigned char aSrcConstantAlpha;
+    unsigned char aAlphaFormat;
+
+    friend SvStream& operator>>( SvStream& rIn, BLENDFUNCTION& rBlendFun );
+};
+
+SvStream& operator>>( SvStream& rIn, BLENDFUNCTION& rBlendFun )
+{
+    rIn >> rBlendFun.aBlendOperation >> rBlendFun.aBlendFlags >>
+             rBlendFun.aSrcConstantAlpha >> rBlendFun.aAlphaFormat;
+    return rIn;
+}
 SvStream& operator>>( SvStream& rIn, XForm& rXForm )
 {
     if ( sizeof( float ) != 4 )
@@ -923,6 +938,65 @@ sal_Bool EnhWMFReader::ReadEnhWMF()
                 }
                 break;
 
+                case EMR_ALPHABLEND:
+                {
+                    sal_Int32 xDest(0), yDest(0), cxDest(0), cyDest(0);
+
+                    BLENDFUNCTION aFunc;
+                    sal_Int32 xSrc(0), ySrc(0);
+                    XForm xformSrc;
+                    sal_uInt32 BkColorSrc(0), iUsageSrc(0), offBmiSrc(0);
+                    sal_uInt32 cbBmiSrc(0), offBitsSrc(0), cbBitsSrc(0), cxSrc(0), cySrc(0);
+
+                    sal_uInt32   nStart = pWMF->Tell() - 8;
+                    pWMF->SeekRel( 0x10 );
+
+                    *pWMF >> xDest >> yDest >> cxDest >> cyDest >> aFunc >> xSrc >> ySrc
+                            >> xformSrc >> BkColorSrc >> iUsageSrc >> offBmiSrc >> cbBmiSrc
+                                >> offBitsSrc >> cbBitsSrc >>cxSrc>>cySrc ;
+
+                    sal_uInt32  dwRop = SRCAND|SRCINVERT;
+
+                    Bitmap      aBitmap;
+                    Rectangle   aRect( Point( xDest, yDest ), Size( cxDest+1, cyDest+1 ) );
+
+                    if ( (cbBitsSrc > (SAL_MAX_UINT32 - 14)) || ((SAL_MAX_UINT32 - 14) - cbBitsSrc < cbBmiSrc) )
+                        bStatus = sal_False;
+                    else
+                    {
+                        sal_uInt32 nSize = cbBmiSrc + cbBitsSrc + 14;
+                        if ( nSize <= ( nEndPos - nStartPos ) )
+                        {
+                            char* pBuf = new char[ nSize ];
+                            SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE );
+                            aTmp.ObjectOwnsMemory( sal_True );
+                            aTmp << (sal_uInt8)'B'
+                                 << (sal_uInt8)'M'
+                                 << (sal_uInt32)cbBitsSrc
+                                 << (sal_uInt16)0
+                                 << (sal_uInt16)0
+                                 << (sal_uInt32)cbBmiSrc + 14;
+                            pWMF->Seek( nStart + offBmiSrc );
+                            pWMF->Read( pBuf + 14, cbBmiSrc );
+                            pWMF->Seek( nStart + offBitsSrc );
+                            pWMF->Read( pBuf + 14 + cbBmiSrc, cbBitsSrc );
+                            aTmp.Seek( 0 );
+                            aBitmap.Read( aTmp, sal_True );
+                            // test if it is sensible to crop
+                            if ( ( cxSrc > 0 ) && ( cySrc > 0 ) &&
+                                ( xSrc >= 0 ) && ( ySrc >= 0 ) &&
+                                    ( xSrc + cxSrc <= aBitmap.GetSizePixel().Width() ) &&
+                                        ( ySrc + cySrc <= aBitmap.GetSizePixel().Height() ) )
+                            {
+                                Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) );
+                                aBitmap.Crop( aCropRect );
+                            }
+                            aBmpSaveList.push_back( new BSaveStruct( aBitmap, aRect, dwRop, pOut->GetFillStyle () ) );
+                        }
+                    }
+                }
+                break;
+
                 case EMR_BITBLT :   // PASSTHROUGH INTENDED
                 case EMR_STRETCHBLT :
                 {
@@ -980,7 +1054,7 @@ sal_Bool EnhWMFReader::ReadEnhWMF()
                                 Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) );
                                 aBitmap.Crop( aCropRect );
                             }
-                        aBmpSaveList.push_back( new BSaveStruct( aBitmap, aRect, dwRop, pOut->GetFillStyle () ) );
+                            aBmpSaveList.push_back( new BSaveStruct( aBitmap, aRect, dwRop, pOut->GetFillStyle () ) );
                         }
                     }
                 }
@@ -1304,7 +1378,6 @@ sal_Bool EnhWMFReader::ReadEnhWMF()
                 case EMR_COLORCORRECTPALETTE :      WinMtfAssertHandler( "ColorCorrectPalette" );       break;
                 case EMR_SETICMPROFILEA :           WinMtfAssertHandler( "SetICMProfileA" );            break;
                 case EMR_SETICMPROFILEW :           WinMtfAssertHandler( "SetICMProfileW" );            break;
-                case EMR_ALPHABLEND :               WinMtfAssertHandler( "Alphablend" );                break;
                 case EMR_TRANSPARENTBLT :           WinMtfAssertHandler( "TransparenBlt" );             break;
                 case EMR_TRANSPARENTDIB :           WinMtfAssertHandler( "TransparenDib" );             break;
                 case EMR_GRADIENTFILL :             WinMtfAssertHandler( "GradientFill" );              break;


More information about the Libreoffice-commits mailing list