Fixed issue 356 and added transform parser for Webkit (fixes transform-loss bug on imported elements)
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1076 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -661,6 +661,40 @@ function BatchCommand(text) {
|
|||||||
this._elem.setAttribute("transform", tstr);
|
this._elem.setAttribute("transform", tstr);
|
||||||
};
|
};
|
||||||
this._list = this;
|
this._list = this;
|
||||||
|
this._init = function() {
|
||||||
|
// Transform attribute parser
|
||||||
|
var str = this._elem.getAttribute("transform");
|
||||||
|
if(!str) return;
|
||||||
|
|
||||||
|
// TODO: Add skew support in future
|
||||||
|
var re = /\s*((scale|matrix|rotate|translate)\s*\(.*?\))\s*,?\s*/;
|
||||||
|
var arr = [];
|
||||||
|
var m = true;
|
||||||
|
while(m) {
|
||||||
|
m = str.match(re);
|
||||||
|
str = str.replace(re,'');
|
||||||
|
if(m && m[1]) {
|
||||||
|
var x = m[1];
|
||||||
|
var bits = x.split(/\s*\(/);
|
||||||
|
var name = bits[0];
|
||||||
|
var val_bits = bits[1].match(/\s*(.*?)\s*\)/);
|
||||||
|
var val_arr = val_bits[1].split(/[, ]+/);
|
||||||
|
var letters = 'abcdef'.split('');
|
||||||
|
var mtx = svgroot.createSVGMatrix();
|
||||||
|
$.each(val_arr, function(i, item) {
|
||||||
|
val_arr[i] = parseFloat(item);
|
||||||
|
if(name == 'matrix') {
|
||||||
|
mtx[letters[i]] = val_arr[i];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var xform = svgroot.createSVGTransform();
|
||||||
|
var fname = 'set' + name.charAt(0).toUpperCase() + name.slice(1);
|
||||||
|
var values = name=='matrix'?[mtx]:val_arr;
|
||||||
|
xform[fname].apply(xform, values);
|
||||||
|
this._list.appendItem(xform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.numberOfItems = 0;
|
this.numberOfItems = 0;
|
||||||
this.clear = function() {
|
this.clear = function() {
|
||||||
@@ -1099,14 +1133,7 @@ function BatchCommand(text) {
|
|||||||
svgcontent.insertBefore(node, svgcontent.firstChild);
|
svgcontent.insertBefore(node, svgcontent.firstChild);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
svgcontent.removeAttribute('id');
|
|
||||||
var res = canvas.getResolution();
|
|
||||||
assignAttributes(svgcontent, {width: res.w, height: res.h});
|
|
||||||
svgcontent.removeAttribute('viewBox');
|
|
||||||
var output = svgToString(svgcontent, 0);
|
var output = svgToString(svgcontent, 0);
|
||||||
assignAttributes(svgcontent, {id: 'svgcontent', 'viewBox':[0,0,res.w,res.h].join(' ')});
|
|
||||||
svgcontent.removeAttribute('width');
|
|
||||||
svgcontent.removeAttribute('height');
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1119,44 +1146,53 @@ function BatchCommand(text) {
|
|||||||
var i;
|
var i;
|
||||||
var childs = elem.childNodes;
|
var childs = elem.childNodes;
|
||||||
for (i=0; i<indent; i++) out.push(" ");
|
for (i=0; i<indent; i++) out.push(" ");
|
||||||
out.push("<"); out.push(elem.nodeName);
|
out.push("<"); out.push(elem.nodeName);
|
||||||
for (i=attrs.length-1; i>=0; i--) {
|
if(elem.id == 'svgcontent') {
|
||||||
attr = attrs.item(i);
|
// Process root element separately; Prevents errors caused
|
||||||
var attrVal = attr.nodeValue;
|
// in webkit when removing attributes
|
||||||
|
var res = canvas.getResolution();
|
||||||
if (attrVal != "") {
|
out.push(' width="' + res.w + '" height="' + res.h
|
||||||
if(attrVal.indexOf('pointer-events') == 0) continue;
|
+ '" xmlns:xlink="'+xlinkns+'" xmlns="'+svgns+'"');
|
||||||
out.push(" ");
|
} else {
|
||||||
if(attr.localName == 'd') attrVal = convertPath(elem, true);
|
for (i=attrs.length-1; i>=0; i--) {
|
||||||
if(!isNaN(attrVal)) {
|
attr = attrs.item(i);
|
||||||
attrVal = shortFloat(attrVal);
|
var attrVal = attr.nodeValue;
|
||||||
}
|
|
||||||
|
|
||||||
// Embed images when saving
|
if (attrVal != "") {
|
||||||
if(save_options.apply
|
if(attrVal.indexOf('pointer-events') == 0) continue;
|
||||||
&& elem.nodeName == 'image'
|
out.push(" ");
|
||||||
&& attr.localName == 'href'
|
if(attr.localName == 'd') attrVal = convertPath(elem, true);
|
||||||
&& save_options.images
|
if(!isNaN(attrVal)) {
|
||||||
&& save_options.images == 'embed') {
|
attrVal = shortFloat(attrVal);
|
||||||
var img = encodableImages[attrVal];
|
}
|
||||||
if(img) attrVal = img;
|
|
||||||
|
// Embed images when saving
|
||||||
|
if(save_options.apply
|
||||||
|
&& elem.nodeName == 'image'
|
||||||
|
&& attr.localName == 'href'
|
||||||
|
&& save_options.images
|
||||||
|
&& save_options.images == 'embed') {
|
||||||
|
var img = encodableImages[attrVal];
|
||||||
|
if(img) attrVal = img;
|
||||||
|
}
|
||||||
|
|
||||||
|
// map various namespaces to our fixed namespace prefixes
|
||||||
|
// TODO: put this into a map and do a look-up instead of if-else
|
||||||
|
if (attr.namespaceURI == xlinkns) {
|
||||||
|
out.push('xlink:');
|
||||||
|
}
|
||||||
|
else if(attr.namespaceURI == 'http://www.w3.org/2000/xmlns/' && attr.localName != 'xmlns') {
|
||||||
|
out.push('xmlns:');
|
||||||
|
}
|
||||||
|
else if(attr.namespaceURI == xmlns) {
|
||||||
|
out.push('xml:');
|
||||||
|
}
|
||||||
|
out.push(attr.localName); out.push("=\"");
|
||||||
|
out.push(attrVal); out.push("\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
// map various namespaces to our fixed namespace prefixes
|
|
||||||
// TODO: put this into a map and do a look-up instead of if-else
|
|
||||||
if (attr.namespaceURI == xlinkns) {
|
|
||||||
out.push('xlink:');
|
|
||||||
}
|
|
||||||
else if(attr.namespaceURI == 'http://www.w3.org/2000/xmlns/' && attr.localName != 'xmlns') {
|
|
||||||
out.push('xmlns:');
|
|
||||||
}
|
|
||||||
else if(attr.namespaceURI == xmlns) {
|
|
||||||
out.push('xml:');
|
|
||||||
}
|
|
||||||
out.push(attr.localName); out.push("=\"");
|
|
||||||
out.push(attrVal); out.push("\"");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elem.hasChildNodes()) {
|
if (elem.hasChildNodes()) {
|
||||||
out.push(">");
|
out.push(">");
|
||||||
indent++;
|
indent++;
|
||||||
@@ -4445,6 +4481,8 @@ function BatchCommand(text) {
|
|||||||
// identify layers
|
// identify layers
|
||||||
identifyLayers();
|
identifyLayers();
|
||||||
|
|
||||||
|
// reset transform lists
|
||||||
|
svgTransformLists = {};
|
||||||
canvas.clearSelection();
|
canvas.clearSelection();
|
||||||
addCommandToHistory(batchCmd);
|
addCommandToHistory(batchCmd);
|
||||||
call("changed", [svgcontent]);
|
call("changed", [svgcontent]);
|
||||||
@@ -4874,7 +4912,6 @@ function BatchCommand(text) {
|
|||||||
selectorManager.initGroup();
|
selectorManager.initGroup();
|
||||||
// reset the rubber band box
|
// reset the rubber band box
|
||||||
rubberBox = selectorManager.getRubberBandBox();
|
rubberBox = selectorManager.getRubberBandBox();
|
||||||
|
|
||||||
call("cleared");
|
call("cleared");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -5371,6 +5408,7 @@ function BatchCommand(text) {
|
|||||||
var t = svgTransformLists[elem.id];
|
var t = svgTransformLists[elem.id];
|
||||||
if (!t) {
|
if (!t) {
|
||||||
svgTransformLists[elem.id] = new SVGEditTransformList(elem);
|
svgTransformLists[elem.id] = new SVGEditTransformList(elem);
|
||||||
|
svgTransformLists[elem.id]._init();
|
||||||
t = svgTransformLists[elem.id];
|
t = svgTransformLists[elem.id];
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
|
|||||||
Reference in New Issue
Block a user