pdfjs-dist 2.1.266 → 2.5.207
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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8382 -18492
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +58239 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +750 -899
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +40 -37
- package/lib/pdf.js +226 -59
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
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 2020 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.
|
@@ -27,63 +27,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
27
27
|
exports.isPDFFunction = isPDFFunction;
|
28
28
|
exports.PostScriptCompiler = exports.PostScriptEvaluator = exports.PDFFunctionFactory = void 0;
|
29
29
|
|
30
|
-
var _util = require("../shared/util");
|
30
|
+
var _util = require("../shared/util.js");
|
31
31
|
|
32
|
-
var _primitives = require("./primitives");
|
32
|
+
var _primitives = require("./primitives.js");
|
33
33
|
|
34
|
-
var _ps_parser = require("./ps_parser");
|
35
|
-
|
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); }
|
37
|
-
|
38
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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
|
-
|
44
|
-
var IsEvalSupportedCached = {
|
45
|
-
get value() {
|
46
|
-
return (0, _util.shadow)(this, 'value', (0, _util.isEvalSupported)());
|
47
|
-
}
|
48
|
-
|
49
|
-
};
|
50
|
-
|
51
|
-
var PDFFunctionFactory =
|
52
|
-
/*#__PURE__*/
|
53
|
-
function () {
|
54
|
-
function PDFFunctionFactory(_ref) {
|
55
|
-
var xref = _ref.xref,
|
56
|
-
_ref$isEvalSupported = _ref.isEvalSupported,
|
57
|
-
isEvalSupported = _ref$isEvalSupported === void 0 ? true : _ref$isEvalSupported;
|
58
|
-
|
59
|
-
_classCallCheck(this, PDFFunctionFactory);
|
34
|
+
var _ps_parser = require("./ps_parser.js");
|
60
35
|
|
36
|
+
class PDFFunctionFactory {
|
37
|
+
constructor({
|
38
|
+
xref,
|
39
|
+
isEvalSupported = true
|
40
|
+
}) {
|
61
41
|
this.xref = xref;
|
62
42
|
this.isEvalSupported = isEvalSupported !== false;
|
63
43
|
}
|
64
44
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
});
|
73
|
-
}
|
74
|
-
}, {
|
75
|
-
key: "createFromArray",
|
76
|
-
value: function createFromArray(fnObj) {
|
77
|
-
return PDFFunction.parseArray({
|
78
|
-
xref: this.xref,
|
79
|
-
isEvalSupported: this.isEvalSupported,
|
80
|
-
fnObj: fnObj
|
81
|
-
});
|
82
|
-
}
|
83
|
-
}]);
|
45
|
+
create(fn) {
|
46
|
+
return PDFFunction.parse({
|
47
|
+
xref: this.xref,
|
48
|
+
isEvalSupported: this.isEvalSupported,
|
49
|
+
fn
|
50
|
+
});
|
51
|
+
}
|
84
52
|
|
85
|
-
|
86
|
-
|
53
|
+
createFromArray(fnObj) {
|
54
|
+
return PDFFunction.parseArray({
|
55
|
+
xref: this.xref,
|
56
|
+
isEvalSupported: this.isEvalSupported,
|
57
|
+
fnObj
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
87
62
|
|
88
63
|
exports.PDFFunctionFactory = PDFFunctionFactory;
|
89
64
|
|
@@ -92,14 +67,14 @@ function toNumberArray(arr) {
|
|
92
67
|
return null;
|
93
68
|
}
|
94
69
|
|
95
|
-
|
70
|
+
const length = arr.length;
|
96
71
|
|
97
|
-
for (
|
98
|
-
if (typeof arr[i] !==
|
99
|
-
|
72
|
+
for (let i = 0; i < length; i++) {
|
73
|
+
if (typeof arr[i] !== "number") {
|
74
|
+
const result = new Array(length);
|
100
75
|
|
101
|
-
for (
|
102
|
-
result[
|
76
|
+
for (let j = 0; j < length; j++) {
|
77
|
+
result[j] = +arr[j];
|
103
78
|
}
|
104
79
|
|
105
80
|
return result;
|
@@ -110,12 +85,12 @@ function toNumberArray(arr) {
|
|
110
85
|
}
|
111
86
|
|
112
87
|
var PDFFunction = function PDFFunctionClosure() {
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
88
|
+
const CONSTRUCT_SAMPLED = 0;
|
89
|
+
const CONSTRUCT_INTERPOLATED = 2;
|
90
|
+
const CONSTRUCT_STICHED = 3;
|
91
|
+
const CONSTRUCT_POSTSCRIPT = 4;
|
117
92
|
return {
|
118
|
-
getSampleArray
|
93
|
+
getSampleArray(size, outputSize, bps, stream) {
|
119
94
|
var i, ii;
|
120
95
|
var length = 1;
|
121
96
|
|
@@ -127,7 +102,7 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
127
102
|
var array = new Array(length);
|
128
103
|
var codeSize = 0;
|
129
104
|
var codeBuf = 0;
|
130
|
-
var sampleMul = 1.0 / (
|
105
|
+
var sampleMul = 1.0 / (2.0 ** bps - 1);
|
131
106
|
var strBytes = stream.getBytes((length * bps + 7) / 8);
|
132
107
|
var strIdx = 0;
|
133
108
|
|
@@ -145,10 +120,12 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
145
120
|
|
146
121
|
return array;
|
147
122
|
},
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
123
|
+
|
124
|
+
getIR({
|
125
|
+
xref,
|
126
|
+
isEvalSupported,
|
127
|
+
fn
|
128
|
+
}) {
|
152
129
|
var dict = fn.dict;
|
153
130
|
|
154
131
|
if (!dict) {
|
@@ -156,80 +133,85 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
156
133
|
}
|
157
134
|
|
158
135
|
var types = [this.constructSampled, null, this.constructInterpolated, this.constructStiched, this.constructPostScript];
|
159
|
-
var typeNum = dict.get(
|
136
|
+
var typeNum = dict.get("FunctionType");
|
160
137
|
var typeFn = types[typeNum];
|
161
138
|
|
162
139
|
if (!typeFn) {
|
163
|
-
throw new _util.FormatError(
|
140
|
+
throw new _util.FormatError("Unknown type of function");
|
164
141
|
}
|
165
142
|
|
166
143
|
return typeFn.call(this, {
|
167
|
-
xref
|
168
|
-
isEvalSupported
|
169
|
-
fn
|
170
|
-
dict
|
144
|
+
xref,
|
145
|
+
isEvalSupported,
|
146
|
+
fn,
|
147
|
+
dict
|
171
148
|
});
|
172
149
|
},
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
150
|
+
|
151
|
+
fromIR({
|
152
|
+
xref,
|
153
|
+
isEvalSupported,
|
154
|
+
IR
|
155
|
+
}) {
|
177
156
|
var type = IR[0];
|
178
157
|
|
179
158
|
switch (type) {
|
180
159
|
case CONSTRUCT_SAMPLED:
|
181
160
|
return this.constructSampledFromIR({
|
182
|
-
xref
|
183
|
-
isEvalSupported
|
184
|
-
IR
|
161
|
+
xref,
|
162
|
+
isEvalSupported,
|
163
|
+
IR
|
185
164
|
});
|
186
165
|
|
187
166
|
case CONSTRUCT_INTERPOLATED:
|
188
167
|
return this.constructInterpolatedFromIR({
|
189
|
-
xref
|
190
|
-
isEvalSupported
|
191
|
-
IR
|
168
|
+
xref,
|
169
|
+
isEvalSupported,
|
170
|
+
IR
|
192
171
|
});
|
193
172
|
|
194
173
|
case CONSTRUCT_STICHED:
|
195
174
|
return this.constructStichedFromIR({
|
196
|
-
xref
|
197
|
-
isEvalSupported
|
198
|
-
IR
|
175
|
+
xref,
|
176
|
+
isEvalSupported,
|
177
|
+
IR
|
199
178
|
});
|
200
179
|
|
201
180
|
default:
|
202
181
|
return this.constructPostScriptFromIR({
|
203
|
-
xref
|
204
|
-
isEvalSupported
|
205
|
-
IR
|
182
|
+
xref,
|
183
|
+
isEvalSupported,
|
184
|
+
IR
|
206
185
|
});
|
207
186
|
}
|
208
187
|
},
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
188
|
+
|
189
|
+
parse({
|
190
|
+
xref,
|
191
|
+
isEvalSupported,
|
192
|
+
fn
|
193
|
+
}) {
|
194
|
+
const IR = this.getIR({
|
195
|
+
xref,
|
196
|
+
isEvalSupported,
|
197
|
+
fn
|
217
198
|
});
|
218
199
|
return this.fromIR({
|
219
|
-
xref
|
220
|
-
isEvalSupported
|
221
|
-
IR
|
200
|
+
xref,
|
201
|
+
isEvalSupported,
|
202
|
+
IR
|
222
203
|
});
|
223
204
|
},
|
224
|
-
parseArray: function parseArray(_ref5) {
|
225
|
-
var xref = _ref5.xref,
|
226
|
-
isEvalSupported = _ref5.isEvalSupported,
|
227
|
-
fnObj = _ref5.fnObj;
|
228
205
|
|
206
|
+
parseArray({
|
207
|
+
xref,
|
208
|
+
isEvalSupported,
|
209
|
+
fnObj
|
210
|
+
}) {
|
229
211
|
if (!Array.isArray(fnObj)) {
|
230
212
|
return this.parse({
|
231
|
-
xref
|
232
|
-
isEvalSupported
|
213
|
+
xref,
|
214
|
+
isEvalSupported,
|
233
215
|
fn: fnObj
|
234
216
|
});
|
235
217
|
}
|
@@ -238,8 +220,8 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
238
220
|
|
239
221
|
for (var j = 0, jj = fnObj.length; j < jj; j++) {
|
240
222
|
fnArray.push(this.parse({
|
241
|
-
xref
|
242
|
-
isEvalSupported
|
223
|
+
xref,
|
224
|
+
isEvalSupported,
|
243
225
|
fn: xref.fetchIfRef(fnObj[j])
|
244
226
|
}));
|
245
227
|
}
|
@@ -250,12 +232,13 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
250
232
|
}
|
251
233
|
};
|
252
234
|
},
|
253
|
-
constructSampled: function constructSampled(_ref6) {
|
254
|
-
var xref = _ref6.xref,
|
255
|
-
isEvalSupported = _ref6.isEvalSupported,
|
256
|
-
fn = _ref6.fn,
|
257
|
-
dict = _ref6.dict;
|
258
235
|
|
236
|
+
constructSampled({
|
237
|
+
xref,
|
238
|
+
isEvalSupported,
|
239
|
+
fn,
|
240
|
+
dict
|
241
|
+
}) {
|
259
242
|
function toMultiArray(arr) {
|
260
243
|
var inputLength = arr.length;
|
261
244
|
var out = [];
|
@@ -269,26 +252,26 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
269
252
|
return out;
|
270
253
|
}
|
271
254
|
|
272
|
-
var domain = toNumberArray(dict.getArray(
|
273
|
-
var range = toNumberArray(dict.getArray(
|
255
|
+
var domain = toNumberArray(dict.getArray("Domain"));
|
256
|
+
var range = toNumberArray(dict.getArray("Range"));
|
274
257
|
|
275
258
|
if (!domain || !range) {
|
276
|
-
throw new _util.FormatError(
|
259
|
+
throw new _util.FormatError("No domain or range");
|
277
260
|
}
|
278
261
|
|
279
262
|
var inputSize = domain.length / 2;
|
280
263
|
var outputSize = range.length / 2;
|
281
264
|
domain = toMultiArray(domain);
|
282
265
|
range = toMultiArray(range);
|
283
|
-
var size = toNumberArray(dict.getArray(
|
284
|
-
var bps = dict.get(
|
285
|
-
var order = dict.get(
|
266
|
+
var size = toNumberArray(dict.getArray("Size"));
|
267
|
+
var bps = dict.get("BitsPerSample");
|
268
|
+
var order = dict.get("Order") || 1;
|
286
269
|
|
287
270
|
if (order !== 1) {
|
288
|
-
(0, _util.info)(
|
271
|
+
(0, _util.info)("No support for cubic spline interpolation: " + order);
|
289
272
|
}
|
290
273
|
|
291
|
-
var encode = toNumberArray(dict.getArray(
|
274
|
+
var encode = toNumberArray(dict.getArray("Encode"));
|
292
275
|
|
293
276
|
if (!encode) {
|
294
277
|
encode = [];
|
@@ -300,7 +283,7 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
300
283
|
encode = toMultiArray(encode);
|
301
284
|
}
|
302
285
|
|
303
|
-
var decode = toNumberArray(dict.getArray(
|
286
|
+
var decode = toNumberArray(dict.getArray("Decode"));
|
304
287
|
|
305
288
|
if (!decode) {
|
306
289
|
decode = range;
|
@@ -309,13 +292,14 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
309
292
|
}
|
310
293
|
|
311
294
|
var samples = this.getSampleArray(size, outputSize, bps, fn);
|
312
|
-
return [CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size, outputSize,
|
295
|
+
return [CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size, outputSize, 2 ** bps - 1, range];
|
313
296
|
},
|
314
|
-
constructSampledFromIR: function constructSampledFromIR(_ref7) {
|
315
|
-
var xref = _ref7.xref,
|
316
|
-
isEvalSupported = _ref7.isEvalSupported,
|
317
|
-
IR = _ref7.IR;
|
318
297
|
|
298
|
+
constructSampledFromIR({
|
299
|
+
xref,
|
300
|
+
isEvalSupported,
|
301
|
+
IR
|
302
|
+
}) {
|
319
303
|
function interpolate(x, xmin, xmax, ymin, ymax) {
|
320
304
|
return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
|
321
305
|
}
|
@@ -380,14 +364,16 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
380
364
|
}
|
381
365
|
};
|
382
366
|
},
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
var
|
367
|
+
|
368
|
+
constructInterpolated({
|
369
|
+
xref,
|
370
|
+
isEvalSupported,
|
371
|
+
fn,
|
372
|
+
dict
|
373
|
+
}) {
|
374
|
+
var c0 = toNumberArray(dict.getArray("C0")) || [0];
|
375
|
+
var c1 = toNumberArray(dict.getArray("C1")) || [1];
|
376
|
+
var n = dict.get("N");
|
391
377
|
var length = c0.length;
|
392
378
|
var diff = [];
|
393
379
|
|
@@ -397,58 +383,64 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
397
383
|
|
398
384
|
return [CONSTRUCT_INTERPOLATED, c0, diff, n];
|
399
385
|
},
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
386
|
+
|
387
|
+
constructInterpolatedFromIR({
|
388
|
+
xref,
|
389
|
+
isEvalSupported,
|
390
|
+
IR
|
391
|
+
}) {
|
404
392
|
var c0 = IR[1];
|
405
393
|
var diff = IR[2];
|
406
394
|
var n = IR[3];
|
407
395
|
var length = diff.length;
|
408
396
|
return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
|
409
|
-
var x = n === 1 ? src[srcOffset] :
|
397
|
+
var x = n === 1 ? src[srcOffset] : src[srcOffset] ** n;
|
410
398
|
|
411
399
|
for (var j = 0; j < length; ++j) {
|
412
400
|
dest[destOffset + j] = c0[j] + x * diff[j];
|
413
401
|
}
|
414
402
|
};
|
415
403
|
},
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
404
|
+
|
405
|
+
constructStiched({
|
406
|
+
xref,
|
407
|
+
isEvalSupported,
|
408
|
+
fn,
|
409
|
+
dict
|
410
|
+
}) {
|
411
|
+
var domain = toNumberArray(dict.getArray("Domain"));
|
422
412
|
|
423
413
|
if (!domain) {
|
424
|
-
throw new _util.FormatError(
|
414
|
+
throw new _util.FormatError("No domain");
|
425
415
|
}
|
426
416
|
|
427
417
|
var inputSize = domain.length / 2;
|
428
418
|
|
429
419
|
if (inputSize !== 1) {
|
430
|
-
throw new _util.FormatError(
|
420
|
+
throw new _util.FormatError("Bad domain for stiched function");
|
431
421
|
}
|
432
422
|
|
433
|
-
var fnRefs = dict.get(
|
423
|
+
var fnRefs = dict.get("Functions");
|
434
424
|
var fns = [];
|
435
425
|
|
436
426
|
for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
|
437
427
|
fns.push(this.parse({
|
438
|
-
xref
|
439
|
-
isEvalSupported
|
428
|
+
xref,
|
429
|
+
isEvalSupported,
|
440
430
|
fn: xref.fetchIfRef(fnRefs[i])
|
441
431
|
}));
|
442
432
|
}
|
443
433
|
|
444
|
-
var bounds = toNumberArray(dict.getArray(
|
445
|
-
var encode = toNumberArray(dict.getArray(
|
434
|
+
var bounds = toNumberArray(dict.getArray("Bounds"));
|
435
|
+
var encode = toNumberArray(dict.getArray("Encode"));
|
446
436
|
return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
|
447
437
|
},
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
438
|
+
|
439
|
+
constructStichedFromIR({
|
440
|
+
xref,
|
441
|
+
isEvalSupported,
|
442
|
+
IR
|
443
|
+
}) {
|
452
444
|
var domain = IR[1];
|
453
445
|
var bounds = IR[2];
|
454
446
|
var encode = IR[3];
|
@@ -491,20 +483,22 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
491
483
|
fns[i](tmpBuf, 0, dest, destOffset);
|
492
484
|
};
|
493
485
|
},
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
486
|
+
|
487
|
+
constructPostScript({
|
488
|
+
xref,
|
489
|
+
isEvalSupported,
|
490
|
+
fn,
|
491
|
+
dict
|
492
|
+
}) {
|
493
|
+
var domain = toNumberArray(dict.getArray("Domain"));
|
494
|
+
var range = toNumberArray(dict.getArray("Range"));
|
501
495
|
|
502
496
|
if (!domain) {
|
503
|
-
throw new _util.FormatError(
|
497
|
+
throw new _util.FormatError("No domain.");
|
504
498
|
}
|
505
499
|
|
506
500
|
if (!range) {
|
507
|
-
throw new _util.FormatError(
|
501
|
+
throw new _util.FormatError("No range.");
|
508
502
|
}
|
509
503
|
|
510
504
|
var lexer = new _ps_parser.PostScriptLexer(fn);
|
@@ -512,23 +506,25 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
512
506
|
var code = parser.parse();
|
513
507
|
return [CONSTRUCT_POSTSCRIPT, domain, range, code];
|
514
508
|
},
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
509
|
+
|
510
|
+
constructPostScriptFromIR({
|
511
|
+
xref,
|
512
|
+
isEvalSupported,
|
513
|
+
IR
|
514
|
+
}) {
|
519
515
|
var domain = IR[1];
|
520
516
|
var range = IR[2];
|
521
517
|
var code = IR[3];
|
522
518
|
|
523
|
-
if (isEvalSupported && IsEvalSupportedCached.value) {
|
524
|
-
|
519
|
+
if (isEvalSupported && _util.IsEvalSupportedCached.value) {
|
520
|
+
const compiled = new PostScriptCompiler().compile(code, domain, range);
|
525
521
|
|
526
522
|
if (compiled) {
|
527
|
-
return new Function(
|
523
|
+
return new Function("src", "srcOffset", "dest", "destOffset", compiled);
|
528
524
|
}
|
529
525
|
}
|
530
526
|
|
531
|
-
(0, _util.info)(
|
527
|
+
(0, _util.info)("Unable to compile PS function");
|
532
528
|
var numOutputs = range.length >> 1;
|
533
529
|
var numInputs = domain.length >> 1;
|
534
530
|
var evaluator = new PostScriptEvaluator(code);
|
@@ -538,13 +534,13 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
538
534
|
var tmpBuf = new Float32Array(numInputs);
|
539
535
|
return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) {
|
540
536
|
var i, value;
|
541
|
-
var key =
|
537
|
+
var key = "";
|
542
538
|
var input = tmpBuf;
|
543
539
|
|
544
540
|
for (i = 0; i < numInputs; i++) {
|
545
541
|
value = src[srcOffset + i];
|
546
542
|
input[i] = value;
|
547
|
-
key += value +
|
543
|
+
key += value + "_";
|
548
544
|
}
|
549
545
|
|
550
546
|
var cachedValue = cache[key];
|
@@ -583,13 +579,14 @@ var PDFFunction = function PDFFunctionClosure() {
|
|
583
579
|
dest.set(output, destOffset);
|
584
580
|
};
|
585
581
|
}
|
582
|
+
|
586
583
|
};
|
587
584
|
}();
|
588
585
|
|
589
586
|
function isPDFFunction(v) {
|
590
587
|
var fnDict;
|
591
588
|
|
592
|
-
if (
|
589
|
+
if (typeof v !== "object") {
|
593
590
|
return false;
|
594
591
|
} else if ((0, _primitives.isDict)(v)) {
|
595
592
|
fnDict = v;
|
@@ -599,7 +596,7 @@ function isPDFFunction(v) {
|
|
599
596
|
return false;
|
600
597
|
}
|
601
598
|
|
602
|
-
return fnDict.has(
|
599
|
+
return fnDict.has("FunctionType");
|
603
600
|
}
|
604
601
|
|
605
602
|
var PostScriptStack = function PostScriptStackClosure() {
|
@@ -612,21 +609,21 @@ var PostScriptStack = function PostScriptStackClosure() {
|
|
612
609
|
PostScriptStack.prototype = {
|
613
610
|
push: function PostScriptStack_push(value) {
|
614
611
|
if (this.stack.length >= MAX_STACK_SIZE) {
|
615
|
-
throw new Error(
|
612
|
+
throw new Error("PostScript function stack overflow.");
|
616
613
|
}
|
617
614
|
|
618
615
|
this.stack.push(value);
|
619
616
|
},
|
620
617
|
pop: function PostScriptStack_pop() {
|
621
618
|
if (this.stack.length <= 0) {
|
622
|
-
throw new Error(
|
619
|
+
throw new Error("PostScript function stack underflow.");
|
623
620
|
}
|
624
621
|
|
625
622
|
return this.stack.pop();
|
626
623
|
},
|
627
624
|
copy: function PostScriptStack_copy(n) {
|
628
625
|
if (this.stack.length + n >= MAX_STACK_SIZE) {
|
629
|
-
throw new Error(
|
626
|
+
throw new Error("PostScript function stack overflow.");
|
630
627
|
}
|
631
628
|
|
632
629
|
var stack = this.stack;
|
@@ -685,13 +682,13 @@ var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
|
|
685
682
|
while (counter < length) {
|
686
683
|
operator = operators[counter++];
|
687
684
|
|
688
|
-
if (typeof operator ===
|
685
|
+
if (typeof operator === "number") {
|
689
686
|
stack.push(operator);
|
690
687
|
continue;
|
691
688
|
}
|
692
689
|
|
693
690
|
switch (operator) {
|
694
|
-
case
|
691
|
+
case "jz":
|
695
692
|
b = stack.pop();
|
696
693
|
a = stack.pop();
|
697
694
|
|
@@ -701,23 +698,23 @@ var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
|
|
701
698
|
|
702
699
|
break;
|
703
700
|
|
704
|
-
case
|
701
|
+
case "j":
|
705
702
|
a = stack.pop();
|
706
703
|
counter = a;
|
707
704
|
break;
|
708
705
|
|
709
|
-
case
|
706
|
+
case "abs":
|
710
707
|
a = stack.pop();
|
711
708
|
stack.push(Math.abs(a));
|
712
709
|
break;
|
713
710
|
|
714
|
-
case
|
711
|
+
case "add":
|
715
712
|
b = stack.pop();
|
716
713
|
a = stack.pop();
|
717
714
|
stack.push(a + b);
|
718
715
|
break;
|
719
716
|
|
720
|
-
case
|
717
|
+
case "and":
|
721
718
|
b = stack.pop();
|
722
719
|
a = stack.pop();
|
723
720
|
|
@@ -729,12 +726,12 @@ var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
|
|
729
726
|
|
730
727
|
break;
|
731
728
|
|
732
|
-
case
|
729
|
+
case "atan":
|
733
730
|
a = stack.pop();
|
734
731
|
stack.push(Math.atan(a));
|
735
732
|
break;
|
736
733
|
|
737
|
-
case
|
734
|
+
case "bitshift":
|
738
735
|
b = stack.pop();
|
739
736
|
a = stack.pop();
|
740
737
|
|
@@ -746,133 +743,133 @@ var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
|
|
746
743
|
|
747
744
|
break;
|
748
745
|
|
749
|
-
case
|
746
|
+
case "ceiling":
|
750
747
|
a = stack.pop();
|
751
748
|
stack.push(Math.ceil(a));
|
752
749
|
break;
|
753
750
|
|
754
|
-
case
|
751
|
+
case "copy":
|
755
752
|
a = stack.pop();
|
756
753
|
stack.copy(a);
|
757
754
|
break;
|
758
755
|
|
759
|
-
case
|
756
|
+
case "cos":
|
760
757
|
a = stack.pop();
|
761
758
|
stack.push(Math.cos(a));
|
762
759
|
break;
|
763
760
|
|
764
|
-
case
|
761
|
+
case "cvi":
|
765
762
|
a = stack.pop() | 0;
|
766
763
|
stack.push(a);
|
767
764
|
break;
|
768
765
|
|
769
|
-
case
|
766
|
+
case "cvr":
|
770
767
|
break;
|
771
768
|
|
772
|
-
case
|
769
|
+
case "div":
|
773
770
|
b = stack.pop();
|
774
771
|
a = stack.pop();
|
775
772
|
stack.push(a / b);
|
776
773
|
break;
|
777
774
|
|
778
|
-
case
|
775
|
+
case "dup":
|
779
776
|
stack.copy(1);
|
780
777
|
break;
|
781
778
|
|
782
|
-
case
|
779
|
+
case "eq":
|
783
780
|
b = stack.pop();
|
784
781
|
a = stack.pop();
|
785
782
|
stack.push(a === b);
|
786
783
|
break;
|
787
784
|
|
788
|
-
case
|
785
|
+
case "exch":
|
789
786
|
stack.roll(2, 1);
|
790
787
|
break;
|
791
788
|
|
792
|
-
case
|
789
|
+
case "exp":
|
793
790
|
b = stack.pop();
|
794
791
|
a = stack.pop();
|
795
|
-
stack.push(
|
792
|
+
stack.push(a ** b);
|
796
793
|
break;
|
797
794
|
|
798
|
-
case
|
795
|
+
case "false":
|
799
796
|
stack.push(false);
|
800
797
|
break;
|
801
798
|
|
802
|
-
case
|
799
|
+
case "floor":
|
803
800
|
a = stack.pop();
|
804
801
|
stack.push(Math.floor(a));
|
805
802
|
break;
|
806
803
|
|
807
|
-
case
|
804
|
+
case "ge":
|
808
805
|
b = stack.pop();
|
809
806
|
a = stack.pop();
|
810
807
|
stack.push(a >= b);
|
811
808
|
break;
|
812
809
|
|
813
|
-
case
|
810
|
+
case "gt":
|
814
811
|
b = stack.pop();
|
815
812
|
a = stack.pop();
|
816
813
|
stack.push(a > b);
|
817
814
|
break;
|
818
815
|
|
819
|
-
case
|
816
|
+
case "idiv":
|
820
817
|
b = stack.pop();
|
821
818
|
a = stack.pop();
|
822
819
|
stack.push(a / b | 0);
|
823
820
|
break;
|
824
821
|
|
825
|
-
case
|
822
|
+
case "index":
|
826
823
|
a = stack.pop();
|
827
824
|
stack.index(a);
|
828
825
|
break;
|
829
826
|
|
830
|
-
case
|
827
|
+
case "le":
|
831
828
|
b = stack.pop();
|
832
829
|
a = stack.pop();
|
833
830
|
stack.push(a <= b);
|
834
831
|
break;
|
835
832
|
|
836
|
-
case
|
833
|
+
case "ln":
|
837
834
|
a = stack.pop();
|
838
835
|
stack.push(Math.log(a));
|
839
836
|
break;
|
840
837
|
|
841
|
-
case
|
838
|
+
case "log":
|
842
839
|
a = stack.pop();
|
843
840
|
stack.push(Math.log(a) / Math.LN10);
|
844
841
|
break;
|
845
842
|
|
846
|
-
case
|
843
|
+
case "lt":
|
847
844
|
b = stack.pop();
|
848
845
|
a = stack.pop();
|
849
846
|
stack.push(a < b);
|
850
847
|
break;
|
851
848
|
|
852
|
-
case
|
849
|
+
case "mod":
|
853
850
|
b = stack.pop();
|
854
851
|
a = stack.pop();
|
855
852
|
stack.push(a % b);
|
856
853
|
break;
|
857
854
|
|
858
|
-
case
|
855
|
+
case "mul":
|
859
856
|
b = stack.pop();
|
860
857
|
a = stack.pop();
|
861
858
|
stack.push(a * b);
|
862
859
|
break;
|
863
860
|
|
864
|
-
case
|
861
|
+
case "ne":
|
865
862
|
b = stack.pop();
|
866
863
|
a = stack.pop();
|
867
864
|
stack.push(a !== b);
|
868
865
|
break;
|
869
866
|
|
870
|
-
case
|
867
|
+
case "neg":
|
871
868
|
a = stack.pop();
|
872
869
|
stack.push(-a);
|
873
870
|
break;
|
874
871
|
|
875
|
-
case
|
872
|
+
case "not":
|
876
873
|
a = stack.pop();
|
877
874
|
|
878
875
|
if ((0, _util.isBool)(a)) {
|
@@ -883,7 +880,7 @@ var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
|
|
883
880
|
|
884
881
|
break;
|
885
882
|
|
886
|
-
case
|
883
|
+
case "or":
|
887
884
|
b = stack.pop();
|
888
885
|
a = stack.pop();
|
889
886
|
|
@@ -895,48 +892,48 @@ var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
|
|
895
892
|
|
896
893
|
break;
|
897
894
|
|
898
|
-
case
|
895
|
+
case "pop":
|
899
896
|
stack.pop();
|
900
897
|
break;
|
901
898
|
|
902
|
-
case
|
899
|
+
case "roll":
|
903
900
|
b = stack.pop();
|
904
901
|
a = stack.pop();
|
905
902
|
stack.roll(a, b);
|
906
903
|
break;
|
907
904
|
|
908
|
-
case
|
905
|
+
case "round":
|
909
906
|
a = stack.pop();
|
910
907
|
stack.push(Math.round(a));
|
911
908
|
break;
|
912
909
|
|
913
|
-
case
|
910
|
+
case "sin":
|
914
911
|
a = stack.pop();
|
915
912
|
stack.push(Math.sin(a));
|
916
913
|
break;
|
917
914
|
|
918
|
-
case
|
915
|
+
case "sqrt":
|
919
916
|
a = stack.pop();
|
920
917
|
stack.push(Math.sqrt(a));
|
921
918
|
break;
|
922
919
|
|
923
|
-
case
|
920
|
+
case "sub":
|
924
921
|
b = stack.pop();
|
925
922
|
a = stack.pop();
|
926
923
|
stack.push(a - b);
|
927
924
|
break;
|
928
925
|
|
929
|
-
case
|
926
|
+
case "true":
|
930
927
|
stack.push(true);
|
931
928
|
break;
|
932
929
|
|
933
|
-
case
|
930
|
+
case "truncate":
|
934
931
|
a = stack.pop();
|
935
932
|
a = a < 0 ? Math.ceil(a) : Math.floor(a);
|
936
933
|
stack.push(a);
|
937
934
|
break;
|
938
935
|
|
939
|
-
case
|
936
|
+
case "xor":
|
940
937
|
b = stack.pop();
|
941
938
|
a = stack.pop();
|
942
939
|
|
@@ -949,7 +946,7 @@ var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
|
|
949
946
|
break;
|
950
947
|
|
951
948
|
default:
|
952
|
-
throw new _util.FormatError(
|
949
|
+
throw new _util.FormatError(`Unknown operator ${operator}`);
|
953
950
|
}
|
954
951
|
}
|
955
952
|
|
@@ -967,11 +964,11 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
967
964
|
}
|
968
965
|
|
969
966
|
AstNode.prototype.visit = function (visitor) {
|
970
|
-
(0, _util.unreachable)(
|
967
|
+
(0, _util.unreachable)("abstract method");
|
971
968
|
};
|
972
969
|
|
973
970
|
function AstArgument(index, min, max) {
|
974
|
-
AstNode.call(this,
|
971
|
+
AstNode.call(this, "args");
|
975
972
|
this.index = index;
|
976
973
|
this.min = min;
|
977
974
|
this.max = max;
|
@@ -984,7 +981,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
984
981
|
};
|
985
982
|
|
986
983
|
function AstLiteral(number) {
|
987
|
-
AstNode.call(this,
|
984
|
+
AstNode.call(this, "literal");
|
988
985
|
this.number = number;
|
989
986
|
this.min = number;
|
990
987
|
this.max = number;
|
@@ -997,7 +994,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
997
994
|
};
|
998
995
|
|
999
996
|
function AstBinaryOperation(op, arg1, arg2, min, max) {
|
1000
|
-
AstNode.call(this,
|
997
|
+
AstNode.call(this, "binary");
|
1001
998
|
this.op = op;
|
1002
999
|
this.arg1 = arg1;
|
1003
1000
|
this.arg2 = arg2;
|
@@ -1012,7 +1009,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1012
1009
|
};
|
1013
1010
|
|
1014
1011
|
function AstMin(arg, max) {
|
1015
|
-
AstNode.call(this,
|
1012
|
+
AstNode.call(this, "max");
|
1016
1013
|
this.arg = arg;
|
1017
1014
|
this.min = arg.min;
|
1018
1015
|
this.max = max;
|
@@ -1025,7 +1022,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1025
1022
|
};
|
1026
1023
|
|
1027
1024
|
function AstVariable(index, min, max) {
|
1028
|
-
AstNode.call(this,
|
1025
|
+
AstNode.call(this, "var");
|
1029
1026
|
this.index = index;
|
1030
1027
|
this.min = min;
|
1031
1028
|
this.max = max;
|
@@ -1038,7 +1035,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1038
1035
|
};
|
1039
1036
|
|
1040
1037
|
function AstVariableDefinition(variable, arg) {
|
1041
|
-
AstNode.call(this,
|
1038
|
+
AstNode.call(this, "definition");
|
1042
1039
|
this.variable = variable;
|
1043
1040
|
this.arg = arg;
|
1044
1041
|
}
|
@@ -1054,67 +1051,74 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1054
1051
|
}
|
1055
1052
|
|
1056
1053
|
ExpressionBuilderVisitor.prototype = {
|
1057
|
-
visitArgument
|
1058
|
-
this.parts.push(
|
1054
|
+
visitArgument(arg) {
|
1055
|
+
this.parts.push("Math.max(", arg.min, ", Math.min(", arg.max, ", src[srcOffset + ", arg.index, "]))");
|
1059
1056
|
},
|
1060
|
-
|
1061
|
-
|
1057
|
+
|
1058
|
+
visitVariable(variable) {
|
1059
|
+
this.parts.push("v", variable.index);
|
1062
1060
|
},
|
1063
|
-
|
1061
|
+
|
1062
|
+
visitLiteral(literal) {
|
1064
1063
|
this.parts.push(literal.number);
|
1065
1064
|
},
|
1066
|
-
|
1067
|
-
|
1065
|
+
|
1066
|
+
visitBinaryOperation(operation) {
|
1067
|
+
this.parts.push("(");
|
1068
1068
|
operation.arg1.visit(this);
|
1069
|
-
this.parts.push(
|
1069
|
+
this.parts.push(" ", operation.op, " ");
|
1070
1070
|
operation.arg2.visit(this);
|
1071
|
-
this.parts.push(
|
1071
|
+
this.parts.push(")");
|
1072
1072
|
},
|
1073
|
-
|
1074
|
-
|
1073
|
+
|
1074
|
+
visitVariableDefinition(definition) {
|
1075
|
+
this.parts.push("var ");
|
1075
1076
|
definition.variable.visit(this);
|
1076
|
-
this.parts.push(
|
1077
|
+
this.parts.push(" = ");
|
1077
1078
|
definition.arg.visit(this);
|
1078
|
-
this.parts.push(
|
1079
|
+
this.parts.push(";");
|
1079
1080
|
},
|
1080
|
-
|
1081
|
-
|
1081
|
+
|
1082
|
+
visitMin(max) {
|
1083
|
+
this.parts.push("Math.min(");
|
1082
1084
|
max.arg.visit(this);
|
1083
|
-
this.parts.push(
|
1085
|
+
this.parts.push(", ", max.max, ")");
|
1084
1086
|
},
|
1085
|
-
|
1086
|
-
|
1087
|
+
|
1088
|
+
toString() {
|
1089
|
+
return this.parts.join("");
|
1087
1090
|
}
|
1091
|
+
|
1088
1092
|
};
|
1089
1093
|
|
1090
1094
|
function buildAddOperation(num1, num2) {
|
1091
|
-
if (num2.type ===
|
1095
|
+
if (num2.type === "literal" && num2.number === 0) {
|
1092
1096
|
return num1;
|
1093
1097
|
}
|
1094
1098
|
|
1095
|
-
if (num1.type ===
|
1099
|
+
if (num1.type === "literal" && num1.number === 0) {
|
1096
1100
|
return num2;
|
1097
1101
|
}
|
1098
1102
|
|
1099
|
-
if (num2.type ===
|
1103
|
+
if (num2.type === "literal" && num1.type === "literal") {
|
1100
1104
|
return new AstLiteral(num1.number + num2.number);
|
1101
1105
|
}
|
1102
1106
|
|
1103
|
-
return new AstBinaryOperation(
|
1107
|
+
return new AstBinaryOperation("+", num1, num2, num1.min + num2.min, num1.max + num2.max);
|
1104
1108
|
}
|
1105
1109
|
|
1106
1110
|
function buildMulOperation(num1, num2) {
|
1107
|
-
if (num2.type ===
|
1111
|
+
if (num2.type === "literal") {
|
1108
1112
|
if (num2.number === 0) {
|
1109
1113
|
return new AstLiteral(0);
|
1110
1114
|
} else if (num2.number === 1) {
|
1111
1115
|
return num1;
|
1112
|
-
} else if (num1.type ===
|
1116
|
+
} else if (num1.type === "literal") {
|
1113
1117
|
return new AstLiteral(num1.number * num2.number);
|
1114
1118
|
}
|
1115
1119
|
}
|
1116
1120
|
|
1117
|
-
if (num1.type ===
|
1121
|
+
if (num1.type === "literal") {
|
1118
1122
|
if (num1.number === 0) {
|
1119
1123
|
return new AstLiteral(0);
|
1120
1124
|
} else if (num1.number === 1) {
|
@@ -1124,23 +1128,23 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1124
1128
|
|
1125
1129
|
var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
|
1126
1130
|
var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
|
1127
|
-
return new AstBinaryOperation(
|
1131
|
+
return new AstBinaryOperation("*", num1, num2, min, max);
|
1128
1132
|
}
|
1129
1133
|
|
1130
1134
|
function buildSubOperation(num1, num2) {
|
1131
|
-
if (num2.type ===
|
1135
|
+
if (num2.type === "literal") {
|
1132
1136
|
if (num2.number === 0) {
|
1133
1137
|
return num1;
|
1134
|
-
} else if (num1.type ===
|
1138
|
+
} else if (num1.type === "literal") {
|
1135
1139
|
return new AstLiteral(num1.number - num2.number);
|
1136
1140
|
}
|
1137
1141
|
}
|
1138
1142
|
|
1139
|
-
if (num2.type ===
|
1143
|
+
if (num2.type === "binary" && num2.op === "-" && num1.type === "literal" && num1.number === 1 && num2.arg1.type === "literal" && num2.arg1.number === 1) {
|
1140
1144
|
return num2.arg2;
|
1141
1145
|
}
|
1142
1146
|
|
1143
|
-
return new AstBinaryOperation(
|
1147
|
+
return new AstBinaryOperation("-", num1, num2, num1.min - num2.max, num1.max - num2.min);
|
1144
1148
|
}
|
1145
1149
|
|
1146
1150
|
function buildMinOperation(num1, max) {
|
@@ -1158,7 +1162,6 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1158
1162
|
PostScriptCompiler.prototype = {
|
1159
1163
|
compile: function PostScriptCompiler_compile(code, domain, range) {
|
1160
1164
|
var stack = [];
|
1161
|
-
var i, ii;
|
1162
1165
|
var instructions = [];
|
1163
1166
|
var inputSize = domain.length >> 1,
|
1164
1167
|
outputSize = range.length >> 1;
|
@@ -1166,20 +1169,20 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1166
1169
|
var n, j;
|
1167
1170
|
var num1, num2, ast1, ast2, tmpVar, item;
|
1168
1171
|
|
1169
|
-
for (i = 0; i < inputSize; i++) {
|
1172
|
+
for (let i = 0; i < inputSize; i++) {
|
1170
1173
|
stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
|
1171
1174
|
}
|
1172
1175
|
|
1173
|
-
for (i = 0, ii = code.length; i < ii; i++) {
|
1176
|
+
for (let i = 0, ii = code.length; i < ii; i++) {
|
1174
1177
|
item = code[i];
|
1175
1178
|
|
1176
|
-
if (typeof item ===
|
1179
|
+
if (typeof item === "number") {
|
1177
1180
|
stack.push(new AstLiteral(item));
|
1178
1181
|
continue;
|
1179
1182
|
}
|
1180
1183
|
|
1181
1184
|
switch (item) {
|
1182
|
-
case
|
1185
|
+
case "add":
|
1183
1186
|
if (stack.length < 2) {
|
1184
1187
|
return null;
|
1185
1188
|
}
|
@@ -1189,14 +1192,14 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1189
1192
|
stack.push(buildAddOperation(num1, num2));
|
1190
1193
|
break;
|
1191
1194
|
|
1192
|
-
case
|
1195
|
+
case "cvr":
|
1193
1196
|
if (stack.length < 1) {
|
1194
1197
|
return null;
|
1195
1198
|
}
|
1196
1199
|
|
1197
1200
|
break;
|
1198
1201
|
|
1199
|
-
case
|
1202
|
+
case "mul":
|
1200
1203
|
if (stack.length < 2) {
|
1201
1204
|
return null;
|
1202
1205
|
}
|
@@ -1206,7 +1209,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1206
1209
|
stack.push(buildMulOperation(num1, num2));
|
1207
1210
|
break;
|
1208
1211
|
|
1209
|
-
case
|
1212
|
+
case "sub":
|
1210
1213
|
if (stack.length < 2) {
|
1211
1214
|
return null;
|
1212
1215
|
}
|
@@ -1216,7 +1219,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1216
1219
|
stack.push(buildSubOperation(num1, num2));
|
1217
1220
|
break;
|
1218
1221
|
|
1219
|
-
case
|
1222
|
+
case "exch":
|
1220
1223
|
if (stack.length < 2) {
|
1221
1224
|
return null;
|
1222
1225
|
}
|
@@ -1226,7 +1229,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1226
1229
|
stack.push(ast1, ast2);
|
1227
1230
|
break;
|
1228
1231
|
|
1229
|
-
case
|
1232
|
+
case "pop":
|
1230
1233
|
if (stack.length < 1) {
|
1231
1234
|
return null;
|
1232
1235
|
}
|
@@ -1234,14 +1237,14 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1234
1237
|
stack.pop();
|
1235
1238
|
break;
|
1236
1239
|
|
1237
|
-
case
|
1240
|
+
case "index":
|
1238
1241
|
if (stack.length < 1) {
|
1239
1242
|
return null;
|
1240
1243
|
}
|
1241
1244
|
|
1242
1245
|
num1 = stack.pop();
|
1243
1246
|
|
1244
|
-
if (num1.type !==
|
1247
|
+
if (num1.type !== "literal") {
|
1245
1248
|
return null;
|
1246
1249
|
}
|
1247
1250
|
|
@@ -1253,7 +1256,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1253
1256
|
|
1254
1257
|
ast1 = stack[stack.length - n - 1];
|
1255
1258
|
|
1256
|
-
if (ast1.type ===
|
1259
|
+
if (ast1.type === "literal" || ast1.type === "var") {
|
1257
1260
|
stack.push(ast1);
|
1258
1261
|
break;
|
1259
1262
|
}
|
@@ -1264,12 +1267,12 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1264
1267
|
instructions.push(new AstVariableDefinition(tmpVar, ast1));
|
1265
1268
|
break;
|
1266
1269
|
|
1267
|
-
case
|
1270
|
+
case "dup":
|
1268
1271
|
if (stack.length < 1) {
|
1269
1272
|
return null;
|
1270
1273
|
}
|
1271
1274
|
|
1272
|
-
if (typeof code[i + 1] ===
|
1275
|
+
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]) {
|
1273
1276
|
num1 = stack.pop();
|
1274
1277
|
stack.push(buildMinOperation(num1, code[i + 1]));
|
1275
1278
|
i += 6;
|
@@ -1278,7 +1281,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1278
1281
|
|
1279
1282
|
ast1 = stack[stack.length - 1];
|
1280
1283
|
|
1281
|
-
if (ast1.type ===
|
1284
|
+
if (ast1.type === "literal" || ast1.type === "var") {
|
1282
1285
|
stack.push(ast1);
|
1283
1286
|
break;
|
1284
1287
|
}
|
@@ -1289,7 +1292,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1289
1292
|
instructions.push(new AstVariableDefinition(tmpVar, ast1));
|
1290
1293
|
break;
|
1291
1294
|
|
1292
|
-
case
|
1295
|
+
case "roll":
|
1293
1296
|
if (stack.length < 2) {
|
1294
1297
|
return null;
|
1295
1298
|
}
|
@@ -1297,7 +1300,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1297
1300
|
num2 = stack.pop();
|
1298
1301
|
num1 = stack.pop();
|
1299
1302
|
|
1300
|
-
if (num2.type !==
|
1303
|
+
if (num2.type !== "literal" || num1.type !== "literal") {
|
1301
1304
|
return null;
|
1302
1305
|
}
|
1303
1306
|
|
@@ -1340,20 +1343,20 @@ var PostScriptCompiler = function PostScriptCompilerClosure() {
|
|
1340
1343
|
var out = [statementBuilder.toString()];
|
1341
1344
|
|
1342
1345
|
if (min > expr.min) {
|
1343
|
-
out.unshift(
|
1344
|
-
out.push(
|
1346
|
+
out.unshift("Math.max(", min, ", ");
|
1347
|
+
out.push(")");
|
1345
1348
|
}
|
1346
1349
|
|
1347
1350
|
if (max < expr.max) {
|
1348
|
-
out.unshift(
|
1349
|
-
out.push(
|
1351
|
+
out.unshift("Math.min(", max, ", ");
|
1352
|
+
out.push(")");
|
1350
1353
|
}
|
1351
1354
|
|
1352
|
-
out.unshift(
|
1353
|
-
out.push(
|
1354
|
-
result.push(out.join(
|
1355
|
+
out.unshift("dest[destOffset + ", i, "] = ");
|
1356
|
+
out.push(";");
|
1357
|
+
result.push(out.join(""));
|
1355
1358
|
});
|
1356
|
-
return result.join(
|
1359
|
+
return result.join("\n");
|
1357
1360
|
}
|
1358
1361
|
};
|
1359
1362
|
return PostScriptCompiler;
|