summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2014-04-19 19:34:07 +1000
committerChris Sherlock <chris.sherlock79@gmail.com>2014-04-19 19:44:33 +1000
commit2d786ef2961002893d532a7d2087055857e51c17 (patch)
tree741e54300a9d768c5353dd25daf498a0685622b4
parentfa801a69a2660a15bffe409f422364c011c7534f (diff)
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
-rw-r--r--include/vcl/outdev.hxx4
-rw-r--r--vcl/source/outdev/bitmap.cxx53
2 files changed, 17 insertions, 40 deletions
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index d0bd887ada50..7507d08a9b60 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 3bbf39234252..23d1177726e0 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;