pdfjs-dist 2.0.943 → 2.1.266

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

Potentially problematic release.


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

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