Added support for 'Fit to ...' zoom options
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@653 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
fe42d462b5
commit
b6a1128fd1
|
@ -422,13 +422,26 @@ function svg_edit_setup() {
|
|||
$('#zoom_dropdown li').bind('mouseup',function() {
|
||||
var item = $(this);
|
||||
var val = item.attr('data-val');
|
||||
var res = svgCanvas.getResolution();
|
||||
var scrbar = 15;
|
||||
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 {
|
||||
var percent = parseInt(item.text());
|
||||
$('#zoom').val(percent);
|
||||
var zoomlevel = percent/100;
|
||||
var res = svgCanvas.getResolution();
|
||||
setResolution(res.w * zoomlevel, res.h * zoomlevel, true);
|
||||
svgCanvas.setZoom(zoomlevel);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
var res = canvas.getResolution();
|
||||
svgroot.setAttribute("width", res.w * zoomlevel);
|
||||
svgroot.setAttribute("height", res.h * zoomlevel);
|
||||
current_zoom = zoomlevel;
|
||||
if(selectedElements[0]) {
|
||||
selectorManager.requestSelector(selectedElements[0]).resize();
|
||||
}
|
||||
$.each(selectedElements, function(i, elem) {
|
||||
if(!elem) return;
|
||||
selectorManager.requestSelector(elem).resize();
|
||||
});
|
||||
}
|
||||
|
||||
this.getMode = function() {
|
||||
|
|
Loading…
Reference in New Issue