Mercurial > hg > orthanc-stone
annotate Applications/StoneWebViewer/WebApplication/print.js @ 2052:d77fea5934fb
cleanup todo
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 Mar 2023 17:20:01 +0200 |
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 |
1575 | 23 function beforePrint(event) { |
24 var body = $('body'); | |
25 body.addClass('print'); | |
1562 | 26 |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
27 if (0) { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
28 // This is Letter |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
29 body.css('width', '8.5in'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
30 body.css('height', '11in'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
31 } else { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
32 // This is A4 |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
33 body.css('width', '210mm'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
34 body.css('height', '296mm'); // If using "297mm", Firefox creates a second blank page |
1562 | 35 } |
36 | |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
37 // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
38 var realToCSSPixels = window.devicePixelRatio; |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
39 |
1657
66e5fcdf5597
pdf viewer is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1654
diff
changeset
|
40 $('.viewport-canvas').each(function(key, canvas) { |
1575 | 41 if ($(canvas).is(':visible')) { |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
42 $(canvas).width(Math.floor(realToCSSPixels * $(canvas).get(0).clientWidth)); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
43 $(canvas).height(Math.floor(realToCSSPixels * $(canvas).get(0).clientHeight)); |
1563 | 44 } |
45 }); | |
1562 | 46 |
1575 | 47 stone.FitForPrint(); |
48 }; | |
1563 | 49 |
50 | |
1575 | 51 function afterPrint() { |
52 var body = $('body'); | |
53 body.removeClass('print'); | |
54 body.css('width', '100%'); | |
55 body.css('height', '100%'); | |
1657
66e5fcdf5597
pdf viewer is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1654
diff
changeset
|
56 $('.viewport-canvas').css('width', '100%'); |
66e5fcdf5597
pdf viewer is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1654
diff
changeset
|
57 $('.viewport-canvas').css('height', '100%'); |
1575 | 58 |
59 stone.FitForPrint(); | |
1562 | 60 } |
61 | |
1575 | 62 |
63 window.addEventListener('beforeprint', function(event) { | |
64 beforePrint(event); | |
1563 | 65 }); |
66 | |
1575 | 67 |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
68 window.matchMedia('print').addListener(function(mql) { |
1575 | 69 if (mql.matches) { |
70 // webkit equivalent of onbeforeprint | |
1562 | 71 beforePrint(); |
72 } | |
73 }); | |
74 | |
1575 | 75 |
76 window.addEventListener('afterprint', function() { | |
1562 | 77 afterPrint(); |
1575 | 78 }); |
1562 | 79 |
1575 | 80 |
81 /*vm.cancelPrintMode = function() { | |
1562 | 82 afterPrint(); |
83 } | |
84 */ |