From de4e28b5ccb8f1ec9d13dfac7836b802ed41733a Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 20 May 2013 19:07:39 -0700 Subject: [PATCH] Fixed bug with linear gradient when drawing it without CPGradient --- AppKit/CPGradient.j | 4 ++++ AppKit/CoreGraphics/CGContextCanvas.j | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/AppKit/CPGradient.j b/AppKit/CPGradient.j index dfa7a3437..0c42d0176 100644 --- a/AppKit/CPGradient.j +++ b/AppKit/CPGradient.j @@ -70,6 +70,10 @@ CPGradientDrawsAfterEndingLocation = kCGGradientDrawsAfterEndLocation; { if (self = [super init]) { + // We reverse the location because we reverse the colors in CGContextDrawLinearGradient + // This is needed to get the same behavior as Cocoa when drawing a CGContextDrawLinearGradient without the object CPGradient + someLocations.reverse(); + var cgColors = [], count = [someColors count], colorSpace = [aColorSpace CGColorSpace] || CGColorSpaceCreateDeviceRGB; diff --git a/AppKit/CoreGraphics/CGContextCanvas.j b/AppKit/CoreGraphics/CGContextCanvas.j index e69e0161c..e531ca463 100644 --- a/AppKit/CoreGraphics/CGContextCanvas.j +++ b/AppKit/CoreGraphics/CGContextCanvas.j @@ -594,9 +594,8 @@ function to_string(aColor) function CGContextDrawLinearGradient(aContext, aGradient, aStartPoint, anEndPoint, options) { - var colors = aGradient.colors, + var colors = aGradient.colors.slice(0).reverse(), count = colors.length, - linearGradient = aContext.createLinearGradient(aStartPoint.x, aStartPoint.y, anEndPoint.x, anEndPoint.y); while (count--) @@ -611,7 +610,6 @@ function CGContextDrawRadialGradient(aContext, aGradient, aStartCenter, aStartRa { var colors = aGradient.colors, count = colors.length, - linearGradient = aContext.createRadialGradient(aStartCenter.x, aStartCenter.y, aStartRadius, anEndCenter.x, anEndCenter.y, anEndRadius); while (count--)