From de053ec42922b6060e3031d6441724d81495e10f Mon Sep 17 00:00:00 2001 From: Durga Madhab Date: Fri, 1 Jun 2018 14:18:06 +0530 Subject: [PATCH 1/6] fabric.Color.reRGBa regex ignore case ignore case for rgba --- src/color.class.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/color.class.js b/src/color.class.js index 8f954e08cbe..775a4251a57 100644 --- a/src/color.class.js +++ b/src/color.class.js @@ -280,7 +280,7 @@ * @memberOf fabric.Color */ // eslint-disable-next-line max-len - fabric.Color.reRGBa = /^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/; + fabric.Color.reRGBa = /^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/i; /** * Regex matching color in HSL or HSLA formats (ex: hsl(200, 80%, 10%), hsla(300, 50%, 80%, 0.5), hsla( 300 , 50% , 80% , 0.5 )) From 486ce91d2f5aada98dc247b79681c3cfdabe0b7a Mon Sep 17 00:00:00 2001 From: Durga Madhab Date: Fri, 1 Jun 2018 14:23:57 +0530 Subject: [PATCH 2/6] fabric.Color.reHSLa ignore case ignore case for hsla --- src/color.class.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/color.class.js b/src/color.class.js index 775a4251a57..bf9dffd30b5 100644 --- a/src/color.class.js +++ b/src/color.class.js @@ -288,7 +288,7 @@ * @field * @memberOf fabric.Color */ - fabric.Color.reHSLa = /^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/; + fabric.Color.reHSLa = /^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/i; /** * Regex matching color in HEX format (ex: #FF5544CC, #FF5555, 010155, aff) From d754e27821b83af27cb5a52a83ebfd6330ac8468 Mon Sep 17 00:00:00 2001 From: Durga Madhab Date: Sat, 2 Jun 2018 18:27:49 +0530 Subject: [PATCH 3/6] test case RGBA / HSLA added test case for RGB/RGBA and HSL/HSLA (uppercase) --- test/unit/color.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/test/unit/color.js b/test/unit/color.js index 4c0157c54e8..145b8c35fb2 100644 --- a/test/unit/color.js +++ b/test/unit/color.js @@ -88,8 +88,8 @@ var oColor = new fabric.Color('ffffffff'); assert.ok(typeof oColor.toHexa === 'function'); assert.equal(oColor.toHexa(), 'FFFFFFFF'); - oColor.setSource([255,255,255,0.8]); - assert.equal(oColor.toHexa(), 'FFFFFFCC'); + oColor.setSource([255,255,255,0.1]); + assert.equal(oColor.toHexa(), 'FFFFFF1A'); }); QUnit.test('getAlpha', function(assert) { @@ -173,6 +173,25 @@ assert.equal(oColor.toHex(), 'FFFFFF'); }); + QUnit.test('fromRgb (uppercase)', function(assert) { + assert.ok(typeof fabric.Color.fromRgb === 'function'); + var originalRgb = 'RGB(255,255,255)'; + var oColor = fabric.Color.fromRgb(originalRgb); + assert.ok(oColor); + assert.ok(oColor instanceof fabric.Color); + assert.equal(oColor.toHex(), 'FFFFFF'); + }); + + QUnit.test('fromRgba (uppercase)', function(assert) { + assert.ok(typeof fabric.Color.fromRgba === 'function'); + var originalRgba = 'RGBA(255,255,255,0.5)'; + var oColor = fabric.Color.fromRgba(originalRgba); + assert.ok(oColor); + assert.ok(oColor instanceof fabric.Color); + assert.equal(oColor.toHex(), 'FFFFFF'); + assert.equal(oColor.getAlpha(), 0.5, 'alpha should be set properly'); + }); + QUnit.test('fromRgba', function(assert) { assert.ok(typeof fabric.Color.fromRgba === 'function'); var originalRgba = 'rgba(255,255,255,0.5)'; @@ -253,6 +272,27 @@ assert.equal(oColor.toHex(), '180637'); }); + QUnit.test('fromHsl (uppercase)', function(assert) { + assert.ok(typeof fabric.Color.fromHsl === 'function'); + var originalHsl = 'HSL(270,50%,40%)'; + var oColor = fabric.Color.fromHsl(originalHsl); + assert.ok(oColor); + assert.ok(oColor instanceof fabric.Color); + assert.equal(oColor.toHex(), '663399'); + assert.equal(oColor.toRgba(), 'rgba(102,51,153,1)'); + }); + + QUnit.test('fromHsla (uppercase)', function(assert) { + assert.ok(typeof fabric.Color.fromHsla === 'function'); + var originalHsla = 'HSLA(108,50%,50%,0.7)'; + var oColor = fabric.Color.fromHsla(originalHsla); + assert.ok(oColor); + assert.ok(oColor instanceof fabric.Color); + assert.equal(oColor.toHex(), '59BF40'); + assert.equal(oColor.toRgba(), 'rgba(89,191,64,0.7)'); + assert.equal(oColor.getAlpha(), 0.7, 'alpha should be set properly'); + }); + QUnit.test('fromHsla', function(assert) { assert.ok(typeof fabric.Color.fromHsla === 'function'); var originalHsla = 'hsla(262,80%,12%,0.2)'; From 1a191e3ae4630bf67954e9f3f14e923f8f015f87 Mon Sep 17 00:00:00 2001 From: Durga Madhab Date: Sat, 2 Jun 2018 18:46:40 +0530 Subject: [PATCH 4/6] Update color.js --- test/unit/color.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/color.js b/test/unit/color.js index 145b8c35fb2..a03e9c78fcd 100644 --- a/test/unit/color.js +++ b/test/unit/color.js @@ -88,8 +88,8 @@ var oColor = new fabric.Color('ffffffff'); assert.ok(typeof oColor.toHexa === 'function'); assert.equal(oColor.toHexa(), 'FFFFFFFF'); - oColor.setSource([255,255,255,0.1]); - assert.equal(oColor.toHexa(), 'FFFFFF1A'); + oColor.setSource([255,255,255,0.8]); + assert.equal(oColor.toHexa(), 'FFFFFFCC'); }); QUnit.test('getAlpha', function(assert) { From 250dfae4ed02746f35220fbc3102fa09f1ceea2e Mon Sep 17 00:00:00 2001 From: Durga Date: Wed, 27 Jun 2018 17:46:40 +0530 Subject: [PATCH 5/6] toSVG() excludeFromExport for backgroundImage and overlayImage --- src/static_canvas.class.js | 2 +- test/unit/canvas_static.js | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/static_canvas.class.js b/src/static_canvas.class.js index 68f75bb9b66..1eb459d2c7d 100644 --- a/src/static_canvas.class.js +++ b/src/static_canvas.class.js @@ -1400,7 +1400,7 @@ * @private */ _setSVGBgOverlayImage: function(markup, property, reviver) { - if (this[property] && this[property].toSVG) { + if (this[property] && !this[property].excludeFromExport && this[property].toSVG) { markup.push(this[property].toSVG(reviver)); } }, diff --git a/test/unit/canvas_static.js b/test/unit/canvas_static.js index d55895da5bd..43213026dab 100644 --- a/test/unit/canvas_static.js +++ b/test/unit/canvas_static.js @@ -866,6 +866,48 @@ canvas.renderOnAddRemove = true; }); + QUnit.test('toSVG with exclude from export background', function(assert) { + assert.ok(typeof canvas.toSVG === 'function'); + canvas.clear(); + + var circle = new fabric.Circle({excludeFromExport: true}), + rect = new fabric.Rect(), + imageBG = new fabric.Image({width: 0, height: 0}), + imageOL = new fabric.Image({width: 0, height: 0}); + + canvas.renderOnAddRemove = false; + canvas.add(circle, rect); + + canvas.setBackgroundImage(imageBG); + canvas.setOverlayImage(imageOL); + + var reviverCount = 0, + len = canvas.size(); + + function reviver(svg) { + reviverCount++; + return svg; + } + + canvas.toSVG(null, reviver); + assert.equal(reviverCount, len + 1 , 'reviver should include backgroundImage and overlayImage'); + + reviverCount = 0; + + canvas.setBackgroundImage(imageBG,canvas.renderAll.bind(canvas),{ + excludeFromExport: true + }); + canvas.setOverlayImage(imageOL,canvas.renderAll.bind(canvas),{ + excludeFromExport: true + }); + canvas.toSVG(null, reviver); + assert.equal(reviverCount, len - 1 , 'reviver should not include objects with excludeFromExport and backgroundImage'); + + canvas.setBackgroundImage(null); + canvas.setOverlayImage(null); + canvas.renderOnAddRemove = true; + }); + QUnit.test('toJSON', function(assert) { assert.ok(typeof canvas.toJSON === 'function'); assert.equal(JSON.stringify(canvas.toJSON()), '{"version":"' + fabric.version + '","objects":[]}'); From acca8a0c852e433167f2e554bf9ca66c4d6a1cae Mon Sep 17 00:00:00 2001 From: Durga Date: Wed, 27 Jun 2018 17:46:49 +0530 Subject: [PATCH 6/6] toSVG() excludeFromExport for backgroundImage and overlayImage --- test/unit/canvas_static.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/canvas_static.js b/test/unit/canvas_static.js index 43213026dab..c78c0e02518 100644 --- a/test/unit/canvas_static.js +++ b/test/unit/canvas_static.js @@ -901,7 +901,7 @@ excludeFromExport: true }); canvas.toSVG(null, reviver); - assert.equal(reviverCount, len - 1 , 'reviver should not include objects with excludeFromExport and backgroundImage'); + assert.equal(reviverCount, len - 1 , 'reviver should not include objects with excludeFromExport and backgroundImage & overlayImage'); canvas.setBackgroundImage(null); canvas.setOverlayImage(null);