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