Fixed issue 82: Resizable Canvas
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@420 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
aaea4016f8
commit
8b5c79a33f
|
@ -267,7 +267,7 @@ div.color_block {
|
||||||
}
|
}
|
||||||
|
|
||||||
#svg_editor #tools_bottom_1 {
|
#svg_editor #tools_bottom_1 {
|
||||||
width: 100px;
|
width: 115px;
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,8 @@
|
||||||
<option>1024x768</option>
|
<option>1024x768</option>
|
||||||
<option>1280x960</option>
|
<option>1280x960</option>
|
||||||
<option>1600x1200</option>
|
<option>1600x1200</option>
|
||||||
|
<option>Fit to Content</option>
|
||||||
|
<option>Custom</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -848,14 +848,39 @@ function svg_edit_setup() {
|
||||||
});
|
});
|
||||||
|
|
||||||
function changeResolution(x,y) {
|
function changeResolution(x,y) {
|
||||||
|
var new_res = x+'x'+y;
|
||||||
|
var found = false;
|
||||||
|
$('#resolution option').each(function() {
|
||||||
|
if($(this).text() == new_res) {
|
||||||
$('#resolution').val(x+'x'+y);
|
$('#resolution').val(x+'x'+y);
|
||||||
// $('#svgroot').css( { 'width': x+'px', 'height': y+'px' } );
|
found = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(!found) $('#resolution').val('Custom');
|
||||||
|
|
||||||
$('#svgcanvas').css( { 'width': x+'px', 'height': y+'px' } );
|
$('#svgcanvas').css( { 'width': x+'px', 'height': y+'px' } );
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#resolution').change(function(){
|
$('#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(this.value == 'Fit to content'){
|
||||||
|
var x = '', y = '';
|
||||||
|
} else {
|
||||||
var res = this.value.split('x');
|
var res = this.value.split('x');
|
||||||
var x = parseInt(res[0]), y = parseInt(res[1]);
|
var x = parseInt(res[0]), y = parseInt(res[1]);
|
||||||
|
}
|
||||||
svgCanvas.setResolution(x,y);
|
svgCanvas.setResolution(x,y);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1969,8 +1969,25 @@ function SvgCanvas(c)
|
||||||
h = svgroot.getAttribute("height");
|
h = svgroot.getAttribute("height");
|
||||||
|
|
||||||
var handle = svgroot.suspendRedraw(1000);
|
var handle = svgroot.suspendRedraw(1000);
|
||||||
|
|
||||||
|
if(!x) {
|
||||||
|
canvas.clearSelection();
|
||||||
|
|
||||||
|
// Get bounding box
|
||||||
|
var bbox = svgroot.getBBox();
|
||||||
|
|
||||||
|
if(bbox) {
|
||||||
|
x = bbox.x + bbox.width;
|
||||||
|
y = bbox.y + bbox.height;
|
||||||
|
} else {
|
||||||
|
alert('No content to fit to');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
svgroot.setAttribute("width", x);
|
svgroot.setAttribute("width", x);
|
||||||
svgroot.setAttribute("height", y);
|
svgroot.setAttribute("height", y);
|
||||||
|
|
||||||
svgroot.unsuspendRedraw(handle);
|
svgroot.unsuspendRedraw(handle);
|
||||||
addCommandToHistory(new ChangeElementCommand(svgroot, {"width":w,"height":h}, "resolution"));
|
addCommandToHistory(new ChangeElementCommand(svgroot, {"width":w,"height":h}, "resolution"));
|
||||||
call("changed", [svgroot]);
|
call("changed", [svgroot]);
|
||||||
|
|
Loading…
Reference in New Issue