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.

Files changed (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. 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 2018 Mozilla Foundation
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,61 +19,57 @@
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.PartialEvaluator = undefined;
27
+ exports.PartialEvaluator = void 0;
28
28
 
29
- var _regenerator = require('babel-runtime/regenerator');
29
+ var _util = require("../shared/util.js");
30
30
 
31
- var _regenerator2 = _interopRequireDefault(_regenerator);
31
+ var _cmap = require("./cmap.js");
32
32
 
33
- var _util = require('../shared/util');
33
+ var _primitives = require("./primitives.js");
34
34
 
35
- var _cmap = require('./cmap');
35
+ var _fonts = require("./fonts.js");
36
36
 
37
- var _stream = require('./stream');
37
+ var _encodings = require("./encodings.js");
38
38
 
39
- var _primitives = require('./primitives');
39
+ var _core_utils = require("./core_utils.js");
40
40
 
41
- var _fonts = require('./fonts');
41
+ var _unicode = require("./unicode.js");
42
42
 
43
- var _encodings = require('./encodings');
43
+ var _standard_fonts = require("./standard_fonts.js");
44
44
 
45
- var _unicode = require('./unicode');
45
+ var _pattern = require("./pattern.js");
46
46
 
47
- var _standard_fonts = require('./standard_fonts');
47
+ var _parser = require("./parser.js");
48
48
 
49
- var _pattern = require('./pattern');
49
+ var _bidi = require("./bidi.js");
50
50
 
51
- var _parser = require('./parser');
51
+ var _colorspace = require("./colorspace.js");
52
52
 
53
- var _bidi = require('./bidi');
53
+ var _stream = require("./stream.js");
54
54
 
55
- var _colorspace = require('./colorspace');
55
+ var _glyphlist = require("./glyphlist.js");
56
56
 
57
- var _glyphlist = require('./glyphlist');
57
+ var _metrics = require("./metrics.js");
58
58
 
59
- var _metrics = require('./metrics');
59
+ var _function = require("./function.js");
60
60
 
61
- var _function = require('./function');
61
+ var _jpeg_stream = require("./jpeg_stream.js");
62
62
 
63
- var _jpeg_stream = require('./jpeg_stream');
63
+ var _murmurhash = require("./murmurhash3.js");
64
64
 
65
- var _murmurhash = require('./murmurhash3');
65
+ var _image_utils = require("./image_utils.js");
66
66
 
67
- var _operator_list = require('./operator_list');
67
+ var _operator_list = require("./operator_list.js");
68
68
 
69
- var _image = require('./image');
70
-
71
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
72
-
73
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
69
+ var _image = require("./image.js");
74
70
 
75
71
  var PartialEvaluator = function PartialEvaluatorClosure() {
76
- var DefaultPartialEvaluatorOptions = {
72
+ const DefaultPartialEvaluatorOptions = {
77
73
  forceDataSchema: false,
78
74
  maxImageSize: -1,
79
75
  disableFontFace: false,
@@ -81,68 +77,17 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
81
77
  ignoreErrors: false,
82
78
  isEvalSupported: true
83
79
  };
84
- function NativeImageDecoder(_ref) {
85
- var xref = _ref.xref,
86
- resources = _ref.resources,
87
- handler = _ref.handler,
88
- _ref$forceDataSchema = _ref.forceDataSchema,
89
- forceDataSchema = _ref$forceDataSchema === undefined ? false : _ref$forceDataSchema,
90
- pdfFunctionFactory = _ref.pdfFunctionFactory;
91
80
 
92
- this.xref = xref;
93
- this.resources = resources;
94
- this.handler = handler;
95
- this.forceDataSchema = forceDataSchema;
96
- this.pdfFunctionFactory = pdfFunctionFactory;
97
- }
98
- NativeImageDecoder.prototype = {
99
- canDecode: function canDecode(image) {
100
- return image instanceof _jpeg_stream.JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources, this.pdfFunctionFactory);
101
- },
102
- decode: function decode(image) {
103
- var dict = image.dict;
104
- var colorSpace = dict.get('ColorSpace', 'CS');
105
- colorSpace = _colorspace.ColorSpace.parse(colorSpace, this.xref, this.resources, this.pdfFunctionFactory);
106
- return this.handler.sendWithPromise('JpegDecode', [image.getIR(this.forceDataSchema), colorSpace.numComps]).then(function (_ref2) {
107
- var data = _ref2.data,
108
- width = _ref2.width,
109
- height = _ref2.height;
110
-
111
- return new _stream.Stream(data, 0, data.length, image.dict);
112
- });
113
- }
114
- };
115
- NativeImageDecoder.isSupported = function (image, xref, res, pdfFunctionFactory) {
116
- var dict = image.dict;
117
- if (dict.has('DecodeParms') || dict.has('DP')) {
118
- return false;
119
- }
120
- var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory);
121
- return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
122
- };
123
- NativeImageDecoder.isDecodable = function (image, xref, res, pdfFunctionFactory) {
124
- var dict = image.dict;
125
- if (dict.has('DecodeParms') || dict.has('DP')) {
126
- return false;
127
- }
128
- var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory);
129
- return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
130
- };
131
- function PartialEvaluator(_ref3) {
132
- var _this = this;
133
-
134
- var pdfManager = _ref3.pdfManager,
135
- xref = _ref3.xref,
136
- handler = _ref3.handler,
137
- pageIndex = _ref3.pageIndex,
138
- idFactory = _ref3.idFactory,
139
- fontCache = _ref3.fontCache,
140
- builtInCMapCache = _ref3.builtInCMapCache,
141
- _ref3$options = _ref3.options,
142
- options = _ref3$options === undefined ? null : _ref3$options,
143
- pdfFunctionFactory = _ref3.pdfFunctionFactory;
144
-
145
- this.pdfManager = pdfManager;
81
+ function PartialEvaluator({
82
+ xref,
83
+ handler,
84
+ pageIndex,
85
+ idFactory,
86
+ fontCache,
87
+ builtInCMapCache,
88
+ options = null,
89
+ pdfFunctionFactory
90
+ }) {
146
91
  this.xref = xref;
147
92
  this.handler = handler;
148
93
  this.pageIndex = pageIndex;
@@ -151,55 +96,56 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
151
96
  this.builtInCMapCache = builtInCMapCache;
152
97
  this.options = options || DefaultPartialEvaluatorOptions;
153
98
  this.pdfFunctionFactory = pdfFunctionFactory;
154
- this.fetchBuiltInCMap = function () {
155
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(name) {
156
- var data;
157
- return _regenerator2.default.wrap(function _callee$(_context) {
158
- while (1) {
159
- switch (_context.prev = _context.next) {
160
- case 0:
161
- if (!_this.builtInCMapCache.has(name)) {
162
- _context.next = 2;
163
- break;
164
- }
99
+ this.parsingType3Font = false;
165
100
 
166
- return _context.abrupt('return', _this.builtInCMapCache.get(name));
101
+ this.fetchBuiltInCMap = async name => {
102
+ if (this.builtInCMapCache.has(name)) {
103
+ return this.builtInCMapCache.get(name);
104
+ }
167
105
 
168
- case 2:
169
- _context.next = 4;
170
- return _this.handler.sendWithPromise('FetchBuiltInCMap', { name: name });
106
+ const readableStream = this.handler.sendWithStream("FetchBuiltInCMap", {
107
+ name
108
+ });
109
+ const reader = readableStream.getReader();
110
+ const data = await new Promise(function (resolve, reject) {
111
+ function pump() {
112
+ reader.read().then(function ({
113
+ value,
114
+ done
115
+ }) {
116
+ if (done) {
117
+ return;
118
+ }
171
119
 
172
- case 4:
173
- data = _context.sent;
120
+ resolve(value);
121
+ pump();
122
+ }, reject);
123
+ }
174
124
 
175
- if (data.compressionType !== _util.CMapCompressionType.NONE) {
176
- _this.builtInCMapCache.set(name, data);
177
- }
178
- return _context.abrupt('return', data);
125
+ pump();
126
+ });
179
127
 
180
- case 7:
181
- case 'end':
182
- return _context.stop();
183
- }
184
- }
185
- }, _callee, _this);
186
- }));
128
+ if (data.compressionType !== _util.CMapCompressionType.NONE) {
129
+ this.builtInCMapCache.set(name, data);
130
+ }
187
131
 
188
- return function (_x) {
189
- return _ref4.apply(this, arguments);
190
- };
191
- }();
132
+ return data;
133
+ };
192
134
  }
135
+
193
136
  var TIME_SLOT_DURATION_MS = 20;
194
137
  var CHECK_TIME_EVERY = 100;
138
+
195
139
  function TimeSlotManager() {
196
140
  this.reset();
197
141
  }
142
+
198
143
  TimeSlotManager.prototype = {
199
144
  check: function TimeSlotManager_check() {
200
145
  if (++this.checked < CHECK_TIME_EVERY) {
201
146
  return false;
202
147
  }
148
+
203
149
  this.checked = 0;
204
150
  return this.endTime <= Date.now();
205
151
  },
@@ -208,319 +154,505 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
208
154
  this.checked = 0;
209
155
  }
210
156
  };
211
- function normalizeBlendMode(value) {
157
+
158
+ function normalizeBlendMode(value, parsingArray = false) {
159
+ if (Array.isArray(value)) {
160
+ for (let i = 0, ii = value.length; i < ii; i++) {
161
+ const maybeBM = normalizeBlendMode(value[i], true);
162
+
163
+ if (maybeBM) {
164
+ return maybeBM;
165
+ }
166
+ }
167
+
168
+ (0, _util.warn)(`Unsupported blend mode Array: ${value}`);
169
+ return "source-over";
170
+ }
171
+
212
172
  if (!(0, _primitives.isName)(value)) {
213
- return 'source-over';
173
+ if (parsingArray) {
174
+ return null;
175
+ }
176
+
177
+ return "source-over";
214
178
  }
179
+
215
180
  switch (value.name) {
216
- case 'Normal':
217
- case 'Compatible':
218
- return 'source-over';
219
- case 'Multiply':
220
- return 'multiply';
221
- case 'Screen':
222
- return 'screen';
223
- case 'Overlay':
224
- return 'overlay';
225
- case 'Darken':
226
- return 'darken';
227
- case 'Lighten':
228
- return 'lighten';
229
- case 'ColorDodge':
230
- return 'color-dodge';
231
- case 'ColorBurn':
232
- return 'color-burn';
233
- case 'HardLight':
234
- return 'hard-light';
235
- case 'SoftLight':
236
- return 'soft-light';
237
- case 'Difference':
238
- return 'difference';
239
- case 'Exclusion':
240
- return 'exclusion';
241
- case 'Hue':
242
- return 'hue';
243
- case 'Saturation':
244
- return 'saturation';
245
- case 'Color':
246
- return 'color';
247
- case 'Luminosity':
248
- return 'luminosity';
181
+ case "Normal":
182
+ case "Compatible":
183
+ return "source-over";
184
+
185
+ case "Multiply":
186
+ return "multiply";
187
+
188
+ case "Screen":
189
+ return "screen";
190
+
191
+ case "Overlay":
192
+ return "overlay";
193
+
194
+ case "Darken":
195
+ return "darken";
196
+
197
+ case "Lighten":
198
+ return "lighten";
199
+
200
+ case "ColorDodge":
201
+ return "color-dodge";
202
+
203
+ case "ColorBurn":
204
+ return "color-burn";
205
+
206
+ case "HardLight":
207
+ return "hard-light";
208
+
209
+ case "SoftLight":
210
+ return "soft-light";
211
+
212
+ case "Difference":
213
+ return "difference";
214
+
215
+ case "Exclusion":
216
+ return "exclusion";
217
+
218
+ case "Hue":
219
+ return "hue";
220
+
221
+ case "Saturation":
222
+ return "saturation";
223
+
224
+ case "Color":
225
+ return "color";
226
+
227
+ case "Luminosity":
228
+ return "luminosity";
229
+ }
230
+
231
+ if (parsingArray) {
232
+ return null;
249
233
  }
250
- (0, _util.warn)('Unsupported blend mode: ' + value.name);
251
- return 'source-over';
234
+
235
+ (0, _util.warn)(`Unsupported blend mode: ${value.name}`);
236
+ return "source-over";
252
237
  }
238
+
253
239
  var deferred = Promise.resolve();
254
240
  var TILING_PATTERN = 1,
255
241
  SHADING_PATTERN = 2;
256
242
  PartialEvaluator.prototype = {
257
- clone: function clone() {
258
- var newOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DefaultPartialEvaluatorOptions;
259
-
243
+ clone(newOptions = DefaultPartialEvaluatorOptions) {
260
244
  var newEvaluator = Object.create(this);
261
245
  newEvaluator.options = newOptions;
262
246
  return newEvaluator;
263
247
  },
264
248
 
265
249
  hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
266
- if (!(0, _primitives.isDict)(resources)) {
250
+ if (!(resources instanceof _primitives.Dict)) {
267
251
  return false;
268
252
  }
253
+
269
254
  var processed = Object.create(null);
255
+
270
256
  if (resources.objId) {
271
257
  processed[resources.objId] = true;
272
258
  }
259
+
273
260
  var nodes = [resources],
274
261
  xref = this.xref;
262
+
275
263
  while (nodes.length) {
276
- var key, i, ii;
277
264
  var node = nodes.shift();
278
- var graphicStates = node.get('ExtGState');
279
- if ((0, _primitives.isDict)(graphicStates)) {
265
+ var graphicStates = node.get("ExtGState");
266
+
267
+ if (graphicStates instanceof _primitives.Dict) {
280
268
  var graphicStatesKeys = graphicStates.getKeys();
281
- for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
282
- key = graphicStatesKeys[i];
283
- var graphicState = graphicStates.get(key);
284
- var bm = graphicState.get('BM');
285
- if ((0, _primitives.isName)(bm) && bm.name !== 'Normal') {
286
- return true;
269
+
270
+ for (let i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
271
+ const key = graphicStatesKeys[i];
272
+ let graphicState = graphicStates.getRaw(key);
273
+
274
+ if (graphicState instanceof _primitives.Ref) {
275
+ if (processed[graphicState.toString()]) {
276
+ continue;
277
+ }
278
+
279
+ try {
280
+ graphicState = xref.fetch(graphicState);
281
+ } catch (ex) {
282
+ if (ex instanceof _core_utils.MissingDataException) {
283
+ throw ex;
284
+ }
285
+
286
+ if (this.options.ignoreErrors) {
287
+ if (graphicState instanceof _primitives.Ref) {
288
+ processed[graphicState.toString()] = true;
289
+ }
290
+
291
+ this.handler.send("UnsupportedFeature", {
292
+ featureId: _util.UNSUPPORTED_FEATURES.unknown
293
+ });
294
+ (0, _util.warn)(`hasBlendModes - ignoring ExtGState: "${ex}".`);
295
+ continue;
296
+ }
297
+
298
+ throw ex;
299
+ }
300
+ }
301
+
302
+ if (!(graphicState instanceof _primitives.Dict)) {
303
+ continue;
304
+ }
305
+
306
+ if (graphicState.objId) {
307
+ processed[graphicState.objId] = true;
308
+ }
309
+
310
+ const bm = graphicState.get("BM");
311
+
312
+ if (bm instanceof _primitives.Name) {
313
+ if (bm.name !== "Normal") {
314
+ return true;
315
+ }
316
+
317
+ continue;
318
+ }
319
+
320
+ if (bm !== undefined && Array.isArray(bm)) {
321
+ for (let j = 0, jj = bm.length; j < jj; j++) {
322
+ if (bm[j] instanceof _primitives.Name && bm[j].name !== "Normal") {
323
+ return true;
324
+ }
325
+ }
287
326
  }
288
327
  }
289
328
  }
290
- var xObjects = node.get('XObject');
291
- if (!(0, _primitives.isDict)(xObjects)) {
329
+
330
+ var xObjects = node.get("XObject");
331
+
332
+ if (!(xObjects instanceof _primitives.Dict)) {
292
333
  continue;
293
334
  }
335
+
294
336
  var xObjectsKeys = xObjects.getKeys();
295
- for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
296
- key = xObjectsKeys[i];
337
+
338
+ for (let i = 0, ii = xObjectsKeys.length; i < ii; i++) {
339
+ const key = xObjectsKeys[i];
297
340
  var xObject = xObjects.getRaw(key);
298
- if ((0, _primitives.isRef)(xObject)) {
341
+
342
+ if (xObject instanceof _primitives.Ref) {
299
343
  if (processed[xObject.toString()]) {
300
344
  continue;
301
345
  }
302
- xObject = xref.fetch(xObject);
346
+
347
+ try {
348
+ xObject = xref.fetch(xObject);
349
+ } catch (ex) {
350
+ if (ex instanceof _core_utils.MissingDataException) {
351
+ throw ex;
352
+ }
353
+
354
+ if (this.options.ignoreErrors) {
355
+ if (xObject instanceof _primitives.Ref) {
356
+ processed[xObject.toString()] = true;
357
+ }
358
+
359
+ this.handler.send("UnsupportedFeature", {
360
+ featureId: _util.UNSUPPORTED_FEATURES.unknown
361
+ });
362
+ (0, _util.warn)(`hasBlendModes - ignoring XObject: "${ex}".`);
363
+ continue;
364
+ }
365
+
366
+ throw ex;
367
+ }
303
368
  }
369
+
304
370
  if (!(0, _primitives.isStream)(xObject)) {
305
371
  continue;
306
372
  }
373
+
307
374
  if (xObject.dict.objId) {
308
375
  if (processed[xObject.dict.objId]) {
309
376
  continue;
310
377
  }
378
+
311
379
  processed[xObject.dict.objId] = true;
312
380
  }
313
- var xResources = xObject.dict.get('Resources');
314
- if ((0, _primitives.isDict)(xResources) && (!xResources.objId || !processed[xResources.objId])) {
381
+
382
+ var xResources = xObject.dict.get("Resources");
383
+
384
+ if (xResources instanceof _primitives.Dict && (!xResources.objId || !processed[xResources.objId])) {
315
385
  nodes.push(xResources);
386
+
316
387
  if (xResources.objId) {
317
388
  processed[xResources.objId] = true;
318
389
  }
319
390
  }
320
391
  }
321
392
  }
393
+
322
394
  return false;
323
395
  },
324
- buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
396
+
397
+ async buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
325
398
  var dict = xobj.dict;
326
- var matrix = dict.getArray('Matrix');
327
- var bbox = dict.getArray('BBox');
328
- var group = dict.get('Group');
399
+ var matrix = dict.getArray("Matrix");
400
+ var bbox = dict.getArray("BBox");
401
+
402
+ if (Array.isArray(bbox) && bbox.length === 4) {
403
+ bbox = _util.Util.normalizeRect(bbox);
404
+ } else {
405
+ bbox = null;
406
+ }
407
+
408
+ var group = dict.get("Group");
409
+
329
410
  if (group) {
330
411
  var groupOptions = {
331
- matrix: matrix,
332
- bbox: bbox,
333
- smask: smask,
412
+ matrix,
413
+ bbox,
414
+ smask,
334
415
  isolated: false,
335
416
  knockout: false
336
417
  };
337
- var groupSubtype = group.get('S');
418
+ var groupSubtype = group.get("S");
338
419
  var colorSpace = null;
339
- if ((0, _primitives.isName)(groupSubtype, 'Transparency')) {
340
- groupOptions.isolated = group.get('I') || false;
341
- groupOptions.knockout = group.get('K') || false;
342
- if (group.has('CS')) {
343
- colorSpace = _colorspace.ColorSpace.parse(group.get('CS'), this.xref, resources, this.pdfFunctionFactory);
420
+
421
+ if ((0, _primitives.isName)(groupSubtype, "Transparency")) {
422
+ groupOptions.isolated = group.get("I") || false;
423
+ groupOptions.knockout = group.get("K") || false;
424
+
425
+ if (group.has("CS")) {
426
+ colorSpace = await this.parseColorSpace({
427
+ cs: group.get("CS"),
428
+ resources
429
+ });
344
430
  }
345
431
  }
432
+
346
433
  if (smask && smask.backdrop) {
347
434
  colorSpace = colorSpace || _colorspace.ColorSpace.singletons.rgb;
348
435
  smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
349
436
  }
437
+
350
438
  operatorList.addOp(_util.OPS.beginGroup, [groupOptions]);
351
439
  }
440
+
352
441
  operatorList.addOp(_util.OPS.paintFormXObjectBegin, [matrix, bbox]);
353
442
  return this.getOperatorList({
354
443
  stream: xobj,
355
- task: task,
356
- resources: dict.get('Resources') || resources,
357
- operatorList: operatorList,
358
- initialState: initialState
444
+ task,
445
+ resources: dict.get("Resources") || resources,
446
+ operatorList,
447
+ initialState
359
448
  }).then(function () {
360
449
  operatorList.addOp(_util.OPS.paintFormXObjectEnd, []);
450
+
361
451
  if (group) {
362
452
  operatorList.addOp(_util.OPS.endGroup, [groupOptions]);
363
453
  }
364
454
  });
365
455
  },
366
- buildPaintImageXObject: function buildPaintImageXObject(_ref5) {
367
- var _this2 = this;
368
-
369
- var resources = _ref5.resources,
370
- image = _ref5.image,
371
- _ref5$isInline = _ref5.isInline,
372
- isInline = _ref5$isInline === undefined ? false : _ref5$isInline,
373
- operatorList = _ref5.operatorList,
374
- cacheKey = _ref5.cacheKey,
375
- imageCache = _ref5.imageCache,
376
- _ref5$forceDisableNat = _ref5.forceDisableNativeImageDecoder,
377
- forceDisableNativeImageDecoder = _ref5$forceDisableNat === undefined ? false : _ref5$forceDisableNat;
378
456
 
457
+ async buildPaintImageXObject({
458
+ resources,
459
+ image,
460
+ isInline = false,
461
+ operatorList,
462
+ cacheKey,
463
+ imageCache,
464
+ forceDisableNativeImageDecoder = false
465
+ }) {
379
466
  var dict = image.dict;
380
- var w = dict.get('Width', 'W');
381
- var h = dict.get('Height', 'H');
467
+ var w = dict.get("Width", "W");
468
+ var h = dict.get("Height", "H");
469
+
382
470
  if (!(w && (0, _util.isNum)(w)) || !(h && (0, _util.isNum)(h))) {
383
- (0, _util.warn)('Image dimensions are missing, or not numbers.');
384
- return Promise.resolve();
471
+ (0, _util.warn)("Image dimensions are missing, or not numbers.");
472
+ return undefined;
385
473
  }
474
+
386
475
  var maxImageSize = this.options.maxImageSize;
476
+
387
477
  if (maxImageSize !== -1 && w * h > maxImageSize) {
388
- (0, _util.warn)('Image exceeded maximum allowed size and was removed.');
389
- return Promise.resolve();
478
+ (0, _util.warn)("Image exceeded maximum allowed size and was removed.");
479
+ return undefined;
390
480
  }
391
- var imageMask = dict.get('ImageMask', 'IM') || false;
481
+
482
+ var imageMask = dict.get("ImageMask", "IM") || false;
392
483
  var imgData, args;
484
+
393
485
  if (imageMask) {
394
- var width = dict.get('Width', 'W');
395
- var height = dict.get('Height', 'H');
486
+ var width = dict.get("Width", "W");
487
+ var height = dict.get("Height", "H");
396
488
  var bitStrideLength = width + 7 >> 3;
397
489
  var imgArray = image.getBytes(bitStrideLength * height, true);
398
- var decode = dict.getArray('Decode', 'D');
490
+ var decode = dict.getArray("Decode", "D");
399
491
  imgData = _image.PDFImage.createMask({
400
- imgArray: imgArray,
401
- width: width,
402
- height: height,
492
+ imgArray,
493
+ width,
494
+ height,
403
495
  imageIsFromDecodeStream: image instanceof _stream.DecodeStream,
404
496
  inverseDecode: !!decode && decode[0] > 0
405
497
  });
406
- imgData.cached = true;
498
+ imgData.cached = !!cacheKey;
407
499
  args = [imgData];
408
500
  operatorList.addOp(_util.OPS.paintImageMaskXObject, args);
501
+
409
502
  if (cacheKey) {
410
503
  imageCache[cacheKey] = {
411
504
  fn: _util.OPS.paintImageMaskXObject,
412
- args: args
505
+ args
413
506
  };
414
507
  }
415
- return Promise.resolve();
508
+
509
+ return undefined;
416
510
  }
417
- var softMask = dict.get('SMask', 'SM') || false;
418
- var mask = dict.get('Mask') || false;
511
+
512
+ var softMask = dict.get("SMask", "SM") || false;
513
+ var mask = dict.get("Mask") || false;
419
514
  var SMALL_IMAGE_DIMENSIONS = 200;
515
+
420
516
  if (isInline && !softMask && !mask && !(image instanceof _jpeg_stream.JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
421
- var imageObj = new _image.PDFImage({
517
+ const imageObj = new _image.PDFImage({
422
518
  xref: this.xref,
423
519
  res: resources,
424
- image: image,
425
- isInline: isInline,
520
+ image,
521
+ isInline,
426
522
  pdfFunctionFactory: this.pdfFunctionFactory
427
523
  });
428
524
  imgData = imageObj.createImageData(true);
429
525
  operatorList.addOp(_util.OPS.paintInlineImageXObject, [imgData]);
430
- return Promise.resolve();
526
+ return undefined;
527
+ }
528
+
529
+ const nativeImageDecoderSupport = forceDisableNativeImageDecoder ? _util.NativeImageDecoding.NONE : this.options.nativeImageDecoderSupport;
530
+ let objId = `img_${this.idFactory.createObjId()}`;
531
+
532
+ if (this.parsingType3Font) {
533
+ (0, _util.assert)(nativeImageDecoderSupport === _util.NativeImageDecoding.NONE, "Type3 image resources should be completely decoded in the worker.");
534
+ objId = `${this.idFactory.getDocId()}_type3res_${objId}`;
431
535
  }
432
- var nativeImageDecoderSupport = forceDisableNativeImageDecoder ? _util.NativeImageDecoding.NONE : this.options.nativeImageDecoderSupport;
433
- var objId = 'img_' + this.idFactory.createObjId();
434
- if (nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && !softMask && !mask && image instanceof _jpeg_stream.JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources, this.pdfFunctionFactory)) {
435
- return this.handler.sendWithPromise('obj', [objId, this.pageIndex, 'JpegStream', image.getIR(this.options.forceDataSchema)]).then(function () {
536
+
537
+ if (nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && !softMask && !mask && image instanceof _jpeg_stream.JpegStream && _image_utils.NativeImageDecoder.isSupported(image, this.xref, resources, this.pdfFunctionFactory) && image.maybeValidDimensions) {
538
+ return this.handler.sendWithPromise("obj", [objId, this.pageIndex, "JpegStream", image.getIR(this.options.forceDataSchema)]).then(function () {
436
539
  operatorList.addDependency(objId);
437
540
  args = [objId, w, h];
438
541
  operatorList.addOp(_util.OPS.paintJpegXObject, args);
542
+
439
543
  if (cacheKey) {
440
544
  imageCache[cacheKey] = {
441
545
  fn: _util.OPS.paintJpegXObject,
442
- args: args
546
+ args
443
547
  };
444
548
  }
445
- }, function (reason) {
446
- (0, _util.warn)('Native JPEG decoding failed -- trying to recover: ' + (reason && reason.message));
447
- return _this2.buildPaintImageXObject({
448
- resources: resources,
449
- image: image,
450
- isInline: isInline,
451
- operatorList: operatorList,
452
- cacheKey: cacheKey,
453
- imageCache: imageCache,
549
+ }, reason => {
550
+ (0, _util.warn)("Native JPEG decoding failed -- trying to recover: " + (reason && reason.message));
551
+ return this.buildPaintImageXObject({
552
+ resources,
553
+ image,
554
+ isInline,
555
+ operatorList,
556
+ cacheKey,
557
+ imageCache,
454
558
  forceDisableNativeImageDecoder: true
455
559
  });
456
560
  });
457
561
  }
562
+
458
563
  var nativeImageDecoder = null;
564
+
459
565
  if (nativeImageDecoderSupport === _util.NativeImageDecoding.DECODE && (image instanceof _jpeg_stream.JpegStream || mask instanceof _jpeg_stream.JpegStream || softMask instanceof _jpeg_stream.JpegStream)) {
460
- nativeImageDecoder = new NativeImageDecoder({
566
+ nativeImageDecoder = new _image_utils.NativeImageDecoder({
461
567
  xref: this.xref,
462
- resources: resources,
568
+ resources,
463
569
  handler: this.handler,
464
570
  forceDataSchema: this.options.forceDataSchema,
465
571
  pdfFunctionFactory: this.pdfFunctionFactory
466
572
  });
467
573
  }
574
+
468
575
  operatorList.addDependency(objId);
469
576
  args = [objId, w, h];
470
- _image.PDFImage.buildImage({
577
+
578
+ const imgPromise = _image.PDFImage.buildImage({
471
579
  handler: this.handler,
472
580
  xref: this.xref,
473
581
  res: resources,
474
- image: image,
475
- isInline: isInline,
582
+ image,
583
+ isInline,
476
584
  nativeDecoder: nativeImageDecoder,
477
585
  pdfFunctionFactory: this.pdfFunctionFactory
478
- }).then(function (imageObj) {
586
+ }).then(imageObj => {
479
587
  var imgData = imageObj.createImageData(false);
480
- _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', imgData], [imgData.data.buffer]);
481
- }).catch(function (reason) {
482
- (0, _util.warn)('Unable to decode image: ' + reason);
483
- _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', null]);
588
+
589
+ if (this.parsingType3Font) {
590
+ return this.handler.sendWithPromise("commonobj", [objId, "FontType3Res", imgData], [imgData.data.buffer]);
591
+ }
592
+
593
+ this.handler.send("obj", [objId, this.pageIndex, "Image", imgData], [imgData.data.buffer]);
594
+ return undefined;
595
+ }).catch(reason => {
596
+ (0, _util.warn)("Unable to decode image: " + reason);
597
+
598
+ if (this.parsingType3Font) {
599
+ return this.handler.sendWithPromise("commonobj", [objId, "FontType3Res", null]);
600
+ }
601
+
602
+ this.handler.send("obj", [objId, this.pageIndex, "Image", null]);
603
+ return undefined;
484
604
  });
605
+
606
+ if (this.parsingType3Font) {
607
+ await imgPromise;
608
+ }
609
+
485
610
  operatorList.addOp(_util.OPS.paintImageXObject, args);
611
+
486
612
  if (cacheKey) {
487
613
  imageCache[cacheKey] = {
488
614
  fn: _util.OPS.paintImageXObject,
489
- args: args
615
+ args
490
616
  };
491
617
  }
492
- return Promise.resolve();
618
+
619
+ return undefined;
493
620
  },
494
621
 
495
622
  handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
496
- var smaskContent = smask.get('G');
623
+ var smaskContent = smask.get("G");
497
624
  var smaskOptions = {
498
- subtype: smask.get('S').name,
499
- backdrop: smask.get('BC')
625
+ subtype: smask.get("S").name,
626
+ backdrop: smask.get("BC")
500
627
  };
501
- var transferObj = smask.get('TR');
628
+ var transferObj = smask.get("TR");
629
+
502
630
  if ((0, _function.isPDFFunction)(transferObj)) {
503
- var transferFn = this.pdfFunctionFactory.create(transferObj);
631
+ const transferFn = this.pdfFunctionFactory.create(transferObj);
504
632
  var transferMap = new Uint8Array(256);
505
633
  var tmp = new Float32Array(1);
634
+
506
635
  for (var i = 0; i < 256; i++) {
507
636
  tmp[0] = i / 255;
508
637
  transferFn(tmp, 0, tmp, 0);
509
638
  transferMap[i] = tmp[0] * 255 | 0;
510
639
  }
640
+
511
641
  smaskOptions.transferMap = transferMap;
512
642
  }
643
+
513
644
  return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
514
645
  },
515
- handleTilingType: function handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
516
- var _this3 = this;
517
646
 
518
- var tilingOpList = new _operator_list.OperatorList();
519
- var resourcesArray = [patternDict.get('Resources'), resources];
520
- var patternResources = _primitives.Dict.merge(this.xref, resourcesArray);
647
+ handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
648
+ const tilingOpList = new _operator_list.OperatorList();
649
+ const resourcesArray = [patternDict.get("Resources"), resources];
650
+
651
+ const patternResources = _primitives.Dict.merge(this.xref, resourcesArray);
652
+
521
653
  return this.getOperatorList({
522
654
  stream: pattern,
523
- task: task,
655
+ task,
524
656
  resources: patternResources,
525
657
  operatorList: tilingOpList
526
658
  }).then(function () {
@@ -531,138 +663,162 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
531
663
  }).then(function (tilingPatternIR) {
532
664
  operatorList.addDependencies(tilingOpList.dependencies);
533
665
  operatorList.addOp(fn, tilingPatternIR);
534
- }, function (reason) {
535
- if (_this3.options.ignoreErrors) {
536
- _this3.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.unknown });
537
- (0, _util.warn)('handleTilingType - ignoring pattern: "' + reason + '".');
666
+ }, reason => {
667
+ if (reason instanceof _util.AbortException) {
538
668
  return;
539
669
  }
670
+
671
+ if (this.options.ignoreErrors) {
672
+ this.handler.send("UnsupportedFeature", {
673
+ featureId: _util.UNSUPPORTED_FEATURES.unknown
674
+ });
675
+ (0, _util.warn)(`handleTilingType - ignoring pattern: "${reason}".`);
676
+ return;
677
+ }
678
+
540
679
  throw reason;
541
680
  });
542
681
  },
543
682
 
544
683
  handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
545
- var _this4 = this;
546
-
547
684
  var fontName;
685
+
548
686
  if (fontArgs) {
549
687
  fontArgs = fontArgs.slice();
550
688
  fontName = fontArgs[0].name;
551
689
  }
552
- return this.loadFont(fontName, fontRef, resources).then(function (translated) {
690
+
691
+ return this.loadFont(fontName, fontRef, resources).then(translated => {
553
692
  if (!translated.font.isType3Font) {
554
693
  return translated;
555
694
  }
556
- return translated.loadType3Data(_this4, resources, operatorList, task).then(function () {
695
+
696
+ return translated.loadType3Data(this, resources, operatorList, task).then(function () {
557
697
  return translated;
558
- }).catch(function (reason) {
559
- _this4.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.font });
560
- return new TranslatedFont('g_font_error', new _fonts.ErrorFont('Type3 font load error: ' + reason), translated.font);
698
+ }).catch(reason => {
699
+ this.handler.send("UnsupportedFeature", {
700
+ featureId: _util.UNSUPPORTED_FEATURES.font
701
+ });
702
+ return new TranslatedFont("g_font_error", new _fonts.ErrorFont("Type3 font load error: " + reason), translated.font);
561
703
  });
562
- }).then(function (translated) {
704
+ }).then(translated => {
563
705
  state.font = translated.font;
564
- translated.send(_this4.handler);
706
+ translated.send(this.handler);
565
707
  return translated.loadedName;
566
708
  });
567
709
  },
568
- handleText: function PartialEvaluator_handleText(chars, state) {
569
- var _this5 = this;
570
-
571
- var font = state.font;
572
- var glyphs = font.charsToGlyphs(chars);
573
- var isAddToPathSet = !!(state.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
574
- if (font.data && (isAddToPathSet || this.options.disableFontFace || state.fillColorSpace.name === 'Pattern')) {
575
- var buildPath = function buildPath(fontChar) {
576
- if (!font.renderer.hasBuiltPath(fontChar)) {
577
- var path = font.renderer.getPathJs(fontChar);
578
- _this5.handler.send('commonobj', [font.loadedName + '_path_' + fontChar, 'FontPath', path]);
579
- }
580
- };
581
- for (var i = 0, ii = glyphs.length; i < ii; i++) {
582
- var glyph = glyphs[i];
583
- buildPath(glyph.fontChar);
584
- var accent = glyph.accent;
585
- if (accent && accent.fontChar) {
586
- buildPath(accent.fontChar);
587
- }
710
+
711
+ handleText(chars, state) {
712
+ const font = state.font;
713
+ const glyphs = font.charsToGlyphs(chars);
714
+
715
+ if (font.data) {
716
+ const isAddToPathSet = !!(state.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
717
+
718
+ if (isAddToPathSet || state.fillColorSpace.name === "Pattern" || font.disableFontFace || this.options.disableFontFace) {
719
+ PartialEvaluator.buildFontPaths(font, glyphs, this.handler);
588
720
  }
589
721
  }
722
+
590
723
  return glyphs;
591
724
  },
592
- setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, stateManager) {
593
- var _this6 = this;
594
725
 
726
+ ensureStateFont(state) {
727
+ if (state.font) {
728
+ return;
729
+ }
730
+
731
+ const reason = new _util.FormatError("Missing setFont (Tf) operator before text rendering operator.");
732
+
733
+ if (this.options.ignoreErrors) {
734
+ this.handler.send("UnsupportedFeature", {
735
+ featureId: _util.UNSUPPORTED_FEATURES.font
736
+ });
737
+ (0, _util.warn)(`ensureStateFont: "${reason}".`);
738
+ return;
739
+ }
740
+
741
+ throw reason;
742
+ },
743
+
744
+ setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, stateManager) {
595
745
  var gStateObj = [];
596
746
  var gStateKeys = gState.getKeys();
597
747
  var promise = Promise.resolve();
598
748
 
599
- var _loop = function _loop() {
600
- var key = gStateKeys[i];
601
- var value = gState.get(key);
749
+ for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
750
+ const key = gStateKeys[i];
751
+ const value = gState.get(key);
752
+
602
753
  switch (key) {
603
- case 'Type':
754
+ case "Type":
604
755
  break;
605
- case 'LW':
606
- case 'LC':
607
- case 'LJ':
608
- case 'ML':
609
- case 'D':
610
- case 'RI':
611
- case 'FL':
612
- case 'CA':
613
- case 'ca':
756
+
757
+ case "LW":
758
+ case "LC":
759
+ case "LJ":
760
+ case "ML":
761
+ case "D":
762
+ case "RI":
763
+ case "FL":
764
+ case "CA":
765
+ case "ca":
614
766
  gStateObj.push([key, value]);
615
767
  break;
616
- case 'Font':
617
- promise = promise.then(function () {
618
- return _this6.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
768
+
769
+ case "Font":
770
+ promise = promise.then(() => {
771
+ return this.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
619
772
  operatorList.addDependency(loadedName);
620
773
  gStateObj.push([key, [loadedName, value[1]]]);
621
774
  });
622
775
  });
623
776
  break;
624
- case 'BM':
777
+
778
+ case "BM":
625
779
  gStateObj.push([key, normalizeBlendMode(value)]);
626
780
  break;
627
- case 'SMask':
628
- if ((0, _primitives.isName)(value, 'None')) {
781
+
782
+ case "SMask":
783
+ if ((0, _primitives.isName)(value, "None")) {
629
784
  gStateObj.push([key, false]);
630
785
  break;
631
786
  }
787
+
632
788
  if ((0, _primitives.isDict)(value)) {
633
- promise = promise.then(function () {
634
- return _this6.handleSMask(value, resources, operatorList, task, stateManager);
789
+ promise = promise.then(() => {
790
+ return this.handleSMask(value, resources, operatorList, task, stateManager);
635
791
  });
636
792
  gStateObj.push([key, true]);
637
793
  } else {
638
- (0, _util.warn)('Unsupported SMask type');
794
+ (0, _util.warn)("Unsupported SMask type");
639
795
  }
796
+
640
797
  break;
641
- case 'OP':
642
- case 'op':
643
- case 'OPM':
644
- case 'BG':
645
- case 'BG2':
646
- case 'UCR':
647
- case 'UCR2':
648
- case 'TR':
649
- case 'TR2':
650
- case 'HT':
651
- case 'SM':
652
- case 'SA':
653
- case 'AIS':
654
- case 'TK':
655
- (0, _util.info)('graphic state operator ' + key);
798
+
799
+ case "OP":
800
+ case "op":
801
+ case "OPM":
802
+ case "BG":
803
+ case "BG2":
804
+ case "UCR":
805
+ case "UCR2":
806
+ case "TR":
807
+ case "TR2":
808
+ case "HT":
809
+ case "SM":
810
+ case "SA":
811
+ case "AIS":
812
+ case "TK":
813
+ (0, _util.info)("graphic state operator " + key);
656
814
  break;
815
+
657
816
  default:
658
- (0, _util.info)('Unknown graphic state operator ' + key);
817
+ (0, _util.info)("Unknown graphic state operator " + key);
659
818
  break;
660
819
  }
661
- };
662
-
663
- for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
664
- _loop();
665
820
  }
821
+
666
822
  return promise.then(function () {
667
823
  if (gStateObj.length > 0) {
668
824
  operatorList.addOp(_util.OPS.setGState, [gStateObj]);
@@ -670,171 +826,251 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
670
826
  });
671
827
  },
672
828
  loadFont: function PartialEvaluator_loadFont(fontName, font, resources) {
673
- var _this7 = this;
674
-
675
829
  function errorFont() {
676
- return Promise.resolve(new TranslatedFont('g_font_error', new _fonts.ErrorFont('Font ' + fontName + ' is not available'), font));
830
+ return Promise.resolve(new TranslatedFont("g_font_error", new _fonts.ErrorFont("Font " + fontName + " is not available"), font));
677
831
  }
832
+
678
833
  var fontRef,
679
834
  xref = this.xref;
835
+
680
836
  if (font) {
681
837
  if (!(0, _primitives.isRef)(font)) {
682
- throw new Error('The "font" object should be a reference.');
838
+ throw new _util.FormatError('The "font" object should be a reference.');
683
839
  }
840
+
684
841
  fontRef = font;
685
842
  } else {
686
- var fontRes = resources.get('Font');
843
+ var fontRes = resources.get("Font");
844
+
687
845
  if (fontRes) {
688
846
  fontRef = fontRes.getRaw(fontName);
689
- } else {
690
- (0, _util.warn)('fontRes not available');
691
- return errorFont();
692
847
  }
693
848
  }
849
+
694
850
  if (!fontRef) {
695
- (0, _util.warn)('fontRef not available');
696
- return errorFont();
851
+ const partialMsg = `Font "${fontName || font && font.toString()}" is not available`;
852
+
853
+ if (!this.options.ignoreErrors && !this.parsingType3Font) {
854
+ (0, _util.warn)(`${partialMsg}.`);
855
+ return errorFont();
856
+ }
857
+
858
+ this.handler.send("UnsupportedFeature", {
859
+ featureId: _util.UNSUPPORTED_FEATURES.font
860
+ });
861
+ (0, _util.warn)(`${partialMsg} -- attempting to fallback to a default font.`);
862
+ fontRef = PartialEvaluator.getFallbackFontDict();
697
863
  }
864
+
698
865
  if (this.fontCache.has(fontRef)) {
699
866
  return this.fontCache.get(fontRef);
700
867
  }
868
+
701
869
  font = xref.fetchIfRef(fontRef);
870
+
702
871
  if (!(0, _primitives.isDict)(font)) {
703
872
  return errorFont();
704
873
  }
874
+
705
875
  if (font.translated) {
706
876
  return font.translated;
707
877
  }
878
+
708
879
  var fontCapability = (0, _util.createPromiseCapability)();
709
880
  var preEvaluatedFont = this.preEvaluateFont(font);
710
- var descriptor = preEvaluatedFont.descriptor;
881
+ const {
882
+ descriptor,
883
+ hash
884
+ } = preEvaluatedFont;
711
885
  var fontRefIsRef = (0, _primitives.isRef)(fontRef),
712
886
  fontID;
887
+
713
888
  if (fontRefIsRef) {
714
889
  fontID = fontRef.toString();
715
890
  }
716
- if ((0, _primitives.isDict)(descriptor)) {
891
+
892
+ if (hash && (0, _primitives.isDict)(descriptor)) {
717
893
  if (!descriptor.fontAliases) {
718
894
  descriptor.fontAliases = Object.create(null);
719
895
  }
896
+
720
897
  var fontAliases = descriptor.fontAliases;
721
- var hash = preEvaluatedFont.hash;
898
+
722
899
  if (fontAliases[hash]) {
723
900
  var aliasFontRef = fontAliases[hash].aliasRef;
901
+
724
902
  if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
725
903
  this.fontCache.putAlias(fontRef, aliasFontRef);
726
904
  return this.fontCache.get(fontRef);
727
905
  }
728
906
  } else {
729
- fontAliases[hash] = { fontID: _fonts.Font.getFontID() };
907
+ fontAliases[hash] = {
908
+ fontID: _fonts.Font.getFontID()
909
+ };
730
910
  }
911
+
731
912
  if (fontRefIsRef) {
732
913
  fontAliases[hash].aliasRef = fontRef;
733
914
  }
915
+
734
916
  fontID = fontAliases[hash].fontID;
735
917
  }
918
+
736
919
  if (fontRefIsRef) {
737
920
  this.fontCache.put(fontRef, fontCapability.promise);
738
921
  } else {
739
922
  if (!fontID) {
740
923
  fontID = this.idFactory.createObjId();
741
924
  }
742
- this.fontCache.put('id_' + fontID, fontCapability.promise);
925
+
926
+ this.fontCache.put(`id_${fontID}`, fontCapability.promise);
743
927
  }
928
+
744
929
  (0, _util.assert)(fontID, 'The "fontID" must be defined.');
745
- font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
930
+ font.loadedName = `${this.idFactory.getDocId()}_f${fontID}`;
746
931
  font.translated = fontCapability.promise;
747
932
  var translatedPromise;
933
+
748
934
  try {
749
935
  translatedPromise = this.translateFont(preEvaluatedFont);
750
936
  } catch (e) {
751
937
  translatedPromise = Promise.reject(e);
752
938
  }
939
+
753
940
  translatedPromise.then(function (translatedFont) {
754
941
  if (translatedFont.fontType !== undefined) {
755
942
  var xrefFontStats = xref.stats.fontTypes;
756
943
  xrefFontStats[translatedFont.fontType] = true;
757
944
  }
945
+
758
946
  fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
759
- }).catch(function (reason) {
760
- _this7.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.font });
947
+ }).catch(reason => {
948
+ this.handler.send("UnsupportedFeature", {
949
+ featureId: _util.UNSUPPORTED_FEATURES.font
950
+ });
951
+
761
952
  try {
762
- var descriptor = preEvaluatedFont.descriptor;
763
- var fontFile3 = descriptor && descriptor.get('FontFile3');
764
- var subtype = fontFile3 && fontFile3.get('Subtype');
953
+ var fontFile3 = descriptor && descriptor.get("FontFile3");
954
+ var subtype = fontFile3 && fontFile3.get("Subtype");
765
955
  var fontType = (0, _fonts.getFontType)(preEvaluatedFont.type, subtype && subtype.name);
766
956
  var xrefFontStats = xref.stats.fontTypes;
767
957
  xrefFontStats[fontType] = true;
768
958
  } catch (ex) {}
959
+
769
960
  fontCapability.resolve(new TranslatedFont(font.loadedName, new _fonts.ErrorFont(reason instanceof Error ? reason.message : reason), font));
770
961
  });
771
962
  return fontCapability.promise;
772
963
  },
773
- buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
964
+
965
+ buildPath(operatorList, fn, args, parsingText = false) {
774
966
  var lastIndex = operatorList.length - 1;
967
+
775
968
  if (!args) {
776
969
  args = [];
777
970
  }
971
+
778
972
  if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== _util.OPS.constructPath) {
973
+ if (parsingText) {
974
+ (0, _util.warn)(`Encountered path operator "${fn}" inside of a text object.`);
975
+ operatorList.addOp(_util.OPS.save, null);
976
+ }
977
+
779
978
  operatorList.addOp(_util.OPS.constructPath, [[fn], args]);
979
+
980
+ if (parsingText) {
981
+ operatorList.addOp(_util.OPS.restore, null);
982
+ }
780
983
  } else {
781
984
  var opArgs = operatorList.argsArray[lastIndex];
782
985
  opArgs[0].push(fn);
783
986
  Array.prototype.push.apply(opArgs[1], args);
784
987
  }
785
988
  },
786
- handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task) {
989
+
990
+ parseColorSpace({
991
+ cs,
992
+ resources
993
+ }) {
994
+ return new Promise(resolve => {
995
+ resolve(_colorspace.ColorSpace.parse(cs, this.xref, resources, this.pdfFunctionFactory));
996
+ }).catch(reason => {
997
+ if (reason instanceof _util.AbortException) {
998
+ return null;
999
+ }
1000
+
1001
+ if (this.options.ignoreErrors) {
1002
+ this.handler.send("UnsupportedFeature", {
1003
+ featureId: _util.UNSUPPORTED_FEATURES.unknown
1004
+ });
1005
+ (0, _util.warn)(`parseColorSpace - ignoring ColorSpace: "${reason}".`);
1006
+ return null;
1007
+ }
1008
+
1009
+ throw reason;
1010
+ });
1011
+ },
1012
+
1013
+ async handleColorN(operatorList, fn, args, cs, patterns, resources, task) {
787
1014
  var patternName = args[args.length - 1];
788
1015
  var pattern;
1016
+
789
1017
  if ((0, _primitives.isName)(patternName) && (pattern = patterns.get(patternName.name))) {
790
1018
  var dict = (0, _primitives.isStream)(pattern) ? pattern.dict : pattern;
791
- var typeNum = dict.get('PatternType');
1019
+ var typeNum = dict.get("PatternType");
1020
+
792
1021
  if (typeNum === TILING_PATTERN) {
793
1022
  var color = cs.base ? cs.base.getRgb(args, 0) : null;
794
1023
  return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
795
1024
  } else if (typeNum === SHADING_PATTERN) {
796
- var shading = dict.get('Shading');
797
- var matrix = dict.getArray('Matrix');
1025
+ var shading = dict.get("Shading");
1026
+ var matrix = dict.getArray("Matrix");
798
1027
  pattern = _pattern.Pattern.parseShading(shading, matrix, this.xref, resources, this.handler, this.pdfFunctionFactory);
799
1028
  operatorList.addOp(fn, pattern.getIR());
800
- return Promise.resolve();
1029
+ return undefined;
801
1030
  }
802
- return Promise.reject(new Error('Unknown PatternType: ' + typeNum));
1031
+
1032
+ throw new _util.FormatError(`Unknown PatternType: ${typeNum}`);
803
1033
  }
804
- operatorList.addOp(fn, args);
805
- return Promise.resolve();
806
- },
807
- getOperatorList: function getOperatorList(_ref6) {
808
- var _this8 = this;
809
1034
 
810
- var stream = _ref6.stream,
811
- task = _ref6.task,
812
- resources = _ref6.resources,
813
- operatorList = _ref6.operatorList,
814
- _ref6$initialState = _ref6.initialState,
815
- initialState = _ref6$initialState === undefined ? null : _ref6$initialState;
1035
+ throw new _util.FormatError(`Unknown PatternName: ${patternName}`);
1036
+ },
816
1037
 
1038
+ getOperatorList({
1039
+ stream,
1040
+ task,
1041
+ resources,
1042
+ operatorList,
1043
+ initialState = null
1044
+ }) {
817
1045
  resources = resources || _primitives.Dict.empty;
818
1046
  initialState = initialState || new EvalState();
1047
+
819
1048
  if (!operatorList) {
820
1049
  throw new Error('getOperatorList: missing "operatorList" parameter');
821
1050
  }
1051
+
822
1052
  var self = this;
823
1053
  var xref = this.xref;
1054
+ let parsingText = false;
824
1055
  var imageCache = Object.create(null);
825
- var xobjs = resources.get('XObject') || _primitives.Dict.empty;
826
- var patterns = resources.get('Pattern') || _primitives.Dict.empty;
1056
+
1057
+ var xobjs = resources.get("XObject") || _primitives.Dict.empty;
1058
+
1059
+ var patterns = resources.get("Pattern") || _primitives.Dict.empty;
1060
+
827
1061
  var stateManager = new StateManager(initialState);
828
1062
  var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
829
1063
  var timeSlotManager = new TimeSlotManager();
1064
+
830
1065
  function closePendingRestoreOPS(argument) {
831
1066
  for (var i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
832
1067
  operatorList.addOp(_util.OPS.restore, []);
833
1068
  }
834
1069
  }
1070
+
835
1071
  return new Promise(function promiseBody(resolve, reject) {
836
- var next = function next(promise) {
837
- promise.then(function () {
1072
+ const next = function (promise) {
1073
+ Promise.all([promise, operatorList.ready]).then(function () {
838
1074
  try {
839
1075
  promiseBody(resolve, reject);
840
1076
  } catch (ex) {
@@ -842,6 +1078,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
842
1078
  }
843
1079
  }, reject);
844
1080
  };
1081
+
845
1082
  task.ensureNotTerminated();
846
1083
  timeSlotManager.reset();
847
1084
  var stop,
@@ -849,69 +1086,90 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
849
1086
  i,
850
1087
  ii,
851
1088
  cs;
1089
+
852
1090
  while (!(stop = timeSlotManager.check())) {
853
1091
  operation.args = null;
1092
+
854
1093
  if (!preprocessor.read(operation)) {
855
1094
  break;
856
1095
  }
1096
+
857
1097
  var args = operation.args;
858
1098
  var fn = operation.fn;
1099
+
859
1100
  switch (fn | 0) {
860
1101
  case _util.OPS.paintXObject:
861
1102
  var name = args[0].name;
1103
+
862
1104
  if (name && imageCache[name] !== undefined) {
863
1105
  operatorList.addOp(imageCache[name].fn, imageCache[name].args);
864
1106
  args = null;
865
1107
  continue;
866
1108
  }
1109
+
867
1110
  next(new Promise(function (resolveXObject, rejectXObject) {
868
1111
  if (!name) {
869
- throw new _util.FormatError('XObject must be referred to by name.');
1112
+ throw new _util.FormatError("XObject must be referred to by name.");
870
1113
  }
871
- var xobj = xobjs.get(name);
1114
+
1115
+ const xobj = xobjs.get(name);
1116
+
872
1117
  if (!xobj) {
873
1118
  operatorList.addOp(fn, args);
874
1119
  resolveXObject();
875
1120
  return;
876
1121
  }
1122
+
877
1123
  if (!(0, _primitives.isStream)(xobj)) {
878
- throw new _util.FormatError('XObject should be a stream');
1124
+ throw new _util.FormatError("XObject should be a stream");
879
1125
  }
880
- var type = xobj.dict.get('Subtype');
1126
+
1127
+ const type = xobj.dict.get("Subtype");
1128
+
881
1129
  if (!(0, _primitives.isName)(type)) {
882
- throw new _util.FormatError('XObject should have a Name subtype');
1130
+ throw new _util.FormatError("XObject should have a Name subtype");
883
1131
  }
884
- if (type.name === 'Form') {
1132
+
1133
+ if (type.name === "Form") {
885
1134
  stateManager.save();
886
1135
  self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
887
1136
  stateManager.restore();
888
1137
  resolveXObject();
889
1138
  }, rejectXObject);
890
1139
  return;
891
- } else if (type.name === 'Image') {
1140
+ } else if (type.name === "Image") {
892
1141
  self.buildPaintImageXObject({
893
- resources: resources,
1142
+ resources,
894
1143
  image: xobj,
895
- operatorList: operatorList,
1144
+ operatorList,
896
1145
  cacheKey: name,
897
- imageCache: imageCache
1146
+ imageCache
898
1147
  }).then(resolveXObject, rejectXObject);
899
1148
  return;
900
- } else if (type.name === 'PS') {
901
- (0, _util.info)('Ignored XObject subtype PS');
1149
+ } else if (type.name === "PS") {
1150
+ (0, _util.info)("Ignored XObject subtype PS");
902
1151
  } else {
903
- throw new _util.FormatError('Unhandled XObject subtype ' + type.name);
1152
+ throw new _util.FormatError(`Unhandled XObject subtype ${type.name}`);
904
1153
  }
1154
+
905
1155
  resolveXObject();
906
1156
  }).catch(function (reason) {
1157
+ if (reason instanceof _util.AbortException) {
1158
+ return;
1159
+ }
1160
+
907
1161
  if (self.options.ignoreErrors) {
908
- self.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.unknown });
909
- (0, _util.warn)('getOperatorList - ignoring XObject: "' + reason + '".');
1162
+ self.handler.send("UnsupportedFeature", {
1163
+ featureId: _util.UNSUPPORTED_FEATURES.unknown
1164
+ });
1165
+ (0, _util.warn)(`getOperatorList - ignoring XObject: "${reason}".`);
910
1166
  return;
911
1167
  }
1168
+
912
1169
  throw reason;
913
1170
  }));
914
1171
  return;
1172
+
915
1173
  case _util.OPS.setFont:
916
1174
  var fontSize = args[1];
917
1175
  next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
@@ -919,155 +1177,234 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
919
1177
  operatorList.addOp(_util.OPS.setFont, [loadedName, fontSize]);
920
1178
  }));
921
1179
  return;
1180
+
1181
+ case _util.OPS.beginText:
1182
+ parsingText = true;
1183
+ break;
1184
+
1185
+ case _util.OPS.endText:
1186
+ parsingText = false;
1187
+ break;
1188
+
922
1189
  case _util.OPS.endInlineImage:
923
1190
  var cacheKey = args[0].cacheKey;
1191
+
924
1192
  if (cacheKey) {
925
1193
  var cacheEntry = imageCache[cacheKey];
1194
+
926
1195
  if (cacheEntry !== undefined) {
927
1196
  operatorList.addOp(cacheEntry.fn, cacheEntry.args);
928
1197
  args = null;
929
1198
  continue;
930
1199
  }
931
1200
  }
1201
+
932
1202
  next(self.buildPaintImageXObject({
933
- resources: resources,
1203
+ resources,
934
1204
  image: args[0],
935
1205
  isInline: true,
936
- operatorList: operatorList,
937
- cacheKey: cacheKey,
938
- imageCache: imageCache
1206
+ operatorList,
1207
+ cacheKey,
1208
+ imageCache
939
1209
  }));
940
1210
  return;
1211
+
941
1212
  case _util.OPS.showText:
1213
+ if (!stateManager.state.font) {
1214
+ self.ensureStateFont(stateManager.state);
1215
+ continue;
1216
+ }
1217
+
942
1218
  args[0] = self.handleText(args[0], stateManager.state);
943
1219
  break;
1220
+
944
1221
  case _util.OPS.showSpacedText:
1222
+ if (!stateManager.state.font) {
1223
+ self.ensureStateFont(stateManager.state);
1224
+ continue;
1225
+ }
1226
+
945
1227
  var arr = args[0];
946
1228
  var combinedGlyphs = [];
947
1229
  var arrLength = arr.length;
948
1230
  var state = stateManager.state;
1231
+
949
1232
  for (i = 0; i < arrLength; ++i) {
950
1233
  var arrItem = arr[i];
1234
+
951
1235
  if ((0, _util.isString)(arrItem)) {
952
1236
  Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
953
1237
  } else if ((0, _util.isNum)(arrItem)) {
954
1238
  combinedGlyphs.push(arrItem);
955
1239
  }
956
1240
  }
1241
+
957
1242
  args[0] = combinedGlyphs;
958
1243
  fn = _util.OPS.showText;
959
1244
  break;
1245
+
960
1246
  case _util.OPS.nextLineShowText:
1247
+ if (!stateManager.state.font) {
1248
+ self.ensureStateFont(stateManager.state);
1249
+ continue;
1250
+ }
1251
+
961
1252
  operatorList.addOp(_util.OPS.nextLine);
962
1253
  args[0] = self.handleText(args[0], stateManager.state);
963
1254
  fn = _util.OPS.showText;
964
1255
  break;
1256
+
965
1257
  case _util.OPS.nextLineSetSpacingShowText:
1258
+ if (!stateManager.state.font) {
1259
+ self.ensureStateFont(stateManager.state);
1260
+ continue;
1261
+ }
1262
+
966
1263
  operatorList.addOp(_util.OPS.nextLine);
967
1264
  operatorList.addOp(_util.OPS.setWordSpacing, [args.shift()]);
968
1265
  operatorList.addOp(_util.OPS.setCharSpacing, [args.shift()]);
969
1266
  args[0] = self.handleText(args[0], stateManager.state);
970
1267
  fn = _util.OPS.showText;
971
1268
  break;
1269
+
972
1270
  case _util.OPS.setTextRenderingMode:
973
1271
  stateManager.state.textRenderingMode = args[0];
974
1272
  break;
1273
+
975
1274
  case _util.OPS.setFillColorSpace:
976
- stateManager.state.fillColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources, self.pdfFunctionFactory);
977
- continue;
1275
+ next(self.parseColorSpace({
1276
+ cs: args[0],
1277
+ resources
1278
+ }).then(function (colorSpace) {
1279
+ if (colorSpace) {
1280
+ stateManager.state.fillColorSpace = colorSpace;
1281
+ }
1282
+ }));
1283
+ return;
1284
+
978
1285
  case _util.OPS.setStrokeColorSpace:
979
- stateManager.state.strokeColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources, self.pdfFunctionFactory);
980
- continue;
1286
+ next(self.parseColorSpace({
1287
+ cs: args[0],
1288
+ resources
1289
+ }).then(function (colorSpace) {
1290
+ if (colorSpace) {
1291
+ stateManager.state.strokeColorSpace = colorSpace;
1292
+ }
1293
+ }));
1294
+ return;
1295
+
981
1296
  case _util.OPS.setFillColor:
982
1297
  cs = stateManager.state.fillColorSpace;
983
1298
  args = cs.getRgb(args, 0);
984
1299
  fn = _util.OPS.setFillRGBColor;
985
1300
  break;
1301
+
986
1302
  case _util.OPS.setStrokeColor:
987
1303
  cs = stateManager.state.strokeColorSpace;
988
1304
  args = cs.getRgb(args, 0);
989
1305
  fn = _util.OPS.setStrokeRGBColor;
990
1306
  break;
1307
+
991
1308
  case _util.OPS.setFillGray:
992
1309
  stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.gray;
993
1310
  args = _colorspace.ColorSpace.singletons.gray.getRgb(args, 0);
994
1311
  fn = _util.OPS.setFillRGBColor;
995
1312
  break;
1313
+
996
1314
  case _util.OPS.setStrokeGray:
997
1315
  stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.gray;
998
1316
  args = _colorspace.ColorSpace.singletons.gray.getRgb(args, 0);
999
1317
  fn = _util.OPS.setStrokeRGBColor;
1000
1318
  break;
1319
+
1001
1320
  case _util.OPS.setFillCMYKColor:
1002
1321
  stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.cmyk;
1003
1322
  args = _colorspace.ColorSpace.singletons.cmyk.getRgb(args, 0);
1004
1323
  fn = _util.OPS.setFillRGBColor;
1005
1324
  break;
1325
+
1006
1326
  case _util.OPS.setStrokeCMYKColor:
1007
1327
  stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.cmyk;
1008
1328
  args = _colorspace.ColorSpace.singletons.cmyk.getRgb(args, 0);
1009
1329
  fn = _util.OPS.setStrokeRGBColor;
1010
1330
  break;
1331
+
1011
1332
  case _util.OPS.setFillRGBColor:
1012
1333
  stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.rgb;
1013
1334
  args = _colorspace.ColorSpace.singletons.rgb.getRgb(args, 0);
1014
1335
  break;
1336
+
1015
1337
  case _util.OPS.setStrokeRGBColor:
1016
1338
  stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.rgb;
1017
1339
  args = _colorspace.ColorSpace.singletons.rgb.getRgb(args, 0);
1018
1340
  break;
1341
+
1019
1342
  case _util.OPS.setFillColorN:
1020
1343
  cs = stateManager.state.fillColorSpace;
1021
- if (cs.name === 'Pattern') {
1344
+
1345
+ if (cs.name === "Pattern") {
1022
1346
  next(self.handleColorN(operatorList, _util.OPS.setFillColorN, args, cs, patterns, resources, task));
1023
1347
  return;
1024
1348
  }
1349
+
1025
1350
  args = cs.getRgb(args, 0);
1026
1351
  fn = _util.OPS.setFillRGBColor;
1027
1352
  break;
1353
+
1028
1354
  case _util.OPS.setStrokeColorN:
1029
1355
  cs = stateManager.state.strokeColorSpace;
1030
- if (cs.name === 'Pattern') {
1356
+
1357
+ if (cs.name === "Pattern") {
1031
1358
  next(self.handleColorN(operatorList, _util.OPS.setStrokeColorN, args, cs, patterns, resources, task));
1032
1359
  return;
1033
1360
  }
1361
+
1034
1362
  args = cs.getRgb(args, 0);
1035
1363
  fn = _util.OPS.setStrokeRGBColor;
1036
1364
  break;
1365
+
1037
1366
  case _util.OPS.shadingFill:
1038
- var shadingRes = resources.get('Shading');
1367
+ var shadingRes = resources.get("Shading");
1368
+
1039
1369
  if (!shadingRes) {
1040
- throw new _util.FormatError('No shading resource found');
1370
+ throw new _util.FormatError("No shading resource found");
1041
1371
  }
1372
+
1042
1373
  var shading = shadingRes.get(args[0].name);
1374
+
1043
1375
  if (!shading) {
1044
- throw new _util.FormatError('No shading object found');
1376
+ throw new _util.FormatError("No shading object found");
1045
1377
  }
1378
+
1046
1379
  var shadingFill = _pattern.Pattern.parseShading(shading, null, xref, resources, self.handler, self.pdfFunctionFactory);
1380
+
1047
1381
  var patternIR = shadingFill.getIR();
1048
1382
  args = [patternIR];
1049
1383
  fn = _util.OPS.shadingFill;
1050
1384
  break;
1385
+
1051
1386
  case _util.OPS.setGState:
1052
1387
  var dictName = args[0];
1053
- var extGState = resources.get('ExtGState');
1388
+ var extGState = resources.get("ExtGState");
1389
+
1054
1390
  if (!(0, _primitives.isDict)(extGState) || !extGState.has(dictName.name)) {
1055
1391
  break;
1056
1392
  }
1393
+
1057
1394
  var gState = extGState.get(dictName.name);
1058
1395
  next(self.setGState(resources, gState, operatorList, task, stateManager));
1059
1396
  return;
1397
+
1060
1398
  case _util.OPS.moveTo:
1061
1399
  case _util.OPS.lineTo:
1062
1400
  case _util.OPS.curveTo:
1063
1401
  case _util.OPS.curveTo2:
1064
1402
  case _util.OPS.curveTo3:
1065
1403
  case _util.OPS.closePath:
1066
- self.buildPath(operatorList, fn, args);
1067
- continue;
1068
1404
  case _util.OPS.rectangle:
1069
- self.buildPath(operatorList, fn, args);
1405
+ self.buildPath(operatorList, fn, args, parsingText);
1070
1406
  continue;
1407
+
1071
1408
  case _util.OPS.markPoint:
1072
1409
  case _util.OPS.markPointProps:
1073
1410
  case _util.OPS.beginMarkedContent:
@@ -1076,6 +1413,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1076
1413
  case _util.OPS.beginCompat:
1077
1414
  case _util.OPS.endCompat:
1078
1415
  continue;
1416
+
1079
1417
  default:
1080
1418
  if (args !== null) {
1081
1419
  for (i = 0, ii = args.length; i < ii; i++) {
@@ -1083,46 +1421,53 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1083
1421
  break;
1084
1422
  }
1085
1423
  }
1424
+
1086
1425
  if (i < ii) {
1087
- (0, _util.warn)('getOperatorList - ignoring operator: ' + fn);
1426
+ (0, _util.warn)("getOperatorList - ignoring operator: " + fn);
1088
1427
  continue;
1089
1428
  }
1090
1429
  }
1430
+
1091
1431
  }
1432
+
1092
1433
  operatorList.addOp(fn, args);
1093
1434
  }
1435
+
1094
1436
  if (stop) {
1095
1437
  next(deferred);
1096
1438
  return;
1097
1439
  }
1440
+
1098
1441
  closePendingRestoreOPS();
1099
1442
  resolve();
1100
- }).catch(function (reason) {
1101
- if (_this8.options.ignoreErrors) {
1102
- _this8.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.unknown });
1103
- (0, _util.warn)('getOperatorList - ignoring errors during "' + task.name + '" ' + ('task: "' + reason + '".'));
1443
+ }).catch(reason => {
1444
+ if (reason instanceof _util.AbortException) {
1445
+ return;
1446
+ }
1447
+
1448
+ if (this.options.ignoreErrors) {
1449
+ this.handler.send("UnsupportedFeature", {
1450
+ featureId: _util.UNSUPPORTED_FEATURES.unknown
1451
+ });
1452
+ (0, _util.warn)(`getOperatorList - ignoring errors during "${task.name}" ` + `task: "${reason}".`);
1104
1453
  closePendingRestoreOPS();
1105
1454
  return;
1106
1455
  }
1456
+
1107
1457
  throw reason;
1108
1458
  });
1109
1459
  },
1110
- getTextContent: function getTextContent(_ref7) {
1111
- var _this9 = this;
1112
-
1113
- var stream = _ref7.stream,
1114
- task = _ref7.task,
1115
- resources = _ref7.resources,
1116
- _ref7$stateManager = _ref7.stateManager,
1117
- stateManager = _ref7$stateManager === undefined ? null : _ref7$stateManager,
1118
- _ref7$normalizeWhites = _ref7.normalizeWhitespace,
1119
- normalizeWhitespace = _ref7$normalizeWhites === undefined ? false : _ref7$normalizeWhites,
1120
- _ref7$combineTextItem = _ref7.combineTextItems,
1121
- combineTextItems = _ref7$combineTextItem === undefined ? false : _ref7$combineTextItem,
1122
- sink = _ref7.sink,
1123
- _ref7$seenStyles = _ref7.seenStyles,
1124
- seenStyles = _ref7$seenStyles === undefined ? Object.create(null) : _ref7$seenStyles;
1125
1460
 
1461
+ getTextContent({
1462
+ stream,
1463
+ task,
1464
+ resources,
1465
+ stateManager = null,
1466
+ normalizeWhitespace = false,
1467
+ combineTextItems = false,
1468
+ sink,
1469
+ seenStyles = Object.create(null)
1470
+ }) {
1126
1471
  resources = resources || _primitives.Dict.empty;
1127
1472
  stateManager = stateManager || new StateManager(new TextState());
1128
1473
  var WhitespaceRegexp = /\s/g;
@@ -1156,31 +1501,39 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1156
1501
  var skipEmptyXObjs = Object.create(null);
1157
1502
  var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
1158
1503
  var textState;
1504
+
1159
1505
  function ensureTextContentItem() {
1160
1506
  if (textContentItem.initialized) {
1161
1507
  return textContentItem;
1162
1508
  }
1509
+
1163
1510
  var font = textState.font;
1511
+
1164
1512
  if (!(font.loadedName in seenStyles)) {
1165
1513
  seenStyles[font.loadedName] = true;
1166
1514
  textContent.styles[font.loadedName] = {
1167
1515
  fontFamily: font.fallbackName,
1168
1516
  ascent: font.ascent,
1169
1517
  descent: font.descent,
1170
- vertical: font.vertical
1518
+ vertical: !!font.vertical
1171
1519
  };
1172
1520
  }
1521
+
1173
1522
  textContentItem.fontName = font.loadedName;
1174
1523
  var tsm = [textState.fontSize * textState.textHScale, 0, 0, textState.fontSize, 0, textState.textRise];
1175
- if (font.isType3Font && textState.fontMatrix !== _util.FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
1176
- var glyphHeight = font.bbox[3] - font.bbox[1];
1524
+
1525
+ if (font.isType3Font && textState.fontSize <= 1 && !(0, _util.isArrayEqual)(textState.fontMatrix, _util.FONT_IDENTITY_MATRIX)) {
1526
+ const glyphHeight = font.bbox[3] - font.bbox[1];
1527
+
1177
1528
  if (glyphHeight > 0) {
1178
- glyphHeight = glyphHeight * textState.fontMatrix[3];
1179
- tsm[3] *= glyphHeight;
1529
+ tsm[3] *= glyphHeight * textState.fontMatrix[3];
1180
1530
  }
1181
1531
  }
1532
+
1182
1533
  var trm = _util.Util.transform(textState.ctm, _util.Util.transform(textState.textMatrix, tsm));
1534
+
1183
1535
  textContentItem.transform = trm;
1536
+
1184
1537
  if (!font.vertical) {
1185
1538
  textContentItem.width = 0;
1186
1539
  textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
@@ -1190,6 +1543,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1190
1543
  textContentItem.height = 0;
1191
1544
  textContentItem.vertical = true;
1192
1545
  }
1546
+
1193
1547
  var a = textState.textLineMatrix[0];
1194
1548
  var b = textState.textLineMatrix[1];
1195
1549
  var scaleLineX = Math.sqrt(a * a + b * b);
@@ -1200,6 +1554,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1200
1554
  textContentItem.lastAdvanceWidth = 0;
1201
1555
  textContentItem.lastAdvanceHeight = 0;
1202
1556
  var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
1557
+
1203
1558
  if (spaceWidth) {
1204
1559
  textContentItem.spaceWidth = spaceWidth;
1205
1560
  textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
@@ -1213,20 +1568,25 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1213
1568
  textContentItem.fakeMultiSpaceMax = 0;
1214
1569
  textContentItem.textRunBreakAllowed = false;
1215
1570
  }
1571
+
1216
1572
  textContentItem.initialized = true;
1217
1573
  return textContentItem;
1218
1574
  }
1575
+
1219
1576
  function replaceWhitespace(str) {
1220
1577
  var i = 0,
1221
1578
  ii = str.length,
1222
1579
  code;
1223
- while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
1580
+
1581
+ while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7f) {
1224
1582
  i++;
1225
1583
  }
1226
- return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
1584
+
1585
+ return i < ii ? str.replace(WhitespaceRegexp, " ") : str;
1227
1586
  }
1587
+
1228
1588
  function runBidiTransform(textChunk) {
1229
- var str = textChunk.str.join('');
1589
+ var str = textChunk.str.join("");
1230
1590
  var bidiResult = (0, _bidi.bidi)(str, -1, textChunk.vertical);
1231
1591
  return {
1232
1592
  str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
@@ -1237,42 +1597,53 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1237
1597
  fontName: textChunk.fontName
1238
1598
  };
1239
1599
  }
1600
+
1240
1601
  function handleSetFont(fontName, fontRef) {
1241
1602
  return self.loadFont(fontName, fontRef, resources).then(function (translated) {
1242
1603
  textState.font = translated.font;
1243
1604
  textState.fontMatrix = translated.font.fontMatrix || _util.FONT_IDENTITY_MATRIX;
1244
1605
  });
1245
1606
  }
1607
+
1246
1608
  function buildTextContentItem(chars) {
1247
1609
  var font = textState.font;
1248
1610
  var textChunk = ensureTextContentItem();
1249
1611
  var width = 0;
1250
1612
  var height = 0;
1251
1613
  var glyphs = font.charsToGlyphs(chars);
1614
+
1252
1615
  for (var i = 0; i < glyphs.length; i++) {
1253
1616
  var glyph = glyphs[i];
1254
1617
  var glyphWidth = null;
1618
+
1255
1619
  if (font.vertical && glyph.vmetric) {
1256
1620
  glyphWidth = glyph.vmetric[0];
1257
1621
  } else {
1258
1622
  glyphWidth = glyph.width;
1259
1623
  }
1624
+
1260
1625
  var glyphUnicode = glyph.unicode;
1261
1626
  var NormalizedUnicodes = (0, _unicode.getNormalizedUnicodes)();
1627
+
1262
1628
  if (NormalizedUnicodes[glyphUnicode] !== undefined) {
1263
1629
  glyphUnicode = NormalizedUnicodes[glyphUnicode];
1264
1630
  }
1631
+
1265
1632
  glyphUnicode = (0, _unicode.reverseIfRtl)(glyphUnicode);
1266
1633
  var charSpacing = textState.charSpacing;
1634
+
1267
1635
  if (glyph.isSpace) {
1268
1636
  var wordSpacing = textState.wordSpacing;
1269
1637
  charSpacing += wordSpacing;
1638
+
1270
1639
  if (wordSpacing > 0) {
1271
1640
  addFakeSpaces(wordSpacing, textChunk.str);
1272
1641
  }
1273
1642
  }
1643
+
1274
1644
  var tx = 0;
1275
1645
  var ty = 0;
1646
+
1276
1647
  if (!font.vertical) {
1277
1648
  var w0 = glyphWidth * textState.fontMatrix[0];
1278
1649
  tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
@@ -1282,9 +1653,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1282
1653
  ty = w1 * textState.fontSize + charSpacing;
1283
1654
  height += ty;
1284
1655
  }
1656
+
1285
1657
  textState.translateTextMatrix(tx, ty);
1286
1658
  textChunk.str.push(glyphUnicode);
1287
1659
  }
1660
+
1288
1661
  if (!font.vertical) {
1289
1662
  textChunk.lastAdvanceWidth = width;
1290
1663
  textChunk.width += width;
@@ -1292,42 +1665,56 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1292
1665
  textChunk.lastAdvanceHeight = height;
1293
1666
  textChunk.height += Math.abs(height);
1294
1667
  }
1668
+
1295
1669
  return textChunk;
1296
1670
  }
1671
+
1297
1672
  function addFakeSpaces(width, strBuf) {
1298
1673
  if (width < textContentItem.fakeSpaceMin) {
1299
1674
  return;
1300
1675
  }
1676
+
1301
1677
  if (width < textContentItem.fakeMultiSpaceMin) {
1302
- strBuf.push(' ');
1678
+ strBuf.push(" ");
1303
1679
  return;
1304
1680
  }
1681
+
1305
1682
  var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
1683
+
1306
1684
  while (fakeSpaces-- > 0) {
1307
- strBuf.push(' ');
1685
+ strBuf.push(" ");
1308
1686
  }
1309
1687
  }
1688
+
1310
1689
  function flushTextContentItem() {
1311
1690
  if (!textContentItem.initialized) {
1312
1691
  return;
1313
1692
  }
1314
- textContentItem.width *= textContentItem.textAdvanceScale;
1315
- textContentItem.height *= textContentItem.textAdvanceScale;
1693
+
1694
+ if (!textContentItem.vertical) {
1695
+ textContentItem.width *= textContentItem.textAdvanceScale;
1696
+ } else {
1697
+ textContentItem.height *= textContentItem.textAdvanceScale;
1698
+ }
1699
+
1316
1700
  textContent.items.push(runBidiTransform(textContentItem));
1317
1701
  textContentItem.initialized = false;
1318
1702
  textContentItem.str.length = 0;
1319
1703
  }
1704
+
1320
1705
  function enqueueChunk() {
1321
- var length = textContent.items.length;
1706
+ const length = textContent.items.length;
1707
+
1322
1708
  if (length > 0) {
1323
1709
  sink.enqueue(textContent, length);
1324
1710
  textContent.items = [];
1325
1711
  textContent.styles = Object.create(null);
1326
1712
  }
1327
1713
  }
1714
+
1328
1715
  var timeSlotManager = new TimeSlotManager();
1329
1716
  return new Promise(function promiseBody(resolve, reject) {
1330
- var next = function next(promise) {
1717
+ const next = function (promise) {
1331
1718
  enqueueChunk();
1332
1719
  Promise.all([promise, sink.ready]).then(function () {
1333
1720
  try {
@@ -1337,48 +1724,60 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1337
1724
  }
1338
1725
  }, reject);
1339
1726
  };
1727
+
1340
1728
  task.ensureNotTerminated();
1341
1729
  timeSlotManager.reset();
1342
1730
  var stop,
1343
1731
  operation = {},
1344
1732
  args = [];
1733
+
1345
1734
  while (!(stop = timeSlotManager.check())) {
1346
1735
  args.length = 0;
1347
1736
  operation.args = args;
1737
+
1348
1738
  if (!preprocessor.read(operation)) {
1349
1739
  break;
1350
1740
  }
1741
+
1351
1742
  textState = stateManager.state;
1352
1743
  var fn = operation.fn;
1353
1744
  args = operation.args;
1354
1745
  var advance, diff;
1746
+
1355
1747
  switch (fn | 0) {
1356
1748
  case _util.OPS.setFont:
1357
1749
  var fontNameArg = args[0].name,
1358
1750
  fontSizeArg = args[1];
1751
+
1359
1752
  if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
1360
1753
  break;
1361
1754
  }
1755
+
1362
1756
  flushTextContentItem();
1363
1757
  textState.fontName = fontNameArg;
1364
1758
  textState.fontSize = fontSizeArg;
1365
1759
  next(handleSetFont(fontNameArg, null));
1366
1760
  return;
1761
+
1367
1762
  case _util.OPS.setTextRise:
1368
1763
  flushTextContentItem();
1369
1764
  textState.textRise = args[0];
1370
1765
  break;
1766
+
1371
1767
  case _util.OPS.setHScale:
1372
1768
  flushTextContentItem();
1373
1769
  textState.textHScale = args[0] / 100;
1374
1770
  break;
1771
+
1375
1772
  case _util.OPS.setLeading:
1376
1773
  flushTextContentItem();
1377
1774
  textState.leading = args[0];
1378
1775
  break;
1776
+
1379
1777
  case _util.OPS.moveText:
1380
1778
  var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
1381
1779
  advance = args[0] - args[1];
1780
+
1382
1781
  if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
1383
1782
  textState.translateTextLineMatrix(args[0], args[1]);
1384
1783
  textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
@@ -1387,22 +1786,27 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1387
1786
  addFakeSpaces(diff, textContentItem.str);
1388
1787
  break;
1389
1788
  }
1789
+
1390
1790
  flushTextContentItem();
1391
1791
  textState.translateTextLineMatrix(args[0], args[1]);
1392
1792
  textState.textMatrix = textState.textLineMatrix.slice();
1393
1793
  break;
1794
+
1394
1795
  case _util.OPS.setLeadingMoveText:
1395
1796
  flushTextContentItem();
1396
1797
  textState.leading = -args[1];
1397
1798
  textState.translateTextLineMatrix(args[0], args[1]);
1398
1799
  textState.textMatrix = textState.textLineMatrix.slice();
1399
1800
  break;
1801
+
1400
1802
  case _util.OPS.nextLine:
1401
1803
  flushTextContentItem();
1402
1804
  textState.carriageReturn();
1403
1805
  break;
1806
+
1404
1807
  case _util.OPS.setTextMatrix:
1405
1808
  advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
1809
+
1406
1810
  if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
1407
1811
  textState.translateTextLineMatrix(advance.width, advance.height);
1408
1812
  textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
@@ -1411,35 +1815,48 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1411
1815
  addFakeSpaces(diff, textContentItem.str);
1412
1816
  break;
1413
1817
  }
1818
+
1414
1819
  flushTextContentItem();
1415
1820
  textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
1416
1821
  textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
1417
1822
  break;
1823
+
1418
1824
  case _util.OPS.setCharSpacing:
1419
1825
  textState.charSpacing = args[0];
1420
1826
  break;
1827
+
1421
1828
  case _util.OPS.setWordSpacing:
1422
1829
  textState.wordSpacing = args[0];
1423
1830
  break;
1831
+
1424
1832
  case _util.OPS.beginText:
1425
1833
  flushTextContentItem();
1426
1834
  textState.textMatrix = _util.IDENTITY_MATRIX.slice();
1427
1835
  textState.textLineMatrix = _util.IDENTITY_MATRIX.slice();
1428
1836
  break;
1837
+
1429
1838
  case _util.OPS.showSpacedText:
1839
+ if (!stateManager.state.font) {
1840
+ self.ensureStateFont(stateManager.state);
1841
+ continue;
1842
+ }
1843
+
1430
1844
  var items = args[0];
1431
1845
  var offset;
1846
+
1432
1847
  for (var j = 0, jj = items.length; j < jj; j++) {
1433
- if (typeof items[j] === 'string') {
1848
+ if (typeof items[j] === "string") {
1434
1849
  buildTextContentItem(items[j]);
1435
1850
  } else if ((0, _util.isNum)(items[j])) {
1436
1851
  ensureTextContentItem();
1437
1852
  advance = items[j] * textState.fontSize / 1000;
1438
1853
  var breakTextRun = false;
1854
+
1439
1855
  if (textState.font.vertical) {
1440
1856
  offset = advance;
1441
1857
  textState.translateTextMatrix(0, offset);
1442
1858
  breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
1859
+
1443
1860
  if (!breakTextRun) {
1444
1861
  textContentItem.height += offset;
1445
1862
  }
@@ -1448,10 +1865,12 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1448
1865
  offset = advance * textState.textHScale;
1449
1866
  textState.translateTextMatrix(offset, 0);
1450
1867
  breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
1868
+
1451
1869
  if (!breakTextRun) {
1452
1870
  textContentItem.width += offset;
1453
1871
  }
1454
1872
  }
1873
+
1455
1874
  if (breakTextRun) {
1456
1875
  flushTextContentItem();
1457
1876
  } else if (advance > 0) {
@@ -1459,62 +1878,96 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1459
1878
  }
1460
1879
  }
1461
1880
  }
1881
+
1462
1882
  break;
1883
+
1463
1884
  case _util.OPS.showText:
1885
+ if (!stateManager.state.font) {
1886
+ self.ensureStateFont(stateManager.state);
1887
+ continue;
1888
+ }
1889
+
1464
1890
  buildTextContentItem(args[0]);
1465
1891
  break;
1892
+
1466
1893
  case _util.OPS.nextLineShowText:
1894
+ if (!stateManager.state.font) {
1895
+ self.ensureStateFont(stateManager.state);
1896
+ continue;
1897
+ }
1898
+
1467
1899
  flushTextContentItem();
1468
1900
  textState.carriageReturn();
1469
1901
  buildTextContentItem(args[0]);
1470
1902
  break;
1903
+
1471
1904
  case _util.OPS.nextLineSetSpacingShowText:
1905
+ if (!stateManager.state.font) {
1906
+ self.ensureStateFont(stateManager.state);
1907
+ continue;
1908
+ }
1909
+
1472
1910
  flushTextContentItem();
1473
1911
  textState.wordSpacing = args[0];
1474
1912
  textState.charSpacing = args[1];
1475
1913
  textState.carriageReturn();
1476
1914
  buildTextContentItem(args[2]);
1477
1915
  break;
1916
+
1478
1917
  case _util.OPS.paintXObject:
1479
1918
  flushTextContentItem();
1919
+
1480
1920
  if (!xobjs) {
1481
- xobjs = resources.get('XObject') || _primitives.Dict.empty;
1921
+ xobjs = resources.get("XObject") || _primitives.Dict.empty;
1482
1922
  }
1923
+
1483
1924
  var name = args[0].name;
1925
+
1484
1926
  if (name && skipEmptyXObjs[name] !== undefined) {
1485
1927
  break;
1486
1928
  }
1929
+
1487
1930
  next(new Promise(function (resolveXObject, rejectXObject) {
1488
1931
  if (!name) {
1489
- throw new _util.FormatError('XObject must be referred to by name.');
1932
+ throw new _util.FormatError("XObject must be referred to by name.");
1490
1933
  }
1491
- var xobj = xobjs.get(name);
1934
+
1935
+ const xobj = xobjs.get(name);
1936
+
1492
1937
  if (!xobj) {
1493
1938
  resolveXObject();
1494
1939
  return;
1495
1940
  }
1941
+
1496
1942
  if (!(0, _primitives.isStream)(xobj)) {
1497
- throw new _util.FormatError('XObject should be a stream');
1943
+ throw new _util.FormatError("XObject should be a stream");
1498
1944
  }
1499
- var type = xobj.dict.get('Subtype');
1945
+
1946
+ const type = xobj.dict.get("Subtype");
1947
+
1500
1948
  if (!(0, _primitives.isName)(type)) {
1501
- throw new _util.FormatError('XObject should have a Name subtype');
1949
+ throw new _util.FormatError("XObject should have a Name subtype");
1502
1950
  }
1503
- if (type.name !== 'Form') {
1951
+
1952
+ if (type.name !== "Form") {
1504
1953
  skipEmptyXObjs[name] = true;
1505
1954
  resolveXObject();
1506
1955
  return;
1507
1956
  }
1508
- var currentState = stateManager.state.clone();
1509
- var xObjStateManager = new StateManager(currentState);
1510
- var matrix = xobj.dict.getArray('Matrix');
1957
+
1958
+ const currentState = stateManager.state.clone();
1959
+ const xObjStateManager = new StateManager(currentState);
1960
+ const matrix = xobj.dict.getArray("Matrix");
1961
+
1511
1962
  if (Array.isArray(matrix) && matrix.length === 6) {
1512
1963
  xObjStateManager.transform(matrix);
1513
1964
  }
1965
+
1514
1966
  enqueueChunk();
1515
- var sinkWrapper = {
1967
+ const sinkWrapper = {
1516
1968
  enqueueInvoked: false,
1517
- enqueue: function enqueue(chunk, size) {
1969
+
1970
+ enqueue(chunk, size) {
1518
1971
  this.enqueueInvoked = true;
1519
1972
  sink.enqueue(chunk, size);
1520
1973
  },
@@ -1522,254 +1975,332 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1522
1975
  get desiredSize() {
1523
1976
  return sink.desiredSize;
1524
1977
  },
1978
+
1525
1979
  get ready() {
1526
1980
  return sink.ready;
1527
1981
  }
1982
+
1528
1983
  };
1529
1984
  self.getTextContent({
1530
1985
  stream: xobj,
1531
- task: task,
1532
- resources: xobj.dict.get('Resources') || resources,
1986
+ task,
1987
+ resources: xobj.dict.get("Resources") || resources,
1533
1988
  stateManager: xObjStateManager,
1534
- normalizeWhitespace: normalizeWhitespace,
1535
- combineTextItems: combineTextItems,
1989
+ normalizeWhitespace,
1990
+ combineTextItems,
1536
1991
  sink: sinkWrapper,
1537
- seenStyles: seenStyles
1992
+ seenStyles
1538
1993
  }).then(function () {
1539
1994
  if (!sinkWrapper.enqueueInvoked) {
1540
1995
  skipEmptyXObjs[name] = true;
1541
1996
  }
1997
+
1542
1998
  resolveXObject();
1543
1999
  }, rejectXObject);
1544
2000
  }).catch(function (reason) {
1545
2001
  if (reason instanceof _util.AbortException) {
1546
2002
  return;
1547
2003
  }
2004
+
1548
2005
  if (self.options.ignoreErrors) {
1549
- (0, _util.warn)('getTextContent - ignoring XObject: "' + reason + '".');
2006
+ (0, _util.warn)(`getTextContent - ignoring XObject: "${reason}".`);
1550
2007
  return;
1551
2008
  }
2009
+
1552
2010
  throw reason;
1553
2011
  }));
1554
2012
  return;
2013
+
1555
2014
  case _util.OPS.setGState:
1556
2015
  flushTextContentItem();
1557
2016
  var dictName = args[0];
1558
- var extGState = resources.get('ExtGState');
2017
+ var extGState = resources.get("ExtGState");
2018
+
1559
2019
  if (!(0, _primitives.isDict)(extGState) || !(0, _primitives.isName)(dictName)) {
1560
2020
  break;
1561
2021
  }
2022
+
1562
2023
  var gState = extGState.get(dictName.name);
2024
+
1563
2025
  if (!(0, _primitives.isDict)(gState)) {
1564
2026
  break;
1565
2027
  }
1566
- var gStateFont = gState.get('Font');
2028
+
2029
+ var gStateFont = gState.get("Font");
2030
+
1567
2031
  if (gStateFont) {
1568
2032
  textState.fontName = null;
1569
2033
  textState.fontSize = gStateFont[1];
1570
2034
  next(handleSetFont(null, gStateFont[0]));
1571
2035
  return;
1572
2036
  }
2037
+
1573
2038
  break;
1574
2039
  }
2040
+
1575
2041
  if (textContent.items.length >= sink.desiredSize) {
1576
2042
  stop = true;
1577
2043
  break;
1578
2044
  }
1579
2045
  }
2046
+
1580
2047
  if (stop) {
1581
2048
  next(deferred);
1582
2049
  return;
1583
2050
  }
2051
+
1584
2052
  flushTextContentItem();
1585
2053
  enqueueChunk();
1586
2054
  resolve();
1587
- }).catch(function (reason) {
2055
+ }).catch(reason => {
1588
2056
  if (reason instanceof _util.AbortException) {
1589
2057
  return;
1590
2058
  }
1591
- if (_this9.options.ignoreErrors) {
1592
- (0, _util.warn)('getTextContent - ignoring errors during "' + task.name + '" ' + ('task: "' + reason + '".'));
2059
+
2060
+ if (this.options.ignoreErrors) {
2061
+ (0, _util.warn)(`getTextContent - ignoring errors during "${task.name}" ` + `task: "${reason}".`);
1593
2062
  flushTextContentItem();
1594
2063
  enqueueChunk();
1595
2064
  return;
1596
2065
  }
2066
+
1597
2067
  throw reason;
1598
2068
  });
1599
2069
  },
1600
2070
 
1601
2071
  extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, properties) {
1602
- var _this10 = this;
1603
-
1604
- var xref = this.xref;
1605
- var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
2072
+ const xref = this.xref;
2073
+ let cidToGidBytes;
2074
+ var toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
1606
2075
  var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
2076
+
1607
2077
  if (properties.composite) {
1608
- var cidSystemInfo = dict.get('CIDSystemInfo');
2078
+ var cidSystemInfo = dict.get("CIDSystemInfo");
2079
+
1609
2080
  if ((0, _primitives.isDict)(cidSystemInfo)) {
1610
2081
  properties.cidSystemInfo = {
1611
- registry: (0, _util.stringToPDFString)(cidSystemInfo.get('Registry')),
1612
- ordering: (0, _util.stringToPDFString)(cidSystemInfo.get('Ordering')),
1613
- supplement: cidSystemInfo.get('Supplement')
2082
+ registry: (0, _util.stringToPDFString)(cidSystemInfo.get("Registry")),
2083
+ ordering: (0, _util.stringToPDFString)(cidSystemInfo.get("Ordering")),
2084
+ supplement: cidSystemInfo.get("Supplement")
1614
2085
  };
1615
2086
  }
1616
- var cidToGidMap = dict.get('CIDToGIDMap');
2087
+
2088
+ var cidToGidMap = dict.get("CIDToGIDMap");
2089
+
1617
2090
  if ((0, _primitives.isStream)(cidToGidMap)) {
1618
- properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
2091
+ cidToGidBytes = cidToGidMap.getBytes();
1619
2092
  }
1620
2093
  }
2094
+
1621
2095
  var differences = [];
1622
2096
  var baseEncodingName = null;
1623
2097
  var encoding;
1624
- if (dict.has('Encoding')) {
1625
- encoding = dict.get('Encoding');
2098
+
2099
+ if (dict.has("Encoding")) {
2100
+ encoding = dict.get("Encoding");
2101
+
1626
2102
  if ((0, _primitives.isDict)(encoding)) {
1627
- baseEncodingName = encoding.get('BaseEncoding');
2103
+ baseEncodingName = encoding.get("BaseEncoding");
1628
2104
  baseEncodingName = (0, _primitives.isName)(baseEncodingName) ? baseEncodingName.name : null;
1629
- if (encoding.has('Differences')) {
1630
- var diffEncoding = encoding.get('Differences');
2105
+
2106
+ if (encoding.has("Differences")) {
2107
+ var diffEncoding = encoding.get("Differences");
1631
2108
  var index = 0;
2109
+
1632
2110
  for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
1633
2111
  var data = xref.fetchIfRef(diffEncoding[j]);
2112
+
1634
2113
  if ((0, _util.isNum)(data)) {
1635
2114
  index = data;
1636
2115
  } else if ((0, _primitives.isName)(data)) {
1637
2116
  differences[index++] = data.name;
1638
2117
  } else {
1639
- throw new _util.FormatError('Invalid entry in \'Differences\' array: ' + data);
2118
+ throw new _util.FormatError(`Invalid entry in 'Differences' array: ${data}`);
1640
2119
  }
1641
2120
  }
1642
2121
  }
1643
2122
  } else if ((0, _primitives.isName)(encoding)) {
1644
2123
  baseEncodingName = encoding.name;
1645
2124
  } else {
1646
- throw new _util.FormatError('Encoding is not a Name nor a Dict');
2125
+ throw new _util.FormatError("Encoding is not a Name nor a Dict");
1647
2126
  }
1648
- if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
2127
+
2128
+ if (baseEncodingName !== "MacRomanEncoding" && baseEncodingName !== "MacExpertEncoding" && baseEncodingName !== "WinAnsiEncoding") {
1649
2129
  baseEncodingName = null;
1650
2130
  }
1651
2131
  }
2132
+
1652
2133
  if (baseEncodingName) {
1653
2134
  properties.defaultEncoding = (0, _encodings.getEncoding)(baseEncodingName).slice();
1654
2135
  } else {
1655
2136
  var isSymbolicFont = !!(properties.flags & _fonts.FontFlags.Symbolic);
1656
2137
  var isNonsymbolicFont = !!(properties.flags & _fonts.FontFlags.Nonsymbolic);
1657
2138
  encoding = _encodings.StandardEncoding;
1658
- if (properties.type === 'TrueType' && !isNonsymbolicFont) {
2139
+
2140
+ if (properties.type === "TrueType" && !isNonsymbolicFont) {
1659
2141
  encoding = _encodings.WinAnsiEncoding;
1660
2142
  }
2143
+
1661
2144
  if (isSymbolicFont) {
1662
2145
  encoding = _encodings.MacRomanEncoding;
2146
+
1663
2147
  if (!properties.file) {
1664
2148
  if (/Symbol/i.test(properties.name)) {
1665
2149
  encoding = _encodings.SymbolSetEncoding;
1666
- } else if (/Dingbats/i.test(properties.name)) {
2150
+ } else if (/Dingbats|Wingdings/i.test(properties.name)) {
1667
2151
  encoding = _encodings.ZapfDingbatsEncoding;
1668
2152
  }
1669
2153
  }
1670
2154
  }
2155
+
1671
2156
  properties.defaultEncoding = encoding;
1672
2157
  }
2158
+
1673
2159
  properties.differences = differences;
1674
2160
  properties.baseEncodingName = baseEncodingName;
1675
2161
  properties.hasEncoding = !!baseEncodingName || differences.length > 0;
1676
2162
  properties.dict = dict;
1677
- return toUnicodePromise.then(function (toUnicode) {
2163
+ return toUnicodePromise.then(toUnicode => {
1678
2164
  properties.toUnicode = toUnicode;
1679
- return _this10.buildToUnicode(properties);
1680
- }).then(function (toUnicode) {
2165
+ return this.buildToUnicode(properties);
2166
+ }).then(toUnicode => {
1681
2167
  properties.toUnicode = toUnicode;
2168
+
2169
+ if (cidToGidBytes) {
2170
+ properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, toUnicode);
2171
+ }
2172
+
1682
2173
  return properties;
1683
2174
  });
1684
2175
  },
1685
- _buildSimpleFontToUnicode: function _buildSimpleFontToUnicode(properties) {
1686
- (0, _util.assert)(!properties.composite, 'Must be a simple font.');
1687
- var toUnicode = [],
1688
- charcode = void 0,
1689
- glyphName = void 0;
1690
- var encoding = properties.defaultEncoding.slice();
1691
- var baseEncodingName = properties.baseEncodingName;
1692
- var differences = properties.differences;
1693
- for (charcode in differences) {
1694
- glyphName = differences[charcode];
1695
- if (glyphName === '.notdef') {
2176
+
2177
+ _buildSimpleFontToUnicode(properties, forceGlyphs = false) {
2178
+ (0, _util.assert)(!properties.composite, "Must be a simple font.");
2179
+ const toUnicode = [];
2180
+ const encoding = properties.defaultEncoding.slice();
2181
+ const baseEncodingName = properties.baseEncodingName;
2182
+ const differences = properties.differences;
2183
+
2184
+ for (const charcode in differences) {
2185
+ const glyphName = differences[charcode];
2186
+
2187
+ if (glyphName === ".notdef") {
1696
2188
  continue;
1697
2189
  }
2190
+
1698
2191
  encoding[charcode] = glyphName;
1699
2192
  }
1700
- var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
1701
- for (charcode in encoding) {
1702
- glyphName = encoding[charcode];
1703
- if (glyphName === '') {
2193
+
2194
+ const glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
2195
+
2196
+ for (const charcode in encoding) {
2197
+ let glyphName = encoding[charcode];
2198
+
2199
+ if (glyphName === "") {
1704
2200
  continue;
1705
2201
  } else if (glyphsUnicodeMap[glyphName] === undefined) {
1706
- var code = 0;
2202
+ let code = 0;
2203
+
1707
2204
  switch (glyphName[0]) {
1708
- case 'G':
2205
+ case "G":
1709
2206
  if (glyphName.length === 3) {
1710
2207
  code = parseInt(glyphName.substring(1), 16);
1711
2208
  }
2209
+
1712
2210
  break;
1713
- case 'g':
2211
+
2212
+ case "g":
1714
2213
  if (glyphName.length === 5) {
1715
2214
  code = parseInt(glyphName.substring(1), 16);
1716
2215
  }
2216
+
1717
2217
  break;
1718
- case 'C':
1719
- case 'c':
1720
- if (glyphName.length >= 3) {
1721
- code = +glyphName.substring(1);
2218
+
2219
+ case "C":
2220
+ case "c":
2221
+ if (glyphName.length >= 3 && glyphName.length <= 4) {
2222
+ const codeStr = glyphName.substring(1);
2223
+
2224
+ if (forceGlyphs) {
2225
+ code = parseInt(codeStr, 16);
2226
+ break;
2227
+ }
2228
+
2229
+ code = +codeStr;
2230
+
2231
+ if (Number.isNaN(code) && Number.isInteger(parseInt(codeStr, 16))) {
2232
+ return this._buildSimpleFontToUnicode(properties, true);
2233
+ }
1722
2234
  }
2235
+
1723
2236
  break;
2237
+
1724
2238
  default:
1725
- var unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
2239
+ const unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
2240
+
1726
2241
  if (unicode !== -1) {
1727
2242
  code = unicode;
1728
2243
  }
2244
+
1729
2245
  }
1730
- if (code) {
2246
+
2247
+ if (code > 0 && Number.isInteger(code)) {
1731
2248
  if (baseEncodingName && code === +charcode) {
1732
- var baseEncoding = (0, _encodings.getEncoding)(baseEncodingName);
2249
+ const baseEncoding = (0, _encodings.getEncoding)(baseEncodingName);
2250
+
1733
2251
  if (baseEncoding && (glyphName = baseEncoding[charcode])) {
1734
2252
  toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
1735
2253
  continue;
1736
2254
  }
1737
2255
  }
1738
- toUnicode[charcode] = String.fromCharCode(code);
2256
+
2257
+ toUnicode[charcode] = String.fromCodePoint(code);
1739
2258
  }
2259
+
1740
2260
  continue;
1741
2261
  }
2262
+
1742
2263
  toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
1743
2264
  }
2265
+
1744
2266
  return new _fonts.ToUnicodeMap(toUnicode);
1745
2267
  },
1746
- buildToUnicode: function buildToUnicode(properties) {
2268
+
2269
+ buildToUnicode(properties) {
1747
2270
  properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
2271
+
1748
2272
  if (properties.hasIncludedToUnicodeMap) {
1749
2273
  if (!properties.composite && properties.hasEncoding) {
1750
2274
  properties.fallbackToUnicode = this._buildSimpleFontToUnicode(properties);
1751
2275
  }
2276
+
1752
2277
  return Promise.resolve(properties.toUnicode);
1753
2278
  }
2279
+
1754
2280
  if (!properties.composite) {
1755
2281
  return Promise.resolve(this._buildSimpleFontToUnicode(properties));
1756
2282
  }
1757
- if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof _cmap.IdentityCMap) || properties.cidSystemInfo.registry === 'Adobe' && (properties.cidSystemInfo.ordering === 'GB1' || properties.cidSystemInfo.ordering === 'CNS1' || properties.cidSystemInfo.ordering === 'Japan1' || properties.cidSystemInfo.ordering === 'Korea1'))) {
1758
- var registry = properties.cidSystemInfo.registry;
1759
- var ordering = properties.cidSystemInfo.ordering;
1760
- var ucs2CMapName = _primitives.Name.get(registry + '-' + ordering + '-UCS2');
2283
+
2284
+ if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof _cmap.IdentityCMap) || properties.cidSystemInfo.registry === "Adobe" && (properties.cidSystemInfo.ordering === "GB1" || properties.cidSystemInfo.ordering === "CNS1" || properties.cidSystemInfo.ordering === "Japan1" || properties.cidSystemInfo.ordering === "Korea1"))) {
2285
+ const registry = properties.cidSystemInfo.registry;
2286
+ const ordering = properties.cidSystemInfo.ordering;
2287
+
2288
+ const ucs2CMapName = _primitives.Name.get(registry + "-" + ordering + "-UCS2");
2289
+
1761
2290
  return _cmap.CMapFactory.create({
1762
2291
  encoding: ucs2CMapName,
1763
2292
  fetchBuiltInCMap: this.fetchBuiltInCMap,
1764
2293
  useCMap: null
1765
2294
  }).then(function (ucs2CMap) {
1766
- var cMap = properties.cMap;
1767
- var toUnicode = [];
2295
+ const cMap = properties.cMap;
2296
+ const toUnicode = [];
1768
2297
  cMap.forEach(function (charcode, cid) {
1769
2298
  if (cid > 0xffff) {
1770
- throw new _util.FormatError('Max size of CID is 65,535');
2299
+ throw new _util.FormatError("Max size of CID is 65,535");
1771
2300
  }
1772
- var ucs2 = ucs2CMap.lookup(cid);
2301
+
2302
+ const ucs2 = ucs2CMap.lookup(cid);
2303
+
1773
2304
  if (ucs2) {
1774
2305
  toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
1775
2306
  }
@@ -1777,11 +2308,13 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1777
2308
  return new _fonts.ToUnicodeMap(toUnicode);
1778
2309
  });
1779
2310
  }
2311
+
1780
2312
  return Promise.resolve(new _fonts.IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
1781
2313
  },
1782
2314
 
1783
2315
  readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
1784
2316
  var cmapObj = toUnicode;
2317
+
1785
2318
  if ((0, _primitives.isName)(cmapObj)) {
1786
2319
  return _cmap.CMapFactory.create({
1787
2320
  encoding: cmapObj,
@@ -1789,8 +2322,9 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1789
2322
  useCMap: null
1790
2323
  }).then(function (cmap) {
1791
2324
  if (cmap instanceof _cmap.IdentityCMap) {
1792
- return new _fonts.IdentityToUnicodeMap(0, 0xFFFF);
2325
+ return new _fonts.IdentityToUnicodeMap(0, 0xffff);
1793
2326
  }
2327
+
1794
2328
  return new _fonts.ToUnicodeMap(cmap.getMap());
1795
2329
  });
1796
2330
  } else if ((0, _primitives.isStream)(cmapObj)) {
@@ -1800,41 +2334,66 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1800
2334
  useCMap: null
1801
2335
  }).then(function (cmap) {
1802
2336
  if (cmap instanceof _cmap.IdentityCMap) {
1803
- return new _fonts.IdentityToUnicodeMap(0, 0xFFFF);
2337
+ return new _fonts.IdentityToUnicodeMap(0, 0xffff);
1804
2338
  }
2339
+
1805
2340
  var map = new Array(cmap.length);
1806
2341
  cmap.forEach(function (charCode, token) {
1807
2342
  var str = [];
2343
+
1808
2344
  for (var k = 0; k < token.length; k += 2) {
1809
2345
  var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
1810
- if ((w1 & 0xF800) !== 0xD800) {
2346
+
2347
+ if ((w1 & 0xf800) !== 0xd800) {
1811
2348
  str.push(w1);
1812
2349
  continue;
1813
2350
  }
2351
+
1814
2352
  k += 2;
1815
2353
  var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
1816
2354
  str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
1817
2355
  }
1818
- map[charCode] = String.fromCharCode.apply(String, str);
2356
+
2357
+ map[charCode] = String.fromCodePoint.apply(String, str);
1819
2358
  });
1820
2359
  return new _fonts.ToUnicodeMap(map);
2360
+ }, reason => {
2361
+ if (reason instanceof _util.AbortException) {
2362
+ return null;
2363
+ }
2364
+
2365
+ if (this.options.ignoreErrors) {
2366
+ this.handler.send("UnsupportedFeature", {
2367
+ featureId: _util.UNSUPPORTED_FEATURES.font
2368
+ });
2369
+ (0, _util.warn)(`readToUnicode - ignoring ToUnicode data: "${reason}".`);
2370
+ return null;
2371
+ }
2372
+
2373
+ throw reason;
1821
2374
  });
1822
2375
  }
2376
+
1823
2377
  return Promise.resolve(null);
1824
2378
  },
1825
- readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
1826
- var glyphsData = cidToGidStream.getBytes();
2379
+
2380
+ readCidToGidMap(glyphsData, toUnicode) {
1827
2381
  var result = [];
2382
+
1828
2383
  for (var j = 0, jj = glyphsData.length; j < jj; j++) {
1829
2384
  var glyphID = glyphsData[j++] << 8 | glyphsData[j];
1830
- if (glyphID === 0) {
2385
+ const code = j >> 1;
2386
+
2387
+ if (glyphID === 0 && !toUnicode.has(code)) {
1831
2388
  continue;
1832
2389
  }
1833
- var code = j >> 1;
2390
+
1834
2391
  result[code] = glyphID;
1835
2392
  }
2393
+
1836
2394
  return result;
1837
2395
  },
2396
+
1838
2397
  extractWidths: function PartialEvaluator_extractWidths(dict, descriptor, properties) {
1839
2398
  var xref = this.xref;
1840
2399
  var glyphsWidths = [];
@@ -1842,39 +2401,47 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1842
2401
  var glyphsVMetrics = [];
1843
2402
  var defaultVMetrics;
1844
2403
  var i, ii, j, jj, start, code, widths;
2404
+
1845
2405
  if (properties.composite) {
1846
- defaultWidth = dict.has('DW') ? dict.get('DW') : 1000;
1847
- widths = dict.get('W');
2406
+ defaultWidth = dict.has("DW") ? dict.get("DW") : 1000;
2407
+ widths = dict.get("W");
2408
+
1848
2409
  if (widths) {
1849
2410
  for (i = 0, ii = widths.length; i < ii; i++) {
1850
2411
  start = xref.fetchIfRef(widths[i++]);
1851
2412
  code = xref.fetchIfRef(widths[i]);
2413
+
1852
2414
  if (Array.isArray(code)) {
1853
2415
  for (j = 0, jj = code.length; j < jj; j++) {
1854
2416
  glyphsWidths[start++] = xref.fetchIfRef(code[j]);
1855
2417
  }
1856
2418
  } else {
1857
2419
  var width = xref.fetchIfRef(widths[++i]);
2420
+
1858
2421
  for (j = start; j <= code; j++) {
1859
2422
  glyphsWidths[j] = width;
1860
2423
  }
1861
2424
  }
1862
2425
  }
1863
2426
  }
2427
+
1864
2428
  if (properties.vertical) {
1865
- var vmetrics = dict.getArray('DW2') || [880, -1000];
2429
+ var vmetrics = dict.getArray("DW2") || [880, -1000];
1866
2430
  defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
1867
- vmetrics = dict.get('W2');
2431
+ vmetrics = dict.get("W2");
2432
+
1868
2433
  if (vmetrics) {
1869
2434
  for (i = 0, ii = vmetrics.length; i < ii; i++) {
1870
2435
  start = xref.fetchIfRef(vmetrics[i++]);
1871
2436
  code = xref.fetchIfRef(vmetrics[i]);
2437
+
1872
2438
  if (Array.isArray(code)) {
1873
2439
  for (j = 0, jj = code.length; j < jj; j++) {
1874
2440
  glyphsVMetrics[start++] = [xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j])];
1875
2441
  }
1876
2442
  } else {
1877
2443
  var vmetric = [xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i])];
2444
+
1878
2445
  for (j = start; j <= code; j++) {
1879
2446
  glyphsVMetrics[j] = vmetric;
1880
2447
  }
@@ -1884,15 +2451,19 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1884
2451
  }
1885
2452
  } else {
1886
2453
  var firstChar = properties.firstChar;
1887
- widths = dict.get('Widths');
2454
+ widths = dict.get("Widths");
2455
+
1888
2456
  if (widths) {
1889
2457
  j = firstChar;
2458
+
1890
2459
  for (i = 0, ii = widths.length; i < ii; i++) {
1891
2460
  glyphsWidths[j++] = xref.fetchIfRef(widths[i]);
1892
2461
  }
1893
- defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
2462
+
2463
+ defaultWidth = parseFloat(descriptor.get("MissingWidth")) || 0;
1894
2464
  } else {
1895
- var baseFontName = dict.get('BaseFont');
2465
+ var baseFontName = dict.get("BaseFont");
2466
+
1896
2467
  if ((0, _primitives.isName)(baseFontName)) {
1897
2468
  var metrics = this.getBaseFontMetrics(baseFontName.name);
1898
2469
  glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
@@ -1900,32 +2471,39 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1900
2471
  }
1901
2472
  }
1902
2473
  }
2474
+
1903
2475
  var isMonospace = true;
1904
2476
  var firstWidth = defaultWidth;
2477
+
1905
2478
  for (var glyph in glyphsWidths) {
1906
2479
  var glyphWidth = glyphsWidths[glyph];
2480
+
1907
2481
  if (!glyphWidth) {
1908
2482
  continue;
1909
2483
  }
2484
+
1910
2485
  if (!firstWidth) {
1911
2486
  firstWidth = glyphWidth;
1912
2487
  continue;
1913
2488
  }
2489
+
1914
2490
  if (firstWidth !== glyphWidth) {
1915
2491
  isMonospace = false;
1916
2492
  break;
1917
2493
  }
1918
2494
  }
2495
+
1919
2496
  if (isMonospace) {
1920
2497
  properties.flags |= _fonts.FontFlags.FixedPitch;
1921
2498
  }
2499
+
1922
2500
  properties.defaultWidth = defaultWidth;
1923
2501
  properties.widths = glyphsWidths;
1924
2502
  properties.defaultVMetrics = defaultVMetrics;
1925
2503
  properties.vmetrics = glyphsVMetrics;
1926
2504
  },
1927
2505
  isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
1928
- var fontNameWoStyle = baseFontName.split('-')[0];
2506
+ var fontNameWoStyle = baseFontName.split("-")[0];
1929
2507
  return fontNameWoStyle in (0, _standard_fonts.getSerifFonts)() || fontNameWoStyle.search(/serif/gi) !== -1;
1930
2508
  },
1931
2509
  getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
@@ -1935,74 +2513,93 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
1935
2513
  var stdFontMap = (0, _standard_fonts.getStdFontMap)();
1936
2514
  var lookupName = stdFontMap[name] || name;
1937
2515
  var Metrics = (0, _metrics.getMetrics)();
2516
+
1938
2517
  if (!(lookupName in Metrics)) {
1939
2518
  if (this.isSerifFont(name)) {
1940
- lookupName = 'Times-Roman';
2519
+ lookupName = "Times-Roman";
1941
2520
  } else {
1942
- lookupName = 'Helvetica';
2521
+ lookupName = "Helvetica";
1943
2522
  }
1944
2523
  }
2524
+
1945
2525
  var glyphWidths = Metrics[lookupName];
2526
+
1946
2527
  if ((0, _util.isNum)(glyphWidths)) {
1947
2528
  defaultWidth = glyphWidths;
1948
2529
  monospace = true;
1949
2530
  } else {
1950
2531
  widths = glyphWidths();
1951
2532
  }
2533
+
1952
2534
  return {
1953
- defaultWidth: defaultWidth,
1954
- monospace: monospace,
1955
- widths: widths
2535
+ defaultWidth,
2536
+ monospace,
2537
+ widths
1956
2538
  };
1957
2539
  },
1958
2540
  buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
1959
2541
  var widths = Object.create(null);
1960
2542
  var differences = properties.differences;
1961
2543
  var encoding = properties.defaultEncoding;
2544
+
1962
2545
  for (var charCode = 0; charCode < 256; charCode++) {
1963
2546
  if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
1964
2547
  widths[charCode] = widthsByGlyphName[differences[charCode]];
1965
2548
  continue;
1966
2549
  }
2550
+
1967
2551
  if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
1968
2552
  widths[charCode] = widthsByGlyphName[encoding[charCode]];
1969
2553
  continue;
1970
2554
  }
1971
2555
  }
2556
+
1972
2557
  return widths;
1973
2558
  },
1974
2559
  preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict) {
1975
2560
  var baseDict = dict;
1976
- var type = dict.get('Subtype');
2561
+ var type = dict.get("Subtype");
2562
+
1977
2563
  if (!(0, _primitives.isName)(type)) {
1978
- throw new _util.FormatError('invalid font Subtype');
2564
+ throw new _util.FormatError("invalid font Subtype");
1979
2565
  }
2566
+
1980
2567
  var composite = false;
1981
2568
  var uint8array;
1982
- if (type.name === 'Type0') {
1983
- var df = dict.get('DescendantFonts');
2569
+
2570
+ if (type.name === "Type0") {
2571
+ var df = dict.get("DescendantFonts");
2572
+
1984
2573
  if (!df) {
1985
- throw new _util.FormatError('Descendant fonts are not specified');
2574
+ throw new _util.FormatError("Descendant fonts are not specified");
1986
2575
  }
2576
+
1987
2577
  dict = Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df;
1988
- type = dict.get('Subtype');
2578
+ type = dict.get("Subtype");
2579
+
1989
2580
  if (!(0, _primitives.isName)(type)) {
1990
- throw new _util.FormatError('invalid font Subtype');
2581
+ throw new _util.FormatError("invalid font Subtype");
1991
2582
  }
2583
+
1992
2584
  composite = true;
1993
2585
  }
1994
- var descriptor = dict.get('FontDescriptor');
2586
+
2587
+ var descriptor = dict.get("FontDescriptor");
2588
+
1995
2589
  if (descriptor) {
1996
2590
  var hash = new _murmurhash.MurmurHash3_64();
1997
- var encoding = baseDict.getRaw('Encoding');
2591
+ var encoding = baseDict.getRaw("Encoding");
2592
+
1998
2593
  if ((0, _primitives.isName)(encoding)) {
1999
2594
  hash.update(encoding.name);
2000
2595
  } else if ((0, _primitives.isRef)(encoding)) {
2001
2596
  hash.update(encoding.toString());
2002
2597
  } else if ((0, _primitives.isDict)(encoding)) {
2003
2598
  var keys = encoding.getKeys();
2599
+
2004
2600
  for (var i = 0, ii = keys.length; i < ii; i++) {
2005
2601
  var entry = encoding.getRaw(keys[i]);
2602
+
2006
2603
  if ((0, _primitives.isName)(entry)) {
2007
2604
  hash.update(entry.name);
2008
2605
  } else if ((0, _primitives.isRef)(entry)) {
@@ -2010,19 +2607,27 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
2010
2607
  } else if (Array.isArray(entry)) {
2011
2608
  var diffLength = entry.length,
2012
2609
  diffBuf = new Array(diffLength);
2610
+
2013
2611
  for (var j = 0; j < diffLength; j++) {
2014
2612
  var diffEntry = entry[j];
2613
+
2015
2614
  if ((0, _primitives.isName)(diffEntry)) {
2016
2615
  diffBuf[j] = diffEntry.name;
2017
2616
  } else if ((0, _util.isNum)(diffEntry) || (0, _primitives.isRef)(diffEntry)) {
2018
2617
  diffBuf[j] = diffEntry.toString();
2019
2618
  }
2020
2619
  }
2620
+
2021
2621
  hash.update(diffBuf.join());
2022
2622
  }
2023
2623
  }
2024
2624
  }
2025
- var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
2625
+
2626
+ const firstChar = dict.get("FirstChar") || 0;
2627
+ const lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
2628
+ hash.update(`${firstChar}-${lastChar}`);
2629
+ var toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
2630
+
2026
2631
  if ((0, _primitives.isStream)(toUnicode)) {
2027
2632
  var stream = toUnicode.str || toUnicode;
2028
2633
  uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
@@ -2030,126 +2635,159 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
2030
2635
  } else if ((0, _primitives.isName)(toUnicode)) {
2031
2636
  hash.update(toUnicode.name);
2032
2637
  }
2033
- var widths = dict.get('Widths') || baseDict.get('Widths');
2638
+
2639
+ var widths = dict.get("Widths") || baseDict.get("Widths");
2640
+
2034
2641
  if (widths) {
2035
2642
  uint8array = new Uint8Array(new Uint32Array(widths).buffer);
2036
2643
  hash.update(uint8array);
2037
2644
  }
2038
2645
  }
2646
+
2039
2647
  return {
2040
- descriptor: descriptor,
2041
- dict: dict,
2042
- baseDict: baseDict,
2043
- composite: composite,
2648
+ descriptor,
2649
+ dict,
2650
+ baseDict,
2651
+ composite,
2044
2652
  type: type.name,
2045
- hash: hash ? hash.hexdigest() : ''
2653
+ hash: hash ? hash.hexdigest() : ""
2046
2654
  };
2047
2655
  },
2048
2656
  translateFont: function PartialEvaluator_translateFont(preEvaluatedFont) {
2049
- var _this11 = this;
2050
-
2051
2657
  var baseDict = preEvaluatedFont.baseDict;
2052
2658
  var dict = preEvaluatedFont.dict;
2053
2659
  var composite = preEvaluatedFont.composite;
2054
2660
  var descriptor = preEvaluatedFont.descriptor;
2055
2661
  var type = preEvaluatedFont.type;
2056
- var maxCharIndex = composite ? 0xFFFF : 0xFF;
2662
+ var maxCharIndex = composite ? 0xffff : 0xff;
2057
2663
  var properties;
2664
+ const firstChar = dict.get("FirstChar") || 0;
2665
+ const lastChar = dict.get("LastChar") || maxCharIndex;
2666
+
2058
2667
  if (!descriptor) {
2059
- if (type === 'Type3') {
2668
+ if (type === "Type3") {
2060
2669
  descriptor = new _primitives.Dict(null);
2061
- descriptor.set('FontName', _primitives.Name.get(type));
2062
- descriptor.set('FontBBox', dict.getArray('FontBBox'));
2670
+ descriptor.set("FontName", _primitives.Name.get(type));
2671
+ descriptor.set("FontBBox", dict.getArray("FontBBox") || [0, 0, 0, 0]);
2063
2672
  } else {
2064
- var baseFontName = dict.get('BaseFont');
2673
+ var baseFontName = dict.get("BaseFont");
2674
+
2065
2675
  if (!(0, _primitives.isName)(baseFontName)) {
2066
- throw new _util.FormatError('Base font is not specified');
2676
+ throw new _util.FormatError("Base font is not specified");
2067
2677
  }
2068
- baseFontName = baseFontName.name.replace(/[,_]/g, '-');
2678
+
2679
+ baseFontName = baseFontName.name.replace(/[,_]/g, "-");
2069
2680
  var metrics = this.getBaseFontMetrics(baseFontName);
2070
- var fontNameWoStyle = baseFontName.split('-')[0];
2681
+ var fontNameWoStyle = baseFontName.split("-")[0];
2071
2682
  var flags = (this.isSerifFont(fontNameWoStyle) ? _fonts.FontFlags.Serif : 0) | (metrics.monospace ? _fonts.FontFlags.FixedPitch : 0) | ((0, _standard_fonts.getSymbolsFonts)()[fontNameWoStyle] ? _fonts.FontFlags.Symbolic : _fonts.FontFlags.Nonsymbolic);
2072
2683
  properties = {
2073
- type: type,
2684
+ type,
2074
2685
  name: baseFontName,
2075
2686
  widths: metrics.widths,
2076
2687
  defaultWidth: metrics.defaultWidth,
2077
- flags: flags,
2078
- firstChar: 0,
2079
- lastChar: maxCharIndex
2688
+ flags,
2689
+ firstChar,
2690
+ lastChar
2080
2691
  };
2081
- return this.extractDataStructures(dict, dict, properties).then(function (properties) {
2082
- properties.widths = _this11.buildCharCodeToWidth(metrics.widths, properties);
2692
+ const widths = dict.get("Widths");
2693
+ return this.extractDataStructures(dict, dict, properties).then(properties => {
2694
+ if (widths) {
2695
+ const glyphWidths = [];
2696
+ let j = firstChar;
2697
+
2698
+ for (let i = 0, ii = widths.length; i < ii; i++) {
2699
+ glyphWidths[j++] = this.xref.fetchIfRef(widths[i]);
2700
+ }
2701
+
2702
+ properties.widths = glyphWidths;
2703
+ } else {
2704
+ properties.widths = this.buildCharCodeToWidth(metrics.widths, properties);
2705
+ }
2706
+
2083
2707
  return new _fonts.Font(baseFontName, null, properties);
2084
2708
  });
2085
2709
  }
2086
2710
  }
2087
- var firstChar = dict.get('FirstChar') || 0;
2088
- var lastChar = dict.get('LastChar') || maxCharIndex;
2089
- var fontName = descriptor.get('FontName');
2090
- var baseFont = dict.get('BaseFont');
2711
+
2712
+ var fontName = descriptor.get("FontName");
2713
+ var baseFont = dict.get("BaseFont");
2714
+
2091
2715
  if ((0, _util.isString)(fontName)) {
2092
2716
  fontName = _primitives.Name.get(fontName);
2093
2717
  }
2718
+
2094
2719
  if ((0, _util.isString)(baseFont)) {
2095
2720
  baseFont = _primitives.Name.get(baseFont);
2096
2721
  }
2097
- if (type !== 'Type3') {
2722
+
2723
+ if (type !== "Type3") {
2098
2724
  var fontNameStr = fontName && fontName.name;
2099
2725
  var baseFontStr = baseFont && baseFont.name;
2726
+
2100
2727
  if (fontNameStr !== baseFontStr) {
2101
- (0, _util.info)('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"');
2102
- if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) {
2728
+ (0, _util.info)(`The FontDescriptor\'s FontName is "${fontNameStr}" but ` + `should be the same as the Font\'s BaseFont "${baseFontStr}".`);
2729
+
2730
+ if (fontNameStr && baseFontStr && baseFontStr.startsWith(fontNameStr)) {
2103
2731
  fontName = baseFont;
2104
2732
  }
2105
2733
  }
2106
2734
  }
2735
+
2107
2736
  fontName = fontName || baseFont;
2737
+
2108
2738
  if (!(0, _primitives.isName)(fontName)) {
2109
- throw new _util.FormatError('invalid font name');
2739
+ throw new _util.FormatError("invalid font name");
2110
2740
  }
2111
- var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
2741
+
2742
+ var fontFile = descriptor.get("FontFile", "FontFile2", "FontFile3");
2743
+
2112
2744
  if (fontFile) {
2113
2745
  if (fontFile.dict) {
2114
- var subtype = fontFile.dict.get('Subtype');
2746
+ var subtype = fontFile.dict.get("Subtype");
2747
+
2115
2748
  if (subtype) {
2116
2749
  subtype = subtype.name;
2117
2750
  }
2118
- var length1 = fontFile.dict.get('Length1');
2119
- var length2 = fontFile.dict.get('Length2');
2120
- var length3 = fontFile.dict.get('Length3');
2751
+
2752
+ var length1 = fontFile.dict.get("Length1");
2753
+ var length2 = fontFile.dict.get("Length2");
2754
+ var length3 = fontFile.dict.get("Length3");
2121
2755
  }
2122
2756
  }
2757
+
2123
2758
  properties = {
2124
- type: type,
2759
+ type,
2125
2760
  name: fontName.name,
2126
- subtype: subtype,
2761
+ subtype,
2127
2762
  file: fontFile,
2128
- length1: length1,
2129
- length2: length2,
2130
- length3: length3,
2763
+ length1,
2764
+ length2,
2765
+ length3,
2131
2766
  loadedName: baseDict.loadedName,
2132
- composite: composite,
2767
+ composite,
2133
2768
  wideChars: composite,
2134
2769
  fixedPitch: false,
2135
- fontMatrix: dict.getArray('FontMatrix') || _util.FONT_IDENTITY_MATRIX,
2770
+ fontMatrix: dict.getArray("FontMatrix") || _util.FONT_IDENTITY_MATRIX,
2136
2771
  firstChar: firstChar || 0,
2137
2772
  lastChar: lastChar || maxCharIndex,
2138
- bbox: descriptor.getArray('FontBBox'),
2139
- ascent: descriptor.get('Ascent'),
2140
- descent: descriptor.get('Descent'),
2141
- xHeight: descriptor.get('XHeight'),
2142
- capHeight: descriptor.get('CapHeight'),
2143
- flags: descriptor.get('Flags'),
2144
- italicAngle: descriptor.get('ItalicAngle'),
2773
+ bbox: descriptor.getArray("FontBBox"),
2774
+ ascent: descriptor.get("Ascent"),
2775
+ descent: descriptor.get("Descent"),
2776
+ xHeight: descriptor.get("XHeight"),
2777
+ capHeight: descriptor.get("CapHeight"),
2778
+ flags: descriptor.get("Flags"),
2779
+ italicAngle: descriptor.get("ItalicAngle"),
2145
2780
  isType3Font: false
2146
2781
  };
2147
2782
  var cMapPromise;
2783
+
2148
2784
  if (composite) {
2149
- var cidEncoding = baseDict.get('Encoding');
2785
+ var cidEncoding = baseDict.get("Encoding");
2786
+
2150
2787
  if ((0, _primitives.isName)(cidEncoding)) {
2151
2788
  properties.cidEncoding = cidEncoding.name;
2152
2789
  }
2790
+
2153
2791
  cMapPromise = _cmap.CMapFactory.create({
2154
2792
  encoding: cidEncoding,
2155
2793
  fetchBuiltInCMap: this.fetchBuiltInCMap,
@@ -2161,19 +2799,58 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
2161
2799
  } else {
2162
2800
  cMapPromise = Promise.resolve(undefined);
2163
2801
  }
2164
- return cMapPromise.then(function () {
2165
- return _this11.extractDataStructures(dict, baseDict, properties);
2166
- }).then(function (properties) {
2167
- _this11.extractWidths(dict, descriptor, properties);
2168
- if (type === 'Type3') {
2802
+
2803
+ return cMapPromise.then(() => {
2804
+ return this.extractDataStructures(dict, baseDict, properties);
2805
+ }).then(properties => {
2806
+ this.extractWidths(dict, descriptor, properties);
2807
+
2808
+ if (type === "Type3") {
2169
2809
  properties.isType3Font = true;
2170
2810
  }
2811
+
2171
2812
  return new _fonts.Font(fontName.name, fontFile, properties);
2172
2813
  });
2173
2814
  }
2174
2815
  };
2816
+
2817
+ PartialEvaluator.buildFontPaths = function (font, glyphs, handler) {
2818
+ function buildPath(fontChar) {
2819
+ if (font.renderer.hasBuiltPath(fontChar)) {
2820
+ return;
2821
+ }
2822
+
2823
+ handler.send("commonobj", [`${font.loadedName}_path_${fontChar}`, "FontPath", font.renderer.getPathJs(fontChar)]);
2824
+ }
2825
+
2826
+ for (const glyph of glyphs) {
2827
+ buildPath(glyph.fontChar);
2828
+ const accent = glyph.accent;
2829
+
2830
+ if (accent && accent.fontChar) {
2831
+ buildPath(accent.fontChar);
2832
+ }
2833
+ }
2834
+ };
2835
+
2836
+ PartialEvaluator.getFallbackFontDict = function () {
2837
+ if (this._fallbackFontDict) {
2838
+ return this._fallbackFontDict;
2839
+ }
2840
+
2841
+ const dict = new _primitives.Dict();
2842
+ dict.set("BaseFont", _primitives.Name.get("PDFJS-FallbackFont"));
2843
+ dict.set("Type", _primitives.Name.get("FallbackType"));
2844
+ dict.set("Subtype", _primitives.Name.get("FallbackType"));
2845
+ dict.set("Encoding", _primitives.Name.get("WinAnsiEncoding"));
2846
+ return this._fallbackFontDict = dict;
2847
+ };
2848
+
2175
2849
  return PartialEvaluator;
2176
2850
  }();
2851
+
2852
+ exports.PartialEvaluator = PartialEvaluator;
2853
+
2177
2854
  var TranslatedFont = function TranslatedFontClosure() {
2178
2855
  function TranslatedFont(loadedName, font, dict) {
2179
2856
  this.loadedName = loadedName;
@@ -2182,87 +2859,108 @@ var TranslatedFont = function TranslatedFontClosure() {
2182
2859
  this.type3Loaded = null;
2183
2860
  this.sent = false;
2184
2861
  }
2862
+
2185
2863
  TranslatedFont.prototype = {
2186
- send: function send(handler) {
2864
+ send(handler) {
2187
2865
  if (this.sent) {
2188
2866
  return;
2189
2867
  }
2190
- var fontData = this.font.exportData();
2191
- handler.send('commonobj', [this.loadedName, 'Font', fontData]);
2868
+
2192
2869
  this.sent = true;
2870
+ handler.send("commonobj", [this.loadedName, "Font", this.font.exportData()]);
2871
+ },
2872
+
2873
+ fallback(handler) {
2874
+ if (!this.font.data) {
2875
+ return;
2876
+ }
2877
+
2878
+ this.font.disableFontFace = true;
2879
+ const glyphs = this.font.glyphCacheValues;
2880
+ PartialEvaluator.buildFontPaths(this.font, glyphs, handler);
2193
2881
  },
2194
- loadType3Data: function loadType3Data(evaluator, resources, parentOperatorList, task) {
2882
+
2883
+ loadType3Data(evaluator, resources, parentOperatorList, task) {
2195
2884
  if (!this.font.isType3Font) {
2196
- throw new Error('Must be a Type3 font.');
2885
+ throw new Error("Must be a Type3 font.");
2197
2886
  }
2887
+
2198
2888
  if (this.type3Loaded) {
2199
2889
  return this.type3Loaded;
2200
2890
  }
2891
+
2201
2892
  var type3Options = Object.create(evaluator.options);
2202
2893
  type3Options.ignoreErrors = false;
2894
+ type3Options.nativeImageDecoderSupport = _util.NativeImageDecoding.NONE;
2203
2895
  var type3Evaluator = evaluator.clone(type3Options);
2896
+ type3Evaluator.parsingType3Font = true;
2204
2897
  var translatedFont = this.font;
2205
2898
  var loadCharProcsPromise = Promise.resolve();
2206
- var charProcs = this.dict.get('CharProcs');
2207
- var fontResources = this.dict.get('Resources') || resources;
2899
+ var charProcs = this.dict.get("CharProcs");
2900
+ var fontResources = this.dict.get("Resources") || resources;
2208
2901
  var charProcKeys = charProcs.getKeys();
2209
2902
  var charProcOperatorList = Object.create(null);
2210
2903
 
2211
- var _loop2 = function _loop2() {
2212
- var key = charProcKeys[i];
2904
+ for (var i = 0, n = charProcKeys.length; i < n; ++i) {
2905
+ const key = charProcKeys[i];
2213
2906
  loadCharProcsPromise = loadCharProcsPromise.then(function () {
2214
2907
  var glyphStream = charProcs.get(key);
2215
2908
  var operatorList = new _operator_list.OperatorList();
2216
2909
  return type3Evaluator.getOperatorList({
2217
2910
  stream: glyphStream,
2218
- task: task,
2911
+ task,
2219
2912
  resources: fontResources,
2220
- operatorList: operatorList
2913
+ operatorList
2221
2914
  }).then(function () {
2222
2915
  charProcOperatorList[key] = operatorList.getIR();
2223
2916
  parentOperatorList.addDependencies(operatorList.dependencies);
2224
2917
  }).catch(function (reason) {
2225
- (0, _util.warn)('Type3 font resource "' + key + '" is not available.');
2918
+ (0, _util.warn)(`Type3 font resource "${key}" is not available.`);
2226
2919
  var operatorList = new _operator_list.OperatorList();
2227
2920
  charProcOperatorList[key] = operatorList.getIR();
2228
2921
  });
2229
2922
  });
2230
- };
2231
-
2232
- for (var i = 0, n = charProcKeys.length; i < n; ++i) {
2233
- _loop2();
2234
2923
  }
2924
+
2235
2925
  this.type3Loaded = loadCharProcsPromise.then(function () {
2236
2926
  translatedFont.charProcOperatorList = charProcOperatorList;
2237
2927
  });
2238
2928
  return this.type3Loaded;
2239
2929
  }
2930
+
2240
2931
  };
2241
2932
  return TranslatedFont;
2242
2933
  }();
2934
+
2243
2935
  var StateManager = function StateManagerClosure() {
2244
2936
  function StateManager(initialState) {
2245
2937
  this.state = initialState;
2246
2938
  this.stateStack = [];
2247
2939
  }
2940
+
2248
2941
  StateManager.prototype = {
2249
- save: function save() {
2942
+ save() {
2250
2943
  var old = this.state;
2251
2944
  this.stateStack.push(this.state);
2252
2945
  this.state = old.clone();
2253
2946
  },
2254
- restore: function restore() {
2947
+
2948
+ restore() {
2255
2949
  var prev = this.stateStack.pop();
2950
+
2256
2951
  if (prev) {
2257
2952
  this.state = prev;
2258
2953
  }
2259
2954
  },
2260
- transform: function transform(args) {
2955
+
2956
+ transform(args) {
2261
2957
  this.state.ctm = _util.Util.transform(this.state.ctm, args);
2262
2958
  }
2959
+
2263
2960
  };
2264
2961
  return StateManager;
2265
2962
  }();
2963
+
2266
2964
  var TextState = function TextStateClosure() {
2267
2965
  function TextState() {
2268
2966
  this.ctm = new Float32Array(_util.IDENTITY_MATRIX);
@@ -2278,6 +2976,7 @@ var TextState = function TextStateClosure() {
2278
2976
  this.textHScale = 1;
2279
2977
  this.textRise = 0;
2280
2978
  }
2979
+
2281
2980
  TextState.prototype = {
2282
2981
  setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
2283
2982
  var m = this.textMatrix;
@@ -2309,21 +3008,28 @@ var TextState = function TextStateClosure() {
2309
3008
  },
2310
3009
  calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
2311
3010
  var font = this.font;
3011
+
2312
3012
  if (!font) {
2313
3013
  return null;
2314
3014
  }
3015
+
2315
3016
  var m = this.textLineMatrix;
3017
+
2316
3018
  if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
2317
3019
  return null;
2318
3020
  }
3021
+
2319
3022
  var txDiff = e - m[4],
2320
3023
  tyDiff = f - m[5];
3024
+
2321
3025
  if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
2322
3026
  return null;
2323
3027
  }
3028
+
2324
3029
  var tx,
2325
3030
  ty,
2326
3031
  denominator = a * d - b * c;
3032
+
2327
3033
  if (font.vertical) {
2328
3034
  tx = -tyDiff * c / denominator;
2329
3035
  ty = tyDiff * a / denominator;
@@ -2331,6 +3037,7 @@ var TextState = function TextStateClosure() {
2331
3037
  tx = txDiff * d / denominator;
2332
3038
  ty = -txDiff * b / denominator;
2333
3039
  }
3040
+
2334
3041
  return {
2335
3042
  width: tx,
2336
3043
  height: ty,
@@ -2355,6 +3062,7 @@ var TextState = function TextStateClosure() {
2355
3062
  };
2356
3063
  return TextState;
2357
3064
  }();
3065
+
2358
3066
  var EvalState = function EvalStateClosure() {
2359
3067
  function EvalState() {
2360
3068
  this.ctm = new Float32Array(_util.IDENTITY_MATRIX);
@@ -2363,6 +3071,7 @@ var EvalState = function EvalStateClosure() {
2363
3071
  this.fillColorSpace = _colorspace.ColorSpace.singletons.gray;
2364
3072
  this.strokeColorSpace = _colorspace.ColorSpace.singletons.gray;
2365
3073
  }
3074
+
2366
3075
  EvalState.prototype = {
2367
3076
  clone: function CanvasExtraState_clone() {
2368
3077
  return Object.create(this);
@@ -2370,234 +3079,235 @@ var EvalState = function EvalStateClosure() {
2370
3079
  };
2371
3080
  return EvalState;
2372
3081
  }();
3082
+
2373
3083
  var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
2374
- var getOPMap = (0, _util.getLookupTableFactory)(function (t) {
2375
- t['w'] = {
3084
+ var getOPMap = (0, _core_utils.getLookupTableFactory)(function (t) {
3085
+ t["w"] = {
2376
3086
  id: _util.OPS.setLineWidth,
2377
3087
  numArgs: 1,
2378
3088
  variableArgs: false
2379
3089
  };
2380
- t['J'] = {
3090
+ t["J"] = {
2381
3091
  id: _util.OPS.setLineCap,
2382
3092
  numArgs: 1,
2383
3093
  variableArgs: false
2384
3094
  };
2385
- t['j'] = {
3095
+ t["j"] = {
2386
3096
  id: _util.OPS.setLineJoin,
2387
3097
  numArgs: 1,
2388
3098
  variableArgs: false
2389
3099
  };
2390
- t['M'] = {
3100
+ t["M"] = {
2391
3101
  id: _util.OPS.setMiterLimit,
2392
3102
  numArgs: 1,
2393
3103
  variableArgs: false
2394
3104
  };
2395
- t['d'] = {
3105
+ t["d"] = {
2396
3106
  id: _util.OPS.setDash,
2397
3107
  numArgs: 2,
2398
3108
  variableArgs: false
2399
3109
  };
2400
- t['ri'] = {
3110
+ t["ri"] = {
2401
3111
  id: _util.OPS.setRenderingIntent,
2402
3112
  numArgs: 1,
2403
3113
  variableArgs: false
2404
3114
  };
2405
- t['i'] = {
3115
+ t["i"] = {
2406
3116
  id: _util.OPS.setFlatness,
2407
3117
  numArgs: 1,
2408
3118
  variableArgs: false
2409
3119
  };
2410
- t['gs'] = {
3120
+ t["gs"] = {
2411
3121
  id: _util.OPS.setGState,
2412
3122
  numArgs: 1,
2413
3123
  variableArgs: false
2414
3124
  };
2415
- t['q'] = {
3125
+ t["q"] = {
2416
3126
  id: _util.OPS.save,
2417
3127
  numArgs: 0,
2418
3128
  variableArgs: false
2419
3129
  };
2420
- t['Q'] = {
3130
+ t["Q"] = {
2421
3131
  id: _util.OPS.restore,
2422
3132
  numArgs: 0,
2423
3133
  variableArgs: false
2424
3134
  };
2425
- t['cm'] = {
3135
+ t["cm"] = {
2426
3136
  id: _util.OPS.transform,
2427
3137
  numArgs: 6,
2428
3138
  variableArgs: false
2429
3139
  };
2430
- t['m'] = {
3140
+ t["m"] = {
2431
3141
  id: _util.OPS.moveTo,
2432
3142
  numArgs: 2,
2433
3143
  variableArgs: false
2434
3144
  };
2435
- t['l'] = {
3145
+ t["l"] = {
2436
3146
  id: _util.OPS.lineTo,
2437
3147
  numArgs: 2,
2438
3148
  variableArgs: false
2439
3149
  };
2440
- t['c'] = {
3150
+ t["c"] = {
2441
3151
  id: _util.OPS.curveTo,
2442
3152
  numArgs: 6,
2443
3153
  variableArgs: false
2444
3154
  };
2445
- t['v'] = {
3155
+ t["v"] = {
2446
3156
  id: _util.OPS.curveTo2,
2447
3157
  numArgs: 4,
2448
3158
  variableArgs: false
2449
3159
  };
2450
- t['y'] = {
3160
+ t["y"] = {
2451
3161
  id: _util.OPS.curveTo3,
2452
3162
  numArgs: 4,
2453
3163
  variableArgs: false
2454
3164
  };
2455
- t['h'] = {
3165
+ t["h"] = {
2456
3166
  id: _util.OPS.closePath,
2457
3167
  numArgs: 0,
2458
3168
  variableArgs: false
2459
3169
  };
2460
- t['re'] = {
3170
+ t["re"] = {
2461
3171
  id: _util.OPS.rectangle,
2462
3172
  numArgs: 4,
2463
3173
  variableArgs: false
2464
3174
  };
2465
- t['S'] = {
3175
+ t["S"] = {
2466
3176
  id: _util.OPS.stroke,
2467
3177
  numArgs: 0,
2468
3178
  variableArgs: false
2469
3179
  };
2470
- t['s'] = {
3180
+ t["s"] = {
2471
3181
  id: _util.OPS.closeStroke,
2472
3182
  numArgs: 0,
2473
3183
  variableArgs: false
2474
3184
  };
2475
- t['f'] = {
3185
+ t["f"] = {
2476
3186
  id: _util.OPS.fill,
2477
3187
  numArgs: 0,
2478
3188
  variableArgs: false
2479
3189
  };
2480
- t['F'] = {
3190
+ t["F"] = {
2481
3191
  id: _util.OPS.fill,
2482
3192
  numArgs: 0,
2483
3193
  variableArgs: false
2484
3194
  };
2485
- t['f*'] = {
3195
+ t["f*"] = {
2486
3196
  id: _util.OPS.eoFill,
2487
3197
  numArgs: 0,
2488
3198
  variableArgs: false
2489
3199
  };
2490
- t['B'] = {
3200
+ t["B"] = {
2491
3201
  id: _util.OPS.fillStroke,
2492
3202
  numArgs: 0,
2493
3203
  variableArgs: false
2494
3204
  };
2495
- t['B*'] = {
3205
+ t["B*"] = {
2496
3206
  id: _util.OPS.eoFillStroke,
2497
3207
  numArgs: 0,
2498
3208
  variableArgs: false
2499
3209
  };
2500
- t['b'] = {
3210
+ t["b"] = {
2501
3211
  id: _util.OPS.closeFillStroke,
2502
3212
  numArgs: 0,
2503
3213
  variableArgs: false
2504
3214
  };
2505
- t['b*'] = {
3215
+ t["b*"] = {
2506
3216
  id: _util.OPS.closeEOFillStroke,
2507
3217
  numArgs: 0,
2508
3218
  variableArgs: false
2509
3219
  };
2510
- t['n'] = {
3220
+ t["n"] = {
2511
3221
  id: _util.OPS.endPath,
2512
3222
  numArgs: 0,
2513
3223
  variableArgs: false
2514
3224
  };
2515
- t['W'] = {
3225
+ t["W"] = {
2516
3226
  id: _util.OPS.clip,
2517
3227
  numArgs: 0,
2518
3228
  variableArgs: false
2519
3229
  };
2520
- t['W*'] = {
3230
+ t["W*"] = {
2521
3231
  id: _util.OPS.eoClip,
2522
3232
  numArgs: 0,
2523
3233
  variableArgs: false
2524
3234
  };
2525
- t['BT'] = {
3235
+ t["BT"] = {
2526
3236
  id: _util.OPS.beginText,
2527
3237
  numArgs: 0,
2528
3238
  variableArgs: false
2529
3239
  };
2530
- t['ET'] = {
3240
+ t["ET"] = {
2531
3241
  id: _util.OPS.endText,
2532
3242
  numArgs: 0,
2533
3243
  variableArgs: false
2534
3244
  };
2535
- t['Tc'] = {
3245
+ t["Tc"] = {
2536
3246
  id: _util.OPS.setCharSpacing,
2537
3247
  numArgs: 1,
2538
3248
  variableArgs: false
2539
3249
  };
2540
- t['Tw'] = {
3250
+ t["Tw"] = {
2541
3251
  id: _util.OPS.setWordSpacing,
2542
3252
  numArgs: 1,
2543
3253
  variableArgs: false
2544
3254
  };
2545
- t['Tz'] = {
3255
+ t["Tz"] = {
2546
3256
  id: _util.OPS.setHScale,
2547
3257
  numArgs: 1,
2548
3258
  variableArgs: false
2549
3259
  };
2550
- t['TL'] = {
3260
+ t["TL"] = {
2551
3261
  id: _util.OPS.setLeading,
2552
3262
  numArgs: 1,
2553
3263
  variableArgs: false
2554
3264
  };
2555
- t['Tf'] = {
3265
+ t["Tf"] = {
2556
3266
  id: _util.OPS.setFont,
2557
3267
  numArgs: 2,
2558
3268
  variableArgs: false
2559
3269
  };
2560
- t['Tr'] = {
3270
+ t["Tr"] = {
2561
3271
  id: _util.OPS.setTextRenderingMode,
2562
3272
  numArgs: 1,
2563
3273
  variableArgs: false
2564
3274
  };
2565
- t['Ts'] = {
3275
+ t["Ts"] = {
2566
3276
  id: _util.OPS.setTextRise,
2567
3277
  numArgs: 1,
2568
3278
  variableArgs: false
2569
3279
  };
2570
- t['Td'] = {
3280
+ t["Td"] = {
2571
3281
  id: _util.OPS.moveText,
2572
3282
  numArgs: 2,
2573
3283
  variableArgs: false
2574
3284
  };
2575
- t['TD'] = {
3285
+ t["TD"] = {
2576
3286
  id: _util.OPS.setLeadingMoveText,
2577
3287
  numArgs: 2,
2578
3288
  variableArgs: false
2579
3289
  };
2580
- t['Tm'] = {
3290
+ t["Tm"] = {
2581
3291
  id: _util.OPS.setTextMatrix,
2582
3292
  numArgs: 6,
2583
3293
  variableArgs: false
2584
3294
  };
2585
- t['T*'] = {
3295
+ t["T*"] = {
2586
3296
  id: _util.OPS.nextLine,
2587
3297
  numArgs: 0,
2588
3298
  variableArgs: false
2589
3299
  };
2590
- t['Tj'] = {
3300
+ t["Tj"] = {
2591
3301
  id: _util.OPS.showText,
2592
3302
  numArgs: 1,
2593
3303
  variableArgs: false
2594
3304
  };
2595
- t['TJ'] = {
3305
+ t["TJ"] = {
2596
3306
  id: _util.OPS.showSpacedText,
2597
3307
  numArgs: 1,
2598
3308
  variableArgs: false
2599
3309
  };
2600
- t['\''] = {
3310
+ t["'"] = {
2601
3311
  id: _util.OPS.nextLineShowText,
2602
3312
  numArgs: 1,
2603
3313
  variableArgs: false
@@ -2607,217 +3317,241 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
2607
3317
  numArgs: 3,
2608
3318
  variableArgs: false
2609
3319
  };
2610
- t['d0'] = {
3320
+ t["d0"] = {
2611
3321
  id: _util.OPS.setCharWidth,
2612
3322
  numArgs: 2,
2613
3323
  variableArgs: false
2614
3324
  };
2615
- t['d1'] = {
3325
+ t["d1"] = {
2616
3326
  id: _util.OPS.setCharWidthAndBounds,
2617
3327
  numArgs: 6,
2618
3328
  variableArgs: false
2619
3329
  };
2620
- t['CS'] = {
3330
+ t["CS"] = {
2621
3331
  id: _util.OPS.setStrokeColorSpace,
2622
3332
  numArgs: 1,
2623
3333
  variableArgs: false
2624
3334
  };
2625
- t['cs'] = {
3335
+ t["cs"] = {
2626
3336
  id: _util.OPS.setFillColorSpace,
2627
3337
  numArgs: 1,
2628
3338
  variableArgs: false
2629
3339
  };
2630
- t['SC'] = {
3340
+ t["SC"] = {
2631
3341
  id: _util.OPS.setStrokeColor,
2632
3342
  numArgs: 4,
2633
3343
  variableArgs: true
2634
3344
  };
2635
- t['SCN'] = {
3345
+ t["SCN"] = {
2636
3346
  id: _util.OPS.setStrokeColorN,
2637
3347
  numArgs: 33,
2638
3348
  variableArgs: true
2639
3349
  };
2640
- t['sc'] = {
3350
+ t["sc"] = {
2641
3351
  id: _util.OPS.setFillColor,
2642
3352
  numArgs: 4,
2643
3353
  variableArgs: true
2644
3354
  };
2645
- t['scn'] = {
3355
+ t["scn"] = {
2646
3356
  id: _util.OPS.setFillColorN,
2647
3357
  numArgs: 33,
2648
3358
  variableArgs: true
2649
3359
  };
2650
- t['G'] = {
3360
+ t["G"] = {
2651
3361
  id: _util.OPS.setStrokeGray,
2652
3362
  numArgs: 1,
2653
3363
  variableArgs: false
2654
3364
  };
2655
- t['g'] = {
3365
+ t["g"] = {
2656
3366
  id: _util.OPS.setFillGray,
2657
3367
  numArgs: 1,
2658
3368
  variableArgs: false
2659
3369
  };
2660
- t['RG'] = {
3370
+ t["RG"] = {
2661
3371
  id: _util.OPS.setStrokeRGBColor,
2662
3372
  numArgs: 3,
2663
3373
  variableArgs: false
2664
3374
  };
2665
- t['rg'] = {
3375
+ t["rg"] = {
2666
3376
  id: _util.OPS.setFillRGBColor,
2667
3377
  numArgs: 3,
2668
3378
  variableArgs: false
2669
3379
  };
2670
- t['K'] = {
3380
+ t["K"] = {
2671
3381
  id: _util.OPS.setStrokeCMYKColor,
2672
3382
  numArgs: 4,
2673
3383
  variableArgs: false
2674
3384
  };
2675
- t['k'] = {
3385
+ t["k"] = {
2676
3386
  id: _util.OPS.setFillCMYKColor,
2677
3387
  numArgs: 4,
2678
3388
  variableArgs: false
2679
3389
  };
2680
- t['sh'] = {
3390
+ t["sh"] = {
2681
3391
  id: _util.OPS.shadingFill,
2682
3392
  numArgs: 1,
2683
3393
  variableArgs: false
2684
3394
  };
2685
- t['BI'] = {
3395
+ t["BI"] = {
2686
3396
  id: _util.OPS.beginInlineImage,
2687
3397
  numArgs: 0,
2688
3398
  variableArgs: false
2689
3399
  };
2690
- t['ID'] = {
3400
+ t["ID"] = {
2691
3401
  id: _util.OPS.beginImageData,
2692
3402
  numArgs: 0,
2693
3403
  variableArgs: false
2694
3404
  };
2695
- t['EI'] = {
3405
+ t["EI"] = {
2696
3406
  id: _util.OPS.endInlineImage,
2697
3407
  numArgs: 1,
2698
3408
  variableArgs: false
2699
3409
  };
2700
- t['Do'] = {
3410
+ t["Do"] = {
2701
3411
  id: _util.OPS.paintXObject,
2702
3412
  numArgs: 1,
2703
3413
  variableArgs: false
2704
3414
  };
2705
- t['MP'] = {
3415
+ t["MP"] = {
2706
3416
  id: _util.OPS.markPoint,
2707
3417
  numArgs: 1,
2708
3418
  variableArgs: false
2709
3419
  };
2710
- t['DP'] = {
3420
+ t["DP"] = {
2711
3421
  id: _util.OPS.markPointProps,
2712
3422
  numArgs: 2,
2713
3423
  variableArgs: false
2714
3424
  };
2715
- t['BMC'] = {
3425
+ t["BMC"] = {
2716
3426
  id: _util.OPS.beginMarkedContent,
2717
3427
  numArgs: 1,
2718
3428
  variableArgs: false
2719
3429
  };
2720
- t['BDC'] = {
3430
+ t["BDC"] = {
2721
3431
  id: _util.OPS.beginMarkedContentProps,
2722
3432
  numArgs: 2,
2723
3433
  variableArgs: false
2724
3434
  };
2725
- t['EMC'] = {
3435
+ t["EMC"] = {
2726
3436
  id: _util.OPS.endMarkedContent,
2727
3437
  numArgs: 0,
2728
3438
  variableArgs: false
2729
3439
  };
2730
- t['BX'] = {
3440
+ t["BX"] = {
2731
3441
  id: _util.OPS.beginCompat,
2732
3442
  numArgs: 0,
2733
3443
  variableArgs: false
2734
3444
  };
2735
- t['EX'] = {
3445
+ t["EX"] = {
2736
3446
  id: _util.OPS.endCompat,
2737
3447
  numArgs: 0,
2738
3448
  variableArgs: false
2739
3449
  };
2740
- t['BM'] = null;
2741
- t['BD'] = null;
2742
- t['true'] = null;
2743
- t['fa'] = null;
2744
- t['fal'] = null;
2745
- t['fals'] = null;
2746
- t['false'] = null;
2747
- t['nu'] = null;
2748
- t['nul'] = null;
2749
- t['null'] = null;
3450
+ t["BM"] = null;
3451
+ t["BD"] = null;
3452
+ t["true"] = null;
3453
+ t["fa"] = null;
3454
+ t["fal"] = null;
3455
+ t["fals"] = null;
3456
+ t["false"] = null;
3457
+ t["nu"] = null;
3458
+ t["nul"] = null;
3459
+ t["null"] = null;
2750
3460
  });
2751
- var MAX_INVALID_PATH_OPS = 20;
3461
+ const MAX_INVALID_PATH_OPS = 20;
3462
+
2752
3463
  function EvaluatorPreprocessor(stream, xref, stateManager) {
2753
3464
  this.opMap = getOPMap();
2754
- this.parser = new _parser.Parser(new _parser.Lexer(stream, this.opMap), false, xref);
3465
+ this.parser = new _parser.Parser({
3466
+ lexer: new _parser.Lexer(stream, this.opMap),
3467
+ xref
3468
+ });
2755
3469
  this.stateManager = stateManager;
2756
3470
  this.nonProcessedArgs = [];
2757
3471
  this._numInvalidPathOPS = 0;
2758
3472
  }
3473
+
2759
3474
  EvaluatorPreprocessor.prototype = {
2760
3475
  get savedStatesDepth() {
2761
3476
  return this.stateManager.stateStack.length;
2762
3477
  },
3478
+
2763
3479
  read: function EvaluatorPreprocessor_read(operation) {
2764
3480
  var args = operation.args;
3481
+
2765
3482
  while (true) {
2766
3483
  var obj = this.parser.getObj();
2767
- if ((0, _primitives.isCmd)(obj)) {
3484
+
3485
+ if (obj instanceof _primitives.Cmd) {
2768
3486
  var cmd = obj.cmd;
2769
3487
  var opSpec = this.opMap[cmd];
3488
+
2770
3489
  if (!opSpec) {
2771
- (0, _util.warn)('Unknown command "' + cmd + '".');
3490
+ (0, _util.warn)(`Unknown command "${cmd}".`);
2772
3491
  continue;
2773
3492
  }
3493
+
2774
3494
  var fn = opSpec.id;
2775
3495
  var numArgs = opSpec.numArgs;
2776
3496
  var argsLength = args !== null ? args.length : 0;
3497
+
2777
3498
  if (!opSpec.variableArgs) {
2778
3499
  if (argsLength !== numArgs) {
2779
3500
  var nonProcessedArgs = this.nonProcessedArgs;
3501
+
2780
3502
  while (argsLength > numArgs) {
2781
3503
  nonProcessedArgs.push(args.shift());
2782
3504
  argsLength--;
2783
3505
  }
3506
+
2784
3507
  while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
2785
3508
  if (args === null) {
2786
3509
  args = [];
2787
3510
  }
3511
+
2788
3512
  args.unshift(nonProcessedArgs.pop());
2789
3513
  argsLength++;
2790
3514
  }
2791
3515
  }
3516
+
2792
3517
  if (argsLength < numArgs) {
2793
- var partialMsg = 'command ' + cmd + ': expected ' + numArgs + ' args, ' + ('but received ' + argsLength + ' args.');
3518
+ const partialMsg = `command ${cmd}: expected ${numArgs} args, ` + `but received ${argsLength} args.`;
3519
+
2794
3520
  if (fn >= _util.OPS.moveTo && fn <= _util.OPS.endPath && ++this._numInvalidPathOPS > MAX_INVALID_PATH_OPS) {
2795
- throw new _util.FormatError('Invalid ' + partialMsg);
3521
+ throw new _util.FormatError(`Invalid ${partialMsg}`);
2796
3522
  }
2797
- (0, _util.warn)('Skipping ' + partialMsg);
3523
+
3524
+ (0, _util.warn)(`Skipping ${partialMsg}`);
3525
+
2798
3526
  if (args !== null) {
2799
3527
  args.length = 0;
2800
3528
  }
3529
+
2801
3530
  continue;
2802
3531
  }
2803
3532
  } else if (argsLength > numArgs) {
2804
- (0, _util.info)('Command ' + cmd + ': expected [0, ' + numArgs + '] args, ' + ('but received ' + argsLength + ' args.'));
3533
+ (0, _util.info)(`Command ${cmd}: expected [0, ${numArgs}] args, ` + `but received ${argsLength} args.`);
2805
3534
  }
3535
+
2806
3536
  this.preprocessCommand(fn, args);
2807
3537
  operation.fn = fn;
2808
3538
  operation.args = args;
2809
3539
  return true;
2810
3540
  }
2811
- if ((0, _primitives.isEOF)(obj)) {
3541
+
3542
+ if (obj === _primitives.EOF) {
2812
3543
  return false;
2813
3544
  }
3545
+
2814
3546
  if (obj !== null) {
2815
3547
  if (args === null) {
2816
3548
  args = [];
2817
3549
  }
3550
+
2818
3551
  args.push(obj);
3552
+
2819
3553
  if (args.length > 33) {
2820
- throw new _util.FormatError('Too many arguments');
3554
+ throw new _util.FormatError("Too many arguments");
2821
3555
  }
2822
3556
  }
2823
3557
  }
@@ -2827,9 +3561,11 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
2827
3561
  case _util.OPS.save:
2828
3562
  this.stateManager.save();
2829
3563
  break;
3564
+
2830
3565
  case _util.OPS.restore:
2831
3566
  this.stateManager.restore();
2832
3567
  break;
3568
+
2833
3569
  case _util.OPS.transform:
2834
3570
  this.stateManager.transform(args);
2835
3571
  break;
@@ -2837,5 +3573,4 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
2837
3573
  }
2838
3574
  };
2839
3575
  return EvaluatorPreprocessor;
2840
- }();
2841
- exports.PartialEvaluator = PartialEvaluator;
3576
+ }();