Dealt with remaining bug in issue 470: Support loading files with unit-based width/height
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1406 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
a3f81f06f2
commit
2c889f640b
|
@ -5619,28 +5619,33 @@ function BatchCommand(text) {
|
||||||
|
|
||||||
var content = $(svgcontent);
|
var content = $(svgcontent);
|
||||||
|
|
||||||
|
var attrs = {
|
||||||
|
id: 'svgcontent',
|
||||||
|
overflow: 'visible'
|
||||||
|
};
|
||||||
|
|
||||||
// determine proper size
|
// determine proper size
|
||||||
var w, h;
|
|
||||||
if (content.attr("viewBox")) {
|
if (content.attr("viewBox")) {
|
||||||
var vb = content.attr("viewBox").split(' ');
|
var vb = content.attr("viewBox").split(' ');
|
||||||
w = vb[2];
|
attrs.width = vb[2];
|
||||||
h = vb[3];
|
attrs.height = vb[3];
|
||||||
}
|
}
|
||||||
// handle content that doesn't have a viewBox
|
// handle content that doesn't have a viewBox
|
||||||
else {
|
else {
|
||||||
var dims = content.attr(["width", "height"]);
|
$.each(['width', 'height'], function(i, dim) {
|
||||||
w = convertToNum('width', dims.width);
|
// Set to 100 if not given
|
||||||
h = convertToNum('height', dims.height);
|
var val = content.attr(dim) || 100;
|
||||||
// svgcontent.setAttribute("viewBox", ["0", "0", w, h].join(" "));
|
|
||||||
|
if((val+'').substr(-1) === "%") {
|
||||||
|
// Use user units if percentage given
|
||||||
|
attrs[dim] = parseInt(val);
|
||||||
|
} else {
|
||||||
|
attrs[dim] = convertToNum(dim, val);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
content.attr({
|
content.attr(attrs);
|
||||||
id: 'svgcontent',
|
|
||||||
width: w,
|
|
||||||
height: h,
|
|
||||||
overflow: 'visible'
|
|
||||||
});
|
|
||||||
|
|
||||||
batchCmd.addSubCommand(new InsertElementCommand(svgcontent));
|
batchCmd.addSubCommand(new InsertElementCommand(svgcontent));
|
||||||
// update root to the correct size
|
// update root to the correct size
|
||||||
var changes = content.attr(["width", "height"]);
|
var changes = content.attr(["width", "height"]);
|
||||||
|
|
Loading…
Reference in New Issue