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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
23 function beforePrint(event) {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
24 var body = $('body');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
25 body.addClass('print');
1562
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 }
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
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
e0045462a25c cont print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
44 }
e0045462a25c cont print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
45 });
1562
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
47 stone.FitForPrint();
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
48 };
1563
e0045462a25c cont print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
49
e0045462a25c cont print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
50
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
51 function afterPrint() {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
52 var body = $('body');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
53 body.removeClass('print');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
54 body.css('width', '100%');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
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
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
58
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
59 stone.FitForPrint();
1562
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
62
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
63 window.addEventListener('beforeprint', function(event) {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
64 beforePrint(event);
1563
e0045462a25c cont print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
65 });
e0045462a25c cont print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
66
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
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
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
69 if (mql.matches) {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
70 // webkit equivalent of onbeforeprint
1562
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 beforePrint();
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 });
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
75
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
76 window.addEventListener('afterprint', function() {
1562
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 afterPrint();
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
78 });
1562
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
80
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1563
diff changeset
81 /*vm.cancelPrintMode = function() {
1562
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 afterPrint();
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
2a4a6b967053 starting work on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 */