From e15743747631ae284621bc917cdcd2c86e682f6c Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Wed, 13 Aug 2014 11:40:20 +0200 Subject: [PATCH 1/2] Update parser.js Delete function from parser. moved in element parser. --- src/parser.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/parser.js b/src/parser.js index dd3717a8..f8e84fd2 100644 --- a/src/parser.js +++ b/src/parser.js @@ -632,27 +632,6 @@ extend(fabric, { - /** - * Initializes gradients on instances, according to gradients parsed from a document - * @param {Array} instances - */ - resolveGradients: function(instances) { - for (var i = instances.length; i--; ) { - var instanceFillValue = instances[i].get('fill'); - - if (!(/^url\(/).test(instanceFillValue)) { - continue; - } - - var gradientId = instanceFillValue.slice(5, instanceFillValue.length - 1); - - if (fabric.gradientDefs[gradientId]) { - instances[i].set('fill', - fabric.Gradient.fromElement(fabric.gradientDefs[gradientId], instances[i])); - } - } - }, - /** * Parses an SVG document, returning all of the gradient declarations found in it * @static From 70b879b8b9405edb45998b2506c0714f011156ea Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Wed, 13 Aug 2014 11:46:39 +0200 Subject: [PATCH 2/2] Update elements_parser.js Added mono-object resolveGradient function. to be called befor reviver function. --- src/elements_parser.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/elements_parser.js b/src/elements_parser.js index 170849ab..35637097 100644 --- a/src/elements_parser.js +++ b/src/elements_parser.js @@ -43,6 +43,7 @@ fabric.ElementsParser.prototype._createObject = function(klass, el, index) { } else { var obj = klass.fromElement(el, this.options); + this.resolveGradient(obj); this.reviver && this.reviver(el, obj); this.instances[index] = obj; this.checkIfDone(); @@ -52,18 +53,31 @@ fabric.ElementsParser.prototype._createObject = function(klass, el, index) { fabric.ElementsParser.prototype.createCallback = function(index, el) { var _this = this; return function(obj) { + _this.resolveGradient(obj); _this.reviver && _this.reviver(el, obj); _this.instances[index] = obj; _this.checkIfDone(); }; }; +fabric.ElementsParser.prototype.resolveGradient = function(obj) { + + var instanceFillValue = obj.get('fill'); + if (!(/^url\(/).test(instanceFillValue)) { + return; + } + var gradientId = instanceFillValue.slice(5, instanceFillValue.length - 1); + if (fabric.gradientDefs[gradientId]) { + obj.set('fill', + fabric.Gradient.fromElement(fabric.gradientDefs[gradientId], obj)); + } +}; + fabric.ElementsParser.prototype.checkIfDone = function() { if (--this.numElements === 0) { this.instances = this.instances.filter(function(el) { return el != null; }); - fabric.resolveGradients(this.instances); this.callback(this.instances); } };