pdfjs-dist 2.1.266 → 2.5.207

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