From 280746592c2fe3b864c07daae3a461cc1ae033c6 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Tue, 22 Dec 2015 01:29:11 +0100 Subject: [PATCH 1/2] check for default color property if attribute is not present --- src/parser.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/parser.js b/src/parser.js index adddcc5ecec..7f53c763a7b 100644 --- a/src/parser.js +++ b/src/parser.js @@ -106,10 +106,17 @@ function _setStrokeFillOpacity(attributes) { for (var attr in colorAttributes) { - if (!attributes[attr] || typeof attributes[colorAttributes[attr]] === 'undefined') { + if (typeof attributes[colorAttributes[attr]] === 'undefined') { continue; } + if (!attributes[attr]) { + if (!fabric.Object.prototype[attr]) { + continue; + } + attributes[attr] = fabric.Object.prototype[attr]; + } + if (attributes[attr].indexOf('url(') === 0) { continue; } From 127df5f000489d6b4e1d37c88d9b1d28f370762d Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Tue, 22 Dec 2015 01:34:45 +0100 Subject: [PATCH 2/2] Update parser.js --- test/unit/parser.js | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/unit/parser.js b/test/unit/parser.js index 48e0c946441..6ae176d88f8 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -426,6 +426,52 @@ } }); + test('fill-opacity attribute with fill attribute', function() { + var el = fabric.document.createElement(rect); + var opacityValue = Math.random().toFixed(2); + + el.setAttribute('fill-opacity', opacityValue); + el.setAttribute('fill', '#FF0000'); + var obj = fabric.Rect.fromElement(el); + + equal(obj.fill, 'rgba(255,0,0,' + parseFloat(opacityValue) * 255 + ')', + 'opacity should be parsed correctly from "opacity" attribute of ' + tagNames[i] + ' element'); + }); + + test('fill-opacity attribute without fill attribute', function() { + var el = fabric.document.createElement(rect); + var opacityValue = Math.random().toFixed(2); + + el.setAttribute('fill-opacity', opacityValue); + var obj = fabric.Rect.fromElement(el); + + equal(obj.fill, 'rgba(0,0,0,' + parseFloat(opacityValue) * 255 + ')', + 'opacity should be parsed correctly from "opacity" attribute of ' + tagNames[i] + ' element'); + }); + + test('stroke-opacity attribute with fill attribute', function() { + var el = fabric.document.createElement(rect); + var opacityValue = Math.random().toFixed(2); + + el.setAttribute('fill-opacity', opacityValue); + el.setAttribute('fill', '#FF0000'); + var obj = fabric.Rect.fromElement(el); + + equal(obj.fill, 'rgba(255,0,0,' + parseFloat(opacityValue) * 255 + ')', + 'opacity should be parsed correctly from "opacity" attribute of ' + tagNames[i] + ' element'); + }); + + test('stroke-opacity attribute without fill attribute', function() { + var el = fabric.document.createElement(rect); + var opacityValue = Math.random().toFixed(2); + + el.setAttribute('fill-opacity', opacityValue); + var obj = fabric.Rect.fromElement(el); + + equal(obj.fill, 'rgba(0,0,0,' + parseFloat(opacityValue) * 255 + ')', + 'opacity should be parsed correctly from "opacity" attribute of ' + tagNames[i] + ' element'); + }); + test('getCssRule', function() { ok(fabric.getCSSRules);