Skip to content

Commit

Permalink
Merge pull request #2182 from asturur/fix-restore-stroke-gradient-fro…
Browse files Browse the repository at this point in the history
…m-object

Fix restore stroke gradient from object
  • Loading branch information
kangax committed May 10, 2015
2 parents 934fe47 + 1f84378 commit d3c446d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@
if (options.fill && options.fill.colorStops && !(options.fill instanceof fabric.Gradient)) {
this.set('fill', new fabric.Gradient(options.fill));
}
if (options.stroke && options.stroke.colorStops && !(options.stroke instanceof fabric.Gradient)) {
this.set('stroke', new fabric.Gradient(options.stroke));
}
},

/**
Expand Down Expand Up @@ -1111,7 +1114,7 @@
return;
}

if (!this.shadow.affectStroke) {
if (this.shadow && !this.shadow.affectStroke) {
this._removeShadow(ctx);
}

Expand Down
7 changes: 7 additions & 0 deletions test/unit/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
var rect = fabric.Rect.fromObject(REFERENCE_RECT);
ok(rect instanceof fabric.Rect);
deepEqual(rect.toObject(), REFERENCE_RECT);

var expectedObject = fabric.util.object.extend({ }, REFERENCE_RECT);
expectedObject.fill = {"type":"linear","coords":{"x1":0,"y1":0,"x2":200,"y2":0},"colorStops":[{"offset":"0","color":"rgb(255,0,0)","opacity":1},{"offset":"1","color":"rgb(0,0,255)","opacity":1}],"offsetX":0,"offsetY":0};
expectedObject.stroke = {"type":"linear","coords":{"x1":0,"y1":0,"x2":200,"y2":0},"colorStops":[{"offset":"0","color":"rgb(255,0,0)","opacity":1},{"offset":"1","color":"rgb(0,0,255)","opacity":1}],"offsetX":0,"offsetY":0};
rect = fabric.Rect.fromObject(expectedObject);
ok(rect.fill instanceof fabric.Gradient);
ok(rect.stroke instanceof fabric.Gradient);
});

test('fabric.Rect.fromElement', function() {
Expand Down

0 comments on commit d3c446d

Please sign in to comment.