From 9590cf67f58071025f877e2136411593e25f1837 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Wed, 10 Feb 2010 17:54:14 +0000 Subject: [PATCH] Fixed issue 470: Support loading files with unit-based width/height git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1371 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 69aa453a..26e8afbb 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -5527,33 +5527,34 @@ function BatchCommand(text) { if(!support.goodDecimals) { canvas.fixOperaXML(svgcontent, newDoc.documentElement); } - - svgcontent.id= 'svgcontent'; + var content = $(svgcontent); + // determine proper size var w, h; - if (svgcontent.getAttribute("viewBox")) { - var vb = svgcontent.getAttribute("viewBox").split(' '); + if (content.attr("viewBox")) { + var vb = content.attr("viewBox").split(' '); w = vb[2]; h = vb[3]; } - // handle old content that doesn't have a viewBox + // handle content that doesn't have a viewBox else { - w = svgcontent.getAttribute("width"); - h = svgcontent.getAttribute("height"); + var dims = content.attr(["width", "height"]); + w = convertToNum('width', dims.width); + h = convertToNum('height', dims.height); // svgcontent.setAttribute("viewBox", ["0", "0", w, h].join(" ")); } - svgcontent.setAttribute('width', w); - svgcontent.setAttribute('height', h); - svgcontent.setAttribute('overflow', 'visible'); + content.attr({ + id: 'svgcontent', + width: w, + height: h, + overflow: 'visible' + }); + batchCmd.addSubCommand(new InsertElementCommand(svgcontent)); // update root to the correct size - var changes = {}; - changes['width'] = svgcontent.getAttribute('width'); - changes['height'] = svgcontent.getAttribute('height'); -// svgroot.setAttribute('width', w); -// svgroot.setAttribute('height', h); + var changes = content.attr(["width", "height"]); batchCmd.addSubCommand(new ChangeElementCommand(svgroot, changes)); // reset zoom