# HG changeset patch # User hertzhaft # Date 1329581424 -3600 # Node ID dc09bccf83572c0c4a0e4837dcbbb8782e2f4076 # Parent 5f35e97d8ae3e89e2b6e712408df92503bd2cbf7 better aspect ratio for preview (almost right) diff -r 5f35e97d8ae3 -r dc09bccf8357 webapp/src/main/webapp/jquery/jquery.digilib.geometry.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.geometry.js Sat Feb 18 10:00:26 2012 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.geometry.js Sat Feb 18 17:10:24 2012 +0100 @@ -9,7 +9,7 @@ var size = function(w, h) { var that; if (typeof w === "object") { - // assume its size + // assume an object having width and height that = { width : w.width, height : w.height @@ -20,9 +20,25 @@ height : parseFloat(h) }; } + // returns true if both sizes are equal that.equals = function(other) { return (this.width === other.width && this.height === other.height); }; + // returns the aspect ratio of this size + that.getAspect = function() { + return (this.width / this.height); + }; + // returns a size of a given aspect ratio that fits into this one + that.fitAspect = function(aspect) { + var s = size(this); + if (aspect > this.getAspect()) { + // size is more horizontally stretched than this + s.height = s.width / aspect; + } else { + s.width = s.height * aspect; + } + return s; + }; // adjusts size of jQuery element "$elem" to this size that.adjustDiv = function($elem) { $elem.width(this.width).height(this.height); @@ -301,6 +317,7 @@ } return r.intersect(this); }; + // adjusts position and size of jQuery element "$elem" to this rectangle that.adjustDiv = function($elem) { $elem.offset({ diff -r 5f35e97d8ae3 -r dc09bccf8357 webapp/src/main/webapp/jquery/jquery.digilib.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.js Sat Feb 18 10:00:26 2012 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.js Sat Feb 18 17:10:24 2012 +0100 @@ -937,7 +937,7 @@ // fullscreen $elem.addClass(cssPrefix+'fullscreen'); var imgSize = getFullscreenImgSize(data); - data.fullscreenImgSize = imgSize; + data.maxImgSize = imgSize; // fitwidth/height omits destination height/width if (data.dlOpts.fitheight == null) { settings.dw = imgSize.width; @@ -1109,7 +1109,7 @@ data.imgTrafo = getImgTrafo($img, data.zoomArea, data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir, data.scaleMode, data); - console.debug("imgTrafo=", data.imgTrafo); + console.debug("updateImgTrafo: ", data.imgTrafo); } }; @@ -1266,12 +1266,15 @@ }; if (newZoomArea != null) { // check if aspect ratio has changed - if (newZoomArea.getAspect() !== data.zoomArea.getAspect()) { - console.debug("aspect ratio changed!"); - // what now? + newAspect = newZoomArea.getAspect(); + if (newAspect !== data.zoomArea.getAspect()) { + var newSize = data.maxImgSize.fitAspect(newAspect); + // set scaler to presumed new size + newSize.adjustDiv($scaler); + console.debug("adjusting aspect ratio for preview", data.maxImgSize, newSize); } // get transform for new zoomArea (use 'screen' instead of data.scaleMode) - imgTrafo = getImgTrafo($img, newZoomArea, data.settings.rot, + imgTrafo = getImgTrafo($scaler, newZoomArea, data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir, 'screen', data); // for new background coordinates transform old zoomArea with new Transform @@ -1387,7 +1390,7 @@ data.oldZoomArea = data.zoomArea; data.zoomArea = za; }; - + /** get image quality as a number (0..2). * */ @@ -1451,13 +1454,13 @@ // "both" is default return "both"; }; - + /** * set screen fit mode (width, height, both). */ var setFitMode = function (data, mode) { var settings = data.settings; - var imgSize = data.fullscreenImgSize; + var imgSize = data.maxImgSize; if (mode === 'width') { data.dlOpts.fitwidth = 1; delete data.dlOpts.fitheight;