diff options
author | Armin Le Grand <alg@apache.org> | 2012-12-07 17:15:12 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-10 17:04:38 +0100 |
commit | bbc58f2043eb0787f498f62ac54500bd31d8c89c (patch) | |
tree | 832b790c92eb07c3b38ed746f31831a6b1b891f6 /svx/source/gallery2 | |
parent | 94298db96fa14f6c7c8eb67b2faab3ac01bd5ccd (diff) |
Resolves: #i121445# Added transparency support to the gallery
(cherry picked from commit cf417aec41decab94b5f1e82f6409e97a6c02fb5)
Conflicts:
extras/source/gallery/gallery_system/sg2.sdg
extras/source/gallery/gallery_system/sg2.thm
svx/inc/galtheme.hrc
svx/inc/svx/fontworkgallery.hxx
svx/inc/svx/gallery.hxx
svx/inc/svx/galtheme.hxx
svx/source/gallery2/galctrl.cxx
svx/source/gallery2/galexpl.cxx
svx/source/gallery2/galobj.cxx
svx/source/tbxctrls/fontworkgallery.cxx
vcl/inc/vcl/outdev.hxx
vcl/source/gdi/outdev6.cxx
Change-Id: I519a2cf4e16bb42ecfd9c4b48094e65adcc35599
(cherry picked from commit ddec662e8dc234b7196c1b3c28db5da743557ec6)
Diffstat (limited to 'svx/source/gallery2')
-rw-r--r-- | svx/source/gallery2/galctrl.cxx | 61 | ||||
-rw-r--r-- | svx/source/gallery2/galexpl.cxx | 8 | ||||
-rw-r--r-- | svx/source/gallery2/galobj.cxx | 102 | ||||
-rw-r--r-- | svx/source/gallery2/galtheme.cxx | 9 |
4 files changed, 102 insertions, 78 deletions
diff --git a/svx/source/gallery2/galctrl.cxx b/svx/source/gallery2/galctrl.cxx index 848a230509c4..6811e95b2bdb 100644 --- a/svx/source/gallery2/galctrl.cxx +++ b/svx/source/gallery2/galctrl.cxx @@ -258,6 +258,16 @@ void GalleryPreview::PreviewMedia( const INetURLObject& rURL ) } } +void drawCheckered(OutputDevice& rOut, const Point& rPos, const Size& rSize) +{ + // draw checkered background + static const sal_uInt32 nLen(8); + static const Color aW(COL_WHITE); + static const Color aG(0xef, 0xef, 0xef); + + rOut.DrawCheckered(rPos, rSize, nLen, aW, aG); +} + DBG_NAME(GalleryIconView) GalleryIconView::GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) : @@ -311,21 +321,37 @@ void GalleryIconView::UserDraw( const UserDrawEvent& rUDEvt ) const Rectangle& rRect = rUDEvt.GetRect(); OutputDevice* pDev = rUDEvt.GetDevice(); Graphic aGraphic; + bool bTransparent(false); if( pObj->IsThumbBitmap() ) { - Bitmap aBmp( pObj->GetThumbBmp() ); + BitmapEx aBitmapEx; if( pObj->GetObjKind() == SGA_OBJ_SOUND ) - aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); + { + Bitmap aTemp = pObj->GetThumbBmp().GetBitmap(); + + aTemp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); + aBitmapEx = BitmapEx(aTemp); + } + else + { + aBitmapEx = pObj->GetThumbBmp(); + bTransparent = aBitmapEx.IsTransparent(); + } - if( ( pDev->GetBitCount() <= 8 ) && ( aBmp.GetBitCount() >= 8 ) ) - aBmp.Dither( BMP_DITHER_FLOYD ); + if( ( pDev->GetBitCount() <= 8 ) && ( aBitmapEx.GetBitCount() >= 8 ) ) + { + aBitmapEx.Dither( BMP_DITHER_FLOYD ); + } - aGraphic = aBmp; + aGraphic = aBitmapEx; } else + { aGraphic = pObj->GetThumbMtf(); + bTransparent = true; + } Size aSize( aGraphic.GetSizePixel( pDev ) ); @@ -352,6 +378,12 @@ void GalleryIconView::UserDraw( const UserDrawEvent& rUDEvt ) const Point aPos( ( ( rRect.GetWidth() - aSize.Width() ) >> 1 ) + rRect.Left(), ( ( rRect.GetHeight() - aSize.Height() ) >> 1 ) + rRect.Top() ); + if(bTransparent) + { + // draw checkered background + drawCheckered(*pDev, aPos, aSize); + } + aGraphic.Draw( pDev, aPos, aSize ); } @@ -517,13 +549,24 @@ void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sa { Rectangle aOutputRect( rRect.TopLeft(), Size( rRect.GetHeight(), rRect.GetHeight() ) ); GraphicObject aGrfObj; + bool bTransparent(false); if( pObj->GetObjKind() == SGA_OBJ_SOUND ) + { aGrfObj = Graphic( BitmapEx( GAL_RES( RID_SVXBMP_GALLERY_MEDIA ) ) ); + } else if( pObj->IsThumbBitmap() ) - aGrfObj = Graphic( pObj->GetThumbBmp() ); + { + const BitmapEx aBitmapEx(pObj->GetThumbBmp()); + + bTransparent = aBitmapEx.IsTransparent(); + aGrfObj = Graphic(aBitmapEx); + } else + { aGrfObj = Graphic( pObj->GetThumbMtf() ); + bTransparent = true; + } Size aSize( rDev.LogicToPixel( aGrfObj.GetPrefSize(), aGrfObj.GetPrefMapMode() ) ); @@ -553,6 +596,12 @@ void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sa const Point aPos( ( ( aOutputRect.GetWidth() - aSize.Width() ) >> 1 ) + aOutputRect.Left(), ( ( aOutputRect.GetHeight() - aSize.Height() ) >> 1 ) + aOutputRect.Top() ); + if(bTransparent) + { + // draw checkered background + drawCheckered(rDev, aPos, aSize); + } + aGrfObj.Draw( &rDev, aPos, aSize ); } diff --git a/svx/source/gallery2/galexpl.cxx b/svx/source/gallery2/galexpl.cxx index 1c505c797c81..13899ad21197 100644 --- a/svx/source/gallery2/galexpl.cxx +++ b/svx/source/gallery2/galexpl.cxx @@ -237,7 +237,7 @@ sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL, c // ------------------------------------------------------------------------ sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr nPos, - Graphic* pGraphic, Bitmap* pThumb, + Graphic* pGraphic, BitmapEx* pThumb, sal_Bool bProgress ) { Gallery* pGal = ImplGetGallery(); @@ -266,7 +266,7 @@ sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr n // ------------------------------------------------------------------------ sal_Bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos, - Graphic* pGraphic, Bitmap* pThumb, + Graphic* pGraphic, BitmapEx* pThumb, sal_Bool bProgress ) { Gallery* pGal = ImplGetGallery(); @@ -309,7 +309,7 @@ sal_uIntPtr GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId ) // ------------------------------------------------------------------------ sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrModelPos, - SdrModel* pModel, Bitmap* pThumb ) + SdrModel* pModel, BitmapEx* pThumb ) { Gallery* pGal = ImplGetGallery(); sal_Bool bRet = sal_False; @@ -346,7 +346,7 @@ sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrM // ------------------------------------------------------------------------ sal_Bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId, sal_uIntPtr nSdrModelPos, - SdrModel* pModel, Bitmap* pThumb ) + SdrModel* pModel, BitmapEx* pThumb ) { Gallery* pGal = ImplGetGallery(); return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : sal_False ); diff --git a/svx/source/gallery2/galobj.cxx b/svx/source/gallery2/galobj.cxx index ec88e83c18b6..29791da82d05 100644 --- a/svx/source/gallery2/galobj.cxx +++ b/svx/source/gallery2/galobj.cxx @@ -88,7 +88,8 @@ sal_Bool SgaObject::CreateThumb( const Graphic& rGraphic ) } } - aThumbBmp = aBmpEx.GetBitmap( &aWhite ); + // take over BitmapEx + aThumbBmp = aBmpEx; if( ( aBmpSize.Width() <= S_THUMB ) && ( aBmpSize.Height() <= S_THUMB ) ) { @@ -123,7 +124,7 @@ sal_Bool SgaObject::CreateThumb( const Graphic& rGraphic ) aSize.Height() = (sal_Int32)( S_THUMB / fFactor ); const GraphicConversionParameters aParameters(aSize, false, true, true /*TODO: extra ", true" post-#i121194#*/); - aThumbBmp = rGraphic.GetBitmap(aParameters); + aThumbBmp = rGraphic.GetBitmapEx(aParameters); if( !aThumbBmp.IsEmpty() ) { @@ -341,7 +342,7 @@ SgaObjectSound::~SgaObjectSound() // ------------------------------------------------------------------------ -Bitmap SgaObjectSound::GetThumbBmp() const +BitmapEx SgaObjectSound::GetThumbBmp() const { sal_uInt16 nId; @@ -362,9 +363,8 @@ Bitmap SgaObjectSound::GetThumbBmp() const } const BitmapEx aBmpEx( GAL_RES( nId ) ); - const Color aTransColor( COL_WHITE ); - return aBmpEx.GetBitmap( &aTransColor ); + return aBmpEx; } // ------------------------------------------------------------------------ @@ -506,76 +506,50 @@ sal_Bool SgaObjectSvDraw::CreateThumb( const FmFormModel& rModel ) sal_Bool bRet = sal_False; if ( CreateIMapGraphic( rModel, aGraphic, aImageMap ) ) + { bRet = SgaObject::CreateThumb( aGraphic ); + } else { - VirtualDevice aVDev; + const FmFormPage* pPage = static_cast< const FmFormPage* >(rModel.GetPage(0)); - aVDev.SetOutputSizePixel( Size( S_THUMB*2, S_THUMB*2 ) ); - - bRet = DrawCentered( &aVDev, rModel ); - if( bRet ) + if(pPage) { - aThumbBmp = aVDev.GetBitmap( Point(), aVDev.GetOutputSizePixel() ); - - Size aMS( 2, 2 ); - BmpFilterParam aParam( aMS ); - aThumbBmp.Filter( BMP_FILTER_MOSAIC, &aParam ); - aThumbBmp.Scale( Size( S_THUMB, S_THUMB ) ); + const Rectangle aObjRect(pPage->GetAllObjBoundRect()); - aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS ); - } - } - - return bRet; -} + if(aObjRect.GetWidth() && aObjRect.GetHeight()) + { + VirtualDevice aVDev; + FmFormView aView(const_cast< FmFormModel* >(&rModel), &aVDev); -// ------------------------------------------------------------------------ + aView.ShowSdrPage(const_cast< FmFormPage* >(pPage)); + aView.MarkAllObj(); + aThumbBmp = aView.GetMarkedObjBitmapEx(); -sal_Bool SgaObjectSvDraw::DrawCentered( OutputDevice* pOut, const FmFormModel& rModel ) -{ - const FmFormPage* pPage = static_cast< const FmFormPage* >( rModel.GetPage( 0 ) ); - sal_Bool bRet = sal_False; + const Size aDiscreteSize(aThumbBmp.GetSizePixel()); - if( pOut && pPage ) - { - const Rectangle aObjRect( pPage->GetAllObjBoundRect() ); - const Size aOutSizePix( pOut->GetOutputSizePixel() ); + if(aDiscreteSize.Width() && aDiscreteSize.Height()) + { + sal_uInt32 nTargetSizeX(S_THUMB); + sal_uInt32 nTargetSizeY(S_THUMB); - if( aObjRect.GetWidth() && aObjRect.GetHeight() && aOutSizePix.Width() > 2 && aOutSizePix.Height() > 2 ) - { - FmFormView aView( const_cast< FmFormModel* >( &rModel ), pOut ); - MapMode aMap( rModel.GetScaleUnit() ); - Rectangle aDrawRectPix( Point( 1, 1 ), Size( aOutSizePix.Width() - 2, aOutSizePix.Height() - 2 ) ); - const double fFactor = (double) aObjRect.GetWidth() / aObjRect.GetHeight(); - Fraction aFrac( FRound( fFactor < 1. ? aDrawRectPix.GetWidth() * fFactor : aDrawRectPix.GetWidth() ), - pOut->LogicToPixel( aObjRect.GetSize(), aMap ).Width() ); - - aMap.SetScaleX( aFrac ); - aMap.SetScaleY( aFrac ); - - const Size aDrawSize( pOut->PixelToLogic( aDrawRectPix.GetSize(), aMap ) ); - Point aOrigin( pOut->PixelToLogic( aDrawRectPix.TopLeft(), aMap ) ); - - aOrigin.X() += ( ( aDrawSize.Width() - aObjRect.GetWidth() ) >> 1 ) - aObjRect.Left(); - aOrigin.Y() += ( ( aDrawSize.Height() - aObjRect.GetHeight() ) >> 1 ) - aObjRect.Top(); - aMap.SetOrigin( aOrigin ); - - aView.SetPageVisible( sal_False ); - aView.SetBordVisible( sal_False ); - aView.SetGridVisible( sal_False ); - aView.SetHlplVisible( sal_False ); - aView.SetGlueVisible( sal_False ); - - pOut->Push(); - pOut->SetMapMode( aMap ); - aView.ShowSdrPage( const_cast< FmFormPage* >( pPage )); - aView.CompleteRedraw( pOut, - Region(Rectangle(pOut->PixelToLogic(Point()), - pOut->GetOutputSize()))); - pOut->Pop(); + if(aDiscreteSize.Width() > aDiscreteSize.Height()) + { + nTargetSizeY = (aDiscreteSize.Height() * nTargetSizeX) / aDiscreteSize.Width(); + } + else + { + nTargetSizeX = (aDiscreteSize.Width() * nTargetSizeY) / aDiscreteSize.Height(); + } - bRet = sal_True; + if(!!aThumbBmp) + { + aThumbBmp.Scale(Size(nTargetSizeX, nTargetSizeY), BMP_SCALE_BESTQUALITY); + aThumbBmp.Convert(BMP_CONVERSION_8BIT_COLORS); + bRet = true; + } + } + } } } diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index 35bb9218d8fb..a7624a02fe9d 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -769,7 +769,7 @@ GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, sa // ----------------------------------------------------------------------------- -sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, Bitmap& rBmp, sal_Bool ) +sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, BitmapEx& rBmp, sal_Bool ) { SgaObject* pObj = AcquireObject( nPos ); sal_Bool bRet = sal_False; @@ -841,9 +841,10 @@ sal_Bool GalleryTheme::GetGraphic( sal_uIntPtr nPos, Graphic& rGraphic, sal_Bool if( pObj ) { - Bitmap aBmp( pObj->GetThumbBmp() ); - aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); - rGraphic = aBmp; + rGraphic = pObj->GetThumbBmp(); + //Bitmap aBmp( pObj->GetThumbBmp() ); + //aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); + //rGraphic = aBmp; ReleaseObject( pObj ); bRet = sal_True; } |