Handle viewboxes with non-zero left,top. Minor fix for bboxes of <use>, <foreignObject>

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1427 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-02-22 02:58:19 +00:00
parent 6039875f5a
commit d4c93087fc
2 changed files with 18 additions and 26 deletions

View File

@ -5729,6 +5729,8 @@ function BatchCommand(text) {
else { else {
var ts = "scale(" + (canvash/3)/vb[2] + ")"; var ts = "scale(" + (canvash/3)/vb[2] + ")";
} }
if (vb[0] != 0 || vb[1] != 0)
ts = "translate(" + (-vb[0]) + "," + (-vb[1]) + ") " + ts;
// add all children of the imported <svg> to the <g> we create // add all children of the imported <svg> to the <g> we create
var g = svgdoc.createElementNS(svgns, "g"); var g = svgdoc.createElementNS(svgns, "g");
@ -5850,17 +5852,8 @@ function BatchCommand(text) {
// recalculate dimensions on the top-level children so that unnecessary transforms // recalculate dimensions on the top-level children so that unnecessary transforms
// are removed // are removed
var deepdive = function(node) { walkTreePost(importedNode, function(n){try{recalculateDimensions(n)}catch(e){console.log(e)}});
if (node.nodeType == 1) {
var children = node.childNodes;
var i = children.length;
while (i--) { deepdive(children.item(i)); }
try {
recalculateDimensions(node);
} catch(e) { console.log(e); }
}
}
deepdive(importedNode);
batchCmd.addSubCommand(new InsertElementCommand(svgcontent)); batchCmd.addSubCommand(new InsertElementCommand(svgcontent));
@ -6812,12 +6805,12 @@ function BatchCommand(text) {
ret = getPathBBox(selected); ret = getPathBBox(selected);
} else if(elem.nodeName == 'use' && !isWebkit) { } else if(elem.nodeName == 'use' && !isWebkit) {
ret = selected.getBBox(); ret = selected.getBBox();
ret.x += parseFloat(selected.getAttribute('x')); ret.x += parseFloat(selected.getAttribute('x')||0);
ret.y += parseFloat(selected.getAttribute('y')); ret.y += parseFloat(selected.getAttribute('y')||0);
} else if(elem.nodeName == 'foreignObject') { } else if(elem.nodeName == 'foreignObject') {
ret = selected.getBBox(); ret = selected.getBBox();
ret.x += parseFloat(selected.getAttribute('x')); ret.x += parseFloat(selected.getAttribute('x')||0);
ret.y += parseFloat(selected.getAttribute('y')); ret.y += parseFloat(selected.getAttribute('y')||0);
} else { } else {
try { ret = selected.getBBox(); } try { ret = selected.getBBox(); }
catch(e) { catch(e) {
@ -7552,9 +7545,6 @@ function BatchCommand(text) {
if(!elems) elems = canvas.getVisibleElements(); if(!elems) elems = canvas.getVisibleElements();
if(!elems.length) return false; if(!elems.length) return false;
// Make sure the expected BBox is returned if the element is a group // Make sure the expected BBox is returned if the element is a group
// FIXME: doesn't this mean that every time we call getStrokedBBox() that we are
// re-creating the getCheckedBBox() function? shouldn't we make this a function
// at the 'canvas' level
var getCheckedBBox = function(elem) { var getCheckedBBox = function(elem) {
try { try {
@ -7666,11 +7656,12 @@ function BatchCommand(text) {
var bboxes = []; var bboxes = [];
$.each(elems, function(i, elem) { $.each(elems, function(i, elem) {
var cur_bb = getCheckedBBox(elem); var cur_bb = getCheckedBBox(elem);
if(!cur_bb) return; if(cur_bb) {
var offset = getOffset(elem); var offset = getOffset(elem);
min_x = Math.min(min_x, cur_bb.x - offset); min_x = Math.min(min_x, cur_bb.x - offset);
min_y = Math.min(min_y, cur_bb.y - offset); min_y = Math.min(min_y, cur_bb.y - offset);
bboxes.push(cur_bb); bboxes.push(cur_bb);
}
}); });
full_bb.x = min_x; full_bb.x = min_x;
@ -7678,7 +7669,8 @@ function BatchCommand(text) {
$.each(elems, function(i, elem) { $.each(elems, function(i, elem) {
var cur_bb = bboxes[i]; var cur_bb = bboxes[i];
if (cur_bb) { // ensure that elem is really an element node
if (cur_bb && elem.nodeType == 1) {
var offset = getOffset(elem); var offset = getOffset(elem);
max_x = Math.max(max_x, cur_bb.x + cur_bb.width + offset); max_x = Math.max(max_x, cur_bb.x + cur_bb.width + offset);
max_y = Math.max(max_y, cur_bb.y + cur_bb.height + offset); max_y = Math.max(max_y, cur_bb.y + cur_bb.height + offset);

View File

@ -255,7 +255,7 @@
'</g>'+ '</g>'+
'</svg>'); '</svg>');
svgCanvas.importSvgString('<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'+ svgCanvas.importSvgString('<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink">'+
'<defs>'+ '<defs>'+
'<linearGradient id="svg_2">'+ '<linearGradient id="svg_2">'+
'<stop stop-color="red" offset="0"/>'+ '<stop stop-color="red" offset="0"/>'+
@ -264,7 +264,7 @@
'<rect id="svg_3" width="20" height="20" fill="blue" stroke="url(#svg_2)"/>'+ '<rect id="svg_3" width="20" height="20" fill="blue" stroke="url(#svg_2)"/>'+
'</defs>'+ '</defs>'+
'<circle id="svg_1" cx="50" cy="50" r="40" fill="url(#svg_2)"/>'+ '<circle id="svg_1" cx="50" cy="50" r="40" fill="url(#svg_2)"/>'+
'<use id="svg_4" width="30" height="30" xlink:href="#svg_3"/>'+ '<use id="svg_4" width="30" height="30" xl:href="#svg_3"/>'+
'</svg>'); '</svg>');
var svgcontent = document.getElementById("svgcontent"), var svgcontent = document.getElementById("svgcontent"),