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