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