From: Michael Ang Date: Fri, 18 Sep 2009 00:38:04 +0000 (+0000) Subject: Pass image aspect ratio to page printer. Rotate image for better fit (assume portrai... X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=5d0c050d4de4d88f4d810d85361830e3c891a874;p=bookreader.git Pass image aspect ratio to page printer. Rotate image for better fit (assume portrait orientation) if possible. Fit based on assumed paper size. --- diff --git a/GnuBook/GnuBook.js b/GnuBook/GnuBook.js index b7314d0..86ad43c 100644 --- a/GnuBook/GnuBook.js +++ b/GnuBook/GnuBook.js @@ -2418,8 +2418,10 @@ GnuBook.prototype.printPage = function() { indexToPrint = this.twoPage.currentIndexL; } + var aspectRatio = this.getPageWidth(indexToPrint) / this.getPageHeight(indexToPrint); + htmlStr = '

Click here to print this page

'; - htmlStr += ''; + htmlStr += ''; htmlStr += '

Close popup

'; this.printPopup.innerHTML = htmlStr; diff --git a/GnuBookIA/www/GnuBookPrint.php b/GnuBookIA/www/GnuBookPrint.php index 94450d9..c7c5d0a 100644 --- a/GnuBookIA/www/GnuBookPrint.php +++ b/GnuBookIA/www/GnuBookPrint.php @@ -26,10 +26,32 @@ $server = $_REQUEST['server']; $zip = $_REQUEST['zip']; $index = $_REQUEST['index']; $format = $_REQUEST['format']; +$imgAspect = $_REQUEST['aspect']; + +/* We assume that the print aspect ratio is somewhat close to US Letter in portrait orientation */ +$paperAspect = 8.5/11; + +$rotate = "0"; +if ('jp2' == $format) { + // Rotation is possible + if ($imgAspect > $paperAspect) { + $rotate = "90"; + $imgAspect = 1 / $imgAspect; + } +} $file = sprintf("%s_%s/%s_%04d.%s", $id, $format, $id, $index, $format); + +if ($imgAspect > $paperAspect) { + // wider than paper, fit width + $imgAttrs = "width='100%'"; +} else { + // taller than paper, fit height + $imgAttrs = "height='100%'"; +} + echo "

"; -echo ""; +echo ""; echo "

"; ?> \ No newline at end of file