From 3e34a88e4cde504ca4708577315971c7b3119d55 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 11 Aug 2018 17:35:50 +0200 Subject: [PATCH 1/4] fixed pattern toSVG --- src/pattern.class.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pattern.class.js b/src/pattern.class.js index a5d99971c33..4103f56212f 100644 --- a/src/pattern.class.js +++ b/src/pattern.class.js @@ -133,9 +133,16 @@ patternImgSrc = ''; if (this.repeat === 'repeat-x' || this.repeat === 'no-repeat') { patternHeight = 1; + if (patternOffsetY) { + patternHeight += Math.abs(patternOffsetY); + } } if (this.repeat === 'repeat-y' || this.repeat === 'no-repeat') { patternWidth = 1; + if (patternOffsetX) { + patternWidth += Math.abs(patternOffsetX); + } + } if (patternSource.src) { patternImgSrc = patternSource.src; From 7614482a3581fe82332e4ac378023f33d37c06f8 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 11 Aug 2018 17:48:40 +0200 Subject: [PATCH 2/4] better patterns --- test/unit/pattern.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/pattern.js b/test/unit/pattern.js index e7585b588d8..b5224e0645b 100644 --- a/test/unit/pattern.js +++ b/test/unit/pattern.js @@ -147,7 +147,6 @@ assert.ok(typeof pattern.toSVG === 'function'); - // TODO: test toSVG }); QUnit.test('initPattern from object', function(assert) { From ace4ca051c6e09720869f4bd42dc678c96a0aa3b Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 11 Aug 2018 18:10:19 +0200 Subject: [PATCH 3/4] fixed pattern and added tests --- test/unit/pattern.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/unit/pattern.js b/test/unit/pattern.js index b5224e0645b..ce27fec3d87 100644 --- a/test/unit/pattern.js +++ b/test/unit/pattern.js @@ -143,10 +143,54 @@ }); QUnit.test('toSVG', function(assert) { + fabric.Object.__uid = 0; var pattern = createPattern(); + var rect = new fabric.Rect({ width: 500, height: 500 }); + var expectedSVG = '\n\n\n'; + assert.ok(typeof pattern.toSVG === 'function'); + assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match'); + }); + + QUnit.test('toSVG repeat-y', function(assert) { + fabric.Object.__uid = 0; + var pattern = createPattern(); + pattern.repeat = 'repeat-y'; + var rect = new fabric.Rect({ width: 500, height: 500 }); + var expectedSVG = '\n\n\n'; + assert.ok(typeof pattern.toSVG === 'function'); + assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match repeat-y'); + }); + + QUnit.test('toSVG repeat-x', function(assert) { + fabric.Object.__uid = 0; + var pattern = createPattern(); + pattern.repeat = 'repeat-x'; + var rect = new fabric.Rect({ width: 500, height: 500 }); + var expectedSVG = '\n\n\n'; + assert.ok(typeof pattern.toSVG === 'function'); + assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match repeat-x'); + }); + QUnit.test('toSVG no-repeat', function(assert) { + fabric.Object.__uid = 0; + var pattern = createPattern(); + pattern.repeat = 'no-repeat'; + var rect = new fabric.Rect({ width: 500, height: 500 }); + var expectedSVG = '\n\n\n'; assert.ok(typeof pattern.toSVG === 'function'); + assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match no-repeat'); + }); + QUnit.test('toSVG no-repeat offsetX and offsetY', function(assert) { + fabric.Object.__uid = 0; + var pattern = createPattern(); + pattern.repeat = 'no-repeat'; + pattern.offsetX = 50; + pattern.offsetY = -50; + var rect = new fabric.Rect({ width: 500, height: 500 }); + var expectedSVG = '\n\n\n'; + assert.ok(typeof pattern.toSVG === 'function'); + assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match no-repat offsetX and offsetY'); }); QUnit.test('initPattern from object', function(assert) { From c9d7279c0a5c1076ee3b7698ce211a326f2e48c4 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 11 Aug 2018 19:00:39 +0200 Subject: [PATCH 4/4] better src --- test/unit/pattern.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/pattern.js b/test/unit/pattern.js index ce27fec3d87..0dc6e6a8a0c 100644 --- a/test/unit/pattern.js +++ b/test/unit/pattern.js @@ -146,7 +146,7 @@ fabric.Object.__uid = 0; var pattern = createPattern(); var rect = new fabric.Rect({ width: 500, height: 500 }); - var expectedSVG = '\n\n\n'; + var expectedSVG = '\n\n\n'; assert.ok(typeof pattern.toSVG === 'function'); assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match'); }); @@ -156,7 +156,7 @@ var pattern = createPattern(); pattern.repeat = 'repeat-y'; var rect = new fabric.Rect({ width: 500, height: 500 }); - var expectedSVG = '\n\n\n'; + var expectedSVG = '\n\n\n'; assert.ok(typeof pattern.toSVG === 'function'); assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match repeat-y'); }); @@ -166,7 +166,7 @@ var pattern = createPattern(); pattern.repeat = 'repeat-x'; var rect = new fabric.Rect({ width: 500, height: 500 }); - var expectedSVG = '\n\n\n'; + var expectedSVG = '\n\n\n'; assert.ok(typeof pattern.toSVG === 'function'); assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match repeat-x'); }); @@ -176,7 +176,7 @@ var pattern = createPattern(); pattern.repeat = 'no-repeat'; var rect = new fabric.Rect({ width: 500, height: 500 }); - var expectedSVG = '\n\n\n'; + var expectedSVG = '\n\n\n'; assert.ok(typeof pattern.toSVG === 'function'); assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match no-repeat'); }); @@ -188,7 +188,7 @@ pattern.offsetX = 50; pattern.offsetY = -50; var rect = new fabric.Rect({ width: 500, height: 500 }); - var expectedSVG = '\n\n\n'; + var expectedSVG = '\n\n\n'; assert.ok(typeof pattern.toSVG === 'function'); assert.equal(pattern.toSVG(rect), expectedSVG, 'SVG match no-repat offsetX and offsetY'); });