pdfjs-dist 2.0.943 → 2.4.456
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,126 +19,147 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.PDFPrintService =
|
27
|
+
exports.PDFPrintService = PDFPrintService;
|
28
28
|
|
29
|
-
var _ui_utils = require(
|
29
|
+
var _ui_utils = require("./ui_utils.js");
|
30
30
|
|
31
|
-
var _app = require(
|
31
|
+
var _app = require("./app.js");
|
32
32
|
|
33
|
-
var
|
33
|
+
var _app_options = require("./app_options.js");
|
34
|
+
|
35
|
+
let activeService = null;
|
36
|
+
let overlayManager = null;
|
34
37
|
|
35
|
-
var activeService = null;
|
36
|
-
var overlayManager = null;
|
37
38
|
function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size) {
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
const scratchCanvas = activeService.scratchCanvas;
|
40
|
+
const PRINT_RESOLUTION = _app_options.AppOptions.get("printResolution") || 150;
|
41
|
+
const PRINT_UNITS = PRINT_RESOLUTION / 72.0;
|
41
42
|
scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
|
42
43
|
scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
const width = Math.floor(size.width * _ui_utils.CSS_UNITS) + "px";
|
45
|
+
const height = Math.floor(size.height * _ui_utils.CSS_UNITS) + "px";
|
46
|
+
const ctx = scratchCanvas.getContext("2d");
|
46
47
|
ctx.save();
|
47
|
-
ctx.fillStyle =
|
48
|
+
ctx.fillStyle = "rgb(255, 255, 255)";
|
48
49
|
ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
|
49
50
|
ctx.restore();
|
50
51
|
return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
|
51
|
-
|
52
|
+
const renderContext = {
|
52
53
|
canvasContext: ctx,
|
53
54
|
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
|
54
|
-
viewport: pdfPage.getViewport(
|
55
|
-
|
55
|
+
viewport: pdfPage.getViewport({
|
56
|
+
scale: 1,
|
57
|
+
rotation: size.rotation
|
58
|
+
}),
|
59
|
+
intent: "print"
|
56
60
|
};
|
57
61
|
return pdfPage.render(renderContext).promise;
|
58
62
|
}).then(function () {
|
59
63
|
return {
|
60
|
-
width
|
61
|
-
height
|
64
|
+
width,
|
65
|
+
height
|
62
66
|
};
|
63
67
|
});
|
64
68
|
}
|
69
|
+
|
65
70
|
function PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n) {
|
66
71
|
this.pdfDocument = pdfDocument;
|
67
72
|
this.pagesOverview = pagesOverview;
|
68
73
|
this.printContainer = printContainer;
|
69
74
|
this.l10n = l10n || _ui_utils.NullL10n;
|
70
|
-
this.disableCreateObjectURL = pdfDocument.loadingParams[
|
75
|
+
this.disableCreateObjectURL = pdfDocument.loadingParams["disableCreateObjectURL"];
|
71
76
|
this.currentPage = -1;
|
72
|
-
this.scratchCanvas = document.createElement(
|
77
|
+
this.scratchCanvas = document.createElement("canvas");
|
73
78
|
}
|
79
|
+
|
74
80
|
PDFPrintService.prototype = {
|
75
|
-
layout
|
81
|
+
layout() {
|
76
82
|
this.throwIfInactive();
|
77
|
-
|
78
|
-
body.setAttribute(
|
79
|
-
|
83
|
+
const body = document.querySelector("body");
|
84
|
+
body.setAttribute("data-pdfjsprinting", true);
|
85
|
+
const hasEqualPageSizes = this.pagesOverview.every(function (size) {
|
80
86
|
return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
|
81
87
|
}, this);
|
88
|
+
|
82
89
|
if (!hasEqualPageSizes) {
|
83
|
-
console.warn(
|
90
|
+
console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
|
84
91
|
}
|
85
|
-
|
86
|
-
|
87
|
-
|
92
|
+
|
93
|
+
this.pageStyleSheet = document.createElement("style");
|
94
|
+
const pageSize = this.pagesOverview[0];
|
95
|
+
this.pageStyleSheet.textContent = "@supports ((size:A4) and (size:1pt 1pt)) {" + "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}" + "}";
|
88
96
|
body.appendChild(this.pageStyleSheet);
|
89
97
|
},
|
90
|
-
|
98
|
+
|
99
|
+
destroy() {
|
91
100
|
if (activeService !== this) {
|
92
101
|
return;
|
93
102
|
}
|
94
|
-
|
103
|
+
|
104
|
+
this.printContainer.textContent = "";
|
105
|
+
const body = document.querySelector("body");
|
106
|
+
body.removeAttribute("data-pdfjsprinting");
|
107
|
+
|
95
108
|
if (this.pageStyleSheet) {
|
96
109
|
this.pageStyleSheet.remove();
|
97
110
|
this.pageStyleSheet = null;
|
98
111
|
}
|
112
|
+
|
99
113
|
this.scratchCanvas.width = this.scratchCanvas.height = 0;
|
100
114
|
this.scratchCanvas = null;
|
101
115
|
activeService = null;
|
102
116
|
ensureOverlay().then(function () {
|
103
|
-
if (overlayManager.active !==
|
117
|
+
if (overlayManager.active !== "printServiceOverlay") {
|
104
118
|
return;
|
105
119
|
}
|
106
|
-
|
120
|
+
|
121
|
+
overlayManager.close("printServiceOverlay");
|
107
122
|
});
|
108
123
|
},
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
124
|
+
|
125
|
+
renderPages() {
|
126
|
+
const pageCount = this.pagesOverview.length;
|
127
|
+
|
128
|
+
const renderNextPage = (resolve, reject) => {
|
129
|
+
this.throwIfInactive();
|
130
|
+
|
131
|
+
if (++this.currentPage >= pageCount) {
|
132
|
+
renderProgress(pageCount, pageCount, this.l10n);
|
117
133
|
resolve();
|
118
134
|
return;
|
119
135
|
}
|
120
|
-
|
121
|
-
|
122
|
-
|
136
|
+
|
137
|
+
const index = this.currentPage;
|
138
|
+
renderProgress(index, pageCount, this.l10n);
|
139
|
+
renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index]).then(this.useRenderedPage.bind(this)).then(function () {
|
123
140
|
renderNextPage(resolve, reject);
|
124
141
|
}, reject);
|
125
142
|
};
|
143
|
+
|
126
144
|
return new Promise(renderNextPage);
|
127
145
|
},
|
128
|
-
|
146
|
+
|
147
|
+
useRenderedPage(printItem) {
|
129
148
|
this.throwIfInactive();
|
130
|
-
|
149
|
+
const img = document.createElement("img");
|
131
150
|
img.style.width = printItem.width;
|
132
151
|
img.style.height = printItem.height;
|
133
|
-
|
134
|
-
|
152
|
+
const scratchCanvas = this.scratchCanvas;
|
153
|
+
|
154
|
+
if ("toBlob" in scratchCanvas && !this.disableCreateObjectURL) {
|
135
155
|
scratchCanvas.toBlob(function (blob) {
|
136
|
-
img.src =
|
156
|
+
img.src = URL.createObjectURL(blob);
|
137
157
|
});
|
138
158
|
} else {
|
139
159
|
img.src = scratchCanvas.toDataURL();
|
140
160
|
}
|
141
|
-
|
161
|
+
|
162
|
+
const wrapper = document.createElement("div");
|
142
163
|
wrapper.appendChild(img);
|
143
164
|
this.printContainer.appendChild(wrapper);
|
144
165
|
return new Promise(function (resolve, reject) {
|
@@ -146,16 +167,16 @@ PDFPrintService.prototype = {
|
|
146
167
|
img.onerror = reject;
|
147
168
|
});
|
148
169
|
},
|
149
|
-
performPrint: function performPrint() {
|
150
|
-
var _this2 = this;
|
151
170
|
|
171
|
+
performPrint() {
|
152
172
|
this.throwIfInactive();
|
153
|
-
return new Promise(
|
154
|
-
setTimeout(
|
155
|
-
if (!
|
173
|
+
return new Promise(resolve => {
|
174
|
+
setTimeout(() => {
|
175
|
+
if (!this.active) {
|
156
176
|
resolve();
|
157
177
|
return;
|
158
178
|
}
|
179
|
+
|
159
180
|
print.call(window);
|
160
181
|
setTimeout(resolve, 20);
|
161
182
|
}, 0);
|
@@ -165,36 +186,42 @@ PDFPrintService.prototype = {
|
|
165
186
|
get active() {
|
166
187
|
return this === activeService;
|
167
188
|
},
|
168
|
-
|
189
|
+
|
190
|
+
throwIfInactive() {
|
169
191
|
if (!this.active) {
|
170
|
-
throw new Error(
|
192
|
+
throw new Error("This print request was cancelled or completed.");
|
171
193
|
}
|
172
194
|
}
|
195
|
+
|
173
196
|
};
|
174
|
-
|
175
|
-
|
197
|
+
const print = window.print;
|
198
|
+
|
199
|
+
window.print = function () {
|
176
200
|
if (activeService) {
|
177
|
-
console.warn(
|
201
|
+
console.warn("Ignored window.print() because of a pending print job.");
|
178
202
|
return;
|
179
203
|
}
|
204
|
+
|
180
205
|
ensureOverlay().then(function () {
|
181
206
|
if (activeService) {
|
182
|
-
overlayManager.open(
|
207
|
+
overlayManager.open("printServiceOverlay");
|
183
208
|
}
|
184
209
|
});
|
210
|
+
|
185
211
|
try {
|
186
|
-
dispatchEvent(
|
212
|
+
dispatchEvent("beforeprint");
|
187
213
|
} finally {
|
188
214
|
if (!activeService) {
|
189
|
-
console.error(
|
215
|
+
console.error("Expected print service to be initialized.");
|
190
216
|
ensureOverlay().then(function () {
|
191
|
-
if (overlayManager.active ===
|
192
|
-
overlayManager.close(
|
217
|
+
if (overlayManager.active === "printServiceOverlay") {
|
218
|
+
overlayManager.close("printServiceOverlay");
|
193
219
|
}
|
194
220
|
});
|
195
221
|
return;
|
196
222
|
}
|
197
|
-
|
223
|
+
|
224
|
+
const activeServiceOnEntry = activeService;
|
198
225
|
activeService.renderPages().then(function () {
|
199
226
|
return activeServiceOnEntry.performPrint();
|
200
227
|
}).catch(function () {}).then(function () {
|
@@ -204,81 +231,84 @@ window.print = function print() {
|
|
204
231
|
});
|
205
232
|
}
|
206
233
|
};
|
234
|
+
|
207
235
|
function dispatchEvent(eventType) {
|
208
|
-
|
209
|
-
event.initCustomEvent(eventType, false, false,
|
236
|
+
const event = document.createEvent("CustomEvent");
|
237
|
+
event.initCustomEvent(eventType, false, false, "custom");
|
210
238
|
window.dispatchEvent(event);
|
211
239
|
}
|
240
|
+
|
212
241
|
function abort() {
|
213
242
|
if (activeService) {
|
214
243
|
activeService.destroy();
|
215
|
-
dispatchEvent(
|
244
|
+
dispatchEvent("afterprint");
|
216
245
|
}
|
217
246
|
}
|
247
|
+
|
218
248
|
function renderProgress(index, total, l10n) {
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
249
|
+
const progressContainer = document.getElementById("printServiceOverlay");
|
250
|
+
const progress = Math.round(100 * index / total);
|
251
|
+
const progressBar = progressContainer.querySelector("progress");
|
252
|
+
const progressPerc = progressContainer.querySelector(".relative-progress");
|
223
253
|
progressBar.value = progress;
|
224
|
-
l10n.get(
|
254
|
+
l10n.get("print_progress_percent", {
|
255
|
+
progress
|
256
|
+
}, progress + "%").then(msg => {
|
225
257
|
progressPerc.textContent = msg;
|
226
258
|
});
|
227
259
|
}
|
228
|
-
|
229
|
-
window.addEventListener(
|
260
|
+
|
261
|
+
window.addEventListener("keydown", function (event) {
|
230
262
|
if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
|
231
263
|
window.print();
|
232
|
-
if (hasAttachEvent) {
|
233
|
-
return;
|
234
|
-
}
|
235
264
|
event.preventDefault();
|
265
|
+
|
236
266
|
if (event.stopImmediatePropagation) {
|
237
267
|
event.stopImmediatePropagation();
|
238
268
|
} else {
|
239
269
|
event.stopPropagation();
|
240
270
|
}
|
241
|
-
return;
|
242
271
|
}
|
243
272
|
}, true);
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
if (event.
|
248
|
-
event.keyCode = 0;
|
249
|
-
return false;
|
250
|
-
}
|
251
|
-
});
|
252
|
-
}
|
253
|
-
if ('onbeforeprint' in window) {
|
254
|
-
var stopPropagationIfNeeded = function stopPropagationIfNeeded(event) {
|
255
|
-
if (event.detail !== 'custom' && event.stopImmediatePropagation) {
|
273
|
+
|
274
|
+
if ("onbeforeprint" in window) {
|
275
|
+
const stopPropagationIfNeeded = function (event) {
|
276
|
+
if (event.detail !== "custom" && event.stopImmediatePropagation) {
|
256
277
|
event.stopImmediatePropagation();
|
257
278
|
}
|
258
279
|
};
|
259
|
-
|
260
|
-
window.addEventListener(
|
280
|
+
|
281
|
+
window.addEventListener("beforeprint", stopPropagationIfNeeded);
|
282
|
+
window.addEventListener("afterprint", stopPropagationIfNeeded);
|
261
283
|
}
|
262
|
-
|
284
|
+
|
285
|
+
let overlayPromise;
|
286
|
+
|
263
287
|
function ensureOverlay() {
|
264
288
|
if (!overlayPromise) {
|
265
289
|
overlayManager = _app.PDFViewerApplication.overlayManager;
|
290
|
+
|
266
291
|
if (!overlayManager) {
|
267
|
-
throw new Error(
|
292
|
+
throw new Error("The overlay manager has not yet been initialized.");
|
268
293
|
}
|
269
|
-
|
270
|
-
document.getElementById(
|
294
|
+
|
295
|
+
overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
|
296
|
+
document.getElementById("printCancel").onclick = abort;
|
271
297
|
}
|
298
|
+
|
272
299
|
return overlayPromise;
|
273
300
|
}
|
301
|
+
|
274
302
|
_app.PDFPrintServiceFactory.instance = {
|
275
303
|
supportsPrinting: true,
|
276
|
-
|
304
|
+
|
305
|
+
createPrintService(pdfDocument, pagesOverview, printContainer, l10n) {
|
277
306
|
if (activeService) {
|
278
|
-
throw new Error(
|
307
|
+
throw new Error("The print service is created and active.");
|
279
308
|
}
|
309
|
+
|
280
310
|
activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n);
|
281
311
|
return activeService;
|
282
312
|
}
|
283
|
-
|
284
|
-
|
313
|
+
|
314
|
+
};
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -24,23 +24,18 @@
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
31
|
-
|
32
|
-
var CLEANUP_TIMEOUT = 30000;
|
33
|
-
var RenderingStates = {
|
27
|
+
exports.PDFRenderingQueue = exports.RenderingStates = void 0;
|
28
|
+
const CLEANUP_TIMEOUT = 30000;
|
29
|
+
const RenderingStates = {
|
34
30
|
INITIAL: 0,
|
35
31
|
RUNNING: 1,
|
36
32
|
PAUSED: 2,
|
37
33
|
FINISHED: 3
|
38
34
|
};
|
35
|
+
exports.RenderingStates = RenderingStates;
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
_classCallCheck(this, PDFRenderingQueue);
|
43
|
-
|
37
|
+
class PDFRenderingQueue {
|
38
|
+
constructor() {
|
44
39
|
this.pdfViewer = null;
|
45
40
|
this.pdfThumbnailViewer = null;
|
46
41
|
this.onIdle = null;
|
@@ -50,104 +45,107 @@ var PDFRenderingQueue = function () {
|
|
50
45
|
this.isThumbnailViewEnabled = false;
|
51
46
|
}
|
52
47
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
setViewer(pdfViewer) {
|
49
|
+
this.pdfViewer = pdfViewer;
|
50
|
+
}
|
51
|
+
|
52
|
+
setThumbnailViewer(pdfThumbnailViewer) {
|
53
|
+
this.pdfThumbnailViewer = pdfThumbnailViewer;
|
54
|
+
}
|
55
|
+
|
56
|
+
isHighestPriority(view) {
|
57
|
+
return this.highestPriorityPage === view.renderingId;
|
58
|
+
}
|
59
|
+
|
60
|
+
renderHighestPriority(currentlyVisiblePages) {
|
61
|
+
if (this.idleTimeout) {
|
62
|
+
clearTimeout(this.idleTimeout);
|
63
|
+
this.idleTimeout = null;
|
62
64
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
return this.highestPriorityPage === view.renderingId;
|
65
|
+
|
66
|
+
if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
|
67
|
+
return;
|
67
68
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
if (this.idleTimeout) {
|
72
|
-
clearTimeout(this.idleTimeout);
|
73
|
-
this.idleTimeout = null;
|
74
|
-
}
|
75
|
-
if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
|
76
|
-
return;
|
77
|
-
}
|
78
|
-
if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
|
79
|
-
if (this.pdfThumbnailViewer.forceRendering()) {
|
80
|
-
return;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
if (this.printing) {
|
69
|
+
|
70
|
+
if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
|
71
|
+
if (this.pdfThumbnailViewer.forceRendering()) {
|
84
72
|
return;
|
85
73
|
}
|
86
|
-
if (this.onIdle) {
|
87
|
-
this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
|
88
|
-
}
|
89
74
|
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
var nextPageIndex = visible.last.id;
|
106
|
-
if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
|
107
|
-
return views[nextPageIndex];
|
108
|
-
}
|
109
|
-
} else {
|
110
|
-
var previousPageIndex = visible.first.id - 2;
|
111
|
-
if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
|
112
|
-
return views[previousPageIndex];
|
113
|
-
}
|
114
|
-
}
|
75
|
+
|
76
|
+
if (this.printing) {
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (this.onIdle) {
|
81
|
+
this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
getHighestPriority(visible, views, scrolledDown) {
|
86
|
+
const visibleViews = visible.views;
|
87
|
+
const numVisible = visibleViews.length;
|
88
|
+
|
89
|
+
if (numVisible === 0) {
|
115
90
|
return null;
|
116
91
|
}
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
92
|
+
|
93
|
+
for (let i = 0; i < numVisible; ++i) {
|
94
|
+
const view = visibleViews[i].view;
|
95
|
+
|
96
|
+
if (!this.isViewFinished(view)) {
|
97
|
+
return view;
|
98
|
+
}
|
121
99
|
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
case RenderingStates.RUNNING:
|
135
|
-
this.highestPriorityPage = view.renderingId;
|
136
|
-
break;
|
137
|
-
case RenderingStates.INITIAL:
|
138
|
-
this.highestPriorityPage = view.renderingId;
|
139
|
-
var continueRendering = function continueRendering() {
|
140
|
-
_this.renderHighestPriority();
|
141
|
-
};
|
142
|
-
view.draw().then(continueRendering, continueRendering);
|
143
|
-
break;
|
100
|
+
|
101
|
+
if (scrolledDown) {
|
102
|
+
const nextPageIndex = visible.last.id;
|
103
|
+
|
104
|
+
if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
|
105
|
+
return views[nextPageIndex];
|
106
|
+
}
|
107
|
+
} else {
|
108
|
+
const previousPageIndex = visible.first.id - 2;
|
109
|
+
|
110
|
+
if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
|
111
|
+
return views[previousPageIndex];
|
144
112
|
}
|
145
|
-
return true;
|
146
113
|
}
|
147
|
-
}]);
|
148
114
|
|
149
|
-
|
150
|
-
}
|
115
|
+
return null;
|
116
|
+
}
|
117
|
+
|
118
|
+
isViewFinished(view) {
|
119
|
+
return view.renderingState === RenderingStates.FINISHED;
|
120
|
+
}
|
121
|
+
|
122
|
+
renderView(view) {
|
123
|
+
switch (view.renderingState) {
|
124
|
+
case RenderingStates.FINISHED:
|
125
|
+
return false;
|
126
|
+
|
127
|
+
case RenderingStates.PAUSED:
|
128
|
+
this.highestPriorityPage = view.renderingId;
|
129
|
+
view.resume();
|
130
|
+
break;
|
131
|
+
|
132
|
+
case RenderingStates.RUNNING:
|
133
|
+
this.highestPriorityPage = view.renderingId;
|
134
|
+
break;
|
135
|
+
|
136
|
+
case RenderingStates.INITIAL:
|
137
|
+
this.highestPriorityPage = view.renderingId;
|
138
|
+
view.draw().finally(() => {
|
139
|
+
this.renderHighestPriority();
|
140
|
+
}).catch(reason => {
|
141
|
+
console.error(`renderView: "${reason}"`);
|
142
|
+
});
|
143
|
+
break;
|
144
|
+
}
|
145
|
+
|
146
|
+
return true;
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
151
150
|
|
152
|
-
exports.RenderingStates = RenderingStates;
|
153
151
|
exports.PDFRenderingQueue = PDFRenderingQueue;
|