pdfjs-dist 2.0.489 → 2.2.228

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

Potentially problematic release.


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

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