Kaydet (Commit) 2d786ef2 authored tarafından Chris Sherlock's avatar Chris Sherlock

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
üst fa801a69
...@@ -1146,9 +1146,9 @@ public: ...@@ -1146,9 +1146,9 @@ public:
const Bitmap& rBitmap, const Color& rMaskColor, const Bitmap& rBitmap, const Color& rMaskColor,
sal_uLong nAction ); sal_uLong nAction );
void DrawImage( const Point& rPos, virtual void DrawImage( const Point& rPos,
const Image& rImage, sal_uInt16 nStyle = 0 ); 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 ); const Image& rImage, sal_uInt16 nStyle = 0 );
#ifdef _MSC_VER #ifdef _MSC_VER
......
...@@ -759,42 +759,7 @@ namespace ...@@ -759,42 +759,7 @@ namespace
void OutputDevice::DrawImage( const Point& rPos, const Image& rImage, sal_uInt16 nStyle ) 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" ); DrawImage( rPos, Size(), rImage, nStyle );
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;
}
} }
void OutputDevice::DrawImage( const Point& rPos, const Size& rSize, void OutputDevice::DrawImage( const Point& rPos, const Size& rSize,
...@@ -802,6 +767,8 @@ 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" ); 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() ) if( rImage.mpImplData && !ImplIsRecordLayout() )
{ {
switch( rImage.mpImplData->meType ) switch( rImage.mpImplData->meType )
...@@ -810,9 +777,16 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize, ...@@ -810,9 +777,16 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize,
{ {
const Bitmap &rBitmap = *static_cast< Bitmap* >( rImage.mpImplData->mpData ); const Bitmap &rBitmap = *static_cast< Bitmap* >( rImage.mpImplData->mpData );
if( nStyle & IMAGE_DRAW_DISABLE ) if( nStyle & IMAGE_DRAW_DISABLE )
DrawBitmapEx( rPos, rSize, makeDisabledBitmap(rBitmap) ); {
if ( bIsSizeValid )
DrawBitmapEx( rPos, rSize, makeDisabledBitmap(rBitmap) );
else
DrawBitmapEx( rPos, makeDisabledBitmap(rBitmap) );
}
else else
{
DrawBitmap( rPos, rSize, rBitmap ); DrawBitmap( rPos, rSize, rBitmap );
}
} }
break; break;
...@@ -828,7 +802,10 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize, ...@@ -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->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; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment