pdfjs-dist 2.0.550 → 2.3.200

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

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