Skip to content

Commit

Permalink
fix pattern to svg (#3601)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Jan 2, 2017
1 parent d5220fe commit 0c52336
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/pattern.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@
*/
toSVG: function(object) {
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(),
patternWidth = patternSource.width / object.width,
patternHeight = patternSource.height / object.height,
patternOffsetX = this.offsetX / object.width,
patternOffsetY = this.offsetY / object.height,
patternImgSrc = '';
if (this.repeat === 'repeat-x' || this.repeat === 'no-repeat') {
patternHeight = 1;
Expand Down
25 changes: 14 additions & 11 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1204,9 +1204,6 @@
'version="1.1" ',
'width="', width, '" ',
'height="', height, '" ',
(this.backgroundColor && !this.backgroundColor.toLive
? 'style="background-color: ' + this.backgroundColor + '" '
: null),
viewBox,
'xml:space="preserve">\n',
'<desc>Created with Fabric.js ', fabric.version, '</desc>\n',
Expand Down Expand Up @@ -1324,22 +1321,28 @@
* @private
*/
_setSVGBgOverlayColor: function(markup, property) {
if (this[property] && this[property].source) {
var filler = this[property];
if (!filler) {
return;
}
if (filler.toLive) {
var repeat = filler.repeat;
markup.push(
'<rect x="', this[property].offsetX, '" y="', this[property].offsetY, '" ',
'<rect transform="translate(', this.width / 2, ',', this.height / 2, ')"',
' x="', filler.offsetX - this.width / 2, '" y="', filler.offsetY - this.height / 2, '" ',
'width="',
(this[property].repeat === 'repeat-y' || this[property].repeat === 'no-repeat'
? this[property].source.width
(repeat === 'repeat-y' || repeat === 'no-repeat'
? filler.source.width
: this.width),
'" height="',
(this[property].repeat === 'repeat-x' || this[property].repeat === 'no-repeat'
? this[property].source.height
(repeat === 'repeat-x' || repeat === 'no-repeat'
? filler.source.height
: this.height),
'" fill="url(#' + property.id + ')"',
'" fill="url(#SVGID_' + filler.id + ')"',
'></rect>\n'
);
}
else if (this[property] && property === 'overlayColor') {
else {
markup.push(
'<rect x="0" y="0" ',
'width="', this.width,
Expand Down

0 comments on commit 0c52336

Please sign in to comment.