Pass image aspect ratio to page printer. Rotate image for better fit (assume portrai...
authorMichael Ang <mang@archive.org>
Fri, 18 Sep 2009 00:38:04 +0000 (00:38 +0000)
committerMichael Ang <mang@archive.org>
Fri, 18 Sep 2009 00:38:04 +0000 (00:38 +0000)
GnuBook/GnuBook.js
GnuBookIA/www/GnuBookPrint.php

index b7314d0..86ad43c 100644 (file)
@@ -2418,8 +2418,10 @@ GnuBook.prototype.printPage = function() {
         indexToPrint = this.twoPage.currentIndexL;
     }
     
+    var aspectRatio = this.getPageWidth(indexToPrint) / this.getPageHeight(indexToPrint);
+    
     htmlStr =  '<p style="text-align:center;"><b><a href="javascript:void(0);" onclick="window.frames[0].focus(); window.frames[0].print(); return false;">Click here to print this page</a></b></p>';
-    htmlStr += '<iframe name ="printFrame" id="printFrame" src="/bookreader/GnuBookPrint.php?id='+this.bookId+'&server='+this.server+'&zip='+this.zip+'&index='+this.leafMap[indexToPrint]+'&format='+this.imageFormat+'" width="500px" height="400px"></iframe>';
+    htmlStr += '<iframe name ="printFrame" id="printFrame" src="/bookreader/GnuBookPrint.php?id='+this.bookId+'&server='+this.server+'&zip='+this.zip+'&index='+this.leafMap[indexToPrint]+'&format='+this.imageFormat+'&aspect=' + aspectRatio + '" width="500px" height="400px"></iframe>';
     htmlStr += '<p style="text-align:center;"><a href="" onclick="gb.printPopup = null; $(this.parentNode.parentNode).remove(); return false">Close popup</a></p>';    
 
     this.printPopup.innerHTML = htmlStr;    
index 94450d9..c7c5d0a 100644 (file)
@@ -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 "<p style='text-align:center;'>";
-echo "<img src='http://{$server}/GnuBook/GnuBookImages.php?zip={$zip}&file={$file}&scale=1' height='100%'/>";
+echo "<img src='http://{$server}/GnuBook/GnuBookImages.php?zip={$zip}&file={$file}&scale=1&rotate=$rotate' " . $imgAttrs . " />";
 echo "</p>";
 
 ?>
\ No newline at end of file