vcl/source/outdev/gradient.cxx | 138 ++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 69 deletions(-)
New commits: commit 9e172b671a42e5c31a2d434db31af9b982ee3c1f Author: Christopher Sherlock <chris.sherloc...@gmail.com> AuthorDate: Thu Aug 14 23:43:48 2025 +1000 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Aug 15 22:33:31 2025 +0200 vcl: flatten OutputDevice::DrawGradient() Change-Id: Id365088129fe808703e77f304d9f28cb5d2dd444 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189699 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/source/outdev/gradient.cxx b/vcl/source/outdev/gradient.cxx index d2251799b7e0..4efbc47c91b1 100644 --- a/vcl/source/outdev/gradient.cxx +++ b/vcl/source/outdev/gradient.cxx @@ -53,94 +53,94 @@ void OutputDevice::DrawGradient( const tools::PolyPolygon& rPolyPoly, InitClipRegion(); // don't return on mbOutputClipped here, as we may need to draw the clipped metafile, even if the output is clipped - if ( rPolyPoly.Count() && rPolyPoly[ 0 ].GetSize() ) + if (!rPolyPoly.Count() || !rPolyPoly[0].GetSize()) + return; + + if ( mnDrawMode & ( DrawModeFlags::BlackGradient | DrawModeFlags::WhiteGradient | DrawModeFlags::SettingsGradient) ) { - if ( mnDrawMode & ( DrawModeFlags::BlackGradient | DrawModeFlags::WhiteGradient | DrawModeFlags::SettingsGradient) ) - { - Color aColor = GetSingleColorGradientFill(); + Color aColor = GetSingleColorGradientFill(); - Push( vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR ); - SetLineColor( aColor ); - SetFillColor( aColor ); - DrawPolyPolygon( rPolyPoly ); - Pop(); - return; - } + Push( vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR ); + SetLineColor( aColor ); + SetFillColor( aColor ); + DrawPolyPolygon( rPolyPoly ); + Pop(); + return; + } + + Gradient aGradient( rGradient ); + + if ( mnDrawMode & DrawModeFlags::GrayGradient ) + aGradient.MakeGrayscale(); - Gradient aGradient( rGradient ); + DrawGradientToMetafile( rPolyPoly, rGradient ); - if ( mnDrawMode & DrawModeFlags::GrayGradient ) - aGradient.MakeGrayscale(); + if( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) + return; - DrawGradientToMetafile( rPolyPoly, rGradient ); + // Clip and then draw the gradient + if( !tools::Rectangle( PixelToLogic( Point() ), GetOutputSize() ).IsEmpty() ) + { + const tools::Rectangle aBoundRect( rPolyPoly.GetBoundRect() ); - if( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) - return; + // convert rectangle to pixels + tools::Rectangle aRect( ImplLogicToDevicePixel( aBoundRect ) ); + aRect.Normalize(); - // Clip and then draw the gradient - if( !tools::Rectangle( PixelToLogic( Point() ), GetOutputSize() ).IsEmpty() ) + // do nothing if the rectangle is empty + if ( !aRect.IsEmpty() ) { - const tools::Rectangle aBoundRect( rPolyPoly.GetBoundRect() ); + tools::PolyPolygon aClixPolyPoly( ImplLogicToDevicePixel( rPolyPoly ) ); + bool bDrawn = false; - // convert rectangle to pixels - tools::Rectangle aRect( ImplLogicToDevicePixel( aBoundRect ) ); - aRect.Normalize(); + if( !mpGraphics && !AcquireGraphics() ) + return; - // do nothing if the rectangle is empty - if ( !aRect.IsEmpty() ) - { - tools::PolyPolygon aClixPolyPoly( ImplLogicToDevicePixel( rPolyPoly ) ); - bool bDrawn = false; + // secure clip region + Push( vcl::PushFlags::CLIPREGION ); + IntersectClipRegion( aBoundRect ); + + if (mbInitClipRegion) + InitClipRegion(); - if( !mpGraphics && !AcquireGraphics() ) - return; + // try to draw gradient natively + if (!mbOutputClipped) + bDrawn = mpGraphics->DrawGradient( aClixPolyPoly, aGradient, *this ); - // secure clip region - Push( vcl::PushFlags::CLIPREGION ); - IntersectClipRegion( aBoundRect ); + if (!bDrawn && !mbOutputClipped) + { + // draw gradients without border + if( mbLineColor || mbInitLineColor ) + { + mpGraphics->SetLineColor(); + mbInitLineColor = true; + } - if (mbInitClipRegion) - InitClipRegion(); + mbInitFillColor = true; - // try to draw gradient natively - if (!mbOutputClipped) - bDrawn = mpGraphics->DrawGradient( aClixPolyPoly, aGradient, *this ); + // calculate step count if necessary + if ( !aGradient.GetSteps() ) + aGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); - if (!bDrawn && !mbOutputClipped) + if ( rPolyPoly.IsRect() ) { - // draw gradients without border - if( mbLineColor || mbInitLineColor ) - { - mpGraphics->SetLineColor(); - mbInitLineColor = true; - } - - mbInitFillColor = true; - - // calculate step count if necessary - if ( !aGradient.GetSteps() ) - aGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); - - if ( rPolyPoly.IsRect() ) - { - // because we draw with no border line, we have to expand gradient - // rect to avoid missing lines on the right and bottom edge - aRect.AdjustLeft( -1 ); - aRect.AdjustTop( -1 ); - aRect.AdjustRight( 1 ); - aRect.AdjustBottom( 1 ); - } - - // if the clipping polypolygon is a rectangle, then it's the same size as the bounding of the - // polypolygon, so pass in a NULL for the clipping parameter - if( aGradient.GetStyle() == css::awt::GradientStyle_LINEAR || rGradient.GetStyle() == css::awt::GradientStyle_AXIAL ) - DrawLinearGradient( aRect, aGradient, aClixPolyPoly.IsRect() ? nullptr : &aClixPolyPoly ); - else - DrawComplexGradient( aRect, aGradient, aClixPolyPoly.IsRect() ? nullptr : &aClixPolyPoly ); + // because we draw with no border line, we have to expand gradient + // rect to avoid missing lines on the right and bottom edge + aRect.AdjustLeft( -1 ); + aRect.AdjustTop( -1 ); + aRect.AdjustRight( 1 ); + aRect.AdjustBottom( 1 ); } - Pop(); + // if the clipping polypolygon is a rectangle, then it's the same size as the bounding of the + // polypolygon, so pass in a NULL for the clipping parameter + if( aGradient.GetStyle() == css::awt::GradientStyle_LINEAR || rGradient.GetStyle() == css::awt::GradientStyle_AXIAL ) + DrawLinearGradient( aRect, aGradient, aClixPolyPoly.IsRect() ? nullptr : &aClixPolyPoly ); + else + DrawComplexGradient( aRect, aGradient, aClixPolyPoly.IsRect() ? nullptr : &aClixPolyPoly ); } + + Pop(); } } }