From befb8603e2c31afe9ac8ca737469b78fd5432997 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Mon, 24 Oct 2016 20:46:14 +0200 Subject: [PATCH] gdiplus: Fix GdipCreateLineBrushFromRectWithAngle implementation. The patch fixes isAngleScalable==TRUE argument handling. It also fixes a mistake when width was used instead of height. Signed-off-by: Piotr Caban Signed-off-by: Vincent Povirk Signed-off-by: Alexandre Julliard --- dlls/gdiplus/brush.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/dlls/gdiplus/brush.c b/dlls/gdiplus/brush.c index ed29990b255..a1842768044 100644 --- a/dlls/gdiplus/brush.c +++ b/dlls/gdiplus/brush.c @@ -428,26 +428,43 @@ GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect { GpStatus stat; LinearGradientMode mode; - REAL width, height, exofs, eyofs; + REAL exofs, eyofs; REAL sin_angle, cos_angle, sin_cos_angle; TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable, wrap, line); - sin_angle = sinf(deg2rad(angle)); - cos_angle = cosf(deg2rad(angle)); - sin_cos_angle = sin_angle * cos_angle; + if (!rect || !rect->Width || !rect->Height) + return InvalidParameter; + + angle = fmodf(angle, 360); + if (angle < 0) + angle += 360; if (isAngleScalable) { - width = height = 1.0; + float add_angle = 0; + + while(angle >= 90) { + angle -= 180; + add_angle += M_PI; + } + + if (angle != 90 && angle != -90) + angle = atan((rect->Width / rect->Height) * tan(deg2rad(angle))); + else + angle = deg2rad(angle); + angle += add_angle; } else { - width = rect->Width; - height = rect->Height; + angle = deg2rad(angle); } + sin_angle = sinf(angle); + cos_angle = cosf(angle); + sin_cos_angle = sin_angle * cos_angle; + if (sin_cos_angle >= 0) mode = LinearGradientModeForwardDiagonal; else @@ -459,19 +476,13 @@ GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect { if (sin_cos_angle >= 0) { - exofs = width * sin_cos_angle + height * cos_angle * cos_angle; - eyofs = width * sin_angle * sin_angle + height * sin_cos_angle; + exofs = rect->Height * sin_cos_angle + rect->Width * cos_angle * cos_angle; + eyofs = rect->Height * sin_angle * sin_angle + rect->Width * sin_cos_angle; } else { - exofs = width * sin_angle * sin_angle + height * sin_cos_angle; - eyofs = -width * sin_cos_angle + height * sin_angle * sin_angle; - } - - if (isAngleScalable) - { - exofs = exofs * rect->Width; - eyofs = eyofs * rect->Height; + exofs = rect->Width * sin_angle * sin_angle + rect->Height * sin_cos_angle; + eyofs = -rect->Width * sin_cos_angle + rect->Height * sin_angle * sin_angle; } if (sin_angle >= 0) -- 2.11.4.GIT