Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/WebApplication/print.js @ 1654:39137da83b0b
fix print.js, no need for ua-parser.js anymore
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Nov 2020 09:32:40 +0100 |
parents | 4fb8fdf03314 |
children | 66e5fcdf5597 |
comparison
equal
deleted
inserted
replaced
1653:2e3b2ed239b9 | 1654:39137da83b0b |
---|---|
21 | 21 |
22 function beforePrint(event) { | 22 function beforePrint(event) { |
23 var body = $('body'); | 23 var body = $('body'); |
24 body.addClass('print'); | 24 body.addClass('print'); |
25 | 25 |
26 // because firefox does not support/executes codes after the cloned document as been rendered | 26 if (0) { |
27 // https://bugzilla.mozilla.org/show_bug.cgi?format=default&id=1048317 | 27 // This is Letter |
28 // we cannot calculate using the good body size for the clone document | 28 body.css('width', '8.5in'); |
29 // so we have to hardcode the body width (meaning we can only renders in A4 in firefox); | 29 body.css('height', '11in'); |
30 var uaParser = new UAParser(); | 30 } else { |
31 var isFirefox = (uaParser.getBrowser().name === 'Firefox'); | 31 // This is A4 |
32 var isIE = (uaParser.getBrowser().name === 'IE'); | 32 body.css('width', '210mm'); |
33 var isEdge = (uaParser.getBrowser().name === 'Edge'); | 33 body.css('height', '296mm'); // If using "297mm", Firefox creates a second blank page |
34 //console.log('ua parser', uaParser.getBrowser()); | |
35 | |
36 if (isFirefox || isIE || isEdge) { | |
37 if (0) { | |
38 // This is Letter | |
39 body.css('width', '8.5in'); | |
40 body.css('height', '11in'); | |
41 } else { | |
42 // This is A4 | |
43 body.css('width', '210mm'); | |
44 body.css('height', '296mm'); // If using "297mm", Firefox creates a second blank page | |
45 } | |
46 } | 34 } |
35 | |
36 // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html | |
37 var realToCSSPixels = window.devicePixelRatio; | |
47 | 38 |
48 $('#viewport canvas').each(function(key, canvas) { | 39 $('#viewport canvas').each(function(key, canvas) { |
49 if ($(canvas).is(':visible')) { | 40 if ($(canvas).is(':visible')) { |
50 $(canvas).width($(canvas).parent().width()); | 41 $(canvas).width(Math.floor(realToCSSPixels * $(canvas).get(0).clientWidth)); |
51 $(canvas).height($(canvas).parent().height()); | 42 $(canvas).height(Math.floor(realToCSSPixels * $(canvas).get(0).clientHeight)); |
52 } | 43 } |
53 }); | 44 }); |
54 | 45 |
55 stone.FitForPrint(); | 46 stone.FitForPrint(); |
56 }; | 47 }; |
71 window.addEventListener('beforeprint', function(event) { | 62 window.addEventListener('beforeprint', function(event) { |
72 beforePrint(event); | 63 beforePrint(event); |
73 }); | 64 }); |
74 | 65 |
75 | 66 |
76 var printMedia = window.matchMedia('print'); | 67 window.matchMedia('print').addListener(function(mql) { |
77 printMedia.addListener(function(mql) { | |
78 if (mql.matches) { | 68 if (mql.matches) { |
79 // webkit equivalent of onbeforeprint | 69 // webkit equivalent of onbeforeprint |
80 beforePrint(); | 70 beforePrint(); |
81 } | 71 } |
82 }); | 72 }); |