pdfjs-dist 2.0.550 → 2.3.200
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/bower.json +1 -1
- package/build/pdf.js +21618 -14369
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +22758 -11399
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/image_decoders/pdf.image_decoders.js +11500 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +767 -258
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +433 -61
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +428 -157
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +173 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +575 -272
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1032 -351
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +813 -196
- package/lib/core/function.js +253 -27
- package/lib/core/glyphlist.js +5 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +502 -72
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +293 -52
- package/lib/core/jpx.js +419 -12
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +15 -15
- package/lib/core/murmurhash3.js +56 -34
- package/lib/core/obj.js +1368 -500
- package/lib/core/operator_list.js +159 -43
- package/lib/core/parser.js +544 -199
- package/lib/core/pattern.js +170 -21
- package/lib/core/pdf_manager.js +324 -134
- package/lib/core/primitives.js +169 -61
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +327 -34
- package/lib/core/type1_parser.js +148 -8
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +215 -229
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +618 -192
- package/lib/display/api.js +1798 -882
- package/lib/display/api_compatibility.js +5 -10
- package/lib/display/canvas.js +366 -45
- package/lib/display/content_disposition.js +71 -24
- package/lib/display/display_utils.js +777 -0
- package/lib/display/fetch_stream.js +205 -87
- package/lib/display/font_loader.js +468 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +635 -428
- package/lib/display/network_utils.js +38 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +103 -36
- package/lib/display/svg.js +1232 -519
- package/lib/display/text_layer.js +208 -75
- package/lib/display/transport_stream.js +345 -94
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +60 -4
- package/lib/pdf.js +35 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +170 -572
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +216 -163
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/util.js +495 -385
- package/lib/test/unit/annotation_spec.js +1464 -401
- package/lib/test/unit/api_spec.js +718 -361
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +54 -11
- package/lib/test/unit/clitests_helper.js +9 -10
- package/lib/test/unit/cmap_spec.js +95 -41
- package/lib/test/unit/colorspace_spec.js +115 -63
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +43 -55
- package/lib/test/unit/display_svg_spec.js +34 -18
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +8 -13
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +59 -20
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/message_handler_spec.js +30 -13
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +22 -55
- package/lib/test/unit/network_utils_spec.js +105 -14
- package/lib/test/unit/node_stream_spec.js +58 -34
- package/lib/test/unit/parser_spec.js +162 -71
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +55 -22
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +273 -56
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +9 -7
- package/lib/test/unit/ui_utils_spec.js +236 -36
- package/lib/test/unit/unicode_spec.js +18 -15
- package/lib/test/unit/util_spec.js +87 -128
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1252 -609
- package/lib/web/app_options.js +103 -65
- package/lib/web/base_viewer.js +522 -242
- package/lib/web/chromecom.js +259 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +31 -12
- package/lib/web/firefox_print_service.js +27 -14
- package/lib/web/firefoxcom.js +318 -78
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +28 -4
- package/lib/web/interfaces.js +174 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +22 -14
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +255 -136
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +144 -79
- package/lib/web/pdf_outline_viewer.js +124 -47
- package/lib/web/pdf_page_view.js +194 -74
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +59 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +144 -81
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +104 -33
- package/lib/web/pdf_thumbnail_viewer.js +66 -26
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +82 -87
- package/lib/web/preferences.js +284 -91
- package/lib/web/secondary_toolbar.js +132 -59
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +80 -43
- package/lib/web/ui_utils.js +400 -134
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +3 -8
- package/package.json +3 -2
- package/web/pdf_viewer.css +23 -15
- package/web/pdf_viewer.js +3429 -1245
- package/web/pdf_viewer.js.map +1 -1
- package/external/streams/streams-lib.js +0 -3962
- package/lib/display/dom_utils.js +0 -429
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
@@ -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 2019 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,30 @@
|
|
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(
|
29
|
+
var _util = require("../shared/util");
|
30
30
|
|
31
|
-
var _global_scope = require(
|
31
|
+
var _global_scope = _interopRequireDefault(require("../shared/global_scope"));
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
36
34
|
|
37
35
|
var renderTextLayer = function renderTextLayerClosure() {
|
38
36
|
var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
39
37
|
var NonWhitespaceRegexp = /\S/;
|
38
|
+
|
40
39
|
function isAllWhitespace(str) {
|
41
40
|
return !NonWhitespaceRegexp.test(str);
|
42
41
|
}
|
43
|
-
|
42
|
+
|
44
43
|
function appendText(task, geom, styles) {
|
45
|
-
var textDiv = document.createElement('
|
44
|
+
var textDiv = document.createElement('span');
|
46
45
|
var textDivProperties = {
|
47
|
-
style: null,
|
48
46
|
angle: 0,
|
49
47
|
canvasWidth: 0,
|
50
48
|
isWhitespace: false,
|
@@ -55,27 +53,37 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
55
53
|
paddingTop: 0,
|
56
54
|
scale: 1
|
57
55
|
};
|
56
|
+
|
58
57
|
task._textDivs.push(textDiv);
|
58
|
+
|
59
59
|
if (isAllWhitespace(geom.str)) {
|
60
60
|
textDivProperties.isWhitespace = true;
|
61
|
+
|
61
62
|
task._textDivProperties.set(textDiv, textDivProperties);
|
63
|
+
|
62
64
|
return;
|
63
65
|
}
|
66
|
+
|
64
67
|
var tx = _util.Util.transform(task._viewport.transform, geom.transform);
|
68
|
+
|
65
69
|
var angle = Math.atan2(tx[1], tx[0]);
|
66
70
|
var style = styles[geom.fontName];
|
71
|
+
|
67
72
|
if (style.vertical) {
|
68
73
|
angle += Math.PI / 2;
|
69
74
|
}
|
75
|
+
|
70
76
|
var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
|
71
77
|
var fontAscent = fontHeight;
|
78
|
+
|
72
79
|
if (style.ascent) {
|
73
80
|
fontAscent = style.ascent * fontAscent;
|
74
81
|
} else if (style.descent) {
|
75
82
|
fontAscent = (1 + style.descent) * fontAscent;
|
76
83
|
}
|
77
|
-
|
78
|
-
var top;
|
84
|
+
|
85
|
+
var left, top;
|
86
|
+
|
79
87
|
if (angle === 0) {
|
80
88
|
left = tx[4];
|
81
89
|
top = tx[5] - fontAscent;
|
@@ -83,19 +91,21 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
83
91
|
left = tx[4] + fontAscent * Math.sin(angle);
|
84
92
|
top = tx[5] - fontAscent * Math.cos(angle);
|
85
93
|
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
textDiv.setAttribute('style', textDivProperties.style);
|
94
|
+
|
95
|
+
textDiv.style.left = "".concat(left, "px");
|
96
|
+
textDiv.style.top = "".concat(top, "px");
|
97
|
+
textDiv.style.fontSize = "".concat(fontHeight, "px");
|
98
|
+
textDiv.style.fontFamily = style.fontFamily;
|
92
99
|
textDiv.textContent = geom.str;
|
100
|
+
|
93
101
|
if (task._fontInspectorEnabled) {
|
94
102
|
textDiv.dataset.fontName = geom.fontName;
|
95
103
|
}
|
104
|
+
|
96
105
|
if (angle !== 0) {
|
97
106
|
textDivProperties.angle = angle * (180 / Math.PI);
|
98
107
|
}
|
108
|
+
|
99
109
|
if (geom.str.length > 1) {
|
100
110
|
if (style.vertical) {
|
101
111
|
textDivProperties.canvasWidth = geom.height * task._viewport.scale;
|
@@ -103,26 +113,33 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
103
113
|
textDivProperties.canvasWidth = geom.width * task._viewport.scale;
|
104
114
|
}
|
105
115
|
}
|
116
|
+
|
106
117
|
task._textDivProperties.set(textDiv, textDivProperties);
|
118
|
+
|
107
119
|
if (task._textContentStream) {
|
108
120
|
task._layoutText(textDiv);
|
109
121
|
}
|
122
|
+
|
110
123
|
if (task._enhanceTextSelection) {
|
111
124
|
var angleCos = 1,
|
112
125
|
angleSin = 0;
|
126
|
+
|
113
127
|
if (angle !== 0) {
|
114
128
|
angleCos = Math.cos(angle);
|
115
129
|
angleSin = Math.sin(angle);
|
116
130
|
}
|
131
|
+
|
117
132
|
var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
|
118
133
|
var divHeight = fontHeight;
|
119
134
|
var m, b;
|
135
|
+
|
120
136
|
if (angle !== 0) {
|
121
137
|
m = [angleCos, angleSin, -angleSin, angleCos, left, top];
|
122
138
|
b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
|
123
139
|
} else {
|
124
140
|
b = [left, top, left + divWidth, top + divHeight];
|
125
141
|
}
|
142
|
+
|
126
143
|
task._bounds.push({
|
127
144
|
left: b[0],
|
128
145
|
top: b[1],
|
@@ -134,41 +151,53 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
134
151
|
});
|
135
152
|
}
|
136
153
|
}
|
154
|
+
|
137
155
|
function render(task) {
|
138
156
|
if (task._canceled) {
|
139
157
|
return;
|
140
158
|
}
|
159
|
+
|
141
160
|
var textDivs = task._textDivs;
|
142
161
|
var capability = task._capability;
|
143
162
|
var textDivsLength = textDivs.length;
|
163
|
+
|
144
164
|
if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
145
165
|
task._renderingDone = true;
|
146
166
|
capability.resolve();
|
147
167
|
return;
|
148
168
|
}
|
169
|
+
|
149
170
|
if (!task._textContentStream) {
|
150
171
|
for (var i = 0; i < textDivsLength; i++) {
|
151
172
|
task._layoutText(textDivs[i]);
|
152
173
|
}
|
153
174
|
}
|
175
|
+
|
154
176
|
task._renderingDone = true;
|
155
177
|
capability.resolve();
|
156
178
|
}
|
179
|
+
|
157
180
|
function expand(task) {
|
158
181
|
var bounds = task._bounds;
|
159
182
|
var viewport = task._viewport;
|
160
183
|
var expanded = expandBounds(viewport.width, viewport.height, bounds);
|
184
|
+
|
161
185
|
for (var i = 0; i < expanded.length; i++) {
|
162
186
|
var div = bounds[i].div;
|
187
|
+
|
163
188
|
var divProperties = task._textDivProperties.get(div);
|
189
|
+
|
164
190
|
if (divProperties.angle === 0) {
|
165
191
|
divProperties.paddingLeft = bounds[i].left - expanded[i].left;
|
166
192
|
divProperties.paddingTop = bounds[i].top - expanded[i].top;
|
167
193
|
divProperties.paddingRight = expanded[i].right - bounds[i].right;
|
168
194
|
divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
|
195
|
+
|
169
196
|
task._textDivProperties.set(div, divProperties);
|
197
|
+
|
170
198
|
continue;
|
171
199
|
}
|
200
|
+
|
172
201
|
var e = expanded[i],
|
173
202
|
b = bounds[i];
|
174
203
|
var m = b.m,
|
@@ -178,6 +207,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
178
207
|
var ts = new Float64Array(64);
|
179
208
|
points.forEach(function (p, i) {
|
180
209
|
var t = _util.Util.applyTransform(p, m);
|
210
|
+
|
181
211
|
ts[i + 0] = c && (e.left - t[0]) / c;
|
182
212
|
ts[i + 4] = s && (e.top - t[1]) / s;
|
183
213
|
ts[i + 8] = c && (e.right - t[0]) / c;
|
@@ -195,24 +225,31 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
195
225
|
ts[i + 56] = s && (e.right - t[0]) / s;
|
196
226
|
ts[i + 60] = c && (e.bottom - t[1]) / -c;
|
197
227
|
});
|
228
|
+
|
198
229
|
var findPositiveMin = function findPositiveMin(ts, offset, count) {
|
199
230
|
var result = 0;
|
231
|
+
|
200
232
|
for (var i = 0; i < count; i++) {
|
201
233
|
var t = ts[offset++];
|
234
|
+
|
202
235
|
if (t > 0) {
|
203
236
|
result = result ? Math.min(t, result) : t;
|
204
237
|
}
|
205
238
|
}
|
239
|
+
|
206
240
|
return result;
|
207
241
|
};
|
242
|
+
|
208
243
|
var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
|
209
244
|
divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
|
210
245
|
divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
|
211
246
|
divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
|
212
247
|
divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
|
248
|
+
|
213
249
|
task._textDivProperties.set(div, divProperties);
|
214
250
|
}
|
215
251
|
}
|
252
|
+
|
216
253
|
function expandBounds(width, height, boxes) {
|
217
254
|
var bounds = boxes.map(function (box, i) {
|
218
255
|
return {
|
@@ -255,6 +292,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
255
292
|
});
|
256
293
|
return expanded;
|
257
294
|
}
|
295
|
+
|
258
296
|
function expandBoundsLTR(width, bounds) {
|
259
297
|
bounds.sort(function (a, b) {
|
260
298
|
return a.x1 - b.x1 || a.index - b.index;
|
@@ -275,21 +313,27 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
275
313
|
}];
|
276
314
|
bounds.forEach(function (boundary) {
|
277
315
|
var i = 0;
|
316
|
+
|
278
317
|
while (i < horizon.length && horizon[i].end <= boundary.y1) {
|
279
318
|
i++;
|
280
319
|
}
|
320
|
+
|
281
321
|
var j = horizon.length - 1;
|
322
|
+
|
282
323
|
while (j >= 0 && horizon[j].start >= boundary.y2) {
|
283
324
|
j--;
|
284
325
|
}
|
326
|
+
|
285
327
|
var horizonPart, affectedBoundary;
|
286
328
|
var q,
|
287
329
|
k,
|
288
330
|
maxXNew = -Infinity;
|
331
|
+
|
289
332
|
for (q = i; q <= j; q++) {
|
290
333
|
horizonPart = horizon[q];
|
291
334
|
affectedBoundary = horizonPart.boundary;
|
292
335
|
var xNew;
|
336
|
+
|
293
337
|
if (affectedBoundary.x2 > boundary.x1) {
|
294
338
|
xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
|
295
339
|
} else if (affectedBoundary.x2New === undefined) {
|
@@ -297,14 +341,18 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
297
341
|
} else {
|
298
342
|
xNew = affectedBoundary.x2New;
|
299
343
|
}
|
344
|
+
|
300
345
|
if (xNew > maxXNew) {
|
301
346
|
maxXNew = xNew;
|
302
347
|
}
|
303
348
|
}
|
349
|
+
|
304
350
|
boundary.x1New = maxXNew;
|
351
|
+
|
305
352
|
for (q = i; q <= j; q++) {
|
306
353
|
horizonPart = horizon[q];
|
307
354
|
affectedBoundary = horizonPart.boundary;
|
355
|
+
|
308
356
|
if (affectedBoundary.x2New === undefined) {
|
309
357
|
if (affectedBoundary.x2 > boundary.x1) {
|
310
358
|
if (affectedBoundary.index > boundary.index) {
|
@@ -317,12 +365,15 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
317
365
|
affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
|
318
366
|
}
|
319
367
|
}
|
368
|
+
|
320
369
|
var changedHorizon = [],
|
321
370
|
lastBoundary = null;
|
371
|
+
|
322
372
|
for (q = i; q <= j; q++) {
|
323
373
|
horizonPart = horizon[q];
|
324
374
|
affectedBoundary = horizonPart.boundary;
|
325
375
|
var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
|
376
|
+
|
326
377
|
if (lastBoundary === useBoundary) {
|
327
378
|
changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
|
328
379
|
} else {
|
@@ -334,6 +385,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
334
385
|
lastBoundary = useBoundary;
|
335
386
|
}
|
336
387
|
}
|
388
|
+
|
337
389
|
if (horizon[i].start < boundary.y1) {
|
338
390
|
changedHorizon[0].start = boundary.y1;
|
339
391
|
changedHorizon.unshift({
|
@@ -342,6 +394,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
342
394
|
boundary: horizon[i].boundary
|
343
395
|
});
|
344
396
|
}
|
397
|
+
|
345
398
|
if (boundary.y2 < horizon[j].end) {
|
346
399
|
changedHorizon[changedHorizon.length - 1].end = boundary.y2;
|
347
400
|
changedHorizon.push({
|
@@ -350,36 +403,48 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
350
403
|
boundary: horizon[j].boundary
|
351
404
|
});
|
352
405
|
}
|
406
|
+
|
353
407
|
for (q = i; q <= j; q++) {
|
354
408
|
horizonPart = horizon[q];
|
355
409
|
affectedBoundary = horizonPart.boundary;
|
410
|
+
|
356
411
|
if (affectedBoundary.x2New !== undefined) {
|
357
412
|
continue;
|
358
413
|
}
|
414
|
+
|
359
415
|
var used = false;
|
416
|
+
|
360
417
|
for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
|
361
418
|
used = horizon[k].boundary === affectedBoundary;
|
362
419
|
}
|
420
|
+
|
363
421
|
for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
|
364
422
|
used = horizon[k].boundary === affectedBoundary;
|
365
423
|
}
|
424
|
+
|
366
425
|
for (k = 0; !used && k < changedHorizon.length; k++) {
|
367
426
|
used = changedHorizon[k].boundary === affectedBoundary;
|
368
427
|
}
|
428
|
+
|
369
429
|
if (!used) {
|
370
430
|
affectedBoundary.x2New = maxXNew;
|
371
431
|
}
|
372
432
|
}
|
433
|
+
|
373
434
|
Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
|
374
435
|
});
|
375
436
|
horizon.forEach(function (horizonPart) {
|
376
437
|
var affectedBoundary = horizonPart.boundary;
|
438
|
+
|
377
439
|
if (affectedBoundary.x2New === undefined) {
|
378
440
|
affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
|
379
441
|
}
|
380
442
|
});
|
381
443
|
}
|
444
|
+
|
382
445
|
function TextLayerRenderTask(_ref) {
|
446
|
+
var _this = this;
|
447
|
+
|
383
448
|
var textContent = _ref.textContent,
|
384
449
|
textContentStream = _ref.textContentStream,
|
385
450
|
container = _ref.container,
|
@@ -387,7 +452,6 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
387
452
|
textDivs = _ref.textDivs,
|
388
453
|
textContentItemsStr = _ref.textContentItemsStr,
|
389
454
|
enhanceTextSelection = _ref.enhanceTextSelection;
|
390
|
-
|
391
455
|
this._textContent = textContent;
|
392
456
|
this._textContentStream = textContentStream;
|
393
457
|
this._container = container;
|
@@ -395,7 +459,7 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
395
459
|
this._textDivs = textDivs || [];
|
396
460
|
this._textContentItemsStr = textContentItemsStr || [];
|
397
461
|
this._enhanceTextSelection = !!enhanceTextSelection;
|
398
|
-
this._fontInspectorEnabled = !!(
|
462
|
+
this._fontInspectorEnabled = !!(_global_scope["default"].FontInspector && _global_scope["default"].FontInspector.enabled);
|
399
463
|
this._reader = null;
|
400
464
|
this._layoutTextLastFontSize = null;
|
401
465
|
this._layoutTextLastFontFamily = null;
|
@@ -406,75 +470,110 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
406
470
|
this._capability = (0, _util.createPromiseCapability)();
|
407
471
|
this._renderTimer = null;
|
408
472
|
this._bounds = [];
|
473
|
+
|
474
|
+
this._capability.promise["finally"](function () {
|
475
|
+
if (_this._layoutTextCtx) {
|
476
|
+
_this._layoutTextCtx.canvas.width = 0;
|
477
|
+
_this._layoutTextCtx.canvas.height = 0;
|
478
|
+
_this._layoutTextCtx = null;
|
479
|
+
}
|
480
|
+
})["catch"](function () {});
|
409
481
|
}
|
482
|
+
|
410
483
|
TextLayerRenderTask.prototype = {
|
411
484
|
get promise() {
|
412
485
|
return this._capability.promise;
|
413
486
|
},
|
487
|
+
|
414
488
|
cancel: function TextLayer_cancel() {
|
489
|
+
this._canceled = true;
|
490
|
+
|
415
491
|
if (this._reader) {
|
416
|
-
this._reader.cancel(new _util.AbortException('
|
492
|
+
this._reader.cancel(new _util.AbortException('TextLayer task cancelled.'));
|
493
|
+
|
417
494
|
this._reader = null;
|
418
495
|
}
|
419
|
-
|
496
|
+
|
420
497
|
if (this._renderTimer !== null) {
|
421
498
|
clearTimeout(this._renderTimer);
|
422
499
|
this._renderTimer = null;
|
423
500
|
}
|
424
|
-
|
501
|
+
|
502
|
+
this._capability.reject(new Error('TextLayer task cancelled.'));
|
425
503
|
},
|
426
504
|
_processItems: function _processItems(items, styleCache) {
|
427
505
|
for (var i = 0, len = items.length; i < len; i++) {
|
428
506
|
this._textContentItemsStr.push(items[i].str);
|
507
|
+
|
429
508
|
appendText(this, items[i], styleCache);
|
430
509
|
}
|
431
510
|
},
|
432
511
|
_layoutText: function _layoutText(textDiv) {
|
433
|
-
var textLayerFrag = this._container;
|
434
512
|
var textDivProperties = this._textDivProperties.get(textDiv);
|
513
|
+
|
435
514
|
if (textDivProperties.isWhitespace) {
|
436
515
|
return;
|
437
516
|
}
|
438
|
-
|
439
|
-
var fontFamily = textDiv.style.fontFamily;
|
440
|
-
if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
|
441
|
-
this._layoutTextCtx.font = fontSize + ' ' + fontFamily;
|
442
|
-
this._lastFontSize = fontSize;
|
443
|
-
this._lastFontFamily = fontFamily;
|
444
|
-
}
|
445
|
-
var width = this._layoutTextCtx.measureText(textDiv.textContent).width;
|
517
|
+
|
446
518
|
var transform = '';
|
447
|
-
|
448
|
-
|
449
|
-
|
519
|
+
|
520
|
+
if (textDivProperties.canvasWidth !== 0) {
|
521
|
+
var _textDiv$style = textDiv.style,
|
522
|
+
fontSize = _textDiv$style.fontSize,
|
523
|
+
fontFamily = _textDiv$style.fontFamily;
|
524
|
+
|
525
|
+
if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
|
526
|
+
this._layoutTextCtx.font = "".concat(fontSize, " ").concat(fontFamily);
|
527
|
+
this._layoutTextLastFontSize = fontSize;
|
528
|
+
this._layoutTextLastFontFamily = fontFamily;
|
529
|
+
}
|
530
|
+
|
531
|
+
var _this$_layoutTextCtx$ = this._layoutTextCtx.measureText(textDiv.textContent),
|
532
|
+
width = _this$_layoutTextCtx$.width;
|
533
|
+
|
534
|
+
if (width > 0) {
|
535
|
+
textDivProperties.scale = textDivProperties.canvasWidth / width;
|
536
|
+
transform = "scaleX(".concat(textDivProperties.scale, ")");
|
537
|
+
}
|
450
538
|
}
|
539
|
+
|
451
540
|
if (textDivProperties.angle !== 0) {
|
452
|
-
transform =
|
541
|
+
transform = "rotate(".concat(textDivProperties.angle, "deg) ").concat(transform);
|
453
542
|
}
|
454
|
-
|
455
|
-
|
543
|
+
|
544
|
+
if (transform.length > 0) {
|
545
|
+
if (this._enhanceTextSelection) {
|
546
|
+
textDivProperties.originalTransform = transform;
|
547
|
+
}
|
548
|
+
|
456
549
|
textDiv.style.transform = transform;
|
457
550
|
}
|
551
|
+
|
458
552
|
this._textDivProperties.set(textDiv, textDivProperties);
|
459
|
-
textLayerFrag.appendChild(textDiv);
|
460
|
-
},
|
461
553
|
|
554
|
+
this._container.appendChild(textDiv);
|
555
|
+
},
|
462
556
|
_render: function TextLayer_render(timeout) {
|
463
|
-
var
|
557
|
+
var _this2 = this;
|
464
558
|
|
465
559
|
var capability = (0, _util.createPromiseCapability)();
|
466
560
|
var styleCache = Object.create(null);
|
467
561
|
var canvas = document.createElement('canvas');
|
468
562
|
canvas.mozOpaque = true;
|
469
|
-
this._layoutTextCtx = canvas.getContext('2d', {
|
563
|
+
this._layoutTextCtx = canvas.getContext('2d', {
|
564
|
+
alpha: false
|
565
|
+
});
|
566
|
+
|
470
567
|
if (this._textContent) {
|
471
568
|
var textItems = this._textContent.items;
|
472
569
|
var textStyles = this._textContent.styles;
|
570
|
+
|
473
571
|
this._processItems(textItems, textStyles);
|
572
|
+
|
474
573
|
capability.resolve();
|
475
574
|
} else if (this._textContentStream) {
|
476
575
|
var pump = function pump() {
|
477
|
-
|
576
|
+
_this2._reader.read().then(function (_ref2) {
|
478
577
|
var value = _ref2.value,
|
479
578
|
done = _ref2.done;
|
480
579
|
|
@@ -482,24 +581,30 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
482
581
|
capability.resolve();
|
483
582
|
return;
|
484
583
|
}
|
485
|
-
|
486
|
-
|
584
|
+
|
585
|
+
Object.assign(styleCache, value.styles);
|
586
|
+
|
587
|
+
_this2._processItems(value.items, styleCache);
|
588
|
+
|
487
589
|
pump();
|
488
590
|
}, capability.reject);
|
489
591
|
};
|
592
|
+
|
490
593
|
this._reader = this._textContentStream.getReader();
|
491
594
|
pump();
|
492
595
|
} else {
|
493
596
|
throw new Error('Neither "textContent" nor "textContentStream"' + ' parameters specified.');
|
494
597
|
}
|
598
|
+
|
495
599
|
capability.promise.then(function () {
|
496
600
|
styleCache = null;
|
601
|
+
|
497
602
|
if (!timeout) {
|
498
|
-
render(
|
603
|
+
render(_this2);
|
499
604
|
} else {
|
500
|
-
|
501
|
-
render(
|
502
|
-
|
605
|
+
_this2._renderTimer = setTimeout(function () {
|
606
|
+
render(_this2);
|
607
|
+
_this2._renderTimer = null;
|
503
608
|
}, timeout);
|
504
609
|
}
|
505
610
|
}, this._capability.reject);
|
@@ -508,52 +613,76 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
508
613
|
if (!this._enhanceTextSelection || !this._renderingDone) {
|
509
614
|
return;
|
510
615
|
}
|
616
|
+
|
511
617
|
if (this._bounds !== null) {
|
512
618
|
expand(this);
|
513
619
|
this._bounds = null;
|
514
620
|
}
|
621
|
+
|
622
|
+
var NO_PADDING = '0 0 0 0';
|
623
|
+
var transformBuf = [],
|
624
|
+
paddingBuf = [];
|
625
|
+
|
515
626
|
for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
|
516
627
|
var div = this._textDivs[i];
|
517
|
-
|
518
|
-
|
628
|
+
|
629
|
+
var divProps = this._textDivProperties.get(div);
|
630
|
+
|
631
|
+
if (divProps.isWhitespace) {
|
519
632
|
continue;
|
520
633
|
}
|
634
|
+
|
521
635
|
if (expandDivs) {
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
if (divProperties.angle !== 0) {
|
528
|
-
transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
|
636
|
+
transformBuf.length = 0;
|
637
|
+
paddingBuf.length = 0;
|
638
|
+
|
639
|
+
if (divProps.originalTransform) {
|
640
|
+
transformBuf.push(divProps.originalTransform);
|
529
641
|
}
|
530
|
-
|
531
|
-
|
532
|
-
|
642
|
+
|
643
|
+
if (divProps.paddingTop > 0) {
|
644
|
+
paddingBuf.push("".concat(divProps.paddingTop, "px"));
|
645
|
+
transformBuf.push("translateY(".concat(-divProps.paddingTop, "px)"));
|
646
|
+
} else {
|
647
|
+
paddingBuf.push(0);
|
533
648
|
}
|
534
|
-
|
535
|
-
|
536
|
-
|
649
|
+
|
650
|
+
if (divProps.paddingRight > 0) {
|
651
|
+
paddingBuf.push("".concat(divProps.paddingRight / divProps.scale, "px"));
|
652
|
+
} else {
|
653
|
+
paddingBuf.push(0);
|
537
654
|
}
|
538
|
-
|
539
|
-
|
655
|
+
|
656
|
+
if (divProps.paddingBottom > 0) {
|
657
|
+
paddingBuf.push("".concat(divProps.paddingBottom, "px"));
|
658
|
+
} else {
|
659
|
+
paddingBuf.push(0);
|
540
660
|
}
|
541
|
-
|
542
|
-
|
661
|
+
|
662
|
+
if (divProps.paddingLeft > 0) {
|
663
|
+
paddingBuf.push("".concat(divProps.paddingLeft / divProps.scale, "px"));
|
664
|
+
transformBuf.push("translateX(".concat(-divProps.paddingLeft / divProps.scale, "px)"));
|
665
|
+
} else {
|
666
|
+
paddingBuf.push(0);
|
543
667
|
}
|
544
|
-
|
545
|
-
|
668
|
+
|
669
|
+
var padding = paddingBuf.join(' ');
|
670
|
+
|
671
|
+
if (padding !== NO_PADDING) {
|
672
|
+
div.style.padding = padding;
|
546
673
|
}
|
547
|
-
|
548
|
-
|
674
|
+
|
675
|
+
if (transformBuf.length) {
|
676
|
+
div.style.transform = transformBuf.join(' ');
|
549
677
|
}
|
550
678
|
} else {
|
551
|
-
div.style.padding =
|
552
|
-
div.style.transform =
|
679
|
+
div.style.padding = null;
|
680
|
+
div.style.transform = divProps.originalTransform;
|
553
681
|
}
|
554
682
|
}
|
555
683
|
}
|
556
684
|
};
|
685
|
+
|
557
686
|
function renderTextLayer(renderParameters) {
|
558
687
|
var task = new TextLayerRenderTask({
|
559
688
|
textContent: renderParameters.textContent,
|
@@ -564,9 +693,13 @@ var renderTextLayer = function renderTextLayerClosure() {
|
|
564
693
|
textContentItemsStr: renderParameters.textContentItemsStr,
|
565
694
|
enhanceTextSelection: renderParameters.enhanceTextSelection
|
566
695
|
});
|
696
|
+
|
567
697
|
task._render(renderParameters.timeout);
|
698
|
+
|
568
699
|
return task;
|
569
700
|
}
|
701
|
+
|
570
702
|
return renderTextLayer;
|
571
703
|
}();
|
704
|
+
|
572
705
|
exports.renderTextLayer = renderTextLayer;
|