summaryrefslogtreecommitdiff
path: root/canvas/source/vcl
diff options
context:
space:
mode:
authorPatrick Luby <plubius@neooffice.org>2023-08-15 20:00:57 -0400
committerPatrick Luby <plubius@neooffice.org>2023-08-16 13:47:31 +0200
commitf6cae6f1b661baafe8a1ac4655765ec49d56317d (patch)
treea4964619f83c1af224171b30df53c37d10264508 /canvas/source/vcl
parentd9f2193b72f6bd9e5f551c12331a5e547c3ac557 (diff)
tdf#144073 and tdf#147645: use bounds and angle for gradient
Passing an expanded, rotated polygon noticeably modifies the drawing of the gradient in a slideshow due to moving of the starting and ending colors far off the edges of the drawing surface. So try another way and set the angle of the gradient and draw only the unadjusted bounds. Change-Id: I95441dfa3215396d5bc7edfa9f985335480b37de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155729 Tested-by: Jenkins Reviewed-by: Patrick Luby <plubius@neooffice.org>
Diffstat (limited to 'canvas/source/vcl')
-rw-r--r--canvas/source/vcl/canvashelper_texturefill.cxx54
1 files changed, 20 insertions, 34 deletions
diff --git a/canvas/source/vcl/canvashelper_texturefill.cxx b/canvas/source/vcl/canvashelper_texturefill.cxx
index 13778b990b61..5e9399f56841 100644
--- a/canvas/source/vcl/canvashelper_texturefill.cxx
+++ b/canvas/source/vcl/canvashelper_texturefill.cxx
@@ -154,24 +154,17 @@ namespace vclcanvas
// 2 colors and 2 stops (at 0 and 1) is a linear gradient:
if( rColors.size() == 2 && rValues.maStops.size() == 2 && rValues.maStops[0] == 0 && rValues.maStops[1] == 1)
{
- // tdf#144073: Note that the code below adjusts the gradient area this way.
- // No, I have no idea why.
- aLeftTop -= 2.0*nDiagonalLength*aDirection;
- aLeftBottom -= 2.0*nDiagonalLength*aDirection;
- aRightTop += 2.0*nDiagonalLength*aDirection;
- aRightBottom += 2.0*nDiagonalLength*aDirection;
+ // tdf#144073 and tdf#147645: use bounds and angle for gradient
+ // Passing an expanded, rotated polygon noticeably modifies the
+ // drawing of the gradient in a slideshow due to moving of the
+ // starting and ending colors far off the edges of the drawing
+ // surface. So try another way and set the angle of the
+ // gradient and draw only the unadjusted bounds.
Gradient vclGradient( css::awt::GradientStyle_LINEAR, rColors[ 0 ], rColors[ 1 ] );
- ::tools::Polygon aTempPoly( static_cast<sal_uInt16>(5) );
- aTempPoly[0] = ::Point( ::basegfx::fround( aLeftTop.getX() ),
- ::basegfx::fround( aLeftTop.getY() ) );
- aTempPoly[1] = ::Point( ::basegfx::fround( aRightTop.getX() ),
- ::basegfx::fround( aRightTop.getY() ) );
- aTempPoly[2] = ::Point( ::basegfx::fround( aRightBottom.getX() ),
- ::basegfx::fround( aRightBottom.getY() ) );
- aTempPoly[3] = ::Point( ::basegfx::fround( aLeftBottom.getX() ),
- ::basegfx::fround( aLeftBottom.getY() ) );
- aTempPoly[4] = aTempPoly[0];
- rOutDev.DrawGradient( ::tools::PolyPolygon(aTempPoly), vclGradient );
+ double fRotate = atan2( aDirection.getY(), aDirection.getX() );
+ const double nAngleInTenthOfDegrees = 3600.0 - basegfx::rad2deg<10>( fRotate ) + 900.0;
+ vclGradient.SetAngle( Degree10( ::basegfx::fround( nAngleInTenthOfDegrees ) ) );
+ rOutDev.DrawGradient( rBounds, vclGradient );
return;
}
// 3 colors with first and last being equal and 3 stops (at 0, 0.5 and 1) is an axial gradient:
@@ -179,24 +172,17 @@ namespace vclcanvas
&& rValues.maStops.size() == 3 && rValues.maStops[0] == 0
&& rValues.maStops[1] == 0.5 && rValues.maStops[2] == 1)
{
- // tdf#144073: Note that the code below adjusts the gradient area this way.
- // No, I have no idea why.
- aLeftTop -= 2.0*nDiagonalLength*aDirection;
- aLeftBottom -= 2.0*nDiagonalLength*aDirection;
- aRightTop += 2.0*nDiagonalLength*aDirection;
- aRightBottom += 2.0*nDiagonalLength*aDirection;
+ // tdf#144073 and tdf#147645: use bounds and angle for gradient
+ // Passing an expanded, rotated polygon noticeably modifies the
+ // drawing of the gradient in a slideshow due to moving of the
+ // starting and ending colors far off the edges of the drawing
+ // surface. So try another way and set the angle of the
+ // gradient and draw only the unadjusted bounds.
Gradient vclGradient( css::awt::GradientStyle_AXIAL, rColors[ 1 ], rColors[ 0 ] );
- ::tools::Polygon aTempPoly( static_cast<sal_uInt16>(5) );
- aTempPoly[0] = ::Point( ::basegfx::fround( aLeftTop.getX() ),
- ::basegfx::fround( aLeftTop.getY() ) );
- aTempPoly[1] = ::Point( ::basegfx::fround( aRightTop.getX() ),
- ::basegfx::fround( aRightTop.getY() ) );
- aTempPoly[2] = ::Point( ::basegfx::fround( aRightBottom.getX() ),
- ::basegfx::fround( aRightBottom.getY() ) );
- aTempPoly[3] = ::Point( ::basegfx::fround( aLeftBottom.getX() ),
- ::basegfx::fround( aLeftBottom.getY() ) );
- aTempPoly[4] = aTempPoly[0];
- rOutDev.DrawGradient( ::tools::PolyPolygon(aTempPoly), vclGradient );
+ double fRotate = atan2( aDirection.getY(), aDirection.getX() );
+ const double nAngleInTenthOfDegrees = 3600.0 - basegfx::rad2deg<10>( fRotate ) + 900.0;
+ vclGradient.SetAngle( Degree10( ::basegfx::fround( nAngleInTenthOfDegrees ) ) );
+ rOutDev.DrawGradient( rBounds, vclGradient );
return;
}