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,36 +19,42 @@
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.PostScriptCompiler = exports.PostScriptEvaluator = exports.PDFFunctionFactory = exports.isPDFFunction = undefined;
28
-
29
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
27
+ exports.isPDFFunction = isPDFFunction;
28
+ exports.PostScriptCompiler = exports.PostScriptEvaluator = exports.PDFFunctionFactory = void 0;
30
29
 
31
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
30
+ var _util = require("../shared/util");
32
31
 
33
- var _util = require('../shared/util');
32
+ var _primitives = require("./primitives");
34
33
 
35
- var _primitives = require('./primitives');
34
+ var _ps_parser = require("./ps_parser");
36
35
 
37
- var _ps_parser = require('./ps_parser');
36
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
38
37
 
39
38
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
40
39
 
40
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
41
+
42
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
43
+
41
44
  var IsEvalSupportedCached = {
42
45
  get value() {
43
46
  return (0, _util.shadow)(this, 'value', (0, _util.isEvalSupported)());
44
47
  }
48
+
45
49
  };
46
50
 
47
- var PDFFunctionFactory = function () {
51
+ var PDFFunctionFactory =
52
+ /*#__PURE__*/
53
+ function () {
48
54
  function PDFFunctionFactory(_ref) {
49
55
  var xref = _ref.xref,
50
56
  _ref$isEvalSupported = _ref.isEvalSupported,
51
- isEvalSupported = _ref$isEvalSupported === undefined ? true : _ref$isEvalSupported;
57
+ isEvalSupported = _ref$isEvalSupported === void 0 ? true : _ref$isEvalSupported;
52
58
 
53
59
  _classCallCheck(this, PDFFunctionFactory);
54
60
 
@@ -57,7 +63,7 @@ var PDFFunctionFactory = function () {
57
63
  }
58
64
 
59
65
  _createClass(PDFFunctionFactory, [{
60
- key: 'create',
66
+ key: "create",
61
67
  value: function create(fn) {
62
68
  return PDFFunction.parse({
63
69
  xref: this.xref,
@@ -66,7 +72,7 @@ var PDFFunctionFactory = function () {
66
72
  });
67
73
  }
68
74
  }, {
69
- key: 'createFromArray',
75
+ key: "createFromArray",
70
76
  value: function createFromArray(fnObj) {
71
77
  return PDFFunction.parseArray({
72
78
  xref: this.xref,
@@ -79,22 +85,30 @@ var PDFFunctionFactory = function () {
79
85
  return PDFFunctionFactory;
80
86
  }();
81
87
 
88
+ exports.PDFFunctionFactory = PDFFunctionFactory;
89
+
82
90
  function toNumberArray(arr) {
83
91
  if (!Array.isArray(arr)) {
84
92
  return null;
85
93
  }
94
+
86
95
  var length = arr.length;
96
+
87
97
  for (var i = 0; i < length; i++) {
88
98
  if (typeof arr[i] !== 'number') {
89
99
  var result = new Array(length);
100
+
90
101
  for (var _i = 0; _i < length; _i++) {
91
102
  result[_i] = +arr[_i];
92
103
  }
104
+
93
105
  return result;
94
106
  }
95
107
  }
108
+
96
109
  return arr;
97
110
  }
111
+
98
112
  var PDFFunction = function PDFFunctionClosure() {
99
113
  var CONSTRUCT_SAMPLED = 0;
100
114
  var CONSTRUCT_INTERPOLATED = 2;
@@ -104,9 +118,11 @@ var PDFFunction = function PDFFunctionClosure() {
104
118
  getSampleArray: function getSampleArray(size, outputSize, bps, stream) {
105
119
  var i, ii;
106
120
  var length = 1;
121
+
107
122
  for (i = 0, ii = size.length; i < ii; i++) {
108
123
  length *= size[i];
109
124
  }
125
+
110
126
  length *= outputSize;
111
127
  var array = new Array(length);
112
128
  var codeSize = 0;
@@ -114,33 +130,39 @@ var PDFFunction = function PDFFunctionClosure() {
114
130
  var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
115
131
  var strBytes = stream.getBytes((length * bps + 7) / 8);
116
132
  var strIdx = 0;
133
+
117
134
  for (i = 0; i < length; i++) {
118
135
  while (codeSize < bps) {
119
136
  codeBuf <<= 8;
120
137
  codeBuf |= strBytes[strIdx++];
121
138
  codeSize += 8;
122
139
  }
140
+
123
141
  codeSize -= bps;
124
142
  array[i] = (codeBuf >> codeSize) * sampleMul;
125
143
  codeBuf &= (1 << codeSize) - 1;
126
144
  }
145
+
127
146
  return array;
128
147
  },
129
148
  getIR: function getIR(_ref2) {
130
149
  var xref = _ref2.xref,
131
150
  isEvalSupported = _ref2.isEvalSupported,
132
151
  fn = _ref2.fn;
133
-
134
152
  var dict = fn.dict;
153
+
135
154
  if (!dict) {
136
155
  dict = fn;
137
156
  }
157
+
138
158
  var types = [this.constructSampled, null, this.constructInterpolated, this.constructStiched, this.constructPostScript];
139
159
  var typeNum = dict.get('FunctionType');
140
160
  var typeFn = types[typeNum];
161
+
141
162
  if (!typeFn) {
142
163
  throw new _util.FormatError('Unknown type of function');
143
164
  }
165
+
144
166
  return typeFn.call(this, {
145
167
  xref: xref,
146
168
  isEvalSupported: isEvalSupported,
@@ -152,8 +174,8 @@ var PDFFunction = function PDFFunctionClosure() {
152
174
  var xref = _ref3.xref,
153
175
  isEvalSupported = _ref3.isEvalSupported,
154
176
  IR = _ref3.IR;
155
-
156
177
  var type = IR[0];
178
+
157
179
  switch (type) {
158
180
  case CONSTRUCT_SAMPLED:
159
181
  return this.constructSampledFromIR({
@@ -161,18 +183,21 @@ var PDFFunction = function PDFFunctionClosure() {
161
183
  isEvalSupported: isEvalSupported,
162
184
  IR: IR
163
185
  });
186
+
164
187
  case CONSTRUCT_INTERPOLATED:
165
188
  return this.constructInterpolatedFromIR({
166
189
  xref: xref,
167
190
  isEvalSupported: isEvalSupported,
168
191
  IR: IR
169
192
  });
193
+
170
194
  case CONSTRUCT_STICHED:
171
195
  return this.constructStichedFromIR({
172
196
  xref: xref,
173
197
  isEvalSupported: isEvalSupported,
174
198
  IR: IR
175
199
  });
200
+
176
201
  default:
177
202
  return this.constructPostScriptFromIR({
178
203
  xref: xref,
@@ -185,7 +210,6 @@ var PDFFunction = function PDFFunctionClosure() {
185
210
  var xref = _ref4.xref,
186
211
  isEvalSupported = _ref4.isEvalSupported,
187
212
  fn = _ref4.fn;
188
-
189
213
  var IR = this.getIR({
190
214
  xref: xref,
191
215
  isEvalSupported: isEvalSupported,
@@ -209,7 +233,9 @@ var PDFFunction = function PDFFunctionClosure() {
209
233
  fn: fnObj
210
234
  });
211
235
  }
236
+
212
237
  var fnArray = [];
238
+
213
239
  for (var j = 0, jj = fnObj.length; j < jj; j++) {
214
240
  fnArray.push(this.parse({
215
241
  xref: xref,
@@ -217,6 +243,7 @@ var PDFFunction = function PDFFunctionClosure() {
217
243
  fn: xref.fetchIfRef(fnObj[j])
218
244
  }));
219
245
  }
246
+
220
247
  return function (src, srcOffset, dest, destOffset) {
221
248
  for (var i = 0, ii = fnArray.length; i < ii; i++) {
222
249
  fnArray[i](src, srcOffset, dest, destOffset + i);
@@ -233,17 +260,22 @@ var PDFFunction = function PDFFunctionClosure() {
233
260
  var inputLength = arr.length;
234
261
  var out = [];
235
262
  var index = 0;
263
+
236
264
  for (var i = 0; i < inputLength; i += 2) {
237
265
  out[index] = [arr[i], arr[i + 1]];
238
266
  ++index;
239
267
  }
268
+
240
269
  return out;
241
270
  }
271
+
242
272
  var domain = toNumberArray(dict.getArray('Domain'));
243
273
  var range = toNumberArray(dict.getArray('Range'));
274
+
244
275
  if (!domain || !range) {
245
276
  throw new _util.FormatError('No domain or range');
246
277
  }
278
+
247
279
  var inputSize = domain.length / 2;
248
280
  var outputSize = range.length / 2;
249
281
  domain = toMultiArray(domain);
@@ -251,24 +283,31 @@ var PDFFunction = function PDFFunctionClosure() {
251
283
  var size = toNumberArray(dict.getArray('Size'));
252
284
  var bps = dict.get('BitsPerSample');
253
285
  var order = dict.get('Order') || 1;
286
+
254
287
  if (order !== 1) {
255
288
  (0, _util.info)('No support for cubic spline interpolation: ' + order);
256
289
  }
290
+
257
291
  var encode = toNumberArray(dict.getArray('Encode'));
292
+
258
293
  if (!encode) {
259
294
  encode = [];
295
+
260
296
  for (var i = 0; i < inputSize; ++i) {
261
297
  encode.push([0, size[i] - 1]);
262
298
  }
263
299
  } else {
264
300
  encode = toMultiArray(encode);
265
301
  }
302
+
266
303
  var decode = toNumberArray(dict.getArray('Decode'));
304
+
267
305
  if (!decode) {
268
306
  decode = range;
269
307
  } else {
270
308
  decode = toMultiArray(decode);
271
309
  }
310
+
272
311
  var samples = this.getSampleArray(size, outputSize, bps, fn);
273
312
  return [CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size, outputSize, Math.pow(2, bps) - 1, range];
274
313
  },
@@ -280,6 +319,7 @@ var PDFFunction = function PDFFunctionClosure() {
280
319
  function interpolate(x, xmin, xmax, ymin, ymax) {
281
320
  return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
282
321
  }
322
+
283
323
  return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) {
284
324
  var m = IR[1];
285
325
  var domain = IR[2];
@@ -293,11 +333,14 @@ var PDFFunction = function PDFFunctionClosure() {
293
333
  var cubeN = new Float64Array(cubeVertices);
294
334
  var cubeVertex = new Uint32Array(cubeVertices);
295
335
  var i, j;
336
+
296
337
  for (j = 0; j < cubeVertices; j++) {
297
338
  cubeN[j] = 1;
298
339
  }
340
+
299
341
  var k = n,
300
342
  pos = 1;
343
+
301
344
  for (i = 0; i < m; ++i) {
302
345
  var domain_2i = domain[i][0];
303
346
  var domain_2i_1 = domain[i][1];
@@ -310,6 +353,7 @@ var PDFFunction = function PDFFunctionClosure() {
310
353
  var n1 = e - e0;
311
354
  var offset0 = e0 * k;
312
355
  var offset1 = offset0 + k;
356
+
313
357
  for (j = 0; j < cubeVertices; j++) {
314
358
  if (j & pos) {
315
359
  cubeN[j] *= n1;
@@ -319,14 +363,18 @@ var PDFFunction = function PDFFunctionClosure() {
319
363
  cubeVertex[j] += offset0;
320
364
  }
321
365
  }
366
+
322
367
  k *= size_i;
323
368
  pos <<= 1;
324
369
  }
370
+
325
371
  for (j = 0; j < n; ++j) {
326
372
  var rj = 0;
373
+
327
374
  for (i = 0; i < cubeVertices; i++) {
328
375
  rj += samples[cubeVertex[i] + j] * cubeN[i];
329
376
  }
377
+
330
378
  rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
331
379
  dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
332
380
  }
@@ -337,28 +385,29 @@ var PDFFunction = function PDFFunctionClosure() {
337
385
  isEvalSupported = _ref8.isEvalSupported,
338
386
  fn = _ref8.fn,
339
387
  dict = _ref8.dict;
340
-
341
388
  var c0 = toNumberArray(dict.getArray('C0')) || [0];
342
389
  var c1 = toNumberArray(dict.getArray('C1')) || [1];
343
390
  var n = dict.get('N');
344
391
  var length = c0.length;
345
392
  var diff = [];
393
+
346
394
  for (var i = 0; i < length; ++i) {
347
395
  diff.push(c1[i] - c0[i]);
348
396
  }
397
+
349
398
  return [CONSTRUCT_INTERPOLATED, c0, diff, n];
350
399
  },
351
400
  constructInterpolatedFromIR: function constructInterpolatedFromIR(_ref9) {
352
401
  var xref = _ref9.xref,
353
402
  isEvalSupported = _ref9.isEvalSupported,
354
403
  IR = _ref9.IR;
355
-
356
404
  var c0 = IR[1];
357
405
  var diff = IR[2];
358
406
  var n = IR[3];
359
407
  var length = diff.length;
360
408
  return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
361
409
  var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
410
+
362
411
  for (var j = 0; j < length; ++j) {
363
412
  dest[destOffset + j] = c0[j] + x * diff[j];
364
413
  }
@@ -369,17 +418,21 @@ var PDFFunction = function PDFFunctionClosure() {
369
418
  isEvalSupported = _ref10.isEvalSupported,
370
419
  fn = _ref10.fn,
371
420
  dict = _ref10.dict;
372
-
373
421
  var domain = toNumberArray(dict.getArray('Domain'));
422
+
374
423
  if (!domain) {
375
424
  throw new _util.FormatError('No domain');
376
425
  }
426
+
377
427
  var inputSize = domain.length / 2;
428
+
378
429
  if (inputSize !== 1) {
379
430
  throw new _util.FormatError('Bad domain for stiched function');
380
431
  }
432
+
381
433
  var fnRefs = dict.get('Functions');
382
434
  var fns = [];
435
+
383
436
  for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
384
437
  fns.push(this.parse({
385
438
  xref: xref,
@@ -387,6 +440,7 @@ var PDFFunction = function PDFFunctionClosure() {
387
440
  fn: xref.fetchIfRef(fnRefs[i])
388
441
  }));
389
442
  }
443
+
390
444
  var bounds = toNumberArray(dict.getArray('Bounds'));
391
445
  var encode = toNumberArray(dict.getArray('Encode'));
392
446
  return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
@@ -395,7 +449,6 @@ var PDFFunction = function PDFFunctionClosure() {
395
449
  var xref = _ref11.xref,
396
450
  isEvalSupported = _ref11.isEvalSupported,
397
451
  IR = _ref11.IR;
398
-
399
452
  var domain = IR[1];
400
453
  var bounds = IR[2];
401
454
  var encode = IR[3];
@@ -408,22 +461,30 @@ var PDFFunction = function PDFFunctionClosure() {
408
461
  } else if (v < min) {
409
462
  v = min;
410
463
  }
464
+
411
465
  return v;
412
466
  };
467
+
413
468
  var v = clip(src[srcOffset], domain[0], domain[1]);
469
+
414
470
  for (var i = 0, ii = bounds.length; i < ii; ++i) {
415
471
  if (v < bounds[i]) {
416
472
  break;
417
473
  }
418
474
  }
475
+
419
476
  var dmin = domain[0];
477
+
420
478
  if (i > 0) {
421
479
  dmin = bounds[i - 1];
422
480
  }
481
+
423
482
  var dmax = domain[1];
483
+
424
484
  if (i < bounds.length) {
425
485
  dmax = bounds[i];
426
486
  }
487
+
427
488
  var rmin = encode[2 * i];
428
489
  var rmax = encode[2 * i + 1];
429
490
  tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
@@ -435,15 +496,17 @@ var PDFFunction = function PDFFunctionClosure() {
435
496
  isEvalSupported = _ref12.isEvalSupported,
436
497
  fn = _ref12.fn,
437
498
  dict = _ref12.dict;
438
-
439
499
  var domain = toNumberArray(dict.getArray('Domain'));
440
500
  var range = toNumberArray(dict.getArray('Range'));
501
+
441
502
  if (!domain) {
442
503
  throw new _util.FormatError('No domain.');
443
504
  }
505
+
444
506
  if (!range) {
445
507
  throw new _util.FormatError('No range.');
446
508
  }
509
+
447
510
  var lexer = new _ps_parser.PostScriptLexer(fn);
448
511
  var parser = new _ps_parser.PostScriptParser(lexer);
449
512
  var code = parser.parse();
@@ -453,16 +516,18 @@ var PDFFunction = function PDFFunctionClosure() {
453
516
  var xref = _ref13.xref,
454
517
  isEvalSupported = _ref13.isEvalSupported,
455
518
  IR = _ref13.IR;
456
-
457
519
  var domain = IR[1];
458
520
  var range = IR[2];
459
521
  var code = IR[3];
522
+
460
523
  if (isEvalSupported && IsEvalSupportedCached.value) {
461
524
  var compiled = new PostScriptCompiler().compile(code, domain, range);
525
+
462
526
  if (compiled) {
463
527
  return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
464
528
  }
465
529
  }
530
+
466
531
  (0, _util.info)('Unable to compile PS function');
467
532
  var numOutputs = range.length >> 1;
468
533
  var numInputs = domain.length >> 1;
@@ -475,44 +540,56 @@ var PDFFunction = function PDFFunctionClosure() {
475
540
  var i, value;
476
541
  var key = '';
477
542
  var input = tmpBuf;
543
+
478
544
  for (i = 0; i < numInputs; i++) {
479
545
  value = src[srcOffset + i];
480
546
  input[i] = value;
481
547
  key += value + '_';
482
548
  }
549
+
483
550
  var cachedValue = cache[key];
551
+
484
552
  if (cachedValue !== undefined) {
485
553
  dest.set(cachedValue, destOffset);
486
554
  return;
487
555
  }
556
+
488
557
  var output = new Float32Array(numOutputs);
489
558
  var stack = evaluator.execute(input);
490
559
  var stackIndex = stack.length - numOutputs;
560
+
491
561
  for (i = 0; i < numOutputs; i++) {
492
562
  value = stack[stackIndex + i];
493
563
  var bound = range[i * 2];
564
+
494
565
  if (value < bound) {
495
566
  value = bound;
496
567
  } else {
497
568
  bound = range[i * 2 + 1];
569
+
498
570
  if (value > bound) {
499
571
  value = bound;
500
572
  }
501
573
  }
574
+
502
575
  output[i] = value;
503
576
  }
577
+
504
578
  if (cache_available > 0) {
505
579
  cache_available--;
506
580
  cache[key] = output;
507
581
  }
582
+
508
583
  dest.set(output, destOffset);
509
584
  };
510
585
  }
511
586
  };
512
587
  }();
588
+
513
589
  function isPDFFunction(v) {
514
590
  var fnDict;
515
- if ((typeof v === 'undefined' ? 'undefined' : _typeof(v)) !== 'object') {
591
+
592
+ if (_typeof(v) !== 'object') {
516
593
  return false;
517
594
  } else if ((0, _primitives.isDict)(v)) {
518
595
  fnDict = v;
@@ -521,31 +598,39 @@ function isPDFFunction(v) {
521
598
  } else {
522
599
  return false;
523
600
  }
601
+
524
602
  return fnDict.has('FunctionType');
525
603
  }
604
+
526
605
  var PostScriptStack = function PostScriptStackClosure() {
527
606
  var MAX_STACK_SIZE = 100;
607
+
528
608
  function PostScriptStack(initialStack) {
529
609
  this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0);
530
610
  }
611
+
531
612
  PostScriptStack.prototype = {
532
613
  push: function PostScriptStack_push(value) {
533
614
  if (this.stack.length >= MAX_STACK_SIZE) {
534
615
  throw new Error('PostScript function stack overflow.');
535
616
  }
617
+
536
618
  this.stack.push(value);
537
619
  },
538
620
  pop: function PostScriptStack_pop() {
539
621
  if (this.stack.length <= 0) {
540
622
  throw new Error('PostScript function stack underflow.');
541
623
  }
624
+
542
625
  return this.stack.pop();
543
626
  },
544
627
  copy: function PostScriptStack_copy(n) {
545
628
  if (this.stack.length + n >= MAX_STACK_SIZE) {
546
629
  throw new Error('PostScript function stack overflow.');
547
630
  }
631
+
548
632
  var stack = this.stack;
633
+
549
634
  for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
550
635
  stack.push(stack[i]);
551
636
  }
@@ -561,16 +646,19 @@ var PostScriptStack = function PostScriptStackClosure() {
561
646
  i,
562
647
  j,
563
648
  t;
649
+
564
650
  for (i = l, j = r; i < j; i++, j--) {
565
651
  t = stack[i];
566
652
  stack[i] = stack[j];
567
653
  stack[j] = t;
568
654
  }
655
+
569
656
  for (i = l, j = c - 1; i < j; i++, j--) {
570
657
  t = stack[i];
571
658
  stack[i] = stack[j];
572
659
  stack[j] = t;
573
660
  }
661
+
574
662
  for (i = c, j = r; i < j; i++, j--) {
575
663
  t = stack[i];
576
664
  stack[i] = stack[j];
@@ -580,10 +668,12 @@ var PostScriptStack = function PostScriptStackClosure() {
580
668
  };
581
669
  return PostScriptStack;
582
670
  }();
671
+
583
672
  var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
584
673
  function PostScriptEvaluator(operators) {
585
674
  this.operators = operators;
586
675
  }
676
+
587
677
  PostScriptEvaluator.prototype = {
588
678
  execute: function PostScriptEvaluator_execute(initialStack) {
589
679
  var stack = new PostScriptStack(initialStack);
@@ -591,252 +681,321 @@ var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
591
681
  var operators = this.operators;
592
682
  var length = operators.length;
593
683
  var operator, a, b;
684
+
594
685
  while (counter < length) {
595
686
  operator = operators[counter++];
687
+
596
688
  if (typeof operator === 'number') {
597
689
  stack.push(operator);
598
690
  continue;
599
691
  }
692
+
600
693
  switch (operator) {
601
694
  case 'jz':
602
695
  b = stack.pop();
603
696
  a = stack.pop();
697
+
604
698
  if (!a) {
605
699
  counter = b;
606
700
  }
701
+
607
702
  break;
703
+
608
704
  case 'j':
609
705
  a = stack.pop();
610
706
  counter = a;
611
707
  break;
708
+
612
709
  case 'abs':
613
710
  a = stack.pop();
614
711
  stack.push(Math.abs(a));
615
712
  break;
713
+
616
714
  case 'add':
617
715
  b = stack.pop();
618
716
  a = stack.pop();
619
717
  stack.push(a + b);
620
718
  break;
719
+
621
720
  case 'and':
622
721
  b = stack.pop();
623
722
  a = stack.pop();
723
+
624
724
  if ((0, _util.isBool)(a) && (0, _util.isBool)(b)) {
625
725
  stack.push(a && b);
626
726
  } else {
627
727
  stack.push(a & b);
628
728
  }
729
+
629
730
  break;
731
+
630
732
  case 'atan':
631
733
  a = stack.pop();
632
734
  stack.push(Math.atan(a));
633
735
  break;
736
+
634
737
  case 'bitshift':
635
738
  b = stack.pop();
636
739
  a = stack.pop();
740
+
637
741
  if (a > 0) {
638
742
  stack.push(a << b);
639
743
  } else {
640
744
  stack.push(a >> b);
641
745
  }
746
+
642
747
  break;
748
+
643
749
  case 'ceiling':
644
750
  a = stack.pop();
645
751
  stack.push(Math.ceil(a));
646
752
  break;
753
+
647
754
  case 'copy':
648
755
  a = stack.pop();
649
756
  stack.copy(a);
650
757
  break;
758
+
651
759
  case 'cos':
652
760
  a = stack.pop();
653
761
  stack.push(Math.cos(a));
654
762
  break;
763
+
655
764
  case 'cvi':
656
765
  a = stack.pop() | 0;
657
766
  stack.push(a);
658
767
  break;
768
+
659
769
  case 'cvr':
660
770
  break;
771
+
661
772
  case 'div':
662
773
  b = stack.pop();
663
774
  a = stack.pop();
664
775
  stack.push(a / b);
665
776
  break;
777
+
666
778
  case 'dup':
667
779
  stack.copy(1);
668
780
  break;
781
+
669
782
  case 'eq':
670
783
  b = stack.pop();
671
784
  a = stack.pop();
672
785
  stack.push(a === b);
673
786
  break;
787
+
674
788
  case 'exch':
675
789
  stack.roll(2, 1);
676
790
  break;
791
+
677
792
  case 'exp':
678
793
  b = stack.pop();
679
794
  a = stack.pop();
680
795
  stack.push(Math.pow(a, b));
681
796
  break;
797
+
682
798
  case 'false':
683
799
  stack.push(false);
684
800
  break;
801
+
685
802
  case 'floor':
686
803
  a = stack.pop();
687
804
  stack.push(Math.floor(a));
688
805
  break;
806
+
689
807
  case 'ge':
690
808
  b = stack.pop();
691
809
  a = stack.pop();
692
810
  stack.push(a >= b);
693
811
  break;
812
+
694
813
  case 'gt':
695
814
  b = stack.pop();
696
815
  a = stack.pop();
697
816
  stack.push(a > b);
698
817
  break;
818
+
699
819
  case 'idiv':
700
820
  b = stack.pop();
701
821
  a = stack.pop();
702
822
  stack.push(a / b | 0);
703
823
  break;
824
+
704
825
  case 'index':
705
826
  a = stack.pop();
706
827
  stack.index(a);
707
828
  break;
829
+
708
830
  case 'le':
709
831
  b = stack.pop();
710
832
  a = stack.pop();
711
833
  stack.push(a <= b);
712
834
  break;
835
+
713
836
  case 'ln':
714
837
  a = stack.pop();
715
838
  stack.push(Math.log(a));
716
839
  break;
840
+
717
841
  case 'log':
718
842
  a = stack.pop();
719
843
  stack.push(Math.log(a) / Math.LN10);
720
844
  break;
845
+
721
846
  case 'lt':
722
847
  b = stack.pop();
723
848
  a = stack.pop();
724
849
  stack.push(a < b);
725
850
  break;
851
+
726
852
  case 'mod':
727
853
  b = stack.pop();
728
854
  a = stack.pop();
729
855
  stack.push(a % b);
730
856
  break;
857
+
731
858
  case 'mul':
732
859
  b = stack.pop();
733
860
  a = stack.pop();
734
861
  stack.push(a * b);
735
862
  break;
863
+
736
864
  case 'ne':
737
865
  b = stack.pop();
738
866
  a = stack.pop();
739
867
  stack.push(a !== b);
740
868
  break;
869
+
741
870
  case 'neg':
742
871
  a = stack.pop();
743
872
  stack.push(-a);
744
873
  break;
874
+
745
875
  case 'not':
746
876
  a = stack.pop();
877
+
747
878
  if ((0, _util.isBool)(a)) {
748
879
  stack.push(!a);
749
880
  } else {
750
881
  stack.push(~a);
751
882
  }
883
+
752
884
  break;
885
+
753
886
  case 'or':
754
887
  b = stack.pop();
755
888
  a = stack.pop();
889
+
756
890
  if ((0, _util.isBool)(a) && (0, _util.isBool)(b)) {
757
891
  stack.push(a || b);
758
892
  } else {
759
893
  stack.push(a | b);
760
894
  }
895
+
761
896
  break;
897
+
762
898
  case 'pop':
763
899
  stack.pop();
764
900
  break;
901
+
765
902
  case 'roll':
766
903
  b = stack.pop();
767
904
  a = stack.pop();
768
905
  stack.roll(a, b);
769
906
  break;
907
+
770
908
  case 'round':
771
909
  a = stack.pop();
772
910
  stack.push(Math.round(a));
773
911
  break;
912
+
774
913
  case 'sin':
775
914
  a = stack.pop();
776
915
  stack.push(Math.sin(a));
777
916
  break;
917
+
778
918
  case 'sqrt':
779
919
  a = stack.pop();
780
920
  stack.push(Math.sqrt(a));
781
921
  break;
922
+
782
923
  case 'sub':
783
924
  b = stack.pop();
784
925
  a = stack.pop();
785
926
  stack.push(a - b);
786
927
  break;
928
+
787
929
  case 'true':
788
930
  stack.push(true);
789
931
  break;
932
+
790
933
  case 'truncate':
791
934
  a = stack.pop();
792
935
  a = a < 0 ? Math.ceil(a) : Math.floor(a);
793
936
  stack.push(a);
794
937
  break;
938
+
795
939
  case 'xor':
796
940
  b = stack.pop();
797
941
  a = stack.pop();
942
+
798
943
  if ((0, _util.isBool)(a) && (0, _util.isBool)(b)) {
799
944
  stack.push(a !== b);
800
945
  } else {
801
946
  stack.push(a ^ b);
802
947
  }
948
+
803
949
  break;
950
+
804
951
  default:
805
- throw new _util.FormatError('Unknown operator ' + operator);
952
+ throw new _util.FormatError("Unknown operator ".concat(operator));
806
953
  }
807
954
  }
955
+
808
956
  return stack.stack;
809
957
  }
810
958
  };
811
959
  return PostScriptEvaluator;
812
960
  }();
961
+
962
+ exports.PostScriptEvaluator = PostScriptEvaluator;
963
+
813
964
  var PostScriptCompiler = function PostScriptCompilerClosure() {
814
965
  function AstNode(type) {
815
966
  this.type = type;
816
967
  }
968
+
817
969
  AstNode.prototype.visit = function (visitor) {
818
970
  (0, _util.unreachable)('abstract method');
819
971
  };
972
+
820
973
  function AstArgument(index, min, max) {
821
974
  AstNode.call(this, 'args');
822
975
  this.index = index;
823
976
  this.min = min;
824
977
  this.max = max;
825
978
  }
979
+
826
980
  AstArgument.prototype = Object.create(AstNode.prototype);
981
+
827
982
  AstArgument.prototype.visit = function (visitor) {
828
983
  visitor.visitArgument(this);
829
984
  };
985
+
830
986
  function AstLiteral(number) {
831
987
  AstNode.call(this, 'literal');
832
988
  this.number = number;
833
989
  this.min = number;
834
990
  this.max = number;
835
991
  }
992
+
836
993
  AstLiteral.prototype = Object.create(AstNode.prototype);
994
+
837
995
  AstLiteral.prototype.visit = function (visitor) {
838
996
  visitor.visitLiteral(this);
839
997
  };
998
+
840
999
  function AstBinaryOperation(op, arg1, arg2, min, max) {
841
1000
  AstNode.call(this, 'binary');
842
1001
  this.op = op;
@@ -845,42 +1004,55 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
845
1004
  this.min = min;
846
1005
  this.max = max;
847
1006
  }
1007
+
848
1008
  AstBinaryOperation.prototype = Object.create(AstNode.prototype);
1009
+
849
1010
  AstBinaryOperation.prototype.visit = function (visitor) {
850
1011
  visitor.visitBinaryOperation(this);
851
1012
  };
1013
+
852
1014
  function AstMin(arg, max) {
853
1015
  AstNode.call(this, 'max');
854
1016
  this.arg = arg;
855
1017
  this.min = arg.min;
856
1018
  this.max = max;
857
1019
  }
1020
+
858
1021
  AstMin.prototype = Object.create(AstNode.prototype);
1022
+
859
1023
  AstMin.prototype.visit = function (visitor) {
860
1024
  visitor.visitMin(this);
861
1025
  };
1026
+
862
1027
  function AstVariable(index, min, max) {
863
1028
  AstNode.call(this, 'var');
864
1029
  this.index = index;
865
1030
  this.min = min;
866
1031
  this.max = max;
867
1032
  }
1033
+
868
1034
  AstVariable.prototype = Object.create(AstNode.prototype);
1035
+
869
1036
  AstVariable.prototype.visit = function (visitor) {
870
1037
  visitor.visitVariable(this);
871
1038
  };
1039
+
872
1040
  function AstVariableDefinition(variable, arg) {
873
1041
  AstNode.call(this, 'definition');
874
1042
  this.variable = variable;
875
1043
  this.arg = arg;
876
1044
  }
1045
+
877
1046
  AstVariableDefinition.prototype = Object.create(AstNode.prototype);
1047
+
878
1048
  AstVariableDefinition.prototype.visit = function (visitor) {
879
1049
  visitor.visitVariableDefinition(this);
880
1050
  };
1051
+
881
1052
  function ExpressionBuilderVisitor() {
882
1053
  this.parts = [];
883
1054
  }
1055
+
884
1056
  ExpressionBuilderVisitor.prototype = {
885
1057
  visitArgument: function visitArgument(arg) {
886
1058
  this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))');
@@ -914,18 +1086,23 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
914
1086
  return this.parts.join('');
915
1087
  }
916
1088
  };
1089
+
917
1090
  function buildAddOperation(num1, num2) {
918
1091
  if (num2.type === 'literal' && num2.number === 0) {
919
1092
  return num1;
920
1093
  }
1094
+
921
1095
  if (num1.type === 'literal' && num1.number === 0) {
922
1096
  return num2;
923
1097
  }
1098
+
924
1099
  if (num2.type === 'literal' && num1.type === 'literal') {
925
1100
  return new AstLiteral(num1.number + num2.number);
926
1101
  }
1102
+
927
1103
  return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max);
928
1104
  }
1105
+
929
1106
  function buildMulOperation(num1, num2) {
930
1107
  if (num2.type === 'literal') {
931
1108
  if (num2.number === 0) {
@@ -936,6 +1113,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
936
1113
  return new AstLiteral(num1.number * num2.number);
937
1114
  }
938
1115
  }
1116
+
939
1117
  if (num1.type === 'literal') {
940
1118
  if (num1.number === 0) {
941
1119
  return new AstLiteral(0);
@@ -943,10 +1121,12 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
943
1121
  return num2;
944
1122
  }
945
1123
  }
1124
+
946
1125
  var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
947
1126
  var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
948
1127
  return new AstBinaryOperation('*', num1, num2, min, max);
949
1128
  }
1129
+
950
1130
  function buildSubOperation(num1, num2) {
951
1131
  if (num2.type === 'literal') {
952
1132
  if (num2.number === 0) {
@@ -955,20 +1135,26 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
955
1135
  return new AstLiteral(num1.number - num2.number);
956
1136
  }
957
1137
  }
1138
+
958
1139
  if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) {
959
1140
  return num2.arg2;
960
1141
  }
1142
+
961
1143
  return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min);
962
1144
  }
1145
+
963
1146
  function buildMinOperation(num1, max) {
964
1147
  if (num1.min >= max) {
965
1148
  return new AstLiteral(max);
966
1149
  } else if (num1.max <= max) {
967
1150
  return num1;
968
1151
  }
1152
+
969
1153
  return new AstMin(num1, max);
970
1154
  }
1155
+
971
1156
  function PostScriptCompiler() {}
1157
+
972
1158
  PostScriptCompiler.prototype = {
973
1159
  compile: function PostScriptCompiler_compile(code, domain, range) {
974
1160
  var stack = [];
@@ -979,128 +1165,167 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
979
1165
  var lastRegister = 0;
980
1166
  var n, j;
981
1167
  var num1, num2, ast1, ast2, tmpVar, item;
1168
+
982
1169
  for (i = 0; i < inputSize; i++) {
983
1170
  stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
984
1171
  }
1172
+
985
1173
  for (i = 0, ii = code.length; i < ii; i++) {
986
1174
  item = code[i];
1175
+
987
1176
  if (typeof item === 'number') {
988
1177
  stack.push(new AstLiteral(item));
989
1178
  continue;
990
1179
  }
1180
+
991
1181
  switch (item) {
992
1182
  case 'add':
993
1183
  if (stack.length < 2) {
994
1184
  return null;
995
1185
  }
1186
+
996
1187
  num2 = stack.pop();
997
1188
  num1 = stack.pop();
998
1189
  stack.push(buildAddOperation(num1, num2));
999
1190
  break;
1191
+
1000
1192
  case 'cvr':
1001
1193
  if (stack.length < 1) {
1002
1194
  return null;
1003
1195
  }
1196
+
1004
1197
  break;
1198
+
1005
1199
  case 'mul':
1006
1200
  if (stack.length < 2) {
1007
1201
  return null;
1008
1202
  }
1203
+
1009
1204
  num2 = stack.pop();
1010
1205
  num1 = stack.pop();
1011
1206
  stack.push(buildMulOperation(num1, num2));
1012
1207
  break;
1208
+
1013
1209
  case 'sub':
1014
1210
  if (stack.length < 2) {
1015
1211
  return null;
1016
1212
  }
1213
+
1017
1214
  num2 = stack.pop();
1018
1215
  num1 = stack.pop();
1019
1216
  stack.push(buildSubOperation(num1, num2));
1020
1217
  break;
1218
+
1021
1219
  case 'exch':
1022
1220
  if (stack.length < 2) {
1023
1221
  return null;
1024
1222
  }
1223
+
1025
1224
  ast1 = stack.pop();
1026
1225
  ast2 = stack.pop();
1027
1226
  stack.push(ast1, ast2);
1028
1227
  break;
1228
+
1029
1229
  case 'pop':
1030
1230
  if (stack.length < 1) {
1031
1231
  return null;
1032
1232
  }
1233
+
1033
1234
  stack.pop();
1034
1235
  break;
1236
+
1035
1237
  case 'index':
1036
1238
  if (stack.length < 1) {
1037
1239
  return null;
1038
1240
  }
1241
+
1039
1242
  num1 = stack.pop();
1243
+
1040
1244
  if (num1.type !== 'literal') {
1041
1245
  return null;
1042
1246
  }
1247
+
1043
1248
  n = num1.number;
1249
+
1044
1250
  if (n < 0 || !Number.isInteger(n) || stack.length < n) {
1045
1251
  return null;
1046
1252
  }
1253
+
1047
1254
  ast1 = stack[stack.length - n - 1];
1255
+
1048
1256
  if (ast1.type === 'literal' || ast1.type === 'var') {
1049
1257
  stack.push(ast1);
1050
1258
  break;
1051
1259
  }
1260
+
1052
1261
  tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
1053
1262
  stack[stack.length - n - 1] = tmpVar;
1054
1263
  stack.push(tmpVar);
1055
1264
  instructions.push(new AstVariableDefinition(tmpVar, ast1));
1056
1265
  break;
1266
+
1057
1267
  case 'dup':
1058
1268
  if (stack.length < 1) {
1059
1269
  return null;
1060
1270
  }
1271
+
1061
1272
  if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' && code[i + 3] === i + 7 && code[i + 4] === 'jz' && code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
1062
1273
  num1 = stack.pop();
1063
1274
  stack.push(buildMinOperation(num1, code[i + 1]));
1064
1275
  i += 6;
1065
1276
  break;
1066
1277
  }
1278
+
1067
1279
  ast1 = stack[stack.length - 1];
1280
+
1068
1281
  if (ast1.type === 'literal' || ast1.type === 'var') {
1069
1282
  stack.push(ast1);
1070
1283
  break;
1071
1284
  }
1285
+
1072
1286
  tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
1073
1287
  stack[stack.length - 1] = tmpVar;
1074
1288
  stack.push(tmpVar);
1075
1289
  instructions.push(new AstVariableDefinition(tmpVar, ast1));
1076
1290
  break;
1291
+
1077
1292
  case 'roll':
1078
1293
  if (stack.length < 2) {
1079
1294
  return null;
1080
1295
  }
1296
+
1081
1297
  num2 = stack.pop();
1082
1298
  num1 = stack.pop();
1299
+
1083
1300
  if (num2.type !== 'literal' || num1.type !== 'literal') {
1084
1301
  return null;
1085
1302
  }
1303
+
1086
1304
  j = num2.number;
1087
1305
  n = num1.number;
1306
+
1088
1307
  if (n <= 0 || !Number.isInteger(n) || !Number.isInteger(j) || stack.length < n) {
1089
1308
  return null;
1090
1309
  }
1310
+
1091
1311
  j = (j % n + n) % n;
1312
+
1092
1313
  if (j === 0) {
1093
1314
  break;
1094
1315
  }
1316
+
1095
1317
  Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j));
1096
1318
  break;
1319
+
1097
1320
  default:
1098
1321
  return null;
1099
1322
  }
1100
1323
  }
1324
+
1101
1325
  if (stack.length !== outputSize) {
1102
1326
  return null;
1103
1327
  }
1328
+
1104
1329
  var result = [];
1105
1330
  instructions.forEach(function (instruction) {
1106
1331
  var statementBuilder = new ExpressionBuilderVisitor();
@@ -1113,14 +1338,17 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
1113
1338
  var min = range[i * 2],
1114
1339
  max = range[i * 2 + 1];
1115
1340
  var out = [statementBuilder.toString()];
1341
+
1116
1342
  if (min > expr.min) {
1117
1343
  out.unshift('Math.max(', min, ', ');
1118
1344
  out.push(')');
1119
1345
  }
1346
+
1120
1347
  if (max < expr.max) {
1121
1348
  out.unshift('Math.min(', max, ', ');
1122
1349
  out.push(')');
1123
1350
  }
1351
+
1124
1352
  out.unshift('dest[destOffset + ', i, '] = ');
1125
1353
  out.push(';');
1126
1354
  result.push(out.join(''));
@@ -1130,7 +1358,5 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
1130
1358
  };
1131
1359
  return PostScriptCompiler;
1132
1360
  }();
1133
- exports.isPDFFunction = isPDFFunction;
1134
- exports.PDFFunctionFactory = PDFFunctionFactory;
1135
- exports.PostScriptEvaluator = PostScriptEvaluator;
1361
+
1136
1362
  exports.PostScriptCompiler = PostScriptCompiler;