diff --git a/editor/svg-editor.css b/editor/svg-editor.css index fda29a58..5af01b53 100644 --- a/editor/svg-editor.css +++ b/editor/svg-editor.css @@ -468,7 +468,16 @@ span.zoom_tool { padding: 10px; background-color: #B0B0B0; opacity: 1.0; - text-align: center; +} + +#svg_docprops_container fieldset { + padding: 5px; + margin: 5px; +} + +#svg_docprops_container label { + display: block; + margin-bottom: .2em; } #svg_source_editor #svg_source_textarea { @@ -491,10 +500,15 @@ span.zoom_tool { } #svg_source_editor button, #svg_docprops button { - padding: 5px 2px 6px 28px; + padding: 5px 5px 7px 28px; margin: 5px 20px 0 0; } +#svg_docprops button { + margin-top: 0; + margin-bottom: 5px; +} + #svg_docprops { display: none; } @@ -510,9 +524,9 @@ span.zoom_tool { } #tool_source_save, #tool_docprops_save { - background: #E8E8E8 url(images/save.png) no-repeat 2px 2px; + background: #E8E8E8 url(images/save.png) no-repeat 2px 0; } #tool_source_cancel, #tool_docprops_cancel { - background: #E8E8E8 url(images/cancel.png) no-repeat 2px 2px; + background: #E8E8E8 url(images/cancel.png) no-repeat 2px 0; } diff --git a/editor/svg-editor.html b/editor/svg-editor.html index e3ba4899..12b29924 100644 --- a/editor/svg-editor.html +++ b/editor/svg-editor.html @@ -337,21 +337,29 @@
diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 5a72286f..9537b111 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -725,8 +725,9 @@ function svg_edit_setup() { // update resolution option with actual resolution // TODO: what if SVG source is changed? var res = svgCanvas.getResolution(); - $("#resolution").val(res.w+'x'+res.h).attr("selected", "selected"); - + $('#canvas_width').val(res.w); + $('#canvas_height').val(res.h); + $('#svg_docprops').fadeIn(); }; @@ -751,15 +752,15 @@ function svg_edit_setup() { var saveDocProperties = function(){ // update resolution - var x = '', y = ''; - var resOption = $('#resolution'); - var val = resOption.val(); - if (val && val != 'Fit to content') { - var res = val.split('x'); - x = parseInt(res[0]); - y = parseInt(res[1]); + var x = parseInt($('#canvas_width').val()); + var y = parseInt($('#canvas_height').val()); + if(isNaN(x) || isNaN(y)) { + x ='fit'; + } + if(!svgCanvas.setResolution(x,y)) { + alert('No content to fit to'); + return false; } - svgCanvas.setResolution(x,y); hideDocProperties(); }; @@ -788,6 +789,8 @@ function svg_edit_setup() { var hideDocProperties = function(){ $('#svg_docprops').hide(); + $('#canvas_width,#canvas_height').removeAttr('disabled'); + $('#resolution')[0].selectedIndex = 0; docprops = false; }; @@ -1192,6 +1195,8 @@ function svg_edit_setup() { function setResolution(w, h, center) { w-=0; h-=0; $('#svgcanvas').css( { 'width': w, 'height': h } ); + $('#canvas_width').val(w); + $('#canvas_height').val(h); if(center) { var w_area = $('#workarea'); var scroll_y = h/2 - w_area.height()/2; @@ -1202,25 +1207,18 @@ function svg_edit_setup() { } $('#resolution').change(function(){ - if(this.value == 'Custom') { - var cust_val = prompt("Please enter custom size (i.e. 400x300)",""); - var res_vals = cust_val.match(/(\d+)[x \/,](\d+)/); - if(!res_vals) { - alert('Invalid size. Please format it as WIDTHxHEIGHT (like 400x300)'); - return false; - } else { - var x = res_vals[1], y = res_vals[2]; - if(x == '0' || y == '0') { - alert('Invalid size. Width or height may not be 0.'); - return false; - } - var newOption = [x,'x',y].join(''); - $("#resolution").val(newOption).attr("selected", "selected"); - if ($("#resolution").val() != newOption) { - $('#resolution').append(''); - $("#resolution").val(newOption).attr("selected", "selected"); - } + var wh = $('#canvas_width,#canvas_height'); + if(!this.selectedIndex) { + if($('#canvas_width').val() == 'fit') { + wh.removeAttr("disabled").val(100); } + } else if(this.value == 'content') { + wh.val('fit').attr("disabled","disabled"); + } else { + var dims = this.value.split('x'); + $('#canvas_width').val(dims[0]); + $('#canvas_height').val(dims[1]); + wh.removeAttr("disabled"); } }); diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 385ef8d0..5f16aae0 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -2868,11 +2868,12 @@ function BatchCommand(text) { var vb = svgzoom.getAttribute("viewBox").split(' '); return {'w':vb[2], 'h':vb[3], 'zoom': current_zoom}; }; + this.setResolution = function(x, y) { var res = canvas.getResolution(); var w = res.w, h = res.h; - if(!x) { + if(x == 'fit') { canvas.clearSelection(); // Get bounding box @@ -2890,11 +2891,10 @@ function BatchCommand(text) { }); }); canvas.clearSelection(); - x = bbox.width; - y = bbox.height; + x = Math.round(bbox.width); + y = Math.round(bbox.height); } else { - alert('No content to fit to'); - return; + return false; } } x *= current_zoom; @@ -2914,6 +2914,7 @@ function BatchCommand(text) { svgroot.unsuspendRedraw(handle); call("changed", [svgzoom]); } + return true; }; this.setBBoxZoom = function(val, editor_w, editor_h) { @@ -3667,6 +3668,7 @@ function BatchCommand(text) { this.getStrokedBBox = function(elems) { // TODO: Get correct BBoxes for rotated elements if(!elems) elems = canvas.getVisibleElements(); + if(!elems.length) return false; var full_bb = elems[0].getBBox(); var max_x = full_bb.x + full_bb.width; var max_y = full_bb.y + full_bb.height;