pdfjs-dist 2.2.228 → 2.6.347
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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8816 -19300
- 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 +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -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/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- 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 +1144 -927
- 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 +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- 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 +289 -233
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- 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 +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- 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 +37 -37
- package/lib/pdf.js +220 -58
- 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 +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -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 +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -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 +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- 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 +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
@@ -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,37 +70,40 @@ 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
|
-
|
92
|
-
|
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
|
+
optionalContentConfigPromise,
|
83
|
+
linkService,
|
84
|
+
renderingQueue,
|
85
|
+
checkSetImageDisabled,
|
86
|
+
disableCanvasToImageConversion = false,
|
87
|
+
l10n = _ui_utils.NullL10n
|
88
|
+
}) {
|
97
89
|
this.id = id;
|
98
|
-
this.renderingId =
|
90
|
+
this.renderingId = "thumbnail" + id;
|
99
91
|
this.pageLabel = null;
|
100
92
|
this.pdfPage = null;
|
101
93
|
this.rotation = 0;
|
102
94
|
this.viewport = defaultViewport;
|
103
95
|
this.pdfPageRotate = defaultViewport.rotation;
|
96
|
+
this._optionalContentConfigPromise = optionalContentConfigPromise || null;
|
104
97
|
this.linkService = linkService;
|
105
98
|
this.renderingQueue = renderingQueue;
|
106
99
|
this.renderTask = null;
|
107
100
|
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
|
108
101
|
this.resume = null;
|
102
|
+
|
103
|
+
this._checkSetImageDisabled = checkSetImageDisabled || function () {
|
104
|
+
return false;
|
105
|
+
};
|
106
|
+
|
109
107
|
this.disableCanvasToImageConversion = disableCanvasToImageConversion;
|
110
108
|
this.pageWidth = this.viewport.width;
|
111
109
|
this.pageHeight = this.viewport.height;
|
@@ -114,11 +112,10 @@ function () {
|
|
114
112
|
this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
|
115
113
|
this.scale = this.canvasWidth / this.pageWidth;
|
116
114
|
this.l10n = l10n;
|
117
|
-
|
118
|
-
anchor.href = linkService.getAnchorUrl(
|
119
|
-
|
120
|
-
|
121
|
-
}, 'Page {{page}}').then(function (msg) {
|
115
|
+
const anchor = document.createElement("a");
|
116
|
+
anchor.href = linkService.getAnchorUrl("#page=" + id);
|
117
|
+
|
118
|
+
this._thumbPageTitle.then(msg => {
|
122
119
|
anchor.title = msg;
|
123
120
|
});
|
124
121
|
|
@@ -128,319 +125,314 @@ function () {
|
|
128
125
|
};
|
129
126
|
|
130
127
|
this.anchor = anchor;
|
131
|
-
|
132
|
-
div.className =
|
133
|
-
div.setAttribute(
|
128
|
+
const div = document.createElement("div");
|
129
|
+
div.className = "thumbnail";
|
130
|
+
div.setAttribute("data-page-number", this.id);
|
134
131
|
this.div = div;
|
135
|
-
|
136
|
-
ring.className =
|
137
|
-
|
138
|
-
ring.style.width = this.canvasWidth + borderAdjustment +
|
139
|
-
ring.style.height = this.canvasHeight + borderAdjustment +
|
132
|
+
const ring = document.createElement("div");
|
133
|
+
ring.className = "thumbnailSelectionRing";
|
134
|
+
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
135
|
+
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
136
|
+
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
140
137
|
this.ring = ring;
|
141
138
|
div.appendChild(ring);
|
142
139
|
anchor.appendChild(div);
|
143
140
|
container.appendChild(anchor);
|
144
141
|
}
|
145
142
|
|
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.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
|
163
|
-
this.pageWidth = this.viewport.width;
|
164
|
-
this.pageHeight = this.viewport.height;
|
165
|
-
this.pageRatio = this.pageWidth / this.pageHeight;
|
166
|
-
this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
|
167
|
-
this.scale = this.canvasWidth / this.pageWidth;
|
168
|
-
this.div.removeAttribute('data-loaded');
|
169
|
-
var ring = this.ring;
|
170
|
-
var childNodes = ring.childNodes;
|
171
|
-
|
172
|
-
for (var i = childNodes.length - 1; i >= 0; i--) {
|
173
|
-
ring.removeChild(childNodes[i]);
|
174
|
-
}
|
143
|
+
setPdfPage(pdfPage) {
|
144
|
+
this.pdfPage = pdfPage;
|
145
|
+
this.pdfPageRotate = pdfPage.rotate;
|
146
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
147
|
+
this.viewport = pdfPage.getViewport({
|
148
|
+
scale: 1,
|
149
|
+
rotation: totalRotation
|
150
|
+
});
|
151
|
+
this.reset();
|
152
|
+
}
|
175
153
|
|
176
|
-
|
177
|
-
|
178
|
-
|
154
|
+
reset() {
|
155
|
+
this.cancelRendering();
|
156
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
|
157
|
+
this.pageWidth = this.viewport.width;
|
158
|
+
this.pageHeight = this.viewport.height;
|
159
|
+
this.pageRatio = this.pageWidth / this.pageHeight;
|
160
|
+
this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
|
161
|
+
this.scale = this.canvasWidth / this.pageWidth;
|
162
|
+
this.div.removeAttribute("data-loaded");
|
163
|
+
const ring = this.ring;
|
164
|
+
const childNodes = ring.childNodes;
|
179
165
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
delete this.canvas;
|
184
|
-
}
|
166
|
+
for (let i = childNodes.length - 1; i >= 0; i--) {
|
167
|
+
ring.removeChild(childNodes[i]);
|
168
|
+
}
|
185
169
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
170
|
+
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
171
|
+
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
172
|
+
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
173
|
+
|
174
|
+
if (this.canvas) {
|
175
|
+
this.canvas.width = 0;
|
176
|
+
this.canvas.height = 0;
|
177
|
+
delete this.canvas;
|
190
178
|
}
|
191
|
-
}, {
|
192
|
-
key: "update",
|
193
|
-
value: function update(rotation) {
|
194
|
-
if (typeof rotation !== 'undefined') {
|
195
|
-
this.rotation = rotation;
|
196
|
-
}
|
197
179
|
|
198
|
-
|
199
|
-
this.
|
200
|
-
|
201
|
-
rotation: totalRotation
|
202
|
-
});
|
203
|
-
this.reset();
|
180
|
+
if (this.image) {
|
181
|
+
this.image.removeAttribute("src");
|
182
|
+
delete this.image;
|
204
183
|
}
|
205
|
-
}
|
206
|
-
key: "cancelRendering",
|
207
|
-
value: function cancelRendering() {
|
208
|
-
if (this.renderTask) {
|
209
|
-
this.renderTask.cancel();
|
210
|
-
this.renderTask = null;
|
211
|
-
}
|
184
|
+
}
|
212
185
|
|
213
|
-
|
186
|
+
update(rotation) {
|
187
|
+
if (typeof rotation !== "undefined") {
|
188
|
+
this.rotation = rotation;
|
214
189
|
}
|
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
190
|
|
235
|
-
|
191
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
192
|
+
this.viewport = this.viewport.clone({
|
193
|
+
scale: 1,
|
194
|
+
rotation: totalRotation
|
195
|
+
});
|
196
|
+
this.reset();
|
197
|
+
}
|
198
|
+
|
199
|
+
cancelRendering() {
|
200
|
+
if (this.renderTask) {
|
201
|
+
this.renderTask.cancel();
|
202
|
+
this.renderTask = null;
|
236
203
|
}
|
237
|
-
}, {
|
238
|
-
key: "_convertCanvasToImage",
|
239
|
-
value: function _convertCanvasToImage() {
|
240
|
-
var _this = this;
|
241
204
|
|
242
|
-
|
243
|
-
|
244
|
-
}
|
205
|
+
this.resume = null;
|
206
|
+
}
|
245
207
|
|
246
|
-
|
247
|
-
|
248
|
-
|
208
|
+
_getPageDrawContext(noCtxScale = false) {
|
209
|
+
const canvas = document.createElement("canvas");
|
210
|
+
this.canvas = canvas;
|
211
|
+
canvas.mozOpaque = true;
|
212
|
+
const ctx = canvas.getContext("2d", {
|
213
|
+
alpha: false
|
214
|
+
});
|
215
|
+
const outputScale = (0, _ui_utils.getOutputScale)(ctx);
|
216
|
+
canvas.width = this.canvasWidth * outputScale.sx | 0;
|
217
|
+
canvas.height = this.canvasHeight * outputScale.sy | 0;
|
218
|
+
canvas.style.width = this.canvasWidth + "px";
|
219
|
+
canvas.style.height = this.canvasHeight + "px";
|
220
|
+
|
221
|
+
if (!noCtxScale && outputScale.scaled) {
|
222
|
+
ctx.scale(outputScale.sx, outputScale.sy);
|
223
|
+
}
|
249
224
|
|
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
|
-
}
|
225
|
+
return ctx;
|
226
|
+
}
|
265
227
|
|
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;
|
228
|
+
_convertCanvasToImage() {
|
229
|
+
if (!this.canvas) {
|
230
|
+
return;
|
283
231
|
}
|
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
232
|
|
294
|
-
|
295
|
-
|
233
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
|
234
|
+
return;
|
235
|
+
}
|
296
236
|
|
297
|
-
|
298
|
-
if (renderTask === _this2.renderTask) {
|
299
|
-
_this2.renderTask = null;
|
300
|
-
}
|
237
|
+
const className = "thumbnailImage";
|
301
238
|
|
302
|
-
|
303
|
-
|
304
|
-
return;
|
305
|
-
}
|
239
|
+
if (this.disableCanvasToImageConversion) {
|
240
|
+
this.canvas.className = className;
|
306
241
|
|
307
|
-
|
242
|
+
this._thumbPageCanvas.then(msg => {
|
243
|
+
this.canvas.setAttribute("aria-label", msg);
|
244
|
+
});
|
308
245
|
|
309
|
-
|
246
|
+
this.div.setAttribute("data-loaded", true);
|
247
|
+
this.ring.appendChild(this.canvas);
|
248
|
+
return;
|
249
|
+
}
|
310
250
|
|
311
|
-
|
312
|
-
|
313
|
-
} else {
|
314
|
-
renderCapability.reject(error);
|
315
|
-
}
|
316
|
-
};
|
251
|
+
const image = document.createElement("img");
|
252
|
+
image.className = className;
|
317
253
|
|
318
|
-
|
254
|
+
this._thumbPageCanvas.then(msg => {
|
255
|
+
image.setAttribute("aria-label", msg);
|
256
|
+
});
|
319
257
|
|
320
|
-
|
321
|
-
|
322
|
-
|
258
|
+
image.style.width = this.canvasWidth + "px";
|
259
|
+
image.style.height = this.canvasHeight + "px";
|
260
|
+
image.src = this.canvas.toDataURL();
|
261
|
+
this.image = image;
|
262
|
+
this.div.setAttribute("data-loaded", true);
|
263
|
+
this.ring.appendChild(image);
|
264
|
+
this.canvas.width = 0;
|
265
|
+
this.canvas.height = 0;
|
266
|
+
delete this.canvas;
|
267
|
+
}
|
323
268
|
|
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;
|
269
|
+
draw() {
|
270
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
271
|
+
console.error("Must be in new state before drawing");
|
272
|
+
return Promise.resolve(undefined);
|
351
273
|
}
|
352
|
-
}, {
|
353
|
-
key: "setImage",
|
354
|
-
value: function setImage(pageView) {
|
355
|
-
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
356
|
-
return;
|
357
|
-
}
|
358
274
|
|
359
|
-
|
275
|
+
const {
|
276
|
+
pdfPage
|
277
|
+
} = this;
|
360
278
|
|
361
|
-
|
362
|
-
|
279
|
+
if (!pdfPage) {
|
280
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
281
|
+
return Promise.reject(new Error("pdfPage is not loaded"));
|
282
|
+
}
|
283
|
+
|
284
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
|
285
|
+
const renderCapability = (0, _pdf.createPromiseCapability)();
|
286
|
+
|
287
|
+
const finishRenderTask = error => {
|
288
|
+
if (renderTask === this.renderTask) {
|
289
|
+
this.renderTask = null;
|
363
290
|
}
|
364
291
|
|
365
|
-
if (
|
366
|
-
|
292
|
+
if (error instanceof _pdf.RenderingCancelledException) {
|
293
|
+
renderCapability.resolve(undefined);
|
294
|
+
return;
|
367
295
|
}
|
368
296
|
|
369
297
|
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
370
298
|
|
371
|
-
|
299
|
+
this._convertCanvasToImage();
|
300
|
+
|
301
|
+
if (!error) {
|
302
|
+
renderCapability.resolve(undefined);
|
303
|
+
} else {
|
304
|
+
renderCapability.reject(error);
|
305
|
+
}
|
306
|
+
};
|
307
|
+
|
308
|
+
const ctx = this._getPageDrawContext();
|
372
309
|
|
373
|
-
|
310
|
+
const drawViewport = this.viewport.clone({
|
311
|
+
scale: this.scale
|
312
|
+
});
|
374
313
|
|
375
|
-
|
376
|
-
|
314
|
+
const renderContinueCallback = cont => {
|
315
|
+
if (!this.renderingQueue.isHighestPriority(this)) {
|
316
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
|
377
317
|
|
378
|
-
this.
|
318
|
+
this.resume = () => {
|
319
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
|
320
|
+
cont();
|
321
|
+
};
|
379
322
|
|
380
323
|
return;
|
381
324
|
}
|
382
325
|
|
383
|
-
|
384
|
-
|
385
|
-
var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
386
|
-
var reducedImageCtx = reducedImage.getContext('2d');
|
326
|
+
cont();
|
327
|
+
};
|
387
328
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
329
|
+
const renderContext = {
|
330
|
+
canvasContext: ctx,
|
331
|
+
viewport: drawViewport,
|
332
|
+
optionalContentConfigPromise: this._optionalContentConfigPromise
|
333
|
+
};
|
334
|
+
const renderTask = this.renderTask = pdfPage.render(renderContext);
|
335
|
+
renderTask.onContinue = renderContinueCallback;
|
336
|
+
renderTask.promise.then(function () {
|
337
|
+
finishRenderTask(null);
|
338
|
+
}, function (error) {
|
339
|
+
finishRenderTask(error);
|
340
|
+
});
|
341
|
+
return renderCapability.promise;
|
342
|
+
}
|
392
343
|
|
393
|
-
|
344
|
+
setImage(pageView) {
|
345
|
+
if (this._checkSetImageDisabled()) {
|
346
|
+
return;
|
347
|
+
}
|
394
348
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
349
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
350
|
+
return;
|
351
|
+
}
|
352
|
+
|
353
|
+
const img = pageView.canvas;
|
354
|
+
|
355
|
+
if (!img) {
|
356
|
+
return;
|
357
|
+
}
|
358
|
+
|
359
|
+
if (!this.pdfPage) {
|
360
|
+
this.setPdfPage(pageView.pdfPage);
|
361
|
+
}
|
362
|
+
|
363
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
364
|
+
|
365
|
+
const ctx = this._getPageDrawContext(true);
|
366
|
+
|
367
|
+
const canvas = ctx.canvas;
|
400
368
|
|
401
|
-
|
369
|
+
if (img.width <= 2 * canvas.width) {
|
370
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
402
371
|
|
403
372
|
this._convertCanvasToImage();
|
373
|
+
|
374
|
+
return;
|
404
375
|
}
|
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
376
|
|
417
|
-
|
418
|
-
|
419
|
-
|
377
|
+
let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
378
|
+
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
379
|
+
const reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
380
|
+
const reducedImageCtx = reducedImage.getContext("2d");
|
420
381
|
|
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
|
-
});
|
382
|
+
while (reducedWidth > img.width || reducedHeight > img.height) {
|
383
|
+
reducedWidth >>= 1;
|
384
|
+
reducedHeight >>= 1;
|
430
385
|
}
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
386
|
+
|
387
|
+
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
|
388
|
+
|
389
|
+
while (reducedWidth > 2 * canvas.width) {
|
390
|
+
reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
391
|
+
reducedWidth >>= 1;
|
392
|
+
reducedHeight >>= 1;
|
435
393
|
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
394
|
+
|
395
|
+
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
396
|
+
|
397
|
+
this._convertCanvasToImage();
|
398
|
+
}
|
399
|
+
|
400
|
+
get _thumbPageTitle() {
|
401
|
+
return this.l10n.get("thumb_page_title", {
|
402
|
+
page: this.pageLabel ?? this.id
|
403
|
+
}, "Page {{page}}");
|
404
|
+
}
|
405
|
+
|
406
|
+
get _thumbPageCanvas() {
|
407
|
+
return this.l10n.get("thumb_page_canvas", {
|
408
|
+
page: this.pageLabel ?? this.id
|
409
|
+
}, "Thumbnail of Page {{page}}");
|
410
|
+
}
|
411
|
+
|
412
|
+
setPageLabel(label) {
|
413
|
+
this.pageLabel = typeof label === "string" ? label : null;
|
414
|
+
|
415
|
+
this._thumbPageTitle.then(msg => {
|
416
|
+
this.anchor.title = msg;
|
417
|
+
});
|
418
|
+
|
419
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
|
420
|
+
return;
|
440
421
|
}
|
441
|
-
}]);
|
442
422
|
|
443
|
-
|
444
|
-
|
423
|
+
this._thumbPageCanvas.then(msg => {
|
424
|
+
if (this.image) {
|
425
|
+
this.image.setAttribute("aria-label", msg);
|
426
|
+
} else if (this.disableCanvasToImageConversion && this.canvas) {
|
427
|
+
this.canvas.setAttribute("aria-label", msg);
|
428
|
+
}
|
429
|
+
});
|
430
|
+
}
|
431
|
+
|
432
|
+
static cleanup() {
|
433
|
+
TempImageFactory.destroyCanvas();
|
434
|
+
}
|
435
|
+
|
436
|
+
}
|
445
437
|
|
446
438
|
exports.PDFThumbnailView = PDFThumbnailView;
|