annotate Applications/StoneWebViewer/Resources/Graveyard/print.js @ 2109:9aa99c45cfaa

fixed handling of DefineSourceBasenameForTarget
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 Dec 2023 21:46:19 +0100
parents 07964689cb0b
children c23eef785569
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
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
6 * Copyright (C) 2021-2023 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
1660
05b55b89a134 use local copy of open-sans, remove ua-parser
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
23 // DEPENDENCY: https://github.com/faisalman/ua-parser-js
05b55b89a134 use local copy of open-sans, remove ua-parser
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
24
05b55b89a134 use local copy of open-sans, remove ua-parser
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
25
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 function beforePrint(event){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 console.log('beforePrint');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 var $body = $('body');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 $body.addClass('print');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 // because firefox does not support/executes codes after the cloned document as been rendered
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 // https://bugzilla.mozilla.org/show_bug.cgi?format=default&id=1048317
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 // we cannot calculate using the good body size for the clone document
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 // so we have to hardcode the body width (meaning we can only renders in A4 in firefox);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 var uaParser = new UAParser();
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 var isFirefox = (uaParser.getBrowser().name === 'Firefox');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 var isIE = (uaParser.getBrowser().name === 'IE');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 var isEdge = (uaParser.getBrowser().name === 'Edge');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 console.log('ua parser', uaParser.getBrowser());
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 if(isFirefox || isIE || isEdge){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if (0) {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 // This is Letter
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 $body.css('width', '8.5in');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 $body.css('height', '11in');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 } else {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 // This is A4
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 //$body.css('width', '210mm');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 //$body.css('height', '297mm');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 $body.css('width', '210mm');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 $body.css('height', '297mm'); // Setting "297mm" makes Firefox create 2 pages
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 // console.log('html size', $html.width(), $html.height());
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if(isIE){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 window.alert('GENERAL_PARAGRAPHS.INCOMPATIBLE_PRINT_BROWSER');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 console.log('body size', $body.width(), $body.height());
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 var $splitpane = $('#viewport');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 var splitpaneSize = {width: $splitpane.width(), height: $splitpane.height()};
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 console.log(splitpaneSize);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 var panesCount = {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 x: app.layoutCountX,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 y: app.layoutCountY
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 var panes = [];
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 $('#viewport canvas').each(function(key, value) {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 if ($(value).is(':visible')) {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 console.log(value);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 panes.push(value);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 });
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 console.log(panesCount);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 if (0){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 for(var i = 0; i < panes.length; i++){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 var canvas = panes[i];
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 var paneSize = {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 originalWidth: $(canvas).width(), //canvas.getBoundingClientRect().width,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 originalHeight: $(canvas).height(), //canvas.getBoundingClientRect().height,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 originalRatio: 0,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 paneFinalWidth: splitpaneSize.width / panesCount.x,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 paneFinalHeight: splitpaneSize.height / panesCount.y,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 paneFinalRatio: 0,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 canvasFinalWidth: 0,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 canvasFinalHeight: 0,
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 canvasFinalRatio: 0
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 };
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 paneSize.originalRatio = paneSize.originalWidth / paneSize.originalHeight;
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 paneSize.paneFinalRatio = paneSize.paneFinalWidth / paneSize.paneFinalHeight;
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 if(paneSize.paneFinalRatio > 1){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 // If pane width ratio means it's width is larger than it's height
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 if(paneSize.paneFinalRatio > paneSize.originalRatio){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 // the final pane is larger than the original
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 // So we should fit on the height to recalc the ratio
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 console.log('case 1');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 paneSize.canvasFinalHeight = paneSize.paneFinalHeight;
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 paneSize.canvasFinalWidth = paneSize.canvasFinalHeight * paneSize.originalRatio; // Then we calc the width according the ratio
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 } else {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 // the final pane is higher than or equal to the original
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 // So we should fit on the width
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 console.log('case 2');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 paneSize.canvasFinalWidth = paneSize.paneFinalWidth;
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 paneSize.canvasFinalHeight = paneSize.canvasFinalWidth / paneSize.originalRatio; // Then we calc the width according the ratio
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 } else {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 // If pane width ratio means it's height is higher than it's height
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 if(paneSize.paneFinalRatio > paneSize.originalRatio){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 // the final pane is larger than the original
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 // So we should fit on the height to recalc the ratio
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 console.log('case 3');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 paneSize.canvasFinalHeight = paneSize.paneFinalHeight;
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 paneSize.canvasFinalWidth = paneSize.canvasFinalHeight * paneSize.originalRatio; // Then we calc the width according the ratio
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 } else {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 // the final pane is higher than or equal to the original
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 // So we should fit on the width
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 console.log('case 4');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 paneSize.canvasFinalWidth = paneSize.paneFinalWidth;
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 paneSize.canvasFinalHeight = paneSize.canvasFinalWidth / paneSize.originalRatio; // Then we calc the width according the ratio
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 paneSize.canvasFinalRatio = paneSize.canvasFinalWidth / paneSize.canvasFinalHeight;
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 console.log('paneSizes:', paneSize, 'splitpaneSize:', splitpaneSize, 'panesCount:', panesCount);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 //canvas.resizeCanvas(paneSize.canvasFinalWidth, paneSize.canvasFinalHeight);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 //canvas.draw();
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 console.log(paneSize.canvasFinalWidth + ' ' + paneSize.canvasFinalHeight);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 /*canvas.width = Math.round(paneSize.canvasFinalWidth);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 canvas.height = Math.round(paneSize.canvasFinalHeight);*/
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 $(canvas).width(paneSize.canvasFinalWidth);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 $(canvas).height(paneSize.canvasFinalHeight);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 /*
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 https://stackoverflow.com/questions/27863783/javascript-canvas-disappears-after-changing-width
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 var buffer = document.getElementById('buffer');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 var context = canvas.getContext('2d');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 console.log(context);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 var bufferContext = buffer.getContext('2d');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 console.log(bufferContext);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 bufferContext.drawImage(canvas, 0, 0); //Make a copy of the canvas to hidden buffer
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 canvas.width = Math.round(paneSize.canvasFinalWidth);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 canvas.height = Math.round(paneSize.canvasFinalHeight);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 context.drawImage(buffer, 0, 0); */
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 else {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 for(var i = 0; i < panes.length; i++){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 var canvas = panes[i];
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 $(canvas).width($(canvas).parent().width());
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 $(canvas).height($(canvas).parent().height());
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 stone.AllViewportsUpdateSize(false);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 $(window).trigger('resize'); // to force screen and canvas recalculation
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 };
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 function afterPrint(){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 console.log('afterprint');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 var $body = $('body');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 // var $html = $('html');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 $body.removeClass('print');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 $body.css('width', '100%');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 $body.css('height', '100%');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 $('#viewport canvas').css('width', '100%');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 $('#viewport canvas').css('height', '100%');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 stone.AllViewportsUpdateSize(false);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 $(window).trigger('resize'); // to force screen and canvas recalculation
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 window.addEventListener('beforeprint', function(event){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 beforePrint(event);
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 });
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 var printMedia = window.matchMedia('print');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 printMedia.addListener(function(mql) {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 if(mql.matches) {
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 console.log('webkit equivalent of onbeforeprint');
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 beforePrint();
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 });
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 window.addEventListener('afterprint', function(){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 afterPrint();
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 });$
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 /*vm.cancelPrintMode = function(){
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 afterPrint();
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 */