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.
|
@@ -26,11 +26,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.renderTextLayer = void 0;
|
28
28
|
|
29
|
-
var _util = require("../shared/util");
|
30
|
-
|
31
|
-
var _global_scope = _interopRequireDefault(require("../shared/global_scope"));
|
32
|
-
|
33
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
29
|
+
var _util = require("../shared/util.js");
|
34
30
|
|
35
31
|
var renderTextLayer = function renderTextLayerClosure() {
|
36
32
|
var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
@@ -40,12 +36,9 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
40
36
|
return !NonWhitespaceRegexp.test(str);
|
41
37
|
}
|
42
38
|
|
43
|
-
var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0, 'px; font-family: ', '', ';'];
|
44
|
-
|
45
39
|
function appendText(task, geom, styles) {
|
46
|
-
var textDiv = document.createElement(
|
40
|
+
var textDiv = document.createElement("span");
|
47
41
|
var textDivProperties = {
|
48
|
-
style: null,
|
49
42
|
angle: 0,
|
50
43
|
canvasWidth: 0,
|
51
44
|
isWhitespace: false,
|
@@ -85,8 +78,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
85
78
|
fontAscent = (1 + style.descent) * fontAscent;
|
86
79
|
}
|
87
80
|
|
88
|
-
|
89
|
-
var top;
|
81
|
+
let left, top;
|
90
82
|
|
91
83
|
if (angle === 0) {
|
92
84
|
left = tx[4];
|
@@ -96,12 +88,10 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
96
88
|
top = tx[5] - fontAscent * Math.cos(angle);
|
97
89
|
}
|
98
90
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
textDivProperties.style = styleBuf.join('');
|
104
|
-
textDiv.setAttribute('style', textDivProperties.style);
|
91
|
+
textDiv.style.left = `${left}px`;
|
92
|
+
textDiv.style.top = `${top}px`;
|
93
|
+
textDiv.style.fontSize = `${fontHeight}px`;
|
94
|
+
textDiv.style.fontFamily = style.fontFamily;
|
105
95
|
textDiv.textContent = geom.str;
|
106
96
|
|
107
97
|
if (task._fontInspectorEnabled) {
|
@@ -112,7 +102,20 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
112
102
|
textDivProperties.angle = angle * (180 / Math.PI);
|
113
103
|
}
|
114
104
|
|
105
|
+
let shouldScaleText = false;
|
106
|
+
|
115
107
|
if (geom.str.length > 1) {
|
108
|
+
shouldScaleText = true;
|
109
|
+
} else if (geom.transform[0] !== geom.transform[3]) {
|
110
|
+
const absScaleX = Math.abs(geom.transform[0]),
|
111
|
+
absScaleY = Math.abs(geom.transform[3]);
|
112
|
+
|
113
|
+
if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
|
114
|
+
shouldScaleText = true;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
if (shouldScaleText) {
|
116
119
|
if (style.vertical) {
|
117
120
|
textDivProperties.canvasWidth = geom.height * task._viewport.scale;
|
118
121
|
} else {
|
@@ -153,7 +156,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
153
156
|
bottom: b[3],
|
154
157
|
div: textDiv,
|
155
158
|
size: [divWidth, divHeight],
|
156
|
-
m
|
159
|
+
m
|
157
160
|
});
|
158
161
|
}
|
159
162
|
}
|
@@ -183,6 +186,20 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
183
186
|
capability.resolve();
|
184
187
|
}
|
185
188
|
|
189
|
+
function findPositiveMin(ts, offset, count) {
|
190
|
+
let result = 0;
|
191
|
+
|
192
|
+
for (let i = 0; i < count; i++) {
|
193
|
+
const t = ts[offset++];
|
194
|
+
|
195
|
+
if (t > 0) {
|
196
|
+
result = result ? Math.min(t, result) : t;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
return result;
|
201
|
+
}
|
202
|
+
|
186
203
|
function expand(task) {
|
187
204
|
var bounds = task._bounds;
|
188
205
|
var viewport = task._viewport;
|
@@ -211,41 +228,26 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
211
228
|
s = m[1];
|
212
229
|
var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
|
213
230
|
var ts = new Float64Array(64);
|
214
|
-
points.forEach(function (p,
|
231
|
+
points.forEach(function (p, j) {
|
215
232
|
var t = _util.Util.applyTransform(p, m);
|
216
233
|
|
217
|
-
ts[
|
218
|
-
ts[
|
219
|
-
ts[
|
220
|
-
ts[
|
221
|
-
ts[
|
222
|
-
ts[
|
223
|
-
ts[
|
224
|
-
ts[
|
225
|
-
ts[
|
226
|
-
ts[
|
227
|
-
ts[
|
228
|
-
ts[
|
229
|
-
ts[
|
230
|
-
ts[
|
231
|
-
ts[
|
232
|
-
ts[
|
234
|
+
ts[j + 0] = c && (e.left - t[0]) / c;
|
235
|
+
ts[j + 4] = s && (e.top - t[1]) / s;
|
236
|
+
ts[j + 8] = c && (e.right - t[0]) / c;
|
237
|
+
ts[j + 12] = s && (e.bottom - t[1]) / s;
|
238
|
+
ts[j + 16] = s && (e.left - t[0]) / -s;
|
239
|
+
ts[j + 20] = c && (e.top - t[1]) / c;
|
240
|
+
ts[j + 24] = s && (e.right - t[0]) / -s;
|
241
|
+
ts[j + 28] = c && (e.bottom - t[1]) / c;
|
242
|
+
ts[j + 32] = c && (e.left - t[0]) / -c;
|
243
|
+
ts[j + 36] = s && (e.top - t[1]) / -s;
|
244
|
+
ts[j + 40] = c && (e.right - t[0]) / -c;
|
245
|
+
ts[j + 44] = s && (e.bottom - t[1]) / -s;
|
246
|
+
ts[j + 48] = s && (e.left - t[0]) / s;
|
247
|
+
ts[j + 52] = c && (e.top - t[1]) / -c;
|
248
|
+
ts[j + 56] = s && (e.right - t[0]) / s;
|
249
|
+
ts[j + 60] = c && (e.bottom - t[1]) / -c;
|
233
250
|
});
|
234
|
-
|
235
|
-
var findPositiveMin = function findPositiveMin(ts, offset, count) {
|
236
|
-
var result = 0;
|
237
|
-
|
238
|
-
for (var i = 0; i < count; i++) {
|
239
|
-
var t = ts[offset++];
|
240
|
-
|
241
|
-
if (t > 0) {
|
242
|
-
result = result ? Math.min(t, result) : t;
|
243
|
-
}
|
244
|
-
}
|
245
|
-
|
246
|
-
return result;
|
247
|
-
};
|
248
|
-
|
249
251
|
var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
|
250
252
|
divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
|
251
253
|
divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
|
@@ -448,24 +450,24 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
448
450
|
});
|
449
451
|
}
|
450
452
|
|
451
|
-
function TextLayerRenderTask(
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
enhanceTextSelection = _ref.enhanceTextSelection;
|
453
|
+
function TextLayerRenderTask({
|
454
|
+
textContent,
|
455
|
+
textContentStream,
|
456
|
+
container,
|
457
|
+
viewport,
|
458
|
+
textDivs,
|
459
|
+
textContentItemsStr,
|
460
|
+
enhanceTextSelection
|
461
|
+
}) {
|
461
462
|
this._textContent = textContent;
|
462
463
|
this._textContentStream = textContentStream;
|
463
464
|
this._container = container;
|
465
|
+
this._document = container.ownerDocument;
|
464
466
|
this._viewport = viewport;
|
465
467
|
this._textDivs = textDivs || [];
|
466
468
|
this._textContentItemsStr = textContentItemsStr || [];
|
467
469
|
this._enhanceTextSelection = !!enhanceTextSelection;
|
468
|
-
this._fontInspectorEnabled = !!(
|
470
|
+
this._fontInspectorEnabled = !!(globalThis.FontInspector && globalThis.FontInspector.enabled);
|
469
471
|
this._reader = null;
|
470
472
|
this._layoutTextLastFontSize = null;
|
471
473
|
this._layoutTextLastFontFamily = null;
|
@@ -477,13 +479,13 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
477
479
|
this._renderTimer = null;
|
478
480
|
this._bounds = [];
|
479
481
|
|
480
|
-
this._capability.promise
|
481
|
-
if (
|
482
|
-
|
483
|
-
|
484
|
-
|
482
|
+
this._capability.promise.finally(() => {
|
483
|
+
if (this._layoutTextCtx) {
|
484
|
+
this._layoutTextCtx.canvas.width = 0;
|
485
|
+
this._layoutTextCtx.canvas.height = 0;
|
486
|
+
this._layoutTextCtx = null;
|
485
487
|
}
|
486
|
-
});
|
488
|
+
}).catch(() => {});
|
487
489
|
}
|
488
490
|
|
489
491
|
TextLayerRenderTask.prototype = {
|
@@ -495,7 +497,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
495
497
|
this._canceled = true;
|
496
498
|
|
497
499
|
if (this._reader) {
|
498
|
-
this._reader.cancel(new _util.AbortException(
|
500
|
+
this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
|
499
501
|
|
500
502
|
this._reader = null;
|
501
503
|
}
|
@@ -505,79 +507,89 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
505
507
|
this._renderTimer = null;
|
506
508
|
}
|
507
509
|
|
508
|
-
this._capability.reject(new Error(
|
510
|
+
this._capability.reject(new Error("TextLayer task cancelled."));
|
509
511
|
},
|
510
|
-
|
511
|
-
|
512
|
+
|
513
|
+
_processItems(items, styleCache) {
|
514
|
+
for (let i = 0, len = items.length; i < len; i++) {
|
512
515
|
this._textContentItemsStr.push(items[i].str);
|
513
516
|
|
514
517
|
appendText(this, items[i], styleCache);
|
515
518
|
}
|
516
519
|
},
|
517
|
-
_layoutText: function _layoutText(textDiv) {
|
518
|
-
var textLayerFrag = this._container;
|
519
520
|
|
520
|
-
|
521
|
+
_layoutText(textDiv) {
|
522
|
+
const textDivProperties = this._textDivProperties.get(textDiv);
|
521
523
|
|
522
524
|
if (textDivProperties.isWhitespace) {
|
523
525
|
return;
|
524
526
|
}
|
525
527
|
|
526
|
-
|
527
|
-
var fontFamily = textDiv.style.fontFamily;
|
528
|
+
let transform = "";
|
528
529
|
|
529
|
-
if (
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
530
|
+
if (textDivProperties.canvasWidth !== 0) {
|
531
|
+
const {
|
532
|
+
fontSize,
|
533
|
+
fontFamily
|
534
|
+
} = textDiv.style;
|
534
535
|
|
535
|
-
|
536
|
+
if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
|
537
|
+
this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
|
538
|
+
this._layoutTextLastFontSize = fontSize;
|
539
|
+
this._layoutTextLastFontFamily = fontFamily;
|
540
|
+
}
|
536
541
|
|
537
|
-
|
542
|
+
const {
|
543
|
+
width
|
544
|
+
} = this._layoutTextCtx.measureText(textDiv.textContent);
|
538
545
|
|
539
|
-
|
540
|
-
|
541
|
-
|
546
|
+
if (width > 0) {
|
547
|
+
textDivProperties.scale = textDivProperties.canvasWidth / width;
|
548
|
+
transform = `scaleX(${textDivProperties.scale})`;
|
549
|
+
}
|
542
550
|
}
|
543
551
|
|
544
552
|
if (textDivProperties.angle !== 0) {
|
545
|
-
transform =
|
553
|
+
transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
|
546
554
|
}
|
547
555
|
|
548
556
|
if (transform.length > 0) {
|
549
|
-
|
557
|
+
if (this._enhanceTextSelection) {
|
558
|
+
textDivProperties.originalTransform = transform;
|
559
|
+
}
|
560
|
+
|
550
561
|
textDiv.style.transform = transform;
|
551
562
|
}
|
552
563
|
|
553
564
|
this._textDivProperties.set(textDiv, textDivProperties);
|
554
565
|
|
555
|
-
|
566
|
+
this._container.appendChild(textDiv);
|
556
567
|
},
|
568
|
+
|
557
569
|
_render: function TextLayer_render(timeout) {
|
558
|
-
|
570
|
+
const capability = (0, _util.createPromiseCapability)();
|
571
|
+
let styleCache = Object.create(null);
|
572
|
+
|
573
|
+
const canvas = this._document.createElement("canvas");
|
559
574
|
|
560
|
-
var capability = (0, _util.createPromiseCapability)();
|
561
|
-
var styleCache = Object.create(null);
|
562
|
-
var canvas = document.createElement('canvas');
|
563
575
|
canvas.mozOpaque = true;
|
564
|
-
this._layoutTextCtx = canvas.getContext(
|
576
|
+
this._layoutTextCtx = canvas.getContext("2d", {
|
565
577
|
alpha: false
|
566
578
|
});
|
567
579
|
|
568
580
|
if (this._textContent) {
|
569
|
-
|
570
|
-
|
581
|
+
const textItems = this._textContent.items;
|
582
|
+
const textStyles = this._textContent.styles;
|
571
583
|
|
572
584
|
this._processItems(textItems, textStyles);
|
573
585
|
|
574
586
|
capability.resolve();
|
575
587
|
} else if (this._textContentStream) {
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
588
|
+
const pump = () => {
|
589
|
+
this._reader.read().then(({
|
590
|
+
value,
|
591
|
+
done
|
592
|
+
}) => {
|
581
593
|
if (done) {
|
582
594
|
capability.resolve();
|
583
595
|
return;
|
@@ -585,7 +597,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
585
597
|
|
586
598
|
Object.assign(styleCache, value.styles);
|
587
599
|
|
588
|
-
|
600
|
+
this._processItems(value.items, styleCache);
|
589
601
|
|
590
602
|
pump();
|
591
603
|
}, capability.reject);
|
@@ -594,18 +606,18 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
594
606
|
this._reader = this._textContentStream.getReader();
|
595
607
|
pump();
|
596
608
|
} else {
|
597
|
-
throw new Error('Neither "textContent" nor "textContentStream"' +
|
609
|
+
throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
|
598
610
|
}
|
599
611
|
|
600
|
-
capability.promise.then(
|
612
|
+
capability.promise.then(() => {
|
601
613
|
styleCache = null;
|
602
614
|
|
603
615
|
if (!timeout) {
|
604
|
-
render(
|
616
|
+
render(this);
|
605
617
|
} else {
|
606
|
-
|
607
|
-
render(
|
608
|
-
|
618
|
+
this._renderTimer = setTimeout(() => {
|
619
|
+
render(this);
|
620
|
+
this._renderTimer = null;
|
609
621
|
}, timeout);
|
610
622
|
}
|
611
623
|
}, this._capability.reject);
|
@@ -620,55 +632,60 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
620
632
|
this._bounds = null;
|
621
633
|
}
|
622
634
|
|
635
|
+
const transformBuf = [],
|
636
|
+
paddingBuf = [];
|
637
|
+
|
623
638
|
for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
|
624
|
-
|
639
|
+
const div = this._textDivs[i];
|
625
640
|
|
626
|
-
|
641
|
+
const divProps = this._textDivProperties.get(div);
|
627
642
|
|
628
|
-
if (
|
643
|
+
if (divProps.isWhitespace) {
|
629
644
|
continue;
|
630
645
|
}
|
631
646
|
|
632
647
|
if (expandDivs) {
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
if (divProperties.scale !== 1) {
|
637
|
-
transform = 'scaleX(' + divProperties.scale + ')';
|
638
|
-
}
|
648
|
+
transformBuf.length = 0;
|
649
|
+
paddingBuf.length = 0;
|
639
650
|
|
640
|
-
if (
|
641
|
-
|
651
|
+
if (divProps.originalTransform) {
|
652
|
+
transformBuf.push(divProps.originalTransform);
|
642
653
|
}
|
643
654
|
|
644
|
-
if (
|
645
|
-
|
646
|
-
|
655
|
+
if (divProps.paddingTop > 0) {
|
656
|
+
paddingBuf.push(`${divProps.paddingTop}px`);
|
657
|
+
transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
|
658
|
+
} else {
|
659
|
+
paddingBuf.push(0);
|
647
660
|
}
|
648
661
|
|
649
|
-
if (
|
650
|
-
|
651
|
-
|
662
|
+
if (divProps.paddingRight > 0) {
|
663
|
+
paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
|
664
|
+
} else {
|
665
|
+
paddingBuf.push(0);
|
652
666
|
}
|
653
667
|
|
654
|
-
if (
|
655
|
-
|
668
|
+
if (divProps.paddingBottom > 0) {
|
669
|
+
paddingBuf.push(`${divProps.paddingBottom}px`);
|
670
|
+
} else {
|
671
|
+
paddingBuf.push(0);
|
656
672
|
}
|
657
673
|
|
658
|
-
if (
|
659
|
-
|
674
|
+
if (divProps.paddingLeft > 0) {
|
675
|
+
paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
|
676
|
+
transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
|
677
|
+
} else {
|
678
|
+
paddingBuf.push(0);
|
660
679
|
}
|
661
680
|
|
662
|
-
|
663
|
-
div.setAttribute('style', divProperties.style + padding);
|
664
|
-
}
|
681
|
+
div.style.padding = paddingBuf.join(" ");
|
665
682
|
|
666
|
-
if (
|
667
|
-
div.style.transform =
|
683
|
+
if (transformBuf.length) {
|
684
|
+
div.style.transform = transformBuf.join(" ");
|
668
685
|
}
|
669
686
|
} else {
|
670
|
-
div.style.padding =
|
671
|
-
div.style.transform =
|
687
|
+
div.style.padding = null;
|
688
|
+
div.style.transform = divProps.originalTransform;
|
672
689
|
}
|
673
690
|
}
|
674
691
|
}
|