From 2c889f640b4fb52966b2478e7523c1c936e98a55 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Wed, 17 Feb 2010 21:20:11 +0000 Subject: [PATCH] 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-75d572ba1ddd --- editor/svgcanvas.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 21346b91..12209a90 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -5619,28 +5619,33 @@ function BatchCommand(text) { var content = $(svgcontent); + var attrs = { + id: 'svgcontent', + overflow: 'visible' + }; + // determine proper size - var w, h; if (content.attr("viewBox")) { var vb = content.attr("viewBox").split(' '); - w = vb[2]; - h = vb[3]; + attrs.width = vb[2]; + attrs.height = vb[3]; } // handle content that doesn't have a viewBox else { - var dims = content.attr(["width", "height"]); - w = convertToNum('width', dims.width); - h = convertToNum('height', dims.height); - // svgcontent.setAttribute("viewBox", ["0", "0", w, h].join(" ")); + $.each(['width', 'height'], function(i, dim) { + // Set to 100 if not given + var val = content.attr(dim) || 100; + + if((val+'').substr(-1) === "%") { + // Use user units if percentage given + attrs[dim] = parseInt(val); + } else { + attrs[dim] = convertToNum(dim, val); + } + }); } - content.attr({ - id: 'svgcontent', - width: w, - height: h, - overflow: 'visible' - }); - + content.attr(attrs); batchCmd.addSubCommand(new InsertElementCommand(svgcontent)); // update root to the correct size var changes = content.attr(["width", "height"]);