Mercurial > hg > orthanc-stone
annotate Applications/StoneWebViewer/Resources/Graveyard/print.js @ 2004:6a96a1920fd8
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 02 Nov 2022 15:29:01 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
1 /** |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
2 * Stone of Orthanc |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
7 * |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
9 * modify it under the terms of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
11 * the License, or (at your option) any later version. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
12 * |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
16 * Affero General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
17 * |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
18 * You should have received a copy of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
20 **/ |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
21 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
22 |
1660
05b55b89a134
use local copy of open-sans, remove ua-parser
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
23 // DEPENDENCY: https://github.com/faisalman/ua-parser-js |
05b55b89a134
use local copy of open-sans, remove ua-parser
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
24 |
05b55b89a134
use local copy of open-sans, remove ua-parser
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
25 |
1575 | 26 function beforePrint(event){ |
27 console.log('beforePrint'); | |
28 var $body = $('body'); | |
29 $body.addClass('print'); | |
30 | |
31 // because firefox does not support/executes codes after the cloned document as been rendered | |
32 // https://bugzilla.mozilla.org/show_bug.cgi?format=default&id=1048317 | |
33 // we cannot calculate using the good body size for the clone document | |
34 // so we have to hardcode the body width (meaning we can only renders in A4 in firefox); | |
35 var uaParser = new UAParser(); | |
36 var isFirefox = (uaParser.getBrowser().name === 'Firefox'); | |
37 var isIE = (uaParser.getBrowser().name === 'IE'); | |
38 var isEdge = (uaParser.getBrowser().name === 'Edge'); | |
39 console.log('ua parser', uaParser.getBrowser()); | |
40 if(isFirefox || isIE || isEdge){ | |
41 if (0) { | |
42 // This is Letter | |
43 $body.css('width', '8.5in'); | |
44 $body.css('height', '11in'); | |
45 } else { | |
46 // This is A4 | |
47 //$body.css('width', '210mm'); | |
48 //$body.css('height', '297mm'); | |
49 $body.css('width', '210mm'); | |
50 $body.css('height', '297mm'); // Setting "297mm" makes Firefox create 2 pages | |
51 } | |
52 | |
53 // console.log('html size', $html.width(), $html.height()); | |
54 } | |
55 | |
56 if(isIE){ | |
57 window.alert('GENERAL_PARAGRAPHS.INCOMPATIBLE_PRINT_BROWSER'); | |
58 } | |
59 | |
60 console.log('body size', $body.width(), $body.height()); | |
61 | |
62 var $splitpane = $('#viewport'); | |
63 var splitpaneSize = {width: $splitpane.width(), height: $splitpane.height()}; | |
64 console.log(splitpaneSize); | |
65 var panesCount = { | |
66 x: app.layoutCountX, | |
67 y: app.layoutCountY | |
68 } | |
69 | |
70 var panes = []; | |
71 $('#viewport canvas').each(function(key, value) { | |
72 if ($(value).is(':visible')) { | |
73 console.log(value); | |
74 panes.push(value); | |
75 } | |
76 }); | |
77 | |
78 console.log(panesCount); | |
79 | |
80 if (0){ | |
81 for(var i = 0; i < panes.length; i++){ | |
82 var canvas = panes[i]; | |
83 var paneSize = { | |
84 originalWidth: $(canvas).width(), //canvas.getBoundingClientRect().width, | |
85 originalHeight: $(canvas).height(), //canvas.getBoundingClientRect().height, | |
86 originalRatio: 0, | |
87 paneFinalWidth: splitpaneSize.width / panesCount.x, | |
88 paneFinalHeight: splitpaneSize.height / panesCount.y, | |
89 paneFinalRatio: 0, | |
90 canvasFinalWidth: 0, | |
91 canvasFinalHeight: 0, | |
92 canvasFinalRatio: 0 | |
93 }; | |
94 paneSize.originalRatio = paneSize.originalWidth / paneSize.originalHeight; | |
95 paneSize.paneFinalRatio = paneSize.paneFinalWidth / paneSize.paneFinalHeight; | |
96 | |
97 if(paneSize.paneFinalRatio > 1){ | |
98 // If pane width ratio means it's width is larger than it's height | |
99 if(paneSize.paneFinalRatio > paneSize.originalRatio){ | |
100 // the final pane is larger than the original | |
101 // So we should fit on the height to recalc the ratio | |
102 console.log('case 1'); | |
103 paneSize.canvasFinalHeight = paneSize.paneFinalHeight; | |
104 paneSize.canvasFinalWidth = paneSize.canvasFinalHeight * paneSize.originalRatio; // Then we calc the width according the ratio | |
105 } else { | |
106 // the final pane is higher than or equal to the original | |
107 // So we should fit on the width | |
108 console.log('case 2'); | |
109 paneSize.canvasFinalWidth = paneSize.paneFinalWidth; | |
110 paneSize.canvasFinalHeight = paneSize.canvasFinalWidth / paneSize.originalRatio; // Then we calc the width according the ratio | |
111 | |
112 } | |
113 } else { | |
114 // If pane width ratio means it's height is higher than it's height | |
115 if(paneSize.paneFinalRatio > paneSize.originalRatio){ | |
116 // the final pane is larger than the original | |
117 // So we should fit on the height to recalc the ratio | |
118 console.log('case 3'); | |
119 paneSize.canvasFinalHeight = paneSize.paneFinalHeight; | |
120 paneSize.canvasFinalWidth = paneSize.canvasFinalHeight * paneSize.originalRatio; // Then we calc the width according the ratio | |
121 } else { | |
122 // the final pane is higher than or equal to the original | |
123 // So we should fit on the width | |
124 console.log('case 4'); | |
125 paneSize.canvasFinalWidth = paneSize.paneFinalWidth; | |
126 paneSize.canvasFinalHeight = paneSize.canvasFinalWidth / paneSize.originalRatio; // Then we calc the width according the ratio | |
127 | |
128 } | |
129 } | |
130 | |
131 paneSize.canvasFinalRatio = paneSize.canvasFinalWidth / paneSize.canvasFinalHeight; | |
132 console.log('paneSizes:', paneSize, 'splitpaneSize:', splitpaneSize, 'panesCount:', panesCount); | |
133 //canvas.resizeCanvas(paneSize.canvasFinalWidth, paneSize.canvasFinalHeight); | |
134 //canvas.draw(); | |
135 | |
136 console.log(paneSize.canvasFinalWidth + ' ' + paneSize.canvasFinalHeight); | |
137 /*canvas.width = Math.round(paneSize.canvasFinalWidth); | |
138 canvas.height = Math.round(paneSize.canvasFinalHeight);*/ | |
139 | |
140 $(canvas).width(paneSize.canvasFinalWidth); | |
141 $(canvas).height(paneSize.canvasFinalHeight); | |
142 | |
143 | |
144 /* | |
145 https://stackoverflow.com/questions/27863783/javascript-canvas-disappears-after-changing-width | |
146 | |
147 var buffer = document.getElementById('buffer'); | |
148 var context = canvas.getContext('2d'); | |
149 console.log(context); | |
150 var bufferContext = buffer.getContext('2d'); | |
151 console.log(bufferContext); | |
152 | |
153 bufferContext.drawImage(canvas, 0, 0); //Make a copy of the canvas to hidden buffer | |
154 canvas.width = Math.round(paneSize.canvasFinalWidth); | |
155 canvas.height = Math.round(paneSize.canvasFinalHeight); | |
156 context.drawImage(buffer, 0, 0); */ | |
157 } | |
158 } | |
159 else { | |
160 for(var i = 0; i < panes.length; i++){ | |
161 var canvas = panes[i]; | |
162 $(canvas).width($(canvas).parent().width()); | |
163 $(canvas).height($(canvas).parent().height()); | |
164 } | |
165 } | |
166 | |
167 stone.AllViewportsUpdateSize(false); | |
168 $(window).trigger('resize'); // to force screen and canvas recalculation | |
169 }; | |
170 | |
171 function afterPrint(){ | |
172 console.log('afterprint'); | |
173 var $body = $('body'); | |
174 // var $html = $('html'); | |
175 $body.removeClass('print'); | |
176 $body.css('width', '100%'); | |
177 $body.css('height', '100%'); | |
178 $('#viewport canvas').css('width', '100%'); | |
179 $('#viewport canvas').css('height', '100%'); | |
180 stone.AllViewportsUpdateSize(false); | |
181 $(window).trigger('resize'); // to force screen and canvas recalculation | |
182 } | |
183 | |
184 window.addEventListener('beforeprint', function(event){ | |
185 beforePrint(event); | |
186 }); | |
187 | |
188 var printMedia = window.matchMedia('print'); | |
189 printMedia.addListener(function(mql) { | |
190 if(mql.matches) { | |
191 console.log('webkit equivalent of onbeforeprint'); | |
192 beforePrint(); | |
193 } | |
194 }); | |
195 | |
196 window.addEventListener('afterprint', function(){ | |
197 afterPrint(); | |
198 });$ | |
199 | |
200 /*vm.cancelPrintMode = function(){ | |
201 afterPrint(); | |
202 } | |
203 */ |