From 492a7693c52e8ca770c8a51fc6d6f1bf84aa41d1 Mon Sep 17 00:00:00 2001 From: KJ Tsanaktsidis Date: Thu, 26 Feb 2015 13:39:45 +1100 Subject: [PATCH] Don't destroy the selection group when doing toSVG toSVG now mirrors the behaviour of toJSON and does not destroy the active selection group when serialising. Instead, the effect of the group is simulated on a clone of the object and this is what gets serialised. --- src/static_canvas.class.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/static_canvas.class.js b/src/static_canvas.class.js index e251d4fc..a6a2a3bb 100644 --- a/src/static_canvas.class.js +++ b/src/static_canvas.class.js @@ -1278,18 +1278,17 @@ * @private */ _setSVGObjects: function(markup, reviver) { - var activeGroup = this.getActiveGroup(); - if (activeGroup) { - this.discardActiveGroup(); - } + var selectionGroup = this.getActiveGroup(); for (var i = 0, objects = this.getObjects(), len = objects.length; i < len; i++) { - markup.push(objects[i].toSVG(reviver)); - } - if (activeGroup) { - this.setActiveGroup(new fabric.Group(activeGroup.getObjects())); - activeGroup.forEachObject(function(o) { - o.set('active', true); - }); + if (selectionGroup && objects[i].group === selectionGroup) { + //If the object is in a selection group, simulate what would happen to that + //object when the group is deselected + var objectClone = objects[i].clone(); + selectionGroup.realizeTransform(objectClone); + markup.push(objectClone.toSVG(reviver)); + } else { + markup.push(objects[i].toSVG(reviver)); + } } },