Print icon and link. These are not themselves printed.
[bookreader.git] / GnuBookIA / www / print.php
1 <?
2 /*
3 Copyright(c)2008 Internet Archive. Software license AGPL version 3.
4
5 This file is part of GnuBook.
6
7     GnuBook is free software: you can redistribute it and/or modify
8     it under the terms of the GNU Affero General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11
12     GnuBook is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU Affero General Public License for more details.
16
17     You should have received a copy of the GNU Affero General Public License
18     along with GnuBook.  If not, see <http://www.gnu.org/licenses/>.
19
20 GnuBookPrint.php exists to get around the same-origin policy that prevents
21 us from calling print() on an iframe that comes from a cluster datanode.
22 */
23
24 $id     = $_REQUEST['id'];
25 $server = $_REQUEST['server'];
26 $zip    = $_REQUEST['zip'];
27 $index  = $_REQUEST['index'];
28 $format = $_REQUEST['format'];
29 //$imgAspect = $_REQUEST['aspect'];
30 $width = $_REQUEST['width'];
31 $height = $_REQUEST['height'];
32
33 // $$$ escape the values
34
35 /* We assume that the print aspect ratio is somewhat close to US Letter in portrait orientation */
36 $paperAspect = 8.5/11;
37 $imgAspect = $width / $height;
38
39 // Returns (url, attrs)
40 function imageURL($paperAspect, $index, $format, $width, $height) {
41     global $server, $id, $zip;
42     
43     $rotate = "0";
44     $imgAspect = $width / $height;
45     
46     if ('jp2' == $format) {
47         // Rotation is possible
48         if ($imgAspect > $paperAspect) {
49             $rotate = "90";
50             $imgAspect = 1 / $imgAspect;
51         }
52     }
53     
54     if ($imgAspect > $paperAspect) {
55         // wider than paper, fit width
56         $htmlAttrs = "width='95%'";
57     } else {
58         // taller than paper, fit height
59         $htmlAttrs = "height='95%'";
60     }
61
62     $file = sprintf("%s_%s/%s_%04d.%s", $id, $format, $id, $index, $format);
63     
64     $queryParams = array(
65         'id' => $id, // global
66         'format' => $format,
67         'index' => $index,
68         'file' => $file,
69         'zip' => $zip, // global
70         'rotate' => $rotate,
71         'scale' => 1
72     );
73
74     return "<img src='http://{$server}/GnuBook/GnuBookImages.php?" . http_build_query($queryParams) . "' " . $htmlAttrs . " />";
75 }
76
77 echo "<html><head>";
78 echo '<link rel="stylesheet" type="text/css" href="GnuBook.css" />';
79 echo "<style type='text/css'>";
80 echo "  @media print { .noprint { font-size: 40pt; display: none; } }";
81 echo "</style>";
82 echo "<title>" . $id . "</title><body onload='print(); return false;'>";
83 echo   "<p class='noprint' style='text-align: right'><button class='GBicon rollover print' title='Print' onclick='print(); return false;'></button> <a href='#' onclick='print(); return false;'>Print</a></p>";
84 echo   "<p style='text-align:center;'>";
85 echo     imageURL($paperAspect, $index, $format, $width, $height);
86 echo   "</p>";
87
88 if (isset($_REQUEST['index2'])) {    
89     $index2 = $_REQUEST['index2'];
90     $width2 = $_REQUEST['width2'];
91     $height2 = $_REQUST['height2'];
92     
93     
94     echo "<p style='text-align: center;'>";
95     echo imageURL($paperAspect, $index2, $format, $width2, $height2);
96     echo "</p>";
97 }
98 echo  "</body></html>";
99
100 ?>