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
package/lib/web/pdf_page_view.js
CHANGED
@@ -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,37 +19,29 @@
|
|
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.PDFPageView =
|
27
|
+
exports.PDFPageView = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _ui_utils = require("./ui_utils.js");
|
30
30
|
|
31
|
-
var
|
31
|
+
var _pdf = require("../pdf");
|
32
32
|
|
33
|
-
var
|
33
|
+
var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
|
34
34
|
|
35
|
-
var
|
35
|
+
var _viewer_compatibility = require("./viewer_compatibility.js");
|
36
36
|
|
37
|
-
|
37
|
+
const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
var MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
|
44
|
-
|
45
|
-
var PDFPageView = function () {
|
46
|
-
function PDFPageView(options) {
|
47
|
-
_classCallCheck(this, PDFPageView);
|
48
|
-
|
49
|
-
var container = options.container;
|
50
|
-
var defaultViewport = options.defaultViewport;
|
39
|
+
class PDFPageView {
|
40
|
+
constructor(options) {
|
41
|
+
const container = options.container;
|
42
|
+
const defaultViewport = options.defaultViewport;
|
51
43
|
this.id = options.id;
|
52
|
-
this.renderingId =
|
44
|
+
this.renderingId = "page" + this.id;
|
53
45
|
this.pdfPage = null;
|
54
46
|
this.pageLabel = null;
|
55
47
|
this.rotation = 0;
|
@@ -58,11 +50,11 @@ var PDFPageView = function () {
|
|
58
50
|
this.pdfPageRotate = defaultViewport.rotation;
|
59
51
|
this.hasRestrictedScaling = false;
|
60
52
|
this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
|
61
|
-
this.imageResourcesPath = options.imageResourcesPath ||
|
53
|
+
this.imageResourcesPath = options.imageResourcesPath || "";
|
62
54
|
this.renderInteractiveForms = options.renderInteractiveForms || false;
|
63
55
|
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
64
56
|
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
65
|
-
this.eventBus = options.eventBus || (0,
|
57
|
+
this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)();
|
66
58
|
this.renderingQueue = options.renderingQueue;
|
67
59
|
this.textLayerFactory = options.textLayerFactory;
|
68
60
|
this.annotationLayerFactory = options.annotationLayerFactory;
|
@@ -74,486 +66,548 @@ var PDFPageView = function () {
|
|
74
66
|
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
|
75
67
|
this.resume = null;
|
76
68
|
this.error = null;
|
77
|
-
this.onBeforeDraw = null;
|
78
|
-
this.onAfterDraw = null;
|
79
69
|
this.annotationLayer = null;
|
80
70
|
this.textLayer = null;
|
81
71
|
this.zoomLayer = null;
|
82
|
-
|
83
|
-
div.className =
|
84
|
-
div.style.width = Math.floor(this.viewport.width) +
|
85
|
-
div.style.height = Math.floor(this.viewport.height) +
|
86
|
-
div.setAttribute(
|
72
|
+
const div = document.createElement("div");
|
73
|
+
div.className = "page";
|
74
|
+
div.style.width = Math.floor(this.viewport.width) + "px";
|
75
|
+
div.style.height = Math.floor(this.viewport.height) + "px";
|
76
|
+
div.setAttribute("data-page-number", this.id);
|
87
77
|
this.div = div;
|
88
78
|
container.appendChild(div);
|
89
79
|
}
|
90
80
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
81
|
+
setPdfPage(pdfPage) {
|
82
|
+
this.pdfPage = pdfPage;
|
83
|
+
this.pdfPageRotate = pdfPage.rotate;
|
84
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
85
|
+
this.viewport = pdfPage.getViewport({
|
86
|
+
scale: this.scale * _ui_utils.CSS_UNITS,
|
87
|
+
rotation: totalRotation
|
88
|
+
});
|
89
|
+
this.stats = pdfPage.stats;
|
90
|
+
this.reset();
|
91
|
+
}
|
92
|
+
|
93
|
+
destroy() {
|
94
|
+
this.reset();
|
95
|
+
|
96
|
+
if (this.pdfPage) {
|
97
|
+
this.pdfPage.cleanup();
|
100
98
|
}
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
this.pdfPage.cleanup();
|
107
|
-
}
|
99
|
+
}
|
100
|
+
|
101
|
+
_resetZoomLayer(removeFromDOM = false) {
|
102
|
+
if (!this.zoomLayer) {
|
103
|
+
return;
|
108
104
|
}
|
109
|
-
}, {
|
110
|
-
key: '_resetZoomLayer',
|
111
|
-
value: function _resetZoomLayer() {
|
112
|
-
var removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
113
105
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
if (removeFromDOM) {
|
122
|
-
this.zoomLayer.remove();
|
123
|
-
}
|
124
|
-
this.zoomLayer = null;
|
106
|
+
const zoomLayerCanvas = this.zoomLayer.firstChild;
|
107
|
+
this.paintedViewportMap.delete(zoomLayerCanvas);
|
108
|
+
zoomLayerCanvas.width = 0;
|
109
|
+
zoomLayerCanvas.height = 0;
|
110
|
+
|
111
|
+
if (removeFromDOM) {
|
112
|
+
this.zoomLayer.remove();
|
125
113
|
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
}
|
146
|
-
div.removeAttribute('data-loaded');
|
147
|
-
if (currentAnnotationNode) {
|
148
|
-
this.annotationLayer.hide();
|
149
|
-
} else if (this.annotationLayer) {
|
150
|
-
this.annotationLayer.cancel();
|
151
|
-
this.annotationLayer = null;
|
152
|
-
}
|
153
|
-
if (!currentZoomLayerNode) {
|
154
|
-
if (this.canvas) {
|
155
|
-
this.paintedViewportMap.delete(this.canvas);
|
156
|
-
this.canvas.width = 0;
|
157
|
-
this.canvas.height = 0;
|
158
|
-
delete this.canvas;
|
159
|
-
}
|
160
|
-
this._resetZoomLayer();
|
161
|
-
}
|
162
|
-
if (this.svg) {
|
163
|
-
this.paintedViewportMap.delete(this.svg);
|
164
|
-
delete this.svg;
|
114
|
+
|
115
|
+
this.zoomLayer = null;
|
116
|
+
}
|
117
|
+
|
118
|
+
reset(keepZoomLayer = false, keepAnnotations = false) {
|
119
|
+
this.cancelRendering(keepAnnotations);
|
120
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
|
121
|
+
const div = this.div;
|
122
|
+
div.style.width = Math.floor(this.viewport.width) + "px";
|
123
|
+
div.style.height = Math.floor(this.viewport.height) + "px";
|
124
|
+
const childNodes = div.childNodes;
|
125
|
+
const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
|
126
|
+
const currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
|
127
|
+
|
128
|
+
for (let i = childNodes.length - 1; i >= 0; i--) {
|
129
|
+
const node = childNodes[i];
|
130
|
+
|
131
|
+
if (currentZoomLayerNode === node || currentAnnotationNode === node) {
|
132
|
+
continue;
|
165
133
|
}
|
166
|
-
|
167
|
-
|
168
|
-
div.appendChild(this.loadingIconDiv);
|
134
|
+
|
135
|
+
div.removeChild(node);
|
169
136
|
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
137
|
+
|
138
|
+
div.removeAttribute("data-loaded");
|
139
|
+
|
140
|
+
if (currentAnnotationNode) {
|
141
|
+
this.annotationLayer.hide();
|
142
|
+
} else if (this.annotationLayer) {
|
143
|
+
this.annotationLayer.cancel();
|
144
|
+
this.annotationLayer = null;
|
145
|
+
}
|
146
|
+
|
147
|
+
if (!currentZoomLayerNode) {
|
148
|
+
if (this.canvas) {
|
149
|
+
this.paintedViewportMap.delete(this.canvas);
|
150
|
+
this.canvas.width = 0;
|
151
|
+
this.canvas.height = 0;
|
152
|
+
delete this.canvas;
|
176
153
|
}
|
177
|
-
|
178
|
-
this.
|
179
|
-
|
180
|
-
|
154
|
+
|
155
|
+
this._resetZoomLayer();
|
156
|
+
}
|
157
|
+
|
158
|
+
if (this.svg) {
|
159
|
+
this.paintedViewportMap.delete(this.svg);
|
160
|
+
delete this.svg;
|
161
|
+
}
|
162
|
+
|
163
|
+
this.loadingIconDiv = document.createElement("div");
|
164
|
+
this.loadingIconDiv.className = "loadingIcon";
|
165
|
+
div.appendChild(this.loadingIconDiv);
|
166
|
+
}
|
167
|
+
|
168
|
+
update(scale, rotation) {
|
169
|
+
this.scale = scale || this.scale;
|
170
|
+
|
171
|
+
if (typeof rotation !== "undefined") {
|
172
|
+
this.rotation = rotation;
|
173
|
+
}
|
174
|
+
|
175
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
176
|
+
this.viewport = this.viewport.clone({
|
177
|
+
scale: this.scale * _ui_utils.CSS_UNITS,
|
178
|
+
rotation: totalRotation
|
179
|
+
});
|
180
|
+
|
181
|
+
if (this.svg) {
|
182
|
+
this.cssTransform(this.svg, true);
|
183
|
+
this.eventBus.dispatch("pagerendered", {
|
184
|
+
source: this,
|
185
|
+
pageNumber: this.id,
|
186
|
+
cssTransform: true,
|
187
|
+
timestamp: performance.now()
|
181
188
|
});
|
182
|
-
|
183
|
-
|
184
|
-
|
189
|
+
return;
|
190
|
+
}
|
191
|
+
|
192
|
+
let isScalingRestricted = false;
|
193
|
+
|
194
|
+
if (this.canvas && this.maxCanvasPixels > 0) {
|
195
|
+
const outputScale = this.outputScale;
|
196
|
+
|
197
|
+
if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
|
198
|
+
isScalingRestricted = true;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
if (this.canvas) {
|
203
|
+
if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
|
204
|
+
this.cssTransform(this.canvas, true);
|
205
|
+
this.eventBus.dispatch("pagerendered", {
|
185
206
|
source: this,
|
186
207
|
pageNumber: this.id,
|
187
|
-
cssTransform: true
|
208
|
+
cssTransform: true,
|
209
|
+
timestamp: performance.now()
|
188
210
|
});
|
189
211
|
return;
|
190
212
|
}
|
191
|
-
|
192
|
-
if (this.
|
193
|
-
|
194
|
-
|
195
|
-
isScalingRestricted = true;
|
196
|
-
}
|
197
|
-
}
|
198
|
-
if (this.canvas) {
|
199
|
-
if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
|
200
|
-
this.cssTransform(this.canvas, true);
|
201
|
-
this.eventBus.dispatch('pagerendered', {
|
202
|
-
source: this,
|
203
|
-
pageNumber: this.id,
|
204
|
-
cssTransform: true
|
205
|
-
});
|
206
|
-
return;
|
207
|
-
}
|
208
|
-
if (!this.zoomLayer && !this.canvas.hasAttribute('hidden')) {
|
209
|
-
this.zoomLayer = this.canvas.parentNode;
|
210
|
-
this.zoomLayer.style.position = 'absolute';
|
211
|
-
}
|
212
|
-
}
|
213
|
-
if (this.zoomLayer) {
|
214
|
-
this.cssTransform(this.zoomLayer.firstChild);
|
213
|
+
|
214
|
+
if (!this.zoomLayer && !this.canvas.hasAttribute("hidden")) {
|
215
|
+
this.zoomLayer = this.canvas.parentNode;
|
216
|
+
this.zoomLayer.style.position = "absolute";
|
215
217
|
}
|
216
|
-
this.reset(true, true);
|
217
218
|
}
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
var keepAnnotations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
222
|
-
|
223
|
-
var renderingState = this.renderingState;
|
224
|
-
if (this.paintTask) {
|
225
|
-
this.paintTask.cancel();
|
226
|
-
this.paintTask = null;
|
227
|
-
}
|
228
|
-
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
|
229
|
-
this.resume = null;
|
230
|
-
if (this.textLayer) {
|
231
|
-
this.textLayer.cancel();
|
232
|
-
this.textLayer = null;
|
233
|
-
}
|
234
|
-
if (!keepAnnotations && this.annotationLayer) {
|
235
|
-
this.annotationLayer.cancel();
|
236
|
-
this.annotationLayer = null;
|
237
|
-
}
|
238
|
-
if (renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
239
|
-
this.eventBus.dispatch('pagecancelled', {
|
240
|
-
source: this,
|
241
|
-
pageNumber: this.id,
|
242
|
-
renderingState: renderingState
|
243
|
-
});
|
244
|
-
}
|
219
|
+
|
220
|
+
if (this.zoomLayer) {
|
221
|
+
this.cssTransform(this.zoomLayer.firstChild);
|
245
222
|
}
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
}
|
297
|
-
textLayerDiv.style.transform = 'rotate(' + textAbsRotation + 'deg) ' + 'scale(' + scale + ', ' + scale + ') ' + 'translate(' + transX + ', ' + transY + ')';
|
298
|
-
textLayerDiv.style.transformOrigin = '0% 0%';
|
223
|
+
|
224
|
+
this.reset(true, true);
|
225
|
+
}
|
226
|
+
|
227
|
+
cancelRendering(keepAnnotations = false) {
|
228
|
+
if (this.paintTask) {
|
229
|
+
this.paintTask.cancel();
|
230
|
+
this.paintTask = null;
|
231
|
+
}
|
232
|
+
|
233
|
+
this.resume = null;
|
234
|
+
|
235
|
+
if (this.textLayer) {
|
236
|
+
this.textLayer.cancel();
|
237
|
+
this.textLayer = null;
|
238
|
+
}
|
239
|
+
|
240
|
+
if (!keepAnnotations && this.annotationLayer) {
|
241
|
+
this.annotationLayer.cancel();
|
242
|
+
this.annotationLayer = null;
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
cssTransform(target, redrawAnnotations = false) {
|
247
|
+
const width = this.viewport.width;
|
248
|
+
const height = this.viewport.height;
|
249
|
+
const div = this.div;
|
250
|
+
target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
|
251
|
+
target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
|
252
|
+
const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
|
253
|
+
const absRotation = Math.abs(relativeRotation);
|
254
|
+
let scaleX = 1,
|
255
|
+
scaleY = 1;
|
256
|
+
|
257
|
+
if (absRotation === 90 || absRotation === 270) {
|
258
|
+
scaleX = height / width;
|
259
|
+
scaleY = width / height;
|
260
|
+
}
|
261
|
+
|
262
|
+
const cssTransform = "rotate(" + relativeRotation + "deg) " + "scale(" + scaleX + "," + scaleY + ")";
|
263
|
+
target.style.transform = cssTransform;
|
264
|
+
|
265
|
+
if (this.textLayer) {
|
266
|
+
const textLayerViewport = this.textLayer.viewport;
|
267
|
+
const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
|
268
|
+
const textAbsRotation = Math.abs(textRelativeRotation);
|
269
|
+
let scale = width / textLayerViewport.width;
|
270
|
+
|
271
|
+
if (textAbsRotation === 90 || textAbsRotation === 270) {
|
272
|
+
scale = width / textLayerViewport.height;
|
299
273
|
}
|
300
|
-
|
301
|
-
|
274
|
+
|
275
|
+
const textLayerDiv = this.textLayer.textLayerDiv;
|
276
|
+
let transX, transY;
|
277
|
+
|
278
|
+
switch (textAbsRotation) {
|
279
|
+
case 0:
|
280
|
+
transX = transY = 0;
|
281
|
+
break;
|
282
|
+
|
283
|
+
case 90:
|
284
|
+
transX = 0;
|
285
|
+
transY = "-" + textLayerDiv.style.height;
|
286
|
+
break;
|
287
|
+
|
288
|
+
case 180:
|
289
|
+
transX = "-" + textLayerDiv.style.width;
|
290
|
+
transY = "-" + textLayerDiv.style.height;
|
291
|
+
break;
|
292
|
+
|
293
|
+
case 270:
|
294
|
+
transX = "-" + textLayerDiv.style.width;
|
295
|
+
transY = 0;
|
296
|
+
break;
|
297
|
+
|
298
|
+
default:
|
299
|
+
console.error("Bad rotation value.");
|
300
|
+
break;
|
302
301
|
}
|
302
|
+
|
303
|
+
textLayerDiv.style.transform = "rotate(" + textAbsRotation + "deg) " + "scale(" + scale + ", " + scale + ") " + "translate(" + transX + ", " + transY + ")";
|
304
|
+
textLayerDiv.style.transformOrigin = "0% 0%";
|
303
305
|
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
return this.viewport.convertToPdfPoint(x, y);
|
306
|
+
|
307
|
+
if (redrawAnnotations && this.annotationLayer) {
|
308
|
+
this.annotationLayer.render(this.viewport, "display");
|
308
309
|
}
|
309
|
-
}
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
310
|
+
}
|
311
|
+
|
312
|
+
get width() {
|
313
|
+
return this.viewport.width;
|
314
|
+
}
|
315
|
+
|
316
|
+
get height() {
|
317
|
+
return this.viewport.height;
|
318
|
+
}
|
319
|
+
|
320
|
+
getPagePoint(x, y) {
|
321
|
+
return this.viewport.convertToPdfPoint(x, y);
|
322
|
+
}
|
323
|
+
|
324
|
+
draw() {
|
325
|
+
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
326
|
+
console.error("Must be in new state before drawing");
|
327
|
+
this.reset();
|
328
|
+
}
|
329
|
+
|
330
|
+
const {
|
331
|
+
div,
|
332
|
+
pdfPage
|
333
|
+
} = this;
|
334
|
+
|
335
|
+
if (!pdfPage) {
|
336
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
337
|
+
|
338
|
+
if (this.loadingIconDiv) {
|
339
|
+
div.removeChild(this.loadingIconDiv);
|
340
|
+
delete this.loadingIconDiv;
|
321
341
|
}
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
342
|
+
|
343
|
+
return Promise.reject(new Error("pdfPage is not loaded"));
|
344
|
+
}
|
345
|
+
|
346
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
|
347
|
+
const canvasWrapper = document.createElement("div");
|
348
|
+
canvasWrapper.style.width = div.style.width;
|
349
|
+
canvasWrapper.style.height = div.style.height;
|
350
|
+
canvasWrapper.classList.add("canvasWrapper");
|
351
|
+
|
352
|
+
if (this.annotationLayer && this.annotationLayer.div) {
|
353
|
+
div.insertBefore(canvasWrapper, this.annotationLayer.div);
|
354
|
+
} else {
|
355
|
+
div.appendChild(canvasWrapper);
|
356
|
+
}
|
357
|
+
|
358
|
+
let textLayer = null;
|
359
|
+
|
360
|
+
if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
|
361
|
+
const textLayerDiv = document.createElement("div");
|
362
|
+
textLayerDiv.className = "textLayer";
|
363
|
+
textLayerDiv.style.width = canvasWrapper.style.width;
|
364
|
+
textLayerDiv.style.height = canvasWrapper.style.height;
|
365
|
+
|
329
366
|
if (this.annotationLayer && this.annotationLayer.div) {
|
330
|
-
div.insertBefore(
|
367
|
+
div.insertBefore(textLayerDiv, this.annotationLayer.div);
|
331
368
|
} else {
|
332
|
-
div.appendChild(
|
369
|
+
div.appendChild(textLayerDiv);
|
333
370
|
}
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
_this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
|
353
|
-
_this.resume = function () {
|
354
|
-
_this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
|
355
|
-
cont();
|
356
|
-
};
|
357
|
-
return;
|
358
|
-
}
|
359
|
-
cont();
|
360
|
-
};
|
361
|
-
}
|
362
|
-
var finishPaintTask = function finishPaintTask(error) {
|
363
|
-
if (paintTask === _this.paintTask) {
|
364
|
-
_this.paintTask = null;
|
365
|
-
}
|
366
|
-
if (error instanceof _pdf.RenderingCancelledException) {
|
367
|
-
_this.error = null;
|
368
|
-
return Promise.resolve(undefined);
|
369
|
-
}
|
370
|
-
_this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
371
|
-
if (_this.loadingIconDiv) {
|
372
|
-
div.removeChild(_this.loadingIconDiv);
|
373
|
-
delete _this.loadingIconDiv;
|
374
|
-
}
|
375
|
-
_this._resetZoomLayer(true);
|
376
|
-
_this.error = error;
|
377
|
-
_this.stats = pdfPage.stats;
|
378
|
-
if (_this.onAfterDraw) {
|
379
|
-
_this.onAfterDraw();
|
380
|
-
}
|
381
|
-
_this.eventBus.dispatch('pagerendered', {
|
382
|
-
source: _this,
|
383
|
-
pageNumber: _this.id,
|
384
|
-
cssTransform: false
|
385
|
-
});
|
386
|
-
if (error) {
|
387
|
-
return Promise.reject(error);
|
371
|
+
|
372
|
+
textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
|
373
|
+
}
|
374
|
+
|
375
|
+
this.textLayer = textLayer;
|
376
|
+
let renderContinueCallback = null;
|
377
|
+
|
378
|
+
if (this.renderingQueue) {
|
379
|
+
renderContinueCallback = cont => {
|
380
|
+
if (!this.renderingQueue.isHighestPriority(this)) {
|
381
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
|
382
|
+
|
383
|
+
this.resume = () => {
|
384
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
|
385
|
+
cont();
|
386
|
+
};
|
387
|
+
|
388
|
+
return;
|
388
389
|
}
|
389
|
-
|
390
|
+
|
391
|
+
cont();
|
390
392
|
};
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
if (textLayer) {
|
397
|
-
var readableStream = pdfPage.streamTextContent({ normalizeWhitespace: true });
|
398
|
-
textLayer.setTextContentStream(readableStream);
|
399
|
-
textLayer.render();
|
400
|
-
}
|
401
|
-
});
|
402
|
-
}, function (reason) {
|
403
|
-
return finishPaintTask(reason);
|
404
|
-
});
|
405
|
-
if (this.annotationLayerFactory) {
|
406
|
-
if (!this.annotationLayer) {
|
407
|
-
this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n);
|
408
|
-
}
|
409
|
-
this.annotationLayer.render(this.viewport, 'display');
|
393
|
+
}
|
394
|
+
|
395
|
+
const finishPaintTask = async error => {
|
396
|
+
if (paintTask === this.paintTask) {
|
397
|
+
this.paintTask = null;
|
410
398
|
}
|
411
|
-
|
412
|
-
if (
|
413
|
-
this.
|
399
|
+
|
400
|
+
if (error instanceof _pdf.RenderingCancelledException) {
|
401
|
+
this.error = null;
|
402
|
+
return;
|
414
403
|
}
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
var result = {
|
422
|
-
promise: renderCapability.promise,
|
423
|
-
onRenderContinue: function onRenderContinue(cont) {
|
424
|
-
cont();
|
425
|
-
},
|
426
|
-
cancel: function cancel() {
|
427
|
-
renderTask.cancel();
|
428
|
-
}
|
429
|
-
};
|
430
|
-
var viewport = this.viewport;
|
431
|
-
var canvas = document.createElement('canvas');
|
432
|
-
canvas.id = this.renderingId;
|
433
|
-
canvas.setAttribute('hidden', 'hidden');
|
434
|
-
var isCanvasHidden = true;
|
435
|
-
var showCanvas = function showCanvas() {
|
436
|
-
if (isCanvasHidden) {
|
437
|
-
canvas.removeAttribute('hidden');
|
438
|
-
isCanvasHidden = false;
|
439
|
-
}
|
440
|
-
};
|
441
|
-
canvasWrapper.appendChild(canvas);
|
442
|
-
this.canvas = canvas;
|
443
|
-
canvas.mozOpaque = true;
|
444
|
-
var ctx = canvas.getContext('2d', { alpha: false });
|
445
|
-
var outputScale = (0, _ui_utils.getOutputScale)(ctx);
|
446
|
-
this.outputScale = outputScale;
|
447
|
-
if (this.useOnlyCssZoom) {
|
448
|
-
var actualSizeViewport = viewport.clone({ scale: _ui_utils.CSS_UNITS });
|
449
|
-
outputScale.sx *= actualSizeViewport.width / viewport.width;
|
450
|
-
outputScale.sy *= actualSizeViewport.height / viewport.height;
|
451
|
-
outputScale.scaled = true;
|
404
|
+
|
405
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
406
|
+
|
407
|
+
if (this.loadingIconDiv) {
|
408
|
+
div.removeChild(this.loadingIconDiv);
|
409
|
+
delete this.loadingIconDiv;
|
452
410
|
}
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
411
|
+
|
412
|
+
this._resetZoomLayer(true);
|
413
|
+
|
414
|
+
this.error = error;
|
415
|
+
this.stats = pdfPage.stats;
|
416
|
+
this.eventBus.dispatch("pagerendered", {
|
417
|
+
source: this,
|
418
|
+
pageNumber: this.id,
|
419
|
+
cssTransform: false,
|
420
|
+
timestamp: performance.now()
|
421
|
+
});
|
422
|
+
|
423
|
+
if (error) {
|
424
|
+
throw error;
|
464
425
|
}
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
renderInteractiveForms: this.renderInteractiveForms
|
479
|
-
};
|
480
|
-
var renderTask = this.pdfPage.render(renderContext);
|
481
|
-
renderTask.onContinue = function (cont) {
|
482
|
-
showCanvas();
|
483
|
-
if (result.onRenderContinue) {
|
484
|
-
result.onRenderContinue(cont);
|
485
|
-
} else {
|
486
|
-
cont();
|
426
|
+
};
|
427
|
+
|
428
|
+
const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
|
429
|
+
paintTask.onRenderContinue = renderContinueCallback;
|
430
|
+
this.paintTask = paintTask;
|
431
|
+
const resultPromise = paintTask.promise.then(function () {
|
432
|
+
return finishPaintTask(null).then(function () {
|
433
|
+
if (textLayer) {
|
434
|
+
const readableStream = pdfPage.streamTextContent({
|
435
|
+
normalizeWhitespace: true
|
436
|
+
});
|
437
|
+
textLayer.setTextContentStream(readableStream);
|
438
|
+
textLayer.render();
|
487
439
|
}
|
488
|
-
};
|
489
|
-
renderTask.promise.then(function () {
|
490
|
-
showCanvas();
|
491
|
-
renderCapability.resolve(undefined);
|
492
|
-
}, function (error) {
|
493
|
-
showCanvas();
|
494
|
-
renderCapability.reject(error);
|
495
440
|
});
|
496
|
-
|
441
|
+
}, function (reason) {
|
442
|
+
return finishPaintTask(reason);
|
443
|
+
});
|
444
|
+
|
445
|
+
if (this.annotationLayerFactory) {
|
446
|
+
if (!this.annotationLayer) {
|
447
|
+
this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n);
|
448
|
+
}
|
449
|
+
|
450
|
+
this.annotationLayer.render(this.viewport, "display");
|
497
451
|
}
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
452
|
+
|
453
|
+
div.setAttribute("data-loaded", true);
|
454
|
+
this.eventBus.dispatch("pagerender", {
|
455
|
+
source: this,
|
456
|
+
pageNumber: this.id
|
457
|
+
});
|
458
|
+
return resultPromise;
|
459
|
+
}
|
460
|
+
|
461
|
+
paintOnCanvas(canvasWrapper) {
|
462
|
+
const renderCapability = (0, _pdf.createPromiseCapability)();
|
463
|
+
const result = {
|
464
|
+
promise: renderCapability.promise,
|
465
|
+
|
466
|
+
onRenderContinue(cont) {
|
467
|
+
cont();
|
468
|
+
},
|
469
|
+
|
470
|
+
cancel() {
|
471
|
+
renderTask.cancel();
|
472
|
+
}
|
473
|
+
|
474
|
+
};
|
475
|
+
const viewport = this.viewport;
|
476
|
+
const canvas = document.createElement("canvas");
|
477
|
+
this.l10n.get("page_canvas", {
|
478
|
+
page: this.id
|
479
|
+
}, "Page {{page}}").then(msg => {
|
480
|
+
canvas.setAttribute("aria-label", msg);
|
481
|
+
});
|
482
|
+
canvas.setAttribute("hidden", "hidden");
|
483
|
+
let isCanvasHidden = true;
|
484
|
+
|
485
|
+
const showCanvas = function () {
|
486
|
+
if (isCanvasHidden) {
|
487
|
+
canvas.removeAttribute("hidden");
|
488
|
+
isCanvasHidden = false;
|
489
|
+
}
|
490
|
+
};
|
491
|
+
|
492
|
+
canvasWrapper.appendChild(canvas);
|
493
|
+
this.canvas = canvas;
|
494
|
+
canvas.mozOpaque = true;
|
495
|
+
const ctx = canvas.getContext("2d", {
|
496
|
+
alpha: false
|
497
|
+
});
|
498
|
+
const outputScale = (0, _ui_utils.getOutputScale)(ctx);
|
499
|
+
this.outputScale = outputScale;
|
500
|
+
|
501
|
+
if (this.useOnlyCssZoom) {
|
502
|
+
const actualSizeViewport = viewport.clone({
|
503
|
+
scale: _ui_utils.CSS_UNITS
|
523
504
|
});
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
cont();
|
528
|
-
},
|
529
|
-
cancel: function cancel() {
|
530
|
-
cancelled = true;
|
531
|
-
}
|
532
|
-
};
|
505
|
+
outputScale.sx *= actualSizeViewport.width / viewport.width;
|
506
|
+
outputScale.sy *= actualSizeViewport.height / viewport.height;
|
507
|
+
outputScale.scaled = true;
|
533
508
|
}
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
509
|
+
|
510
|
+
if (this.maxCanvasPixels > 0) {
|
511
|
+
const pixelsInViewport = viewport.width * viewport.height;
|
512
|
+
const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
|
513
|
+
|
514
|
+
if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
|
515
|
+
outputScale.sx = maxScale;
|
516
|
+
outputScale.sy = maxScale;
|
517
|
+
outputScale.scaled = true;
|
518
|
+
this.hasRestrictedScaling = true;
|
540
519
|
} else {
|
541
|
-
this.
|
520
|
+
this.hasRestrictedScaling = false;
|
542
521
|
}
|
543
522
|
}
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
523
|
+
|
524
|
+
const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
|
525
|
+
const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
|
526
|
+
canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
|
527
|
+
canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
|
528
|
+
canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
|
529
|
+
canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
|
530
|
+
this.paintedViewportMap.set(canvas, viewport);
|
531
|
+
const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
|
532
|
+
const renderContext = {
|
533
|
+
canvasContext: ctx,
|
534
|
+
transform,
|
535
|
+
viewport: this.viewport,
|
536
|
+
enableWebGL: this.enableWebGL,
|
537
|
+
renderInteractiveForms: this.renderInteractiveForms
|
538
|
+
};
|
539
|
+
const renderTask = this.pdfPage.render(renderContext);
|
540
|
+
|
541
|
+
renderTask.onContinue = function (cont) {
|
542
|
+
showCanvas();
|
543
|
+
|
544
|
+
if (result.onRenderContinue) {
|
545
|
+
result.onRenderContinue(cont);
|
546
|
+
} else {
|
547
|
+
cont();
|
548
|
+
}
|
549
|
+
};
|
550
|
+
|
551
|
+
renderTask.promise.then(function () {
|
552
|
+
showCanvas();
|
553
|
+
renderCapability.resolve(undefined);
|
554
|
+
}, function (error) {
|
555
|
+
showCanvas();
|
556
|
+
renderCapability.reject(error);
|
557
|
+
});
|
558
|
+
return result;
|
559
|
+
}
|
560
|
+
|
561
|
+
paintOnSvg(wrapper) {
|
562
|
+
let cancelled = false;
|
563
|
+
|
564
|
+
const ensureNotCancelled = () => {
|
565
|
+
if (cancelled) {
|
566
|
+
throw new _pdf.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
|
567
|
+
}
|
568
|
+
};
|
569
|
+
|
570
|
+
const pdfPage = this.pdfPage;
|
571
|
+
const actualSizeViewport = this.viewport.clone({
|
572
|
+
scale: _ui_utils.CSS_UNITS
|
573
|
+
});
|
574
|
+
const promise = pdfPage.getOperatorList().then(opList => {
|
575
|
+
ensureNotCancelled();
|
576
|
+
const svgGfx = new _pdf.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
|
577
|
+
return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
|
578
|
+
ensureNotCancelled();
|
579
|
+
this.svg = svg;
|
580
|
+
this.paintedViewportMap.set(svg, actualSizeViewport);
|
581
|
+
svg.style.width = wrapper.style.width;
|
582
|
+
svg.style.height = wrapper.style.height;
|
583
|
+
this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
|
584
|
+
wrapper.appendChild(svg);
|
585
|
+
});
|
586
|
+
});
|
587
|
+
return {
|
588
|
+
promise,
|
589
|
+
|
590
|
+
onRenderContinue(cont) {
|
591
|
+
cont();
|
592
|
+
},
|
593
|
+
|
594
|
+
cancel() {
|
595
|
+
cancelled = true;
|
596
|
+
}
|
597
|
+
|
598
|
+
};
|
599
|
+
}
|
600
|
+
|
601
|
+
setPageLabel(label) {
|
602
|
+
this.pageLabel = typeof label === "string" ? label : null;
|
603
|
+
|
604
|
+
if (this.pageLabel !== null) {
|
605
|
+
this.div.setAttribute("data-page-label", this.pageLabel);
|
606
|
+
} else {
|
607
|
+
this.div.removeAttribute("data-page-label");
|
553
608
|
}
|
554
|
-
}
|
609
|
+
}
|
555
610
|
|
556
|
-
|
557
|
-
}();
|
611
|
+
}
|
558
612
|
|
559
613
|
exports.PDFPageView = PDFPageView;
|