summaryrefslogtreecommitdiff
path: root/sfx2/source/doc/graphhelp.cxx
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2014-02-03 13:04:06 +0100
committerJan Holesovsky <kendy@collabora.com>2014-02-03 19:09:19 +0100
commit05857ac3232ee88dc9a2bde4c135f07dd25b4c91 (patch)
tree0af3c02893b10e27223c1ca12bea67d3bfbe0167 /sfx2/source/doc/graphhelp.cxx
parent86652eb4f74279a360f5fac160b4b4a66c9bc600 (diff)
thumbnails: Consolidate code.
There were 2 copies of the thumbnailing code; consolidate that to one copy directly in VCL. This kills the attempts to do alpha channel that used to be in the VCL copy of the code - it was producing wrong results, the bitmaps ended up empty. Change-Id: I415c410c287a95e75293bdcba5d71083d1d01dc1
Diffstat (limited to 'sfx2/source/doc/graphhelp.cxx')
-rw-r--r--sfx2/source/doc/graphhelp.cxx108
1 files changed, 2 insertions, 106 deletions
diff --git a/sfx2/source/doc/graphhelp.cxx b/sfx2/source/doc/graphhelp.cxx
index c74042d487d8..7cd16ee195d3 100644
--- a/sfx2/source/doc/graphhelp.cxx
+++ b/sfx2/source/doc/graphhelp.cxx
@@ -264,108 +264,6 @@ sal_Bool GraphicHelper::mergeBitmaps_Impl( const BitmapEx& rBmpEx, const BitmapE
return !rReturn.IsEmpty();
}
-
-//---------------------------------------------------------------
-// static
-sal_Bool GraphicHelper::createThumb_Impl( const GDIMetaFile& rMtf,
- sal_uInt32 nMaximumExtent,
- BitmapEx& rBmpEx,
- const BitmapEx* pOverlay,
- const Rectangle* pOverlayRect )
-{
- // the implementation is provided by KA
-
- // initialization seems to be complicated but is used to avoid rounding errors
- VirtualDevice aVDev;
- const Point aNullPt;
- const Point aTLPix( aVDev.LogicToPixel( aNullPt, rMtf.GetPrefMapMode() ) );
- const Point aBRPix( aVDev.LogicToPixel( Point( rMtf.GetPrefSize().Width() - 1, rMtf.GetPrefSize().Height() - 1 ), rMtf.GetPrefMapMode() ) );
- Size aDrawSize( aVDev.LogicToPixel( rMtf.GetPrefSize(), rMtf.GetPrefMapMode() ) );
- Size aSizePix( labs( aBRPix.X() - aTLPix.X() ) + 1, labs( aBRPix.Y() - aTLPix.Y() ) + 1 );
-
- if ( !rBmpEx.IsEmpty() )
- rBmpEx.SetEmpty();
-
- // determine size that has the same aspect ratio as image size and
- // fits into the rectangle determined by nMaximumExtent
- if ( aSizePix.Width() && aSizePix.Height() &&
- ( sal::static_int_cast<sal_uInt32>(aSizePix.Width()) > nMaximumExtent ||
- sal::static_int_cast<sal_uInt32>(aSizePix.Height()) > nMaximumExtent ) )
- {
- const Size aOldSizePix( aSizePix );
- double fWH = static_cast< double >( aSizePix.Width() ) / aSizePix.Height();
-
- if ( fWH <= 1.0 )
- {
- aSizePix.Width() = FRound( nMaximumExtent * fWH );
- aSizePix.Height() = nMaximumExtent;
- }
- else
- {
- aSizePix.Width() = nMaximumExtent;
- aSizePix.Height() = FRound( nMaximumExtent / fWH );
- }
-
- aDrawSize.Width() = FRound( ( static_cast< double >( aDrawSize.Width() ) * aSizePix.Width() ) / aOldSizePix.Width() );
- aDrawSize.Height() = FRound( ( static_cast< double >( aDrawSize.Height() ) * aSizePix.Height() ) / aOldSizePix.Height() );
- }
-
- Size aFullSize;
- Point aBackPosPix;
- Rectangle aOverlayRect;
-
- // calculate additional positions and sizes if an overlay image is used
- if ( pOverlay )
- {
- aFullSize = Size( nMaximumExtent, nMaximumExtent );
- aOverlayRect = Rectangle( aNullPt, aFullSize );
-
- aOverlayRect.Intersection( pOverlayRect ? *pOverlayRect : Rectangle( aNullPt, pOverlay->GetSizePixel() ) );
-
- if ( !aOverlayRect.IsEmpty() )
- aBackPosPix = Point( ( nMaximumExtent - aSizePix.Width() ) >> 1, ( nMaximumExtent - aSizePix.Height() ) >> 1 );
- else
- pOverlay = NULL;
- }
- else
- {
- aFullSize = aSizePix;
- pOverlay = NULL;
- }
-
- // draw image(s) into VDev and get resulting image
- // do it 4x larger to be able to scale it down & get beautiful antialias
- Size aAntialiasSize(aFullSize.Width() * 4, aFullSize.Height() * 4);
- if (aVDev.SetOutputSizePixel(aAntialiasSize))
- {
- // antialias: provide 4x larger size, and then scale down the result
- Size aAntialias(aDrawSize.Width() * 4, aDrawSize.Height() * 4);
-
- // draw metafile into VDev
- const_cast< GDIMetaFile& >( rMtf ).WindStart();
- const_cast< GDIMetaFile& >( rMtf ).Play( &aVDev, aBackPosPix, aAntialias );
-
- // draw overlay if necessary
- if ( pOverlay )
- aVDev.DrawBitmapEx( aOverlayRect.TopLeft(), aOverlayRect.GetSize(), *pOverlay );
-
- // get paint bitmap
- Bitmap aBmp( aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ) );
-
- // assure that we have a true color image
- if ( aBmp.GetBitCount() != 24 )
- aBmp.Convert( BMP_CONVERSION_24BIT );
-
- // downsize, to get the antialiased picture
- aBmp.Scale(aDrawSize, BMP_SCALE_BESTQUALITY);
-
- rBmpEx = BitmapEx( aBmp );
- }
-
- return !rBmpEx.IsEmpty();
-}
-
-//---------------------------------------------------------------
// static
sal_Bool GraphicHelper::getThumbnailFormatFromGDI_Impl( GDIMetaFile* pMetaFile,
sal_Bool bSigned,
@@ -385,10 +283,8 @@ sal_Bool GraphicHelper::getThumbnailFormatFromGDI_Impl( GDIMetaFile* pMetaFile,
if ( bSigned )
pSignatureBitmap = new BitmapEx( SfxResId( BMP_SIGNATURE ) );
- bResult = createThumb_Impl( *pMetaFile,
- THUMBNAIL_RESOLUTION,
- aResultBitmap,
- pSignatureBitmap );
+ bResult = pMetaFile->CreateThumbnail(THUMBNAIL_RESOLUTION, aResultBitmap, pSignatureBitmap);
+
if ( bResult )
bResult = ( !aResultBitmap.IsEmpty()
&& GraphicConverter::Export( *pStream, aResultBitmap, CVT_PNG ) == 0