Update pattern.class.js

Added hack to support repeat and offset to svg export.
This commit is contained in:
Andrea Bogazzi 2014-10-26 18:49:00 +01:00
parent cac97b0a9b
commit e3f479ceb9

View file

@ -104,8 +104,15 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
var patternSource = typeof this.source === 'function' ? this.source() : this.source,
patternWidth = patternSource.width / object.getWidth(),
patternHeight = patternSource.height / object.getHeight(),
patternOffsetX = this.offsetX / object.getWidth(),
patternOffsetY = this.offsetY / object.getHeight(),
patternImgSrc = '';
if (this.repeat === 'repeat-x' || this.repeat === 'no-repeat') {
patternHeight = 1;
}
if (this.repeat === 'repeat-y' || this.repeat === 'no-repeat') {
patternWidth = 1;
}
if (patternSource.src) {
patternImgSrc = patternSource.src;
}
@ -114,16 +121,16 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
}
return '<pattern id="SVGID_' + this.id +
'" x="' + this.offsetX +
'" y="' + this.offsetY +
'" x="' + patternOffsetX +
'" y="' + patternOffsetY +
'" width="' + patternWidth +
'" height="' + patternHeight + '">' +
'" height="' + patternHeight + '">\n' +
'<image x="0" y="0"' +
' width="' + patternSource.width +
'" height="' + patternSource.height +
'" xlink:href="' + patternImgSrc +
'"></image>' +
'</pattern>';
'"></image>\n' +
'</pattern>\n';
},
/* _TO_SVG_END_ */