Mercurial > hg > orthanc-stone
diff 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 |
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebApplication/print.js Mon Nov 16 22:17:01 2020 +0100 +++ b/Applications/StoneWebViewer/WebApplication/print.js Tue Nov 17 09:32:40 2020 +0100 @@ -23,32 +23,23 @@ var body = $('body'); body.addClass('print'); - // because firefox does not support/executes codes after the cloned document as been rendered - // https://bugzilla.mozilla.org/show_bug.cgi?format=default&id=1048317 - // we cannot calculate using the good body size for the clone document - // so we have to hardcode the body width (meaning we can only renders in A4 in firefox); - var uaParser = new UAParser(); - var isFirefox = (uaParser.getBrowser().name === 'Firefox'); - var isIE = (uaParser.getBrowser().name === 'IE'); - var isEdge = (uaParser.getBrowser().name === 'Edge'); - //console.log('ua parser', uaParser.getBrowser()); - - if (isFirefox || isIE || isEdge) { - if (0) { - // This is Letter - body.css('width', '8.5in'); - body.css('height', '11in'); - } else { - // This is A4 - body.css('width', '210mm'); - body.css('height', '296mm'); // If using "297mm", Firefox creates a second blank page - } + if (0) { + // This is Letter + body.css('width', '8.5in'); + body.css('height', '11in'); + } else { + // This is A4 + body.css('width', '210mm'); + body.css('height', '296mm'); // If using "297mm", Firefox creates a second blank page } + // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html + var realToCSSPixels = window.devicePixelRatio; + $('#viewport canvas').each(function(key, canvas) { if ($(canvas).is(':visible')) { - $(canvas).width($(canvas).parent().width()); - $(canvas).height($(canvas).parent().height()); + $(canvas).width(Math.floor(realToCSSPixels * $(canvas).get(0).clientWidth)); + $(canvas).height(Math.floor(realToCSSPixels * $(canvas).get(0).clientHeight)); } }); @@ -73,8 +64,7 @@ }); -var printMedia = window.matchMedia('print'); -printMedia.addListener(function(mql) { +window.matchMedia('print').addListener(function(mql) { if (mql.matches) { // webkit equivalent of onbeforeprint beforePrint();