include/vcl/gradient.hxx | 6 +-- include/vcl/outdev.hxx | 3 - vcl/source/outdev/gradient.cxx | 69 ++++++++++++++++++----------------------- 3 files changed, 35 insertions(+), 43 deletions(-)
New commits: commit 22dd44f479fe9b3c34b03ae55177c7b66170e41b Author: Chris Sherlock <chris.sherloc...@gmail.com> AuthorDate: Sat Dec 18 12:34:55 2021 +1100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Dec 27 03:51:41 2021 +0100 vcl: change Get{Linear|Complex}GradientSteps() No need to have split out the function, we can just check the gradient style type. However, if we are checking the steps for a metafile we can make this a static function. Change-Id: If0524567ec5974db92aff928e0733ab746ecbeba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127029 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/vcl/gradient.hxx b/include/vcl/gradient.hxx index 59956138033b..5a04616adda5 100644 --- a/include/vcl/gradient.hxx +++ b/include/vcl/gradient.hxx @@ -21,13 +21,13 @@ #define INCLUDED_VCL_GRADIENT_HXX #include <sal/types.h> -#include <vcl/dllapi.h> #include <tools/color.hxx> #include <tools/degree.hxx> - -#include <vcl/vclenum.hxx> +#include <tools/long.hxx> #include <o3tl/cow_wrapper.hxx> +#include <vcl/dllapi.h> +#include <vcl/vclenum.hxx> namespace tools { class Rectangle; } diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx index eec957e14973..9c86567865ba 100644 --- a/include/vcl/outdev.hxx +++ b/include/vcl/outdev.hxx @@ -815,8 +815,7 @@ private: SAL_DLLPRIVATE void DrawLinearGradientToMetafile( const tools::Rectangle& rRect, const Gradient& rGradient ); SAL_DLLPRIVATE void DrawComplexGradientToMetafile( const tools::Rectangle& rRect, const Gradient& rGradient ); - SAL_DLLPRIVATE tools::Long GetLinearGradientSteps( const Gradient& rGradient, const tools::Rectangle& rRect, bool bMtf); - SAL_DLLPRIVATE tools::Long GetComplexGradientSteps( const Gradient& rGradient, const tools::Rectangle& rRect, bool bMtf); + SAL_DLLPRIVATE tools::Long GetGradientSteps(Gradient const& rGradient, tools::Rectangle const& rRect); SAL_DLLPRIVATE Color GetSingleColorGradientFill(); ///@} diff --git a/vcl/source/outdev/gradient.cxx b/vcl/source/outdev/gradient.cxx index f1ae13283f9d..9d8e6d8b1830 100644 --- a/vcl/source/outdev/gradient.cxx +++ b/vcl/source/outdev/gradient.cxx @@ -321,7 +321,7 @@ void OutputDevice::DrawLinearGradient( const tools::Rectangle& rRect, } // calculate step count - tools::Long nStepCount = GetLinearGradientSteps(rGradient, aRect, false/*bMtf*/); + tools::Long nStepCount = GetGradientSteps(rGradient, aRect); // minimal three steps and maximal as max color steps tools::Long nAbsRedSteps = std::abs( nEndRed - nStartRed ); @@ -443,7 +443,7 @@ void OutputDevice::DrawComplexGradient( const tools::Rectangle& rRect, if ( UsePolyPolygonForComplexGradient() ) xPolyPoly = tools::PolyPolygon( 2 ); - tools::Long nStepCount = GetComplexGradientSteps(rGradient, rRect, false/*bMtf*/); + tools::Long nStepCount = GetGradientSteps(rGradient, rRect); // at least three steps and at most the number of colour differences tools::Long nSteps = std::max( nStepCount, tools::Long(2) ); @@ -581,6 +581,20 @@ void OutputDevice::DrawComplexGradient( const tools::Rectangle& rRect, ImplDrawPolygon( rPoly, pClixPolyPoly ); } +static tools::Long GetGradientMetafileSteps(Gradient const& rGradient, tools::Rectangle const& rRect) +{ + // calculate step count + tools::Long nStepCount = rGradient.GetSteps(); + + if (nStepCount) + return nStepCount; + + if (rGradient.GetStyle() == GradientStyle::Linear || rGradient.GetStyle() == GradientStyle::Axial) + return rRect.GetHeight(); + else + return std::min(rRect.GetWidth(), rRect.GetHeight()); +} + void OutputDevice::DrawLinearGradientToMetafile( const tools::Rectangle& rRect, const Gradient& rGradient ) { @@ -679,7 +693,7 @@ void OutputDevice::DrawLinearGradientToMetafile( const tools::Rectangle& rRect, } } - tools::Long nStepCount = GetLinearGradientSteps( rGradient, aRect, true/*bMtf*/ ); + tools::Long nStepCount = GetGradientMetafileSteps(rGradient, aRect); // minimal three steps and maximal as max color steps tools::Long nAbsRedSteps = std::abs( nEndRed - nStartRed ); @@ -780,7 +794,7 @@ void OutputDevice::DrawComplexGradientToMetafile( const tools::Rectangle& rRect, xPolyPoly = tools::PolyPolygon( 2 ); // last parameter - true if complex gradient, false if linear - tools::Long nStepCount = GetComplexGradientSteps(rGradient, rRect, true); + tools::Long nStepCount = GetGradientMetafileSteps(rGradient, rRect); // at least three steps and at most the number of colour differences tools::Long nSteps = std::max(nStepCount, tools::Long(2)); @@ -915,48 +929,27 @@ tools::Long OutputDevice::GetGradientStepCount( tools::Long nMinRect ) return nInc; } -tools::Long OutputDevice::GetLinearGradientSteps(Gradient const& rGradient, tools::Rectangle const& rRect, bool bMtf) +tools::Long OutputDevice::GetGradientSteps(Gradient const& rGradient, tools::Rectangle const& rRect) { // calculate step count - tools::Long nStepCount = rGradient.GetSteps(); - - // generate nStepCount, if not passed - tools::Long nMinRect = rRect.GetHeight(); - - if ( !nStepCount ) - { - tools::Long nInc; + tools::Long nStepCount = rGradient.GetSteps(); - nInc = GetGradientStepCount(nMinRect); - if ( !nInc || bMtf ) - nInc = 1; + if (nStepCount) + return nStepCount; - nStepCount = nMinRect / nInc; - } - - return nStepCount; -} - -tools::Long OutputDevice::GetComplexGradientSteps(Gradient const& rGradient, tools::Rectangle const& rRect, bool bMtf) -{ - // calculate step count - tools::Long nStepCount = rGradient.GetSteps(); - - // generate nStepCount, if not passed - tools::Long nMinRect = std::min(rRect.GetWidth(), rRect.GetHeight()); + tools::Long nMinRect = 0; - if ( !nStepCount ) - { - tools::Long nInc; - nInc = GetGradientStepCount(nMinRect); + if (rGradient.GetStyle() == GradientStyle::Linear || rGradient.GetStyle() == GradientStyle::Axial) + nMinRect = rRect.GetHeight(); + else + nMinRect = std::min(rRect.GetWidth(), rRect.GetHeight()); - if ( !nInc || bMtf ) - nInc = 1; + tools::Long nInc = GetGradientStepCount(nMinRect); - nStepCount = nMinRect / nInc; - } + if (!nInc) + nInc = 1; - return nStepCount; + return nMinRect / nInc; } Color OutputDevice::GetSingleColorGradientFill()