pdfjs-dist 2.0.489 → 2.2.228

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.

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