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

Chris Sherlock chris.sherlock79 at gmail.com
Sat Apr 19 02:46:04 PDT 2014


 include/vcl/outdev.hxx       |    4 +--
 vcl/source/outdev/bitmap.cxx |   53 ++++++++++++-------------------------------
 2 files changed, 17 insertions(+), 40 deletions(-)

New commits:
commit 2d786ef2961002893d532a7d2087055857e51c17
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date:   Sat Apr 19 19:34:07 2014 +1000

    Refactor OutputDevice::DrawImage()
    
    There is a fair amount of code duplication going on here. If no valid
    Size is passed to the function then we should pass on Size(), then in
    the function we call we should check to see if there is a valid size.
    In fact, this is something we should probably check for anyway, so if
    anything this makes the code slightly more robust.
    
    Change-Id: If7b55e5505ada6739375c69b123cf1e34a0fa66d

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index d0bd887..7507d08 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -1146,9 +1146,9 @@ public:
                                           const Bitmap& rBitmap, const Color& rMaskColor,
                                           sal_uLong nAction );
 
-    void                        DrawImage( const Point& rPos,
+    virtual void                DrawImage( const Point& rPos,
                                            const Image& rImage, sal_uInt16 nStyle = 0 );
-    void                        DrawImage( const Point& rPos, const Size& rSize,
+    virtual void                DrawImage( const Point& rPos, const Size& rSize,
                                            const Image& rImage, sal_uInt16 nStyle = 0 );
 
 #ifdef _MSC_VER
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 3bbf392..23d1177 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -759,42 +759,7 @@ namespace
 
 void OutputDevice::DrawImage( const Point& rPos, const Image& rImage, sal_uInt16 nStyle )
 {
-    DBG_ASSERT( GetOutDevType() != OUTDEV_PRINTER, "DrawImage(): Images can't be drawn on any mprinter" );
-
-    if( !rImage.mpImplData || ImplIsRecordLayout() )
-        return;
-
-    switch( rImage.mpImplData->meType )
-    {
-        case IMAGETYPE_BITMAP:
-        {
-            const Bitmap &rBitmap = *static_cast< Bitmap* >( rImage.mpImplData->mpData );
-            if( nStyle & IMAGE_DRAW_DISABLE )
-                DrawBitmapEx( rPos, makeDisabledBitmap(rBitmap) );
-            else
-                DrawBitmap( rPos, rBitmap );
-        }
-        break;
-
-        case IMAGETYPE_IMAGE:
-        {
-            ImplImageData* pData = static_cast< ImplImageData* >( rImage.mpImplData->mpData );
-
-            if( !pData->mpImageBitmap )
-            {
-                const Size aSize( pData->maBmpEx.GetSizePixel() );
-
-                pData->mpImageBitmap = new ImplImageBmp;
-                pData->mpImageBitmap->Create( pData->maBmpEx, aSize.Width(), aSize.Height(), 1 );
-            }
-
-            pData->mpImageBitmap->Draw( 0, this, rPos, nStyle );
-        }
-        break;
-
-        default:
-        break;
-    }
+    DrawImage( rPos, Size(), rImage, nStyle );
 }
 
 void OutputDevice::DrawImage( const Point& rPos, const Size& rSize,
@@ -802,6 +767,8 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize,
 {
     DBG_ASSERT( GetOutDevType() != OUTDEV_PRINTER, "DrawImage(): Images can't be drawn on any mprinter" );
 
+    bool bIsSizeValid = (rSize.getWidth() == 0 || rSize.getHeight() == 0) ? false : true;
+
     if( rImage.mpImplData && !ImplIsRecordLayout() )
     {
         switch( rImage.mpImplData->meType )
@@ -810,9 +777,16 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize,
             {
                 const Bitmap &rBitmap = *static_cast< Bitmap* >( rImage.mpImplData->mpData );
                 if( nStyle & IMAGE_DRAW_DISABLE )
-                    DrawBitmapEx( rPos, rSize, makeDisabledBitmap(rBitmap) );
+                {
+                    if ( bIsSizeValid )
+                        DrawBitmapEx( rPos, rSize, makeDisabledBitmap(rBitmap) );
+                    else
+                        DrawBitmapEx( rPos, makeDisabledBitmap(rBitmap) );
+                }
                 else
+                {
                     DrawBitmap( rPos, rSize, rBitmap );
+                }
             }
             break;
 
@@ -828,7 +802,10 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize,
                     pData->mpImageBitmap->Create( pData->maBmpEx, aSize.Width(), aSize.Height(), 1 );
                 }
 
-                pData->mpImageBitmap->Draw( 0, this, rPos, nStyle, &rSize );
+                if ( bIsSizeValid )
+                    pData->mpImageBitmap->Draw( 0, this, rPos, nStyle, &rSize );
+                else
+                    pData->mpImageBitmap->Draw( 0, this, rPos, nStyle );
             }
             break;
 


More information about the Libreoffice-commits mailing list