Added support for 'Fit to ...' zoom options

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@653 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2009-09-16 14:12:51 +00:00
parent fe42d462b5
commit b6a1128fd1
2 changed files with 65 additions and 5 deletions

View File

@ -422,13 +422,26 @@ function svg_edit_setup() {
$('#zoom_dropdown li').bind('mouseup',function() { $('#zoom_dropdown li').bind('mouseup',function() {
var item = $(this); var item = $(this);
var val = item.attr('data-val'); var val = item.attr('data-val');
var res = svgCanvas.getResolution();
var scrbar = 15;
if(val) { if(val) {
//TODO: Calculate proper zoom from here. var w_area = $('#workarea');
var z_info = svgCanvas.setBBoxZoom(val, w_area.width()-scrbar, w_area.height()-scrbar);
if(!z_info) return;
var zoomlevel = z_info.zoom;
var bb = z_info.bbox;
$('#zoom').val(zoomlevel*100);
setResolution(res.w * zoomlevel, res.h * zoomlevel);
var scrLeft = bb.x * zoomlevel;
var scrOffX = w_area.width()/2 - (bb.width * zoomlevel)/2;
w_area[0].scrollLeft = Math.max(0,scrLeft - scrOffX);
var scrTop = bb.y * zoomlevel;
var scrOffY = w_area.height()/2 - (bb.height * zoomlevel)/2;
w_area[0].scrollTop = Math.max(0,scrTop - scrOffY);
} else { } else {
var percent = parseInt(item.text()); var percent = parseInt(item.text());
$('#zoom').val(percent); $('#zoom').val(percent);
var zoomlevel = percent/100; var zoomlevel = percent/100;
var res = svgCanvas.getResolution();
setResolution(res.w * zoomlevel, res.h * zoomlevel, true); setResolution(res.w * zoomlevel, res.h * zoomlevel, true);
svgCanvas.setZoom(zoomlevel); svgCanvas.setZoom(zoomlevel);
} }

View File

@ -2591,14 +2591,61 @@ function BatchCommand(text) {
} }
}; };
this.setBBoxZoom = function(type, editor_w, editor_h) {
var spacer = .85;
var w_zoom, h_zoom;
switch ( type ) {
case 'selection':
if(!selectedElements[0]) return;
var bb = selectedBBoxes[0];
$.each(selectedBBoxes, function(i, sel) {
if(!sel || !i) return;
// FIXME: Calculations still need some work...
bb.x = Math.min(bb.x, sel.x);
bb.y = Math.min(bb.y, sel.y);
bb.width = Math.max(sel.width + sel.x, bb.width + bb.x) - bb.x;
bb.height = Math.max(sel.height + sel.y, bb.height + bb.y) - bb.y;
});
w_zoom = Math.round((editor_w / bb.width)*100 * spacer)/100;
h_zoom = Math.round((editor_h / bb.height)*100 * spacer)/100;
var zoomlevel = Math.min(w_zoom,h_zoom);
canvas.setZoom(zoomlevel);
return {'zoom': zoomlevel, 'bbox': bb};
case 'canvas':
spacer = .95;
var res = canvas.getResolution();
w_zoom = Math.round((editor_w / res.w)*100)/100;
h_zoom = Math.round((editor_h / res.h)*100)/100;
var zoomlevel = Math.min(w_zoom, h_zoom);
canvas.setZoom(zoomlevel);
return {'zoom': zoomlevel, 'bbox': {width:res.w, height:res.h ,x:0, y:0}};
case 'content':
var bb = svgzoom.getBBox();
w_zoom = Math.round((editor_w / bb.width)*100 * spacer)/100;
h_zoom = Math.round((editor_h / bb.height)*100 * spacer)/100;
var zoomlevel = Math.min(w_zoom,h_zoom);
canvas.setZoom(zoomlevel);
return {'zoom': zoomlevel, 'bbox': bb};
default:
return;
}
}
this.setZoom = function(zoomlevel) { this.setZoom = function(zoomlevel) {
var res = canvas.getResolution(); var res = canvas.getResolution();
svgroot.setAttribute("width", res.w * zoomlevel); svgroot.setAttribute("width", res.w * zoomlevel);
svgroot.setAttribute("height", res.h * zoomlevel); svgroot.setAttribute("height", res.h * zoomlevel);
current_zoom = zoomlevel; current_zoom = zoomlevel;
if(selectedElements[0]) { $.each(selectedElements, function(i, elem) {
selectorManager.requestSelector(selectedElements[0]).resize(); if(!elem) return;
} selectorManager.requestSelector(elem).resize();
});
} }
this.getMode = function() { this.getMode = function() {