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
@@ -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,32 +19,26 @@
|
|
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.renderTextLayer =
|
27
|
+
exports.renderTextLayer = void 0;
|
28
28
|
|
29
|
-
var _util = require(
|
30
|
-
|
31
|
-
var _global_scope = require('../shared/global_scope');
|
32
|
-
|
33
|
-
var _global_scope2 = _interopRequireDefault(_global_scope);
|
34
|
-
|
35
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29
|
+
var _util = require("../shared/util.js");
|
36
30
|
|
37
31
|
var renderTextLayer = function renderTextLayerClosure() {
|
38
32
|
var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
39
33
|
var NonWhitespaceRegexp = /\S/;
|
34
|
+
|
40
35
|
function isAllWhitespace(str) {
|
41
36
|
return !NonWhitespaceRegexp.test(str);
|
42
37
|
}
|
43
|
-
|
38
|
+
|
44
39
|
function appendText(task, geom, styles) {
|
45
|
-
var textDiv = document.createElement(
|
40
|
+
var textDiv = document.createElement("span");
|
46
41
|
var textDivProperties = {
|
47
|
-
style: null,
|
48
42
|
angle: 0,
|
49
43
|
canvasWidth: 0,
|
50
44
|
isWhitespace: false,
|
@@ -55,27 +49,37 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
55
49
|
paddingTop: 0,
|
56
50
|
scale: 1
|
57
51
|
};
|
52
|
+
|
58
53
|
task._textDivs.push(textDiv);
|
54
|
+
|
59
55
|
if (isAllWhitespace(geom.str)) {
|
60
56
|
textDivProperties.isWhitespace = true;
|
57
|
+
|
61
58
|
task._textDivProperties.set(textDiv, textDivProperties);
|
59
|
+
|
62
60
|
return;
|
63
61
|
}
|
62
|
+
|
64
63
|
var tx = _util.Util.transform(task._viewport.transform, geom.transform);
|
64
|
+
|
65
65
|
var angle = Math.atan2(tx[1], tx[0]);
|
66
66
|
var style = styles[geom.fontName];
|
67
|
+
|
67
68
|
if (style.vertical) {
|
68
69
|
angle += Math.PI / 2;
|
69
70
|
}
|
71
|
+
|
70
72
|
var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
|
71
73
|
var fontAscent = fontHeight;
|
74
|
+
|
72
75
|
if (style.ascent) {
|
73
76
|
fontAscent = style.ascent * fontAscent;
|
74
77
|
} else if (style.descent) {
|
75
78
|
fontAscent = (1 + style.descent) * fontAscent;
|
76
79
|
}
|
77
|
-
|
78
|
-
|
80
|
+
|
81
|
+
let left, top;
|
82
|
+
|
79
83
|
if (angle === 0) {
|
80
84
|
left = tx[4];
|
81
85
|
top = tx[5] - fontAscent;
|
@@ -83,19 +87,21 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
83
87
|
left = tx[4] + fontAscent * Math.sin(angle);
|
84
88
|
top = tx[5] - fontAscent * Math.cos(angle);
|
85
89
|
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
textDiv.setAttribute('style', textDivProperties.style);
|
90
|
+
|
91
|
+
textDiv.style.left = `${left}px`;
|
92
|
+
textDiv.style.top = `${top}px`;
|
93
|
+
textDiv.style.fontSize = `${fontHeight}px`;
|
94
|
+
textDiv.style.fontFamily = style.fontFamily;
|
92
95
|
textDiv.textContent = geom.str;
|
96
|
+
|
93
97
|
if (task._fontInspectorEnabled) {
|
94
98
|
textDiv.dataset.fontName = geom.fontName;
|
95
99
|
}
|
100
|
+
|
96
101
|
if (angle !== 0) {
|
97
102
|
textDivProperties.angle = angle * (180 / Math.PI);
|
98
103
|
}
|
104
|
+
|
99
105
|
if (geom.str.length > 1) {
|
100
106
|
if (style.vertical) {
|
101
107
|
textDivProperties.canvasWidth = geom.height * task._viewport.scale;
|
@@ -103,26 +109,33 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
103
109
|
textDivProperties.canvasWidth = geom.width * task._viewport.scale;
|
104
110
|
}
|
105
111
|
}
|
112
|
+
|
106
113
|
task._textDivProperties.set(textDiv, textDivProperties);
|
114
|
+
|
107
115
|
if (task._textContentStream) {
|
108
116
|
task._layoutText(textDiv);
|
109
117
|
}
|
118
|
+
|
110
119
|
if (task._enhanceTextSelection) {
|
111
120
|
var angleCos = 1,
|
112
121
|
angleSin = 0;
|
122
|
+
|
113
123
|
if (angle !== 0) {
|
114
124
|
angleCos = Math.cos(angle);
|
115
125
|
angleSin = Math.sin(angle);
|
116
126
|
}
|
127
|
+
|
117
128
|
var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
|
118
129
|
var divHeight = fontHeight;
|
119
130
|
var m, b;
|
131
|
+
|
120
132
|
if (angle !== 0) {
|
121
133
|
m = [angleCos, angleSin, -angleSin, angleCos, left, top];
|
122
134
|
b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
|
123
135
|
} else {
|
124
136
|
b = [left, top, left + divWidth, top + divHeight];
|
125
137
|
}
|
138
|
+
|
126
139
|
task._bounds.push({
|
127
140
|
left: b[0],
|
128
141
|
top: b[1],
|
@@ -130,45 +143,57 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
130
143
|
bottom: b[3],
|
131
144
|
div: textDiv,
|
132
145
|
size: [divWidth, divHeight],
|
133
|
-
m
|
146
|
+
m
|
134
147
|
});
|
135
148
|
}
|
136
149
|
}
|
150
|
+
|
137
151
|
function render(task) {
|
138
152
|
if (task._canceled) {
|
139
153
|
return;
|
140
154
|
}
|
155
|
+
|
141
156
|
var textDivs = task._textDivs;
|
142
157
|
var capability = task._capability;
|
143
158
|
var textDivsLength = textDivs.length;
|
159
|
+
|
144
160
|
if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
145
161
|
task._renderingDone = true;
|
146
162
|
capability.resolve();
|
147
163
|
return;
|
148
164
|
}
|
165
|
+
|
149
166
|
if (!task._textContentStream) {
|
150
167
|
for (var i = 0; i < textDivsLength; i++) {
|
151
168
|
task._layoutText(textDivs[i]);
|
152
169
|
}
|
153
170
|
}
|
171
|
+
|
154
172
|
task._renderingDone = true;
|
155
173
|
capability.resolve();
|
156
174
|
}
|
175
|
+
|
157
176
|
function expand(task) {
|
158
177
|
var bounds = task._bounds;
|
159
178
|
var viewport = task._viewport;
|
160
179
|
var expanded = expandBounds(viewport.width, viewport.height, bounds);
|
180
|
+
|
161
181
|
for (var i = 0; i < expanded.length; i++) {
|
162
182
|
var div = bounds[i].div;
|
183
|
+
|
163
184
|
var divProperties = task._textDivProperties.get(div);
|
185
|
+
|
164
186
|
if (divProperties.angle === 0) {
|
165
187
|
divProperties.paddingLeft = bounds[i].left - expanded[i].left;
|
166
188
|
divProperties.paddingTop = bounds[i].top - expanded[i].top;
|
167
189
|
divProperties.paddingRight = expanded[i].right - bounds[i].right;
|
168
190
|
divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
|
191
|
+
|
169
192
|
task._textDivProperties.set(div, divProperties);
|
193
|
+
|
170
194
|
continue;
|
171
195
|
}
|
196
|
+
|
172
197
|
var e = expanded[i],
|
173
198
|
b = bounds[i];
|
174
199
|
var m = b.m,
|
@@ -178,6 +203,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
178
203
|
var ts = new Float64Array(64);
|
179
204
|
points.forEach(function (p, i) {
|
180
205
|
var t = _util.Util.applyTransform(p, m);
|
206
|
+
|
181
207
|
ts[i + 0] = c && (e.left - t[0]) / c;
|
182
208
|
ts[i + 4] = s && (e.top - t[1]) / s;
|
183
209
|
ts[i + 8] = c && (e.right - t[0]) / c;
|
@@ -195,24 +221,31 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
195
221
|
ts[i + 56] = s && (e.right - t[0]) / s;
|
196
222
|
ts[i + 60] = c && (e.bottom - t[1]) / -c;
|
197
223
|
});
|
198
|
-
|
224
|
+
|
225
|
+
var findPositiveMin = function (ts, offset, count) {
|
199
226
|
var result = 0;
|
227
|
+
|
200
228
|
for (var i = 0; i < count; i++) {
|
201
229
|
var t = ts[offset++];
|
230
|
+
|
202
231
|
if (t > 0) {
|
203
232
|
result = result ? Math.min(t, result) : t;
|
204
233
|
}
|
205
234
|
}
|
235
|
+
|
206
236
|
return result;
|
207
237
|
};
|
238
|
+
|
208
239
|
var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
|
209
240
|
divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
|
210
241
|
divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
|
211
242
|
divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
|
212
243
|
divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
|
244
|
+
|
213
245
|
task._textDivProperties.set(div, divProperties);
|
214
246
|
}
|
215
247
|
}
|
248
|
+
|
216
249
|
function expandBounds(width, height, boxes) {
|
217
250
|
var bounds = boxes.map(function (box, i) {
|
218
251
|
return {
|
@@ -255,6 +288,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
255
288
|
});
|
256
289
|
return expanded;
|
257
290
|
}
|
291
|
+
|
258
292
|
function expandBoundsLTR(width, bounds) {
|
259
293
|
bounds.sort(function (a, b) {
|
260
294
|
return a.x1 - b.x1 || a.index - b.index;
|
@@ -275,21 +309,27 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
275
309
|
}];
|
276
310
|
bounds.forEach(function (boundary) {
|
277
311
|
var i = 0;
|
312
|
+
|
278
313
|
while (i < horizon.length && horizon[i].end <= boundary.y1) {
|
279
314
|
i++;
|
280
315
|
}
|
316
|
+
|
281
317
|
var j = horizon.length - 1;
|
318
|
+
|
282
319
|
while (j >= 0 && horizon[j].start >= boundary.y2) {
|
283
320
|
j--;
|
284
321
|
}
|
322
|
+
|
285
323
|
var horizonPart, affectedBoundary;
|
286
324
|
var q,
|
287
325
|
k,
|
288
326
|
maxXNew = -Infinity;
|
327
|
+
|
289
328
|
for (q = i; q <= j; q++) {
|
290
329
|
horizonPart = horizon[q];
|
291
330
|
affectedBoundary = horizonPart.boundary;
|
292
331
|
var xNew;
|
332
|
+
|
293
333
|
if (affectedBoundary.x2 > boundary.x1) {
|
294
334
|
xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
|
295
335
|
} else if (affectedBoundary.x2New === undefined) {
|
@@ -297,14 +337,18 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
297
337
|
} else {
|
298
338
|
xNew = affectedBoundary.x2New;
|
299
339
|
}
|
340
|
+
|
300
341
|
if (xNew > maxXNew) {
|
301
342
|
maxXNew = xNew;
|
302
343
|
}
|
303
344
|
}
|
345
|
+
|
304
346
|
boundary.x1New = maxXNew;
|
347
|
+
|
305
348
|
for (q = i; q <= j; q++) {
|
306
349
|
horizonPart = horizon[q];
|
307
350
|
affectedBoundary = horizonPart.boundary;
|
351
|
+
|
308
352
|
if (affectedBoundary.x2New === undefined) {
|
309
353
|
if (affectedBoundary.x2 > boundary.x1) {
|
310
354
|
if (affectedBoundary.index > boundary.index) {
|
@@ -317,12 +361,15 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
317
361
|
affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
|
318
362
|
}
|
319
363
|
}
|
364
|
+
|
320
365
|
var changedHorizon = [],
|
321
366
|
lastBoundary = null;
|
367
|
+
|
322
368
|
for (q = i; q <= j; q++) {
|
323
369
|
horizonPart = horizon[q];
|
324
370
|
affectedBoundary = horizonPart.boundary;
|
325
371
|
var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
|
372
|
+
|
326
373
|
if (lastBoundary === useBoundary) {
|
327
374
|
changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
|
328
375
|
} else {
|
@@ -334,6 +381,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
334
381
|
lastBoundary = useBoundary;
|
335
382
|
}
|
336
383
|
}
|
384
|
+
|
337
385
|
if (horizon[i].start < boundary.y1) {
|
338
386
|
changedHorizon[0].start = boundary.y1;
|
339
387
|
changedHorizon.unshift({
|
@@ -342,6 +390,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
342
390
|
boundary: horizon[i].boundary
|
343
391
|
});
|
344
392
|
}
|
393
|
+
|
345
394
|
if (boundary.y2 < horizon[j].end) {
|
346
395
|
changedHorizon[changedHorizon.length - 1].end = boundary.y2;
|
347
396
|
changedHorizon.push({
|
@@ -350,44 +399,54 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
350
399
|
boundary: horizon[j].boundary
|
351
400
|
});
|
352
401
|
}
|
402
|
+
|
353
403
|
for (q = i; q <= j; q++) {
|
354
404
|
horizonPart = horizon[q];
|
355
405
|
affectedBoundary = horizonPart.boundary;
|
406
|
+
|
356
407
|
if (affectedBoundary.x2New !== undefined) {
|
357
408
|
continue;
|
358
409
|
}
|
410
|
+
|
359
411
|
var used = false;
|
412
|
+
|
360
413
|
for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
|
361
414
|
used = horizon[k].boundary === affectedBoundary;
|
362
415
|
}
|
416
|
+
|
363
417
|
for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
|
364
418
|
used = horizon[k].boundary === affectedBoundary;
|
365
419
|
}
|
420
|
+
|
366
421
|
for (k = 0; !used && k < changedHorizon.length; k++) {
|
367
422
|
used = changedHorizon[k].boundary === affectedBoundary;
|
368
423
|
}
|
424
|
+
|
369
425
|
if (!used) {
|
370
426
|
affectedBoundary.x2New = maxXNew;
|
371
427
|
}
|
372
428
|
}
|
429
|
+
|
373
430
|
Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
|
374
431
|
});
|
375
432
|
horizon.forEach(function (horizonPart) {
|
376
433
|
var affectedBoundary = horizonPart.boundary;
|
434
|
+
|
377
435
|
if (affectedBoundary.x2New === undefined) {
|
378
436
|
affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
|
379
437
|
}
|
380
438
|
});
|
381
439
|
}
|
382
|
-
function TextLayerRenderTask(_ref) {
|
383
|
-
var textContent = _ref.textContent,
|
384
|
-
textContentStream = _ref.textContentStream,
|
385
|
-
container = _ref.container,
|
386
|
-
viewport = _ref.viewport,
|
387
|
-
textDivs = _ref.textDivs,
|
388
|
-
textContentItemsStr = _ref.textContentItemsStr,
|
389
|
-
enhanceTextSelection = _ref.enhanceTextSelection;
|
390
440
|
|
441
|
+
function TextLayerRenderTask({
|
442
|
+
textContent,
|
443
|
+
textContentStream,
|
444
|
+
container,
|
445
|
+
viewport,
|
446
|
+
textDivs,
|
447
|
+
textContentItemsStr,
|
448
|
+
enhanceTextSelection
|
449
|
+
}) {
|
391
450
|
this._textContent = textContent;
|
392
451
|
this._textContentStream = textContentStream;
|
393
452
|
this._container = container;
|
@@ -395,7 +454,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
395
454
|
this._textDivs = textDivs || [];
|
396
455
|
this._textContentItemsStr = textContentItemsStr || [];
|
397
456
|
this._enhanceTextSelection = !!enhanceTextSelection;
|
398
|
-
this._fontInspectorEnabled = !!(
|
457
|
+
this._fontInspectorEnabled = !!(globalThis.FontInspector && globalThis.FontInspector.enabled);
|
399
458
|
this._reader = null;
|
400
459
|
this._layoutTextLastFontSize = null;
|
401
460
|
this._layoutTextLastFontFamily = null;
|
@@ -406,100 +465,144 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
406
465
|
this._capability = (0, _util.createPromiseCapability)();
|
407
466
|
this._renderTimer = null;
|
408
467
|
this._bounds = [];
|
468
|
+
|
469
|
+
this._capability.promise.finally(() => {
|
470
|
+
if (this._layoutTextCtx) {
|
471
|
+
this._layoutTextCtx.canvas.width = 0;
|
472
|
+
this._layoutTextCtx.canvas.height = 0;
|
473
|
+
this._layoutTextCtx = null;
|
474
|
+
}
|
475
|
+
}).catch(() => {});
|
409
476
|
}
|
477
|
+
|
410
478
|
TextLayerRenderTask.prototype = {
|
411
479
|
get promise() {
|
412
480
|
return this._capability.promise;
|
413
481
|
},
|
482
|
+
|
414
483
|
cancel: function TextLayer_cancel() {
|
484
|
+
this._canceled = true;
|
485
|
+
|
415
486
|
if (this._reader) {
|
416
|
-
this._reader.cancel(new _util.AbortException(
|
487
|
+
this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
|
488
|
+
|
417
489
|
this._reader = null;
|
418
490
|
}
|
419
|
-
|
491
|
+
|
420
492
|
if (this._renderTimer !== null) {
|
421
493
|
clearTimeout(this._renderTimer);
|
422
494
|
this._renderTimer = null;
|
423
495
|
}
|
424
|
-
|
496
|
+
|
497
|
+
this._capability.reject(new Error("TextLayer task cancelled."));
|
425
498
|
},
|
426
|
-
|
427
|
-
|
499
|
+
|
500
|
+
_processItems(items, styleCache) {
|
501
|
+
for (let i = 0, len = items.length; i < len; i++) {
|
428
502
|
this._textContentItemsStr.push(items[i].str);
|
503
|
+
|
429
504
|
appendText(this, items[i], styleCache);
|
430
505
|
}
|
431
506
|
},
|
432
|
-
|
433
|
-
|
434
|
-
|
507
|
+
|
508
|
+
_layoutText(textDiv) {
|
509
|
+
const textDivProperties = this._textDivProperties.get(textDiv);
|
510
|
+
|
435
511
|
if (textDivProperties.isWhitespace) {
|
436
512
|
return;
|
437
513
|
}
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
514
|
+
|
515
|
+
let transform = "";
|
516
|
+
|
517
|
+
if (textDivProperties.canvasWidth !== 0) {
|
518
|
+
const {
|
519
|
+
fontSize,
|
520
|
+
fontFamily
|
521
|
+
} = textDiv.style;
|
522
|
+
|
523
|
+
if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
|
524
|
+
this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
|
525
|
+
this._layoutTextLastFontSize = fontSize;
|
526
|
+
this._layoutTextLastFontFamily = fontFamily;
|
527
|
+
}
|
528
|
+
|
529
|
+
const {
|
530
|
+
width
|
531
|
+
} = this._layoutTextCtx.measureText(textDiv.textContent);
|
532
|
+
|
533
|
+
if (width > 0) {
|
534
|
+
textDivProperties.scale = textDivProperties.canvasWidth / width;
|
535
|
+
transform = `scaleX(${textDivProperties.scale})`;
|
536
|
+
}
|
450
537
|
}
|
538
|
+
|
451
539
|
if (textDivProperties.angle !== 0) {
|
452
|
-
transform =
|
540
|
+
transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
|
453
541
|
}
|
454
|
-
|
455
|
-
|
542
|
+
|
543
|
+
if (transform.length > 0) {
|
544
|
+
if (this._enhanceTextSelection) {
|
545
|
+
textDivProperties.originalTransform = transform;
|
546
|
+
}
|
547
|
+
|
456
548
|
textDiv.style.transform = transform;
|
457
549
|
}
|
550
|
+
|
458
551
|
this._textDivProperties.set(textDiv, textDivProperties);
|
459
|
-
|
552
|
+
|
553
|
+
this._container.appendChild(textDiv);
|
460
554
|
},
|
461
555
|
|
462
556
|
_render: function TextLayer_render(timeout) {
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
var styleCache = Object.create(null);
|
467
|
-
var canvas = document.createElement('canvas');
|
557
|
+
const capability = (0, _util.createPromiseCapability)();
|
558
|
+
let styleCache = Object.create(null);
|
559
|
+
const canvas = document.createElement("canvas");
|
468
560
|
canvas.mozOpaque = true;
|
469
|
-
this._layoutTextCtx = canvas.getContext(
|
561
|
+
this._layoutTextCtx = canvas.getContext("2d", {
|
562
|
+
alpha: false
|
563
|
+
});
|
564
|
+
|
470
565
|
if (this._textContent) {
|
471
|
-
|
472
|
-
|
566
|
+
const textItems = this._textContent.items;
|
567
|
+
const textStyles = this._textContent.styles;
|
568
|
+
|
473
569
|
this._processItems(textItems, textStyles);
|
570
|
+
|
474
571
|
capability.resolve();
|
475
572
|
} else if (this._textContentStream) {
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
573
|
+
const pump = () => {
|
574
|
+
this._reader.read().then(({
|
575
|
+
value,
|
576
|
+
done
|
577
|
+
}) => {
|
481
578
|
if (done) {
|
482
579
|
capability.resolve();
|
483
580
|
return;
|
484
581
|
}
|
582
|
+
|
485
583
|
Object.assign(styleCache, value.styles);
|
486
|
-
|
584
|
+
|
585
|
+
this._processItems(value.items, styleCache);
|
586
|
+
|
487
587
|
pump();
|
488
588
|
}, capability.reject);
|
489
589
|
};
|
590
|
+
|
490
591
|
this._reader = this._textContentStream.getReader();
|
491
592
|
pump();
|
492
593
|
} else {
|
493
|
-
throw new Error('Neither "textContent" nor "textContentStream"' +
|
594
|
+
throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
|
494
595
|
}
|
495
|
-
|
596
|
+
|
597
|
+
capability.promise.then(() => {
|
496
598
|
styleCache = null;
|
599
|
+
|
497
600
|
if (!timeout) {
|
498
|
-
render(
|
601
|
+
render(this);
|
499
602
|
} else {
|
500
|
-
|
501
|
-
render(
|
502
|
-
|
603
|
+
this._renderTimer = setTimeout(() => {
|
604
|
+
render(this);
|
605
|
+
this._renderTimer = null;
|
503
606
|
}, timeout);
|
504
607
|
}
|
505
608
|
}, this._capability.reject);
|
@@ -508,52 +611,71 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
508
611
|
if (!this._enhanceTextSelection || !this._renderingDone) {
|
509
612
|
return;
|
510
613
|
}
|
614
|
+
|
511
615
|
if (this._bounds !== null) {
|
512
616
|
expand(this);
|
513
617
|
this._bounds = null;
|
514
618
|
}
|
619
|
+
|
620
|
+
const transformBuf = [],
|
621
|
+
paddingBuf = [];
|
622
|
+
|
515
623
|
for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
|
516
|
-
|
517
|
-
|
518
|
-
|
624
|
+
const div = this._textDivs[i];
|
625
|
+
|
626
|
+
const divProps = this._textDivProperties.get(div);
|
627
|
+
|
628
|
+
if (divProps.isWhitespace) {
|
519
629
|
continue;
|
520
630
|
}
|
631
|
+
|
521
632
|
if (expandDivs) {
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
if (divProperties.angle !== 0) {
|
528
|
-
transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
|
529
|
-
}
|
530
|
-
if (divProperties.paddingLeft !== 0) {
|
531
|
-
padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
|
532
|
-
transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
|
633
|
+
transformBuf.length = 0;
|
634
|
+
paddingBuf.length = 0;
|
635
|
+
|
636
|
+
if (divProps.originalTransform) {
|
637
|
+
transformBuf.push(divProps.originalTransform);
|
533
638
|
}
|
534
|
-
|
535
|
-
|
536
|
-
|
639
|
+
|
640
|
+
if (divProps.paddingTop > 0) {
|
641
|
+
paddingBuf.push(`${divProps.paddingTop}px`);
|
642
|
+
transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
|
643
|
+
} else {
|
644
|
+
paddingBuf.push(0);
|
537
645
|
}
|
538
|
-
|
539
|
-
|
646
|
+
|
647
|
+
if (divProps.paddingRight > 0) {
|
648
|
+
paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
|
649
|
+
} else {
|
650
|
+
paddingBuf.push(0);
|
540
651
|
}
|
541
|
-
|
542
|
-
|
652
|
+
|
653
|
+
if (divProps.paddingBottom > 0) {
|
654
|
+
paddingBuf.push(`${divProps.paddingBottom}px`);
|
655
|
+
} else {
|
656
|
+
paddingBuf.push(0);
|
543
657
|
}
|
544
|
-
|
545
|
-
|
658
|
+
|
659
|
+
if (divProps.paddingLeft > 0) {
|
660
|
+
paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
|
661
|
+
transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
|
662
|
+
} else {
|
663
|
+
paddingBuf.push(0);
|
546
664
|
}
|
547
|
-
|
548
|
-
|
665
|
+
|
666
|
+
div.style.padding = paddingBuf.join(" ");
|
667
|
+
|
668
|
+
if (transformBuf.length) {
|
669
|
+
div.style.transform = transformBuf.join(" ");
|
549
670
|
}
|
550
671
|
} else {
|
551
|
-
div.style.padding =
|
552
|
-
div.style.transform =
|
672
|
+
div.style.padding = null;
|
673
|
+
div.style.transform = divProps.originalTransform;
|
553
674
|
}
|
554
675
|
}
|
555
676
|
}
|
556
677
|
};
|
678
|
+
|
557
679
|
function renderTextLayer(renderParameters) {
|
558
680
|
var task = new TextLayerRenderTask({
|
559
681
|
textContent: renderParameters.textContent,
|
@@ -564,9 +686,13 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
564
686
|
textContentItemsStr: renderParameters.textContentItemsStr,
|
565
687
|
enhanceTextSelection: renderParameters.enhanceTextSelection
|
566
688
|
});
|
689
|
+
|
567
690
|
task._render(renderParameters.timeout);
|
691
|
+
|
568
692
|
return task;
|
569
693
|
}
|
694
|
+
|
570
695
|
return renderTextLayer;
|
571
696
|
}();
|
697
|
+
|
572
698
|
exports.renderTextLayer = renderTextLayer;
|