From c5b6f8d6469850e14362f2c8f08cdf8c956cbf07 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Wed, 2 Sep 2020 11:45:10 +0200 Subject: fix erasing virtual device with alpha MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The background cannot be simply set as background also for the internal alpha virtual device, since this hackish alpha uses black = opaque and white = transparent. So e.g. setting to background to COL_WHITE actually resulted in the content being transparent. Try to map to what the alpha virtual device actually needs. Change-Id: Ie5179769d9bce989eddfc96f5cbd2b94d1d88d53 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101927 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- vcl/source/outdev/outdevstate.cxx | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'vcl/source/outdev') diff --git a/vcl/source/outdev/outdevstate.cxx b/vcl/source/outdev/outdevstate.cxx index 804ba883c210..4ab3093b573b 100644 --- a/vcl/source/outdev/outdevstate.cxx +++ b/vcl/source/outdev/outdevstate.cxx @@ -455,7 +455,44 @@ void OutputDevice::SetBackground( const Wallpaper& rBackground ) mbBackground = true; if( mpAlphaVDev ) - mpAlphaVDev->SetBackground( rBackground ); + { + // Some of these are probably wrong (e.g. if the gradient has transparency), + // but hopefully nobody uses that. If you do, feel free to implement it properly. + if( rBackground.GetStyle() == WallpaperStyle::NONE ) + mpAlphaVDev->SetBackground( rBackground ); + else if( rBackground.IsBitmap()) + { + BitmapEx bitmap = rBackground.GetBitmap(); + if( bitmap.IsAlpha()) + mpAlphaVDev->SetBackground( Wallpaper( BitmapEx( Bitmap( bitmap.GetAlpha())))); + else + { + switch( bitmap.GetTransparentType()) + { + case TransparentType::NONE: + mpAlphaVDev->SetBackground( Wallpaper( COL_BLACK )); + break; + case TransparentType::Color: + { + AlphaMask mask( bitmap.GetBitmap().CreateMask( bitmap.GetTransparentColor())); + mpAlphaVDev->SetBackground( Wallpaper( BitmapEx( bitmap.GetBitmap(), mask ))); + break; + } + case TransparentType::Bitmap: + mpAlphaVDev->SetBackground( Wallpaper( BitmapEx( bitmap.GetMask()))); + break; + } + } + } + else if( rBackground.IsGradient()) + mpAlphaVDev->SetBackground( Wallpaper( COL_BLACK )); + else + { + // Color background. + int transparency = rBackground.GetColor().GetTransparency(); + mpAlphaVDev->SetBackground( Wallpaper( Color( transparency, transparency, transparency ))); + } + } } void OutputDevice::SetFont( const vcl::Font& rNewFont ) -- cgit v1.2.3