Replaced removeUnusedGrads with a more generic removeUnusedDefElems to remove unused filters, markers, etc
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1554 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
f78cd75984
commit
122bb4fc22
|
@ -1526,41 +1526,41 @@ function BatchCommand(text) {
|
||||||
};
|
};
|
||||||
var getUrlFromAttr = this.getUrlFromAttr;
|
var getUrlFromAttr = this.getUrlFromAttr;
|
||||||
|
|
||||||
var removeUnusedGrads = function() {
|
var removeUnusedDefElems = function() {
|
||||||
var defs = svgcontent.getElementsByTagNameNS(svgns, "defs");
|
var defs = svgcontent.getElementsByTagNameNS(svgns, "defs");
|
||||||
if(!defs || !defs.length) return 0;
|
if(!defs || !defs.length) return 0;
|
||||||
|
|
||||||
var all_els = svgcontent.getElementsByTagNameNS(svgns, '*'),
|
var defelem_uses = [],
|
||||||
grad_uses = [],
|
|
||||||
numRemoved = 0;
|
numRemoved = 0;
|
||||||
|
var attrs = ['fill', 'stroke', 'filter', 'marker-start', 'marker-mid', 'marker-end'];
|
||||||
|
var alen = attrs.length;
|
||||||
|
|
||||||
$.each(all_els, function(i, el) {
|
var all_els = svgcontent.getElementsByTagNameNS(svgns, '*');
|
||||||
var fill = getUrlFromAttr(el.getAttribute('fill'));
|
var all_len = all_els.length;
|
||||||
if(fill) {
|
|
||||||
grad_uses.push(fill.substr(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
var stroke = getUrlFromAttr(el.getAttribute('stroke'));
|
for(var i=0; i<all_len; i++) {
|
||||||
if (stroke) {
|
var el = all_els[i];
|
||||||
grad_uses.push(stroke.substr(1));
|
for(var j = 0; j < alen; j++) {
|
||||||
|
var ref = getUrlFromAttr(el.getAttribute(attrs[j]));
|
||||||
|
if(ref) defelem_uses.push(ref.substr(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// gradients can refer to other gradients
|
// gradients can refer to other gradients
|
||||||
var href = el.getAttributeNS(xlinkns, "href");
|
var href = el.getAttributeNS(xlinkns, "href");
|
||||||
if (href && href.indexOf('#') == 0) {
|
if (href && href.indexOf('#') == 0) {
|
||||||
grad_uses.push(href.substr(1));
|
defelem_uses.push(href.substr(1));
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
var grads = $(svgcontent).find("linearGradient, radialGradient");
|
var defelems = $(svgcontent).find("linearGradient, radialGradient, filter, marker");
|
||||||
grad_ids = [],
|
defelem_ids = [],
|
||||||
i = grads.length;
|
i = defelems.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
var grad = grads[i];
|
var defelem = defelems[i];
|
||||||
var id = grad.id;
|
var id = defelem.id;
|
||||||
if($.inArray(id, grad_uses) == -1) {
|
if($.inArray(id, defelem_uses) == -1) {
|
||||||
// Not found, so remove
|
// Not found, so remove
|
||||||
grad.parentNode.removeChild(grad);
|
defelem.parentNode.removeChild(defelem);
|
||||||
numRemoved++;
|
numRemoved++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1579,7 +1579,8 @@ function BatchCommand(text) {
|
||||||
|
|
||||||
var svgCanvasToString = function() {
|
var svgCanvasToString = function() {
|
||||||
// keep calling it until there are none to remove
|
// keep calling it until there are none to remove
|
||||||
while (removeUnusedGrads() > 0) {};
|
while (removeUnusedDefElems() > 0) {};
|
||||||
|
|
||||||
pathActions.clear(true);
|
pathActions.clear(true);
|
||||||
|
|
||||||
// Keep SVG-Edit comment on top
|
// Keep SVG-Edit comment on top
|
||||||
|
@ -9057,7 +9058,7 @@ function BatchCommand(text) {
|
||||||
recalculateDimensions: recalculateDimensions,
|
recalculateDimensions: recalculateDimensions,
|
||||||
remapElement: remapElement,
|
remapElement: remapElement,
|
||||||
RemoveElementCommand: RemoveElementCommand,
|
RemoveElementCommand: RemoveElementCommand,
|
||||||
removeUnusedGrads: removeUnusedGrads,
|
removeUnusedDefElems: removeUnusedDefElems,
|
||||||
resetUndoStack: resetUndoStack,
|
resetUndoStack: resetUndoStack,
|
||||||
round: round,
|
round: round,
|
||||||
runExtensions: runExtensions,
|
runExtensions: runExtensions,
|
||||||
|
|
Loading…
Reference in New Issue