diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2021-12-18 12:34:55 +1100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-12-27 03:51:41 +0100 |
commit | 22dd44f479fe9b3c34b03ae55177c7b66170e41b (patch) | |
tree | b4f09fa5bfd7cc99c1fd312042849d06f361d62b /vcl/source/outdev/gradient.cxx | |
parent | 1de7e1f4640bad725626b574b33eb2db9244f378 (diff) |
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 <quikee@gmail.com>
Diffstat (limited to 'vcl/source/outdev/gradient.cxx')
-rw-r--r-- | vcl/source/outdev/gradient.cxx | 69 |
1 files changed, 31 insertions, 38 deletions
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() |