Skip to content

Commit fb74089

Browse files
committed
Properly render gradients when strokeScaling=false
1 parent b081fd7 commit fb74089

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

dist/paper-core.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/paper-core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../src/load.js

dist/paper-full.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/paper-full.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../src/load.js

src/item/Item.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,16 +4293,16 @@ new function() { // Injection scope for hit-test functions shared with project
42934293
* Not defined in Path as it is required by other classes too,
42944294
* e.g. PointText.
42954295
*/
4296-
_setStyles: function(ctx, param, viewMatrix) {
4296+
_setStyles: function(ctx, param, viewMatrix, strokeMatrix) {
42974297
// We can access internal properties since we're only using this on
42984298
// items without children, where styles would be merged.
42994299
var style = this._style,
43004300
matrix = this._matrix;
43014301
if (style.hasFill()) {
4302-
ctx.fillStyle = style.getFillColor().toCanvasStyle(ctx, matrix);
4302+
ctx.fillStyle = style.getFillColor().toCanvasStyle(ctx, matrix, strokeMatrix);
43034303
}
43044304
if (style.hasStroke()) {
4305-
ctx.strokeStyle = style.getStrokeColor().toCanvasStyle(ctx, matrix);
4305+
ctx.strokeStyle = style.getStrokeColor().toCanvasStyle(ctx, matrix, strokeMatrix);
43064306
ctx.lineWidth = style.getStrokeWidth();
43074307
var strokeJoin = style.getStrokeJoin(),
43084308
strokeCap = style.getStrokeCap(),

src/item/Shape.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ var Shape = Item.extend(/** @lends Shape# */{
261261
ctx.closePath();
262262
}
263263
if (!dontPaint && (hasFill || hasStroke)) {
264-
this._setStyles(ctx, param, viewMatrix);
264+
this._setStyles(ctx, param, viewMatrix, strokeMatrix);
265265
if (hasFill) {
266266
ctx.fill(style.getFillRule());
267267
ctx.shadowColor = 'rgba(0,0,0,0)';

src/path/CompoundPath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
311311
children[i].draw(ctx, param, strokeMatrix);
312312

313313
if (!param.clip) {
314-
this._setStyles(ctx, param, viewMatrix);
314+
this._setStyles(ctx, param, viewMatrix, strokeMatrix);
315315
var style = this._style;
316316
if (style.hasFill()) {
317317
ctx.fill(style.getFillRule());

src/path/Path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ new function() { // Scope for drawing
23182318
if (!dontPaint && (hasFill || hasStroke)) {
23192319
// If the path is part of a compound path or doesn't have a fill
23202320
// or stroke, there is no need to continue.
2321-
this._setStyles(ctx, param, viewMatrix);
2321+
this._setStyles(ctx, param, viewMatrix, strokeMatrix);
23222322
if (hasFill) {
23232323
ctx.fill(style.getFillRule());
23242324
// If shadowColor is defined, clear it after fill, so it

src/style/Color.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,11 @@ var Color = Base.extend(new function() {
899899
+ components.join(',') + ')';
900900
},
901901

902-
toCanvasStyle: function(ctx, matrix) {
903-
if (this._canvasStyle)
902+
toCanvasStyle: function(ctx, matrix, strokeMatrix) {
903+
// strokeMatrix can change without triggering _changed here, so we
904+
// can't use a cached gradient here.
905+
var strokeMayChange = this._type === 'gradient' && strokeMatrix;
906+
if (this._canvasStyle && !strokeMayChange)
904907
return this._canvasStyle;
905908
// Normal colors are simply represented by their CSS string.
906909
if (this._type !== 'gradient')
@@ -923,6 +926,12 @@ var Color = Base.extend(new function() {
923926
if (highlight)
924927
highlight = inverse._transformPoint(highlight);
925928
}
929+
if (strokeMatrix) {
930+
origin = strokeMatrix._transformPoint(origin);
931+
destination = strokeMatrix._transformPoint(destination);
932+
if (highlight)
933+
highlight = strokeMatrix._transformPoint(highlight);
934+
}
926935
if (gradient._radial) {
927936
var radius = destination.getDistance(origin);
928937
if (highlight) {
@@ -948,7 +957,12 @@ var Color = Base.extend(new function() {
948957
offset == null ? i / (l - 1) : offset,
949958
stop._color.toCanvasStyle());
950959
}
951-
return this._canvasStyle = canvasGradient;
960+
// Don't store gradients that may change in the cache.
961+
// If we cached a gradient that was transformed by strokeMatrix
962+
// then set strokeScaling to false, then the transformed gradient
963+
// could get "stuck" in the cache.
964+
if (!strokeMayChange) this._canvasStyle = canvasGradient;
965+
return canvasGradient;
952966
},
953967

954968
/**

0 commit comments

Comments
 (0)