basegfx/source/tools/gradienttools.cxx | 10 ---- drawinglayer/source/texture/texture.cxx | 67 +++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 31 deletions(-)
New commits: commit ae51dfb2379a9e9183afa9a1e5ee4fe4f4f0f7ef Author: Armin Le Grand (allotropia) <[email protected]> AuthorDate: Fri Feb 24 10:56:43 2023 +0100 Commit: Armin Le Grand <[email protected]> CommitDate: Fri Feb 24 16:22:36 2023 +0000 MCGR: Adapted GradientRadial to make use of MCGR Added to make GradientRadial work using the MCGR. It is still 100% backward-compatible, so as long as there is no source using this it will stay invisible - by purpose. Tests look good with this one, see the static variable nUseGradientSteps. Change-Id: Ie7134fe2995b23ceb180c7daf3f5b2310c8a8a78 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147617 Tested-by: Jenkins Reviewed-by: Armin Le Grand <[email protected]> diff --git a/basegfx/source/tools/gradienttools.cxx b/basegfx/source/tools/gradienttools.cxx index b27443898f4e..37671374262c 100644 --- a/basegfx/source/tools/gradienttools.cxx +++ b/basegfx/source/tools/gradienttools.cxx @@ -515,15 +515,7 @@ namespace basegfx return 0.0; } - const double t(1.0 - std::hypot(aCoor.getX(), aCoor.getY())); - const sal_uInt32 nSteps(rGradInfo.getRequestedSteps()); - - if(nSteps && t < 1.0) - { - return floor(t * nSteps) / double(nSteps - 1); - } - - return t; + return 1.0 - std::hypot(aCoor.getX(), aCoor.getY()); } double getEllipticalGradientAlpha(const B2DPoint& rUV, const ODFGradientInfo& rGradInfo) diff --git a/drawinglayer/source/texture/texture.cxx b/drawinglayer/source/texture/texture.cxx index 73110fc8b8fd..44ce9336ac89 100644 --- a/drawinglayer/source/texture/texture.cxx +++ b/drawinglayer/source/texture/texture.cxx @@ -367,42 +367,65 @@ namespace drawinglayer::texture std::vector< B2DHomMatrixAndBColor >& rEntries, basegfx::BColor& rOuterColor) { - if(mnColorSteps.size() <= 1) + // no color at all, done + if (mnColorSteps.empty()) return; - const basegfx::BColor maStart(mnColorSteps.front().getColor()); - const basegfx::BColor maEnd(mnColorSteps.back().getColor()); - const sal_uInt32 nSteps(basegfx::utils::calculateNumberOfSteps( - maGradientInfo.getRequestedSteps(), maStart, maEnd)); + // fill in return parameter rOuterColor before returning + rOuterColor = mnColorSteps.front().getColor(); - rOuterColor = maStart; - const double fStepSize(1.0 / nSteps); - B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; + // only one color, done + if (mnColorSteps.size() < 2) + return; - for(sal_uInt32 a(1); a < nSteps; a++) + // outer loop over ColorSteps, each is from cs_l to cs_r + for (auto cs_l(mnColorSteps.begin()), cs_r(cs_l + 1); cs_r != mnColorSteps.end(); cs_l++, cs_r++) { - const double fSize(1.0 - (fStepSize * a)); - aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::utils::createScaleB2DHomMatrix(fSize, fSize); - aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(nSteps - 1)); - rEntries.push_back(aB2DHomMatrixAndBColor); + // get colors & calculate steps + const basegfx::BColor aCStart(cs_l->getColor()); + const basegfx::BColor aCEnd(cs_r->getColor()); + const sal_uInt32 nSteps(basegfx::utils::calculateNumberOfSteps( + maGradientInfo.getRequestedSteps(), aCStart, aCEnd)); + + // get offsets & calculate StripeWidth + const double fOffsetStart(cs_l->getOffset()); + const double fOffsetEnd(cs_r->getOffset()); + const double fStripeWidth((fOffsetEnd - fOffsetStart) / nSteps); + + // get correct start for innner loop (see above) + const sal_uInt32 nStartInnerLoop(cs_l == mnColorSteps.begin() ? 1 : 0); + + for (sal_uInt32 innerLoop(nStartInnerLoop); innerLoop < nSteps; innerLoop++) + { + // calculate size/radius + const double fSize(1.0 - (fOffsetStart + (fStripeWidth * innerLoop))); + + // set and add at target + B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; + + aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::utils::createScaleB2DHomMatrix(fSize, fSize); + aB2DHomMatrixAndBColor.maBColor = interpolate(aCStart, aCEnd, double(innerLoop) / double(nSteps - 1)); + rEntries.push_back(aB2DHomMatrixAndBColor); + } } } void GeoTexSvxGradientRadial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const { - if(mnColorSteps.size() <= 1) + // no color at all, done + if (mnColorSteps.empty()) + return; + + // just single color, done + if (mnColorSteps.size() < 2) { rBColor = mnColorSteps.front().getColor(); + return; } - else - { - const double fScaler(basegfx::utils::getRadialGradientAlpha(rUV, maGradientInfo)); - const basegfx::BColor maStart(mnColorSteps.front().getColor()); - const basegfx::BColor maEnd(mnColorSteps.back().getColor()); - - rBColor = basegfx::interpolate(maStart, maEnd, fScaler); - } + // texture-back-transform X/Y -> t [0.0..1.0] and determine color + const double fScaler(basegfx::utils::getRadialGradientAlpha(rUV, maGradientInfo)); + rBColor = basegfx::utils::modifyBColor(mnColorSteps, fScaler, mnRequestedSteps); }
