Mercurial > hg > orthanc-stone
annotate Applications/StoneWebViewer/WebApplication/print.js @ 1735:2bb735d76726
fix CMake for wasm samples
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 03 Dec 2020 07:22:00 +0100 |
parents | 66e5fcdf5597 |
children | 9ac2a65d4172 |
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 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
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 |
1575 | 22 function beforePrint(event) { |
23 var body = $('body'); | |
24 body.addClass('print'); | |
1562 | 25 |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
26 if (0) { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
27 // This is Letter |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
28 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
|
29 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
|
30 } else { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
31 // This is A4 |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
32 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
|
33 body.css('height', '296mm'); // If using "297mm", Firefox creates a second blank page |
1562 | 34 } |
35 | |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
36 // 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
|
37 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
|
38 |
1657
66e5fcdf5597
pdf viewer is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1654
diff
changeset
|
39 $('.viewport-canvas').each(function(key, canvas) { |
1575 | 40 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
|
41 $(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
|
42 $(canvas).height(Math.floor(realToCSSPixels * $(canvas).get(0).clientHeight)); |
1563 | 43 } |
44 }); | |
1562 | 45 |
1575 | 46 stone.FitForPrint(); |
47 }; | |
1563 | 48 |
49 | |
1575 | 50 function afterPrint() { |
51 var body = $('body'); | |
52 body.removeClass('print'); | |
53 body.css('width', '100%'); | |
54 body.css('height', '100%'); | |
1657
66e5fcdf5597
pdf viewer is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1654
diff
changeset
|
55 $('.viewport-canvas').css('width', '100%'); |
66e5fcdf5597
pdf viewer is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1654
diff
changeset
|
56 $('.viewport-canvas').css('height', '100%'); |
1575 | 57 |
58 stone.FitForPrint(); | |
1562 | 59 } |
60 | |
1575 | 61 |
62 window.addEventListener('beforeprint', function(event) { | |
63 beforePrint(event); | |
1563 | 64 }); |
65 | |
1575 | 66 |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
67 window.matchMedia('print').addListener(function(mql) { |
1575 | 68 if (mql.matches) { |
69 // webkit equivalent of onbeforeprint | |
1562 | 70 beforePrint(); |
71 } | |
72 }); | |
73 | |
1575 | 74 |
75 window.addEventListener('afterprint', function() { | |
1562 | 76 afterPrint(); |
1575 | 77 }); |
1562 | 78 |
1575 | 79 |
80 /*vm.cancelPrintMode = function() { | |
1562 | 81 afterPrint(); |
82 } | |
83 */ |