pdfjs-dist 2.0.943 → 2.1.266

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 (159) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15329 -11095
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +12497 -4184
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/image_decoders/pdf.image_decoders.js +3438 -1209
  9. package/image_decoders/pdf.image_decoders.js.map +1 -1
  10. package/image_decoders/pdf.image_decoders.min.js +1 -1
  11. package/lib/core/annotation.js +335 -109
  12. package/lib/core/arithmetic_decoder.js +274 -244
  13. package/lib/core/bidi.js +64 -5
  14. package/lib/core/ccitt.js +172 -17
  15. package/lib/core/ccitt_stream.js +14 -5
  16. package/lib/core/cff_parser.js +304 -28
  17. package/lib/core/charsets.js +4 -3
  18. package/lib/core/chunked_stream.js +379 -149
  19. package/lib/core/cmap.js +210 -40
  20. package/lib/core/colorspace.js +332 -187
  21. package/lib/core/crypto.js +289 -44
  22. package/lib/core/document.js +508 -249
  23. package/lib/core/encodings.js +18 -9
  24. package/lib/core/evaluator.js +657 -119
  25. package/lib/core/font_renderer.js +217 -34
  26. package/lib/core/fonts.js +632 -41
  27. package/lib/core/function.js +252 -26
  28. package/lib/core/glyphlist.js +2 -1
  29. package/lib/core/image.js +124 -27
  30. package/lib/core/jbig2.js +425 -65
  31. package/lib/core/jbig2_stream.js +18 -7
  32. package/lib/core/jpeg_stream.js +24 -8
  33. package/lib/core/jpg.js +208 -16
  34. package/lib/core/jpx.js +395 -5
  35. package/lib/core/jpx_stream.js +17 -5
  36. package/lib/core/metrics.js +3 -3
  37. package/lib/core/murmurhash3.js +23 -5
  38. package/lib/core/obj.js +625 -132
  39. package/lib/core/operator_list.js +104 -3
  40. package/lib/core/parser.js +262 -25
  41. package/lib/core/pattern.js +144 -12
  42. package/lib/core/pdf_manager.js +104 -70
  43. package/lib/core/primitives.js +74 -21
  44. package/lib/core/ps_parser.js +133 -44
  45. package/lib/core/standard_fonts.js +9 -9
  46. package/lib/core/stream.js +283 -31
  47. package/lib/core/type1_parser.js +138 -6
  48. package/lib/core/unicode.js +28 -1
  49. package/lib/core/worker.js +192 -57
  50. package/lib/display/annotation_layer.js +303 -123
  51. package/lib/display/api.js +1073 -574
  52. package/lib/display/api_compatibility.js +4 -1
  53. package/lib/display/canvas.js +314 -18
  54. package/lib/display/content_disposition.js +70 -23
  55. package/lib/display/dom_utils.js +112 -59
  56. package/lib/display/fetch_stream.js +95 -50
  57. package/lib/display/font_loader.js +250 -132
  58. package/lib/display/metadata.js +37 -15
  59. package/lib/display/network.js +123 -34
  60. package/lib/display/network_utils.js +23 -10
  61. package/lib/display/node_stream.js +162 -65
  62. package/lib/display/pattern_helper.js +57 -6
  63. package/lib/display/svg.js +194 -18
  64. package/lib/display/text_layer.js +128 -14
  65. package/lib/display/transport_stream.js +83 -27
  66. package/lib/display/webgl.js +63 -17
  67. package/lib/display/worker_options.js +4 -3
  68. package/lib/display/xml_parser.js +162 -52
  69. package/lib/examples/node/domstubs.js +56 -3
  70. package/lib/pdf.js +15 -2
  71. package/lib/pdf.worker.js +4 -2
  72. package/lib/shared/compatibility.js +129 -26
  73. package/lib/shared/global_scope.js +1 -1
  74. package/lib/shared/is_node.js +3 -3
  75. package/lib/shared/message_handler.js +103 -45
  76. package/lib/shared/streams_polyfill.js +20 -16
  77. package/lib/shared/url_polyfill.js +8 -2
  78. package/lib/shared/util.js +246 -84
  79. package/lib/test/unit/annotation_spec.js +99 -73
  80. package/lib/test/unit/api_spec.js +347 -113
  81. package/lib/test/unit/bidi_spec.js +6 -6
  82. package/lib/test/unit/cff_parser_spec.js +17 -5
  83. package/lib/test/unit/clitests_helper.js +7 -8
  84. package/lib/test/unit/cmap_spec.js +79 -25
  85. package/lib/test/unit/colorspace_spec.js +65 -18
  86. package/lib/test/unit/crypto_spec.js +16 -4
  87. package/lib/test/unit/custom_spec.js +40 -52
  88. package/lib/test/unit/display_svg_spec.js +32 -16
  89. package/lib/test/unit/document_spec.js +2 -2
  90. package/lib/test/unit/dom_utils_spec.js +8 -8
  91. package/lib/test/unit/encodings_spec.js +24 -44
  92. package/lib/test/unit/evaluator_spec.js +15 -8
  93. package/lib/test/unit/function_spec.js +16 -4
  94. package/lib/test/unit/jasmine-boot.js +29 -16
  95. package/lib/test/unit/message_handler_spec.js +19 -6
  96. package/lib/test/unit/metadata_spec.js +64 -11
  97. package/lib/test/unit/murmurhash3_spec.js +2 -2
  98. package/lib/test/unit/network_spec.js +19 -4
  99. package/lib/test/unit/network_utils_spec.js +6 -4
  100. package/lib/test/unit/node_stream_spec.js +50 -26
  101. package/lib/test/unit/parser_spec.js +13 -29
  102. package/lib/test/unit/pdf_find_controller_spec.js +144 -32
  103. package/lib/test/unit/pdf_find_utils_spec.js +10 -9
  104. package/lib/test/unit/pdf_history_spec.js +20 -8
  105. package/lib/test/unit/primitives_spec.js +23 -3
  106. package/lib/test/unit/stream_spec.js +8 -3
  107. package/lib/test/unit/test_utils.js +89 -26
  108. package/lib/test/unit/testreporter.js +19 -1
  109. package/lib/test/unit/type1_parser_spec.js +7 -5
  110. package/lib/test/unit/ui_utils_spec.js +162 -38
  111. package/lib/test/unit/unicode_spec.js +13 -10
  112. package/lib/test/unit/util_spec.js +89 -9
  113. package/lib/web/annotation_layer_builder.js +38 -21
  114. package/lib/web/app.js +610 -245
  115. package/lib/web/app_options.js +54 -34
  116. package/lib/web/base_viewer.js +359 -162
  117. package/lib/web/chromecom.js +159 -80
  118. package/lib/web/debugger.js +161 -17
  119. package/lib/web/download_manager.js +29 -11
  120. package/lib/web/firefox_print_service.js +16 -8
  121. package/lib/web/firefoxcom.js +127 -91
  122. package/lib/web/genericcom.js +50 -31
  123. package/lib/web/genericl10n.js +46 -34
  124. package/lib/web/grab_to_pan.js +25 -3
  125. package/lib/web/interfaces.js +108 -61
  126. package/lib/web/overlay_manager.js +67 -45
  127. package/lib/web/password_prompt.js +20 -12
  128. package/lib/web/pdf_attachment_viewer.js +37 -17
  129. package/lib/web/pdf_cursor_tools.js +38 -15
  130. package/lib/web/pdf_document_properties.js +65 -24
  131. package/lib/web/pdf_find_bar.js +48 -20
  132. package/lib/web/pdf_find_controller.js +290 -89
  133. package/lib/web/pdf_find_utils.js +19 -3
  134. package/lib/web/pdf_history.js +186 -49
  135. package/lib/web/pdf_link_service.js +127 -52
  136. package/lib/web/pdf_outline_viewer.js +71 -21
  137. package/lib/web/pdf_page_view.js +188 -63
  138. package/lib/web/pdf_presentation_mode.js +98 -33
  139. package/lib/web/pdf_print_service.js +54 -10
  140. package/lib/web/pdf_rendering_queue.js +26 -4
  141. package/lib/web/pdf_sidebar.js +116 -62
  142. package/lib/web/pdf_sidebar_resizer.js +41 -15
  143. package/lib/web/pdf_single_page_viewer.js +65 -68
  144. package/lib/web/pdf_thumbnail_view.js +102 -31
  145. package/lib/web/pdf_thumbnail_viewer.js +62 -22
  146. package/lib/web/pdf_viewer.component.js +111 -31
  147. package/lib/web/pdf_viewer.js +80 -60
  148. package/lib/web/preferences.js +61 -39
  149. package/lib/web/secondary_toolbar.js +101 -82
  150. package/lib/web/text_layer_builder.js +124 -69
  151. package/lib/web/toolbar.js +67 -27
  152. package/lib/web/ui_utils.js +284 -128
  153. package/lib/web/view_history.js +75 -51
  154. package/lib/web/viewer_compatibility.js +2 -1
  155. package/package.json +1 -1
  156. package/web/pdf_viewer.css +1 -1
  157. package/web/pdf_viewer.js +2200 -973
  158. package/web/pdf_viewer.js.map +1 -1
  159. package/lib/web/dom_events.js +0 -140
@@ -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');
32
-
33
- var _global_scope2 = _interopRequireDefault(_global_scope);
31
+ var _global_scope = _interopRequireDefault(require("../shared/global_scope"));
34
32
 
35
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,35 +409,45 @@ 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) {
383
452
  var textContent = _ref.textContent,
384
453
  textContentStream = _ref.textContentStream,
@@ -387,7 +456,6 @@ var renderTextLayer = function renderTextLayerClosure() {
387
456
  textDivs = _ref.textDivs,
388
457
  textContentItemsStr = _ref.textContentItemsStr,
389
458
  enhanceTextSelection = _ref.enhanceTextSelection;
390
-
391
459
  this._textContent = textContent;
392
460
  this._textContentStream = textContentStream;
393
461
  this._container = container;
@@ -395,7 +463,7 @@ var renderTextLayer = function renderTextLayerClosure() {
395
463
  this._textDivs = textDivs || [];
396
464
  this._textContentItemsStr = textContentItemsStr || [];
397
465
  this._enhanceTextSelection = !!enhanceTextSelection;
398
- this._fontInspectorEnabled = !!(_global_scope2.default.FontInspector && _global_scope2.default.FontInspector.enabled);
466
+ this._fontInspectorEnabled = !!(_global_scope.default.FontInspector && _global_scope.default.FontInspector.enabled);
399
467
  this._reader = null;
400
468
  this._layoutTextLastFontSize = null;
401
469
  this._layoutTextLastFontFamily = null;
@@ -407,58 +475,75 @@ var renderTextLayer = function renderTextLayerClosure() {
407
475
  this._renderTimer = null;
408
476
  this._bounds = [];
409
477
  }
478
+
410
479
  TextLayerRenderTask.prototype = {
411
480
  get promise() {
412
481
  return this._capability.promise;
413
482
  },
483
+
414
484
  cancel: function TextLayer_cancel() {
415
485
  if (this._reader) {
416
486
  this._reader.cancel(new _util.AbortException('text layer task cancelled'));
487
+
417
488
  this._reader = null;
418
489
  }
490
+
419
491
  this._canceled = true;
492
+
420
493
  if (this._renderTimer !== null) {
421
494
  clearTimeout(this._renderTimer);
422
495
  this._renderTimer = null;
423
496
  }
497
+
424
498
  this._capability.reject('canceled');
425
499
  },
426
500
  _processItems: function _processItems(items, styleCache) {
427
501
  for (var 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
507
  _layoutText: function _layoutText(textDiv) {
433
508
  var textLayerFrag = this._container;
509
+
434
510
  var textDivProperties = this._textDivProperties.get(textDiv);
511
+
435
512
  if (textDivProperties.isWhitespace) {
436
513
  return;
437
514
  }
515
+
438
516
  var fontSize = textDiv.style.fontSize;
439
517
  var fontFamily = textDiv.style.fontFamily;
518
+
440
519
  if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
441
520
  this._layoutTextCtx.font = fontSize + ' ' + fontFamily;
442
521
  this._layoutTextLastFontSize = fontSize;
443
522
  this._layoutTextLastFontFamily = fontFamily;
444
523
  }
524
+
445
525
  var width = this._layoutTextCtx.measureText(textDiv.textContent).width;
526
+
446
527
  var transform = '';
528
+
447
529
  if (textDivProperties.canvasWidth !== 0 && width > 0) {
448
530
  textDivProperties.scale = textDivProperties.canvasWidth / width;
449
- transform = 'scaleX(' + textDivProperties.scale + ')';
531
+ transform = "scaleX(".concat(textDivProperties.scale, ")");
450
532
  }
533
+
451
534
  if (textDivProperties.angle !== 0) {
452
- transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
535
+ transform = "rotate(".concat(textDivProperties.angle, "deg) ").concat(transform);
453
536
  }
454
- if (transform !== '') {
537
+
538
+ if (transform.length > 0) {
455
539
  textDivProperties.originalTransform = transform;
456
540
  textDiv.style.transform = transform;
457
541
  }
542
+
458
543
  this._textDivProperties.set(textDiv, textDivProperties);
544
+
459
545
  textLayerFrag.appendChild(textDiv);
460
546
  },
461
-
462
547
  _render: function TextLayer_render(timeout) {
463
548
  var _this = this;
464
549
 
@@ -466,11 +551,16 @@ var renderTextLayer = function renderTextLayerClosure() {
466
551
  var styleCache = Object.create(null);
467
552
  var canvas = document.createElement('canvas');
468
553
  canvas.mozOpaque = true;
469
- this._layoutTextCtx = canvas.getContext('2d', { alpha: false });
554
+ this._layoutTextCtx = canvas.getContext('2d', {
555
+ alpha: false
556
+ });
557
+
470
558
  if (this._textContent) {
471
559
  var textItems = this._textContent.items;
472
560
  var textStyles = this._textContent.styles;
561
+
473
562
  this._processItems(textItems, textStyles);
563
+
474
564
  capability.resolve();
475
565
  } else if (this._textContentStream) {
476
566
  var pump = function pump() {
@@ -482,18 +572,24 @@ var renderTextLayer = function renderTextLayerClosure() {
482
572
  capability.resolve();
483
573
  return;
484
574
  }
575
+
485
576
  Object.assign(styleCache, value.styles);
577
+
486
578
  _this._processItems(value.items, styleCache);
579
+
487
580
  pump();
488
581
  }, capability.reject);
489
582
  };
583
+
490
584
  this._reader = this._textContentStream.getReader();
491
585
  pump();
492
586
  } else {
493
587
  throw new Error('Neither "textContent" nor "textContentStream"' + ' parameters specified.');
494
588
  }
589
+
495
590
  capability.promise.then(function () {
496
591
  styleCache = null;
592
+
497
593
  if (!timeout) {
498
594
  render(_this);
499
595
  } else {
@@ -508,42 +604,55 @@ var renderTextLayer = function renderTextLayerClosure() {
508
604
  if (!this._enhanceTextSelection || !this._renderingDone) {
509
605
  return;
510
606
  }
607
+
511
608
  if (this._bounds !== null) {
512
609
  expand(this);
513
610
  this._bounds = null;
514
611
  }
612
+
515
613
  for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
516
614
  var div = this._textDivs[i];
615
+
517
616
  var divProperties = this._textDivProperties.get(div);
617
+
518
618
  if (divProperties.isWhitespace) {
519
619
  continue;
520
620
  }
621
+
521
622
  if (expandDivs) {
522
623
  var transform = '',
523
624
  padding = '';
625
+
524
626
  if (divProperties.scale !== 1) {
525
627
  transform = 'scaleX(' + divProperties.scale + ')';
526
628
  }
629
+
527
630
  if (divProperties.angle !== 0) {
528
631
  transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
529
632
  }
633
+
530
634
  if (divProperties.paddingLeft !== 0) {
531
635
  padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
532
636
  transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
533
637
  }
638
+
534
639
  if (divProperties.paddingTop !== 0) {
535
640
  padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
536
641
  transform += ' translateY(' + -divProperties.paddingTop + 'px)';
537
642
  }
643
+
538
644
  if (divProperties.paddingRight !== 0) {
539
645
  padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;';
540
646
  }
647
+
541
648
  if (divProperties.paddingBottom !== 0) {
542
649
  padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;';
543
650
  }
651
+
544
652
  if (padding !== '') {
545
653
  div.setAttribute('style', divProperties.style + padding);
546
654
  }
655
+
547
656
  if (transform !== '') {
548
657
  div.style.transform = transform;
549
658
  }
@@ -554,6 +663,7 @@ var renderTextLayer = function renderTextLayerClosure() {
554
663
  }
555
664
  }
556
665
  };
666
+
557
667
  function renderTextLayer(renderParameters) {
558
668
  var task = new TextLayerRenderTask({
559
669
  textContent: renderParameters.textContent,
@@ -564,9 +674,13 @@ var renderTextLayer = function renderTextLayerClosure() {
564
674
  textContentItemsStr: renderParameters.textContentItemsStr,
565
675
  enhanceTextSelection: renderParameters.enhanceTextSelection
566
676
  });
677
+
567
678
  task._render(renderParameters.timeout);
679
+
568
680
  return task;
569
681
  }
682
+
570
683
  return renderTextLayer;
571
684
  }();
685
+
572
686
  exports.renderTextLayer = renderTextLayer;