pdfjs-dist 2.1.266 → 2.5.207
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 +8382 -18492
- 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 +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -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 +58239 -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 +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- 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 +750 -899
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +40 -37
- package/lib/pdf.js +226 -59
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- 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 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -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.
|
@@ -28,45 +28,40 @@ exports.PDFThumbnailView = void 0;
|
|
28
28
|
|
29
29
|
var _pdf = require("../pdf");
|
30
30
|
|
31
|
-
var _ui_utils = require("./ui_utils");
|
31
|
+
var _ui_utils = require("./ui_utils.js");
|
32
32
|
|
33
|
-
var _pdf_rendering_queue = require("./pdf_rendering_queue");
|
33
|
+
var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
|
34
34
|
|
35
|
-
|
35
|
+
const MAX_NUM_SCALING_STEPS = 3;
|
36
|
+
const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
|
37
|
+
const THUMBNAIL_WIDTH = 98;
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
40
|
-
|
41
|
-
var MAX_NUM_SCALING_STEPS = 3;
|
42
|
-
var THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
|
43
|
-
var THUMBNAIL_WIDTH = 98;
|
44
|
-
|
45
|
-
var TempImageFactory = function TempImageFactoryClosure() {
|
46
|
-
var tempCanvasCache = null;
|
39
|
+
const TempImageFactory = function TempImageFactoryClosure() {
|
40
|
+
let tempCanvasCache = null;
|
47
41
|
return {
|
48
|
-
getCanvas
|
49
|
-
|
42
|
+
getCanvas(width, height) {
|
43
|
+
let tempCanvas = tempCanvasCache;
|
50
44
|
|
51
45
|
if (!tempCanvas) {
|
52
|
-
tempCanvas = document.createElement(
|
46
|
+
tempCanvas = document.createElement("canvas");
|
53
47
|
tempCanvasCache = tempCanvas;
|
54
48
|
}
|
55
49
|
|
56
50
|
tempCanvas.width = width;
|
57
51
|
tempCanvas.height = height;
|
58
52
|
tempCanvas.mozOpaque = true;
|
59
|
-
|
53
|
+
const ctx = tempCanvas.getContext("2d", {
|
60
54
|
alpha: false
|
61
55
|
});
|
62
56
|
ctx.save();
|
63
|
-
ctx.fillStyle =
|
57
|
+
ctx.fillStyle = "rgb(255, 255, 255)";
|
64
58
|
ctx.fillRect(0, 0, width, height);
|
65
59
|
ctx.restore();
|
66
60
|
return tempCanvas;
|
67
61
|
},
|
68
|
-
|
69
|
-
|
62
|
+
|
63
|
+
destroyCanvas() {
|
64
|
+
const tempCanvas = tempCanvasCache;
|
70
65
|
|
71
66
|
if (tempCanvas) {
|
72
67
|
tempCanvas.width = 0;
|
@@ -75,27 +70,22 @@ var TempImageFactory = function TempImageFactoryClosure() {
|
|
75
70
|
|
76
71
|
tempCanvasCache = null;
|
77
72
|
}
|
73
|
+
|
78
74
|
};
|
79
75
|
}();
|
80
76
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
disableCanvasToImageConversion = _ref$disableCanvasToI === void 0 ? false : _ref$disableCanvasToI,
|
92
|
-
_ref$l10n = _ref.l10n,
|
93
|
-
l10n = _ref$l10n === void 0 ? _ui_utils.NullL10n : _ref$l10n;
|
94
|
-
|
95
|
-
_classCallCheck(this, PDFThumbnailView);
|
96
|
-
|
77
|
+
class PDFThumbnailView {
|
78
|
+
constructor({
|
79
|
+
container,
|
80
|
+
id,
|
81
|
+
defaultViewport,
|
82
|
+
linkService,
|
83
|
+
renderingQueue,
|
84
|
+
disableCanvasToImageConversion = false,
|
85
|
+
l10n = _ui_utils.NullL10n
|
86
|
+
}) {
|
97
87
|
this.id = id;
|
98
|
-
this.renderingId =
|
88
|
+
this.renderingId = "thumbnail" + id;
|
99
89
|
this.pageLabel = null;
|
100
90
|
this.pdfPage = null;
|
101
91
|
this.rotation = 0;
|
@@ -114,11 +104,10 @@ function () {
|
|
114
104
|
this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
|
115
105
|
this.scale = this.canvasWidth / this.pageWidth;
|
116
106
|
this.l10n = l10n;
|
117
|
-
|
118
|
-
anchor.href = linkService.getAnchorUrl(
|
119
|
-
|
120
|
-
|
121
|
-
}, 'Page {{page}}').then(function (msg) {
|
107
|
+
const anchor = document.createElement("a");
|
108
|
+
anchor.href = linkService.getAnchorUrl("#page=" + id);
|
109
|
+
|
110
|
+
this._thumbPageTitle.then(msg => {
|
122
111
|
anchor.title = msg;
|
123
112
|
});
|
124
113
|
|
@@ -128,319 +117,309 @@ function () {
|
|
128
117
|
};
|
129
118
|
|
130
119
|
this.anchor = anchor;
|
131
|
-
|
132
|
-
div.className =
|
133
|
-
div.setAttribute(
|
120
|
+
const div = document.createElement("div");
|
121
|
+
div.className = "thumbnail";
|
122
|
+
div.setAttribute("data-page-number", this.id);
|
134
123
|
this.div = div;
|
135
|
-
|
136
|
-
ring.className =
|
137
|
-
|
138
|
-
ring.style.width = this.canvasWidth + borderAdjustment +
|
139
|
-
ring.style.height = this.canvasHeight + borderAdjustment +
|
124
|
+
const ring = document.createElement("div");
|
125
|
+
ring.className = "thumbnailSelectionRing";
|
126
|
+
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
127
|
+
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
128
|
+
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
140
129
|
this.ring = ring;
|
141
130
|
div.appendChild(ring);
|
142
131
|
anchor.appendChild(div);
|
143
132
|
container.appendChild(anchor);
|
144
133
|
}
|
145
134
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
this.reset();
|
157
|
-
}
|
158
|
-
}, {
|
159
|
-
key: "reset",
|
160
|
-
value: function reset() {
|
161
|
-
this.cancelRendering();
|
162
|
-
this.pageWidth = this.viewport.width;
|
163
|
-
this.pageHeight = this.viewport.height;
|
164
|
-
this.pageRatio = this.pageWidth / this.pageHeight;
|
165
|
-
this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
|
166
|
-
this.scale = this.canvasWidth / this.pageWidth;
|
167
|
-
this.div.removeAttribute('data-loaded');
|
168
|
-
var ring = this.ring;
|
169
|
-
var childNodes = ring.childNodes;
|
170
|
-
|
171
|
-
for (var i = childNodes.length - 1; i >= 0; i--) {
|
172
|
-
ring.removeChild(childNodes[i]);
|
173
|
-
}
|
135
|
+
setPdfPage(pdfPage) {
|
136
|
+
this.pdfPage = pdfPage;
|
137
|
+
this.pdfPageRotate = pdfPage.rotate;
|
138
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
139
|
+
this.viewport = pdfPage.getViewport({
|
140
|
+
scale: 1,
|
141
|
+
rotation: totalRotation
|
142
|
+
});
|
143
|
+
this.reset();
|
144
|
+
}
|
174
145
|
|
175
|
-
|
176
|
-
|
177
|
-
|
146
|
+
reset() {
|
147
|
+
this.cancelRendering();
|
148
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
|
149
|
+
this.pageWidth = this.viewport.width;
|
150
|
+
this.pageHeight = this.viewport.height;
|
151
|
+
this.pageRatio = this.pageWidth / this.pageHeight;
|
152
|
+
this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
|
153
|
+
this.scale = this.canvasWidth / this.pageWidth;
|
154
|
+
this.div.removeAttribute("data-loaded");
|
155
|
+
const ring = this.ring;
|
156
|
+
const childNodes = ring.childNodes;
|
178
157
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
delete this.canvas;
|
183
|
-
}
|
158
|
+
for (let i = childNodes.length - 1; i >= 0; i--) {
|
159
|
+
ring.removeChild(childNodes[i]);
|
160
|
+
}
|
184
161
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
162
|
+
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
163
|
+
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
164
|
+
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
165
|
+
|
166
|
+
if (this.canvas) {
|
167
|
+
this.canvas.width = 0;
|
168
|
+
this.canvas.height = 0;
|
169
|
+
delete this.canvas;
|
189
170
|
}
|
190
|
-
}, {
|
191
|
-
key: "update",
|
192
|
-
value: function update(rotation) {
|
193
|
-
if (typeof rotation !== 'undefined') {
|
194
|
-
this.rotation = rotation;
|
195
|
-
}
|
196
171
|
|
197
|
-
|
198
|
-
this.
|
199
|
-
|
200
|
-
rotation: totalRotation
|
201
|
-
});
|
202
|
-
this.reset();
|
172
|
+
if (this.image) {
|
173
|
+
this.image.removeAttribute("src");
|
174
|
+
delete this.image;
|
203
175
|
}
|
204
|
-
}
|
205
|
-
key: "cancelRendering",
|
206
|
-
value: function cancelRendering() {
|
207
|
-
if (this.renderTask) {
|
208
|
-
this.renderTask.cancel();
|
209
|
-
this.renderTask = null;
|
210
|
-
}
|
176
|
+
}
|
211
177
|
|
212
|
-
|
213
|
-
|
178
|
+
update(rotation) {
|
179
|
+
if (typeof rotation !== "undefined") {
|
180
|
+
this.rotation = rotation;
|
214
181
|
}
|
215
|
-
}, {
|
216
|
-
key: "_getPageDrawContext",
|
217
|
-
value: function _getPageDrawContext() {
|
218
|
-
var noCtxScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
219
|
-
var canvas = document.createElement('canvas');
|
220
|
-
this.canvas = canvas;
|
221
|
-
canvas.mozOpaque = true;
|
222
|
-
var ctx = canvas.getContext('2d', {
|
223
|
-
alpha: false
|
224
|
-
});
|
225
|
-
var outputScale = (0, _ui_utils.getOutputScale)(ctx);
|
226
|
-
canvas.width = this.canvasWidth * outputScale.sx | 0;
|
227
|
-
canvas.height = this.canvasHeight * outputScale.sy | 0;
|
228
|
-
canvas.style.width = this.canvasWidth + 'px';
|
229
|
-
canvas.style.height = this.canvasHeight + 'px';
|
230
|
-
|
231
|
-
if (!noCtxScale && outputScale.scaled) {
|
232
|
-
ctx.scale(outputScale.sx, outputScale.sy);
|
233
|
-
}
|
234
182
|
|
235
|
-
|
183
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
184
|
+
this.viewport = this.viewport.clone({
|
185
|
+
scale: 1,
|
186
|
+
rotation: totalRotation
|
187
|
+
});
|
188
|
+
this.reset();
|
189
|
+
}
|
190
|
+
|
191
|
+
cancelRendering() {
|
192
|
+
if (this.renderTask) {
|
193
|
+
this.renderTask.cancel();
|
194
|
+
this.renderTask = null;
|
236
195
|
}
|
237
|
-
}, {
|
238
|
-
key: "_convertCanvasToImage",
|
239
|
-
value: function _convertCanvasToImage() {
|
240
|
-
var _this = this;
|
241
196
|
|
242
|
-
|
243
|
-
|
244
|
-
}
|
197
|
+
this.resume = null;
|
198
|
+
}
|
245
199
|
|
246
|
-
|
247
|
-
|
248
|
-
|
200
|
+
_getPageDrawContext(noCtxScale = false) {
|
201
|
+
const canvas = document.createElement("canvas");
|
202
|
+
this.canvas = canvas;
|
203
|
+
canvas.mozOpaque = true;
|
204
|
+
const ctx = canvas.getContext("2d", {
|
205
|
+
alpha: false
|
206
|
+
});
|
207
|
+
const outputScale = (0, _ui_utils.getOutputScale)(ctx);
|
208
|
+
canvas.width = this.canvasWidth * outputScale.sx | 0;
|
209
|
+
canvas.height = this.canvasHeight * outputScale.sy | 0;
|
210
|
+
canvas.style.width = this.canvasWidth + "px";
|
211
|
+
canvas.style.height = this.canvasHeight + "px";
|
212
|
+
|
213
|
+
if (!noCtxScale && outputScale.scaled) {
|
214
|
+
ctx.scale(outputScale.sx, outputScale.sy);
|
215
|
+
}
|
249
216
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
if (this.disableCanvasToImageConversion) {
|
254
|
-
this.canvas.id = id;
|
255
|
-
this.canvas.className = className;
|
256
|
-
this.l10n.get('thumb_page_canvas', {
|
257
|
-
page: this.pageId
|
258
|
-
}, 'Thumbnail of Page {{page}}').then(function (msg) {
|
259
|
-
_this.canvas.setAttribute('aria-label', msg);
|
260
|
-
});
|
261
|
-
this.div.setAttribute('data-loaded', true);
|
262
|
-
this.ring.appendChild(this.canvas);
|
263
|
-
return;
|
264
|
-
}
|
217
|
+
return ctx;
|
218
|
+
}
|
265
219
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
this.l10n.get('thumb_page_canvas', {
|
270
|
-
page: this.pageId
|
271
|
-
}, 'Thumbnail of Page {{page}}').then(function (msg) {
|
272
|
-
image.setAttribute('aria-label', msg);
|
273
|
-
});
|
274
|
-
image.style.width = this.canvasWidth + 'px';
|
275
|
-
image.style.height = this.canvasHeight + 'px';
|
276
|
-
image.src = this.canvas.toDataURL();
|
277
|
-
this.image = image;
|
278
|
-
this.div.setAttribute('data-loaded', true);
|
279
|
-
this.ring.appendChild(image);
|
280
|
-
this.canvas.width = 0;
|
281
|
-
this.canvas.height = 0;
|
282
|
-
delete this.canvas;
|
220
|
+
_convertCanvasToImage() {
|
221
|
+
if (!this.canvas) {
|
222
|
+
return;
|
283
223
|
}
|
284
|
-
}, {
|
285
|
-
key: "draw",
|
286
|
-
value: function draw() {
|
287
|
-
var _this2 = this;
|
288
|
-
|
289
|
-
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
290
|
-
console.error('Must be in new state before drawing');
|
291
|
-
return Promise.resolve(undefined);
|
292
|
-
}
|
293
224
|
|
294
|
-
|
295
|
-
|
225
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
|
226
|
+
return;
|
227
|
+
}
|
296
228
|
|
297
|
-
|
298
|
-
if (renderTask === _this2.renderTask) {
|
299
|
-
_this2.renderTask = null;
|
300
|
-
}
|
229
|
+
const className = "thumbnailImage";
|
301
230
|
|
302
|
-
|
303
|
-
|
304
|
-
return;
|
305
|
-
}
|
231
|
+
if (this.disableCanvasToImageConversion) {
|
232
|
+
this.canvas.className = className;
|
306
233
|
|
307
|
-
|
234
|
+
this._thumbPageCanvas.then(msg => {
|
235
|
+
this.canvas.setAttribute("aria-label", msg);
|
236
|
+
});
|
308
237
|
|
309
|
-
|
238
|
+
this.div.setAttribute("data-loaded", true);
|
239
|
+
this.ring.appendChild(this.canvas);
|
240
|
+
return;
|
241
|
+
}
|
310
242
|
|
311
|
-
|
312
|
-
|
313
|
-
} else {
|
314
|
-
renderCapability.reject(error);
|
315
|
-
}
|
316
|
-
};
|
243
|
+
const image = document.createElement("img");
|
244
|
+
image.className = className;
|
317
245
|
|
318
|
-
|
246
|
+
this._thumbPageCanvas.then(msg => {
|
247
|
+
image.setAttribute("aria-label", msg);
|
248
|
+
});
|
319
249
|
|
320
|
-
|
321
|
-
|
322
|
-
|
250
|
+
image.style.width = this.canvasWidth + "px";
|
251
|
+
image.style.height = this.canvasHeight + "px";
|
252
|
+
image.src = this.canvas.toDataURL();
|
253
|
+
this.image = image;
|
254
|
+
this.div.setAttribute("data-loaded", true);
|
255
|
+
this.ring.appendChild(image);
|
256
|
+
this.canvas.width = 0;
|
257
|
+
this.canvas.height = 0;
|
258
|
+
delete this.canvas;
|
259
|
+
}
|
323
260
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
_this2.resume = function () {
|
329
|
-
_this2.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
|
330
|
-
cont();
|
331
|
-
};
|
332
|
-
|
333
|
-
return;
|
334
|
-
}
|
335
|
-
|
336
|
-
cont();
|
337
|
-
};
|
338
|
-
|
339
|
-
var renderContext = {
|
340
|
-
canvasContext: ctx,
|
341
|
-
viewport: drawViewport
|
342
|
-
};
|
343
|
-
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
|
344
|
-
renderTask.onContinue = renderContinueCallback;
|
345
|
-
renderTask.promise.then(function () {
|
346
|
-
finishRenderTask(null);
|
347
|
-
}, function (error) {
|
348
|
-
finishRenderTask(error);
|
349
|
-
});
|
350
|
-
return renderCapability.promise;
|
261
|
+
draw() {
|
262
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
263
|
+
console.error("Must be in new state before drawing");
|
264
|
+
return Promise.resolve(undefined);
|
351
265
|
}
|
352
|
-
}, {
|
353
|
-
key: "setImage",
|
354
|
-
value: function setImage(pageView) {
|
355
|
-
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
356
|
-
return;
|
357
|
-
}
|
358
266
|
|
359
|
-
|
267
|
+
const {
|
268
|
+
pdfPage
|
269
|
+
} = this;
|
360
270
|
|
361
|
-
|
362
|
-
|
271
|
+
if (!pdfPage) {
|
272
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
273
|
+
return Promise.reject(new Error("pdfPage is not loaded"));
|
274
|
+
}
|
275
|
+
|
276
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
|
277
|
+
const renderCapability = (0, _pdf.createPromiseCapability)();
|
278
|
+
|
279
|
+
const finishRenderTask = error => {
|
280
|
+
if (renderTask === this.renderTask) {
|
281
|
+
this.renderTask = null;
|
363
282
|
}
|
364
283
|
|
365
|
-
if (
|
366
|
-
|
284
|
+
if (error instanceof _pdf.RenderingCancelledException) {
|
285
|
+
renderCapability.resolve(undefined);
|
286
|
+
return;
|
367
287
|
}
|
368
288
|
|
369
289
|
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
370
290
|
|
371
|
-
|
291
|
+
this._convertCanvasToImage();
|
372
292
|
|
373
|
-
|
293
|
+
if (!error) {
|
294
|
+
renderCapability.resolve(undefined);
|
295
|
+
} else {
|
296
|
+
renderCapability.reject(error);
|
297
|
+
}
|
298
|
+
};
|
374
299
|
|
375
|
-
|
376
|
-
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
300
|
+
const ctx = this._getPageDrawContext();
|
377
301
|
|
378
|
-
|
302
|
+
const drawViewport = this.viewport.clone({
|
303
|
+
scale: this.scale
|
304
|
+
});
|
305
|
+
|
306
|
+
const renderContinueCallback = cont => {
|
307
|
+
if (!this.renderingQueue.isHighestPriority(this)) {
|
308
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
|
309
|
+
|
310
|
+
this.resume = () => {
|
311
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
|
312
|
+
cont();
|
313
|
+
};
|
379
314
|
|
380
315
|
return;
|
381
316
|
}
|
382
317
|
|
383
|
-
|
384
|
-
|
385
|
-
var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
386
|
-
var reducedImageCtx = reducedImage.getContext('2d');
|
318
|
+
cont();
|
319
|
+
};
|
387
320
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
321
|
+
const renderContext = {
|
322
|
+
canvasContext: ctx,
|
323
|
+
viewport: drawViewport
|
324
|
+
};
|
325
|
+
const renderTask = this.renderTask = pdfPage.render(renderContext);
|
326
|
+
renderTask.onContinue = renderContinueCallback;
|
327
|
+
renderTask.promise.then(function () {
|
328
|
+
finishRenderTask(null);
|
329
|
+
}, function (error) {
|
330
|
+
finishRenderTask(error);
|
331
|
+
});
|
332
|
+
return renderCapability.promise;
|
333
|
+
}
|
392
334
|
|
393
|
-
|
335
|
+
setImage(pageView) {
|
336
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
337
|
+
return;
|
338
|
+
}
|
394
339
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
340
|
+
const img = pageView.canvas;
|
341
|
+
|
342
|
+
if (!img) {
|
343
|
+
return;
|
344
|
+
}
|
345
|
+
|
346
|
+
if (!this.pdfPage) {
|
347
|
+
this.setPdfPage(pageView.pdfPage);
|
348
|
+
}
|
349
|
+
|
350
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
400
351
|
|
401
|
-
|
352
|
+
const ctx = this._getPageDrawContext(true);
|
353
|
+
|
354
|
+
const canvas = ctx.canvas;
|
355
|
+
|
356
|
+
if (img.width <= 2 * canvas.width) {
|
357
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
402
358
|
|
403
359
|
this._convertCanvasToImage();
|
360
|
+
|
361
|
+
return;
|
404
362
|
}
|
405
|
-
}, {
|
406
|
-
key: "setPageLabel",
|
407
|
-
value: function setPageLabel(label) {
|
408
|
-
var _this3 = this;
|
409
|
-
|
410
|
-
this.pageLabel = typeof label === 'string' ? label : null;
|
411
|
-
this.l10n.get('thumb_page_title', {
|
412
|
-
page: this.pageId
|
413
|
-
}, 'Page {{page}}').then(function (msg) {
|
414
|
-
_this3.anchor.title = msg;
|
415
|
-
});
|
416
363
|
|
417
|
-
|
418
|
-
|
419
|
-
|
364
|
+
let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
365
|
+
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
366
|
+
const reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
367
|
+
const reducedImageCtx = reducedImage.getContext("2d");
|
420
368
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
if (_this3.image) {
|
425
|
-
_this3.image.setAttribute('aria-label', ariaLabel);
|
426
|
-
} else if (_this3.disableCanvasToImageConversion && _this3.canvas) {
|
427
|
-
_this3.canvas.setAttribute('aria-label', ariaLabel);
|
428
|
-
}
|
429
|
-
});
|
369
|
+
while (reducedWidth > img.width || reducedHeight > img.height) {
|
370
|
+
reducedWidth >>= 1;
|
371
|
+
reducedHeight >>= 1;
|
430
372
|
}
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
373
|
+
|
374
|
+
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
|
375
|
+
|
376
|
+
while (reducedWidth > 2 * canvas.width) {
|
377
|
+
reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
378
|
+
reducedWidth >>= 1;
|
379
|
+
reducedHeight >>= 1;
|
435
380
|
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
381
|
+
|
382
|
+
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
383
|
+
|
384
|
+
this._convertCanvasToImage();
|
385
|
+
}
|
386
|
+
|
387
|
+
get _thumbPageTitle() {
|
388
|
+
return this.l10n.get("thumb_page_title", {
|
389
|
+
page: this.pageLabel !== null ? this.pageLabel : this.id
|
390
|
+
}, "Page {{page}}");
|
391
|
+
}
|
392
|
+
|
393
|
+
get _thumbPageCanvas() {
|
394
|
+
return this.l10n.get("thumb_page_canvas", {
|
395
|
+
page: this.pageLabel !== null ? this.pageLabel : this.id
|
396
|
+
}, "Thumbnail of Page {{page}}");
|
397
|
+
}
|
398
|
+
|
399
|
+
setPageLabel(label) {
|
400
|
+
this.pageLabel = typeof label === "string" ? label : null;
|
401
|
+
|
402
|
+
this._thumbPageTitle.then(msg => {
|
403
|
+
this.anchor.title = msg;
|
404
|
+
});
|
405
|
+
|
406
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
|
407
|
+
return;
|
440
408
|
}
|
441
|
-
}]);
|
442
409
|
|
443
|
-
|
444
|
-
|
410
|
+
this._thumbPageCanvas.then(msg => {
|
411
|
+
if (this.image) {
|
412
|
+
this.image.setAttribute("aria-label", msg);
|
413
|
+
} else if (this.disableCanvasToImageConversion && this.canvas) {
|
414
|
+
this.canvas.setAttribute("aria-label", msg);
|
415
|
+
}
|
416
|
+
});
|
417
|
+
}
|
418
|
+
|
419
|
+
static cleanup() {
|
420
|
+
TempImageFactory.destroyCanvas();
|
421
|
+
}
|
422
|
+
|
423
|
+
}
|
445
424
|
|
446
425
|
exports.PDFThumbnailView = PDFThumbnailView;
|