Skip to content

Commit

Permalink
fix path exports svgs (fabricjs#4274)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored and rkrueger11 committed Sep 6, 2017
1 parent c46fa74 commit d267843
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/gradient.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,22 @@
toSVG: function(object) {
var coords = clone(this.coords, true), i, len,
markup, commonAttributes, colorStops = clone(this.colorStops, true),
needsSwap = coords.r1 > coords.r2;
needsSwap = coords.r1 > coords.r2,
offsetX = object.width / 2, offsetY = object.height / 2;
// colorStops must be sorted ascending
colorStops.sort(function(a, b) {
return a.offset - b.offset;
});

if (object.type === 'path') {
offsetX = 0;
offsetY = 0;
}
for (var prop in coords) {
if (prop === 'x1' || prop === 'x2') {
coords[prop] += this.offsetX - object.width / 2;
coords[prop] += this.offsetX - offsetX;
}
else if (prop === 'y1' || prop === 'y2') {
coords[prop] += this.offsetY - object.height / 2;
coords[prop] += this.offsetY - offsetY;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/shapes/ellipse.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@
* @return {String} svg representation of an instance
*/
toSVG: function(reviver) {
var markup = this._createBaseSVGMarkup(), x = 0, y = 0;
var markup = this._createBaseSVGMarkup();
markup.push(
'<ellipse ', this.getSvgId(),
'cx="', x, '" cy="', y, '" ',
'cx="0" cy="0" ',
'rx="', this.rx,
'" ry="', this.ry,
'" style="', this.getSvgStyles(),
Expand Down

0 comments on commit d267843

Please sign in to comment.