pdfjs-dist 2.6.347 → 2.7.570
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/README.md +3 -3
- package/bower.json +1 -1
- package/build/pdf.js +2050 -1087
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +18219 -10436
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/es5/build/pdf.d.ts +1 -0
- package/es5/build/pdf.js +6623 -6654
- package/es5/build/pdf.js.map +1 -1
- package/es5/build/pdf.min.js +1 -1
- package/es5/build/pdf.worker.js +20815 -13888
- package/es5/build/pdf.worker.js.map +1 -1
- package/es5/build/pdf.worker.min.js +1 -1
- package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
- package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
- package/es5/web/pdf_viewer.css +18 -15
- package/es5/web/pdf_viewer.js +1094 -514
- package/es5/web/pdf_viewer.js.map +1 -1
- package/image_decoders/pdf.image_decoders.js +774 -168
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/core/annotation.js +556 -108
- package/lib/core/cff_parser.js +7 -1
- package/lib/core/charsets.js +1 -1
- package/lib/core/cmap.js +20 -1
- package/lib/core/core_utils.js +162 -3
- package/lib/core/crypto.js +1 -1
- package/lib/core/default_appearance.js +132 -0
- package/lib/core/document.js +115 -9
- package/lib/core/encodings.js +1 -1
- package/lib/core/evaluator.js +168 -74
- package/lib/core/fonts.js +97 -11
- package/lib/core/function.js +5 -10
- package/lib/core/glyphlist.js +11 -4529
- package/lib/core/image_utils.js +30 -1
- package/lib/core/jpg.js +1 -1
- package/lib/core/jpx.js +5 -5
- package/lib/core/murmurhash3.js +1 -1
- package/lib/core/obj.js +123 -39
- package/lib/core/pattern.js +4 -4
- package/lib/core/primitives.js +24 -5
- package/lib/core/standard_fonts.js +1 -1
- package/lib/core/stream.js +5 -1
- package/lib/core/unicode.js +15 -1387
- package/lib/core/worker.js +58 -17
- package/lib/core/writer.js +68 -4
- package/lib/display/annotation_layer.js +712 -119
- package/lib/display/annotation_storage.js +21 -4
- package/lib/display/api.js +88 -18
- package/lib/display/canvas.js +414 -375
- package/lib/display/display_utils.js +11 -4
- package/lib/display/fetch_stream.js +3 -3
- package/lib/display/font_loader.js +2 -3
- package/lib/display/metadata.js +54 -20
- package/lib/display/node_stream.js +1 -1
- package/lib/display/optional_content_config.js +1 -1
- package/lib/display/pattern_helper.js +109 -113
- package/lib/display/svg.js +5 -5
- package/lib/display/text_layer.js +54 -54
- package/lib/display/transport_stream.js +4 -4
- package/lib/display/webgl.js +65 -68
- package/lib/examples/node/domstubs.js +9 -4
- package/lib/pdf.js +2 -2
- package/lib/pdf.sandbox.js +311 -0
- package/lib/pdf.worker.js +2 -2
- package/lib/shared/scripting_utils.js +84 -0
- package/lib/shared/util.js +129 -14
- package/lib/{display → shared}/xml_parser.js +112 -4
- package/lib/test/unit/annotation_spec.js +831 -109
- package/lib/test/unit/annotation_storage_spec.js +28 -10
- package/lib/test/unit/api_spec.js +190 -160
- package/lib/test/unit/bidi_spec.js +6 -6
- package/lib/test/unit/cff_parser_spec.js +73 -73
- package/lib/test/unit/clitests_helper.js +2 -0
- package/lib/test/unit/cmap_spec.js +48 -74
- package/lib/test/unit/core_utils_spec.js +34 -0
- package/lib/test/unit/crypto_spec.js +162 -199
- package/lib/test/unit/custom_spec.js +7 -18
- package/lib/test/unit/default_appearance_spec.js +54 -0
- package/lib/test/unit/display_svg_spec.js +24 -19
- package/lib/test/unit/display_utils_spec.js +1 -1
- package/lib/test/unit/document_spec.js +187 -20
- package/lib/test/unit/evaluator_spec.js +30 -30
- package/lib/test/unit/function_spec.js +165 -165
- package/lib/test/unit/jasmine-boot.js +52 -53
- package/lib/test/unit/metadata_spec.js +2 -2
- package/lib/test/unit/murmurhash3_spec.js +29 -16
- package/lib/test/unit/network_spec.js +21 -21
- package/lib/test/unit/pdf_find_controller_spec.js +131 -69
- package/lib/test/unit/pdf_find_utils_spec.js +10 -10
- package/lib/test/unit/scripting_spec.js +1104 -0
- package/lib/test/unit/stream_spec.js +8 -8
- package/lib/test/unit/test_utils.js +16 -19
- package/lib/test/unit/testreporter.js +11 -4
- package/lib/test/unit/type1_parser_spec.js +23 -23
- package/lib/test/unit/ui_utils_spec.js +78 -35
- package/lib/test/unit/unicode_spec.js +7 -7
- package/lib/test/unit/util_spec.js +26 -3
- package/lib/test/unit/writer_spec.js +16 -1
- package/lib/test/unit/xml_spec.js +117 -0
- package/lib/web/annotation_layer_builder.js +18 -6
- package/lib/web/app.js +579 -161
- package/lib/web/app_options.js +14 -0
- package/lib/web/base_tree_viewer.js +50 -0
- package/lib/web/base_viewer.js +350 -14
- package/lib/web/chromecom.js +9 -1
- package/lib/web/debugger.js +1 -2
- package/lib/web/download_manager.js +0 -15
- package/lib/web/firefox_print_service.js +6 -4
- package/lib/web/firefoxcom.js +84 -69
- package/lib/web/generic_scripting.js +55 -0
- package/lib/web/genericcom.js +9 -1
- package/lib/web/grab_to_pan.js +1 -1
- package/lib/web/interfaces.js +9 -3
- package/lib/web/pdf_attachment_viewer.js +1 -3
- package/lib/web/pdf_cursor_tools.js +20 -13
- package/lib/web/pdf_document_properties.js +48 -61
- package/lib/web/pdf_find_bar.js +1 -3
- package/lib/web/pdf_find_controller.js +58 -12
- package/lib/web/pdf_history.js +43 -21
- package/lib/web/pdf_layer_viewer.js +1 -9
- package/lib/web/pdf_link_service.js +108 -78
- package/lib/web/pdf_outline_viewer.js +166 -10
- package/lib/web/pdf_page_view.js +14 -14
- package/lib/web/pdf_presentation_mode.js +21 -31
- package/lib/web/pdf_rendering_queue.js +8 -1
- package/lib/web/pdf_sidebar.js +62 -107
- package/lib/web/pdf_sidebar_resizer.js +11 -21
- package/lib/web/pdf_single_page_viewer.js +8 -0
- package/lib/web/pdf_thumbnail_view.js +26 -26
- package/lib/web/pdf_thumbnail_viewer.js +13 -2
- package/lib/web/pdf_viewer.component.js +2 -2
- package/lib/web/pdf_viewer.js +3 -1
- package/lib/web/preferences.js +33 -44
- package/lib/web/text_layer_builder.js +2 -9
- package/lib/web/ui_utils.js +78 -46
- package/lib/web/viewer_compatibility.js +1 -2
- package/package.json +4 -1
- package/types/display/annotation_layer.d.ts +18 -3
- package/types/display/api.d.ts +110 -54
- package/types/display/canvas.d.ts +1 -1
- package/types/display/display_utils.d.ts +96 -95
- package/types/display/fetch_stream.d.ts +2 -2
- package/types/display/metadata.d.ts +4 -0
- package/types/display/pattern_helper.d.ts +1 -1
- package/types/display/text_layer.d.ts +7 -7
- package/types/display/transport_stream.d.ts +1 -1
- package/types/shared/scripting_utils.d.ts +12 -0
- package/types/shared/util.d.ts +281 -250
- package/types/shared/xml_parser.d.ts +64 -0
- package/web/pdf_viewer.css +18 -15
- package/web/pdf_viewer.js +809 -408
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +1 -1
- package/types/display/xml_parser.d.ts +0 -35
@@ -33,7 +33,7 @@ describe("function", function () {
|
|
33
33
|
toMatchArray(util, customEqualityTesters) {
|
34
34
|
return {
|
35
35
|
compare(actual, expected) {
|
36
|
-
|
36
|
+
const result = {};
|
37
37
|
|
38
38
|
if (actual.length !== expected.length) {
|
39
39
|
result.pass = false;
|
@@ -43,9 +43,9 @@ describe("function", function () {
|
|
43
43
|
|
44
44
|
result.pass = true;
|
45
45
|
|
46
|
-
for (
|
47
|
-
|
48
|
-
|
46
|
+
for (let i = 0; i < expected.length; i++) {
|
47
|
+
const a = actual[i],
|
48
|
+
b = expected[i];
|
49
49
|
|
50
50
|
if (Array.isArray(b)) {
|
51
51
|
if (a.length !== b.length) {
|
@@ -53,9 +53,9 @@ describe("function", function () {
|
|
53
53
|
break;
|
54
54
|
}
|
55
55
|
|
56
|
-
for (
|
57
|
-
|
58
|
-
|
56
|
+
for (let j = 0; j < a.length; j++) {
|
57
|
+
const suba = a[j],
|
58
|
+
subb = b[j];
|
59
59
|
|
60
60
|
if (suba !== subb) {
|
61
61
|
result.pass = false;
|
@@ -80,46 +80,46 @@ describe("function", function () {
|
|
80
80
|
});
|
81
81
|
describe("PostScriptParser", function () {
|
82
82
|
function parse(program) {
|
83
|
-
|
84
|
-
|
83
|
+
const stream = new _stream.StringStream(program);
|
84
|
+
const parser = new _ps_parser.PostScriptParser(new _ps_parser.PostScriptLexer(stream));
|
85
85
|
return parser.parse();
|
86
86
|
}
|
87
87
|
|
88
88
|
it("parses empty programs", function () {
|
89
|
-
|
89
|
+
const output = parse("{}");
|
90
90
|
expect(output.length).toEqual(0);
|
91
91
|
});
|
92
92
|
it("parses positive numbers", function () {
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
const number = 999;
|
94
|
+
const program = parse("{ " + number + " }");
|
95
|
+
const expectedProgram = [number];
|
96
96
|
expect(program).toMatchArray(expectedProgram);
|
97
97
|
});
|
98
98
|
it("parses negative numbers", function () {
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
const number = -999;
|
100
|
+
const program = parse("{ " + number + " }");
|
101
|
+
const expectedProgram = [number];
|
102
102
|
expect(program).toMatchArray(expectedProgram);
|
103
103
|
});
|
104
104
|
it("parses negative floats", function () {
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
const number = 3.3;
|
106
|
+
const program = parse("{ " + number + " }");
|
107
|
+
const expectedProgram = [number];
|
108
108
|
expect(program).toMatchArray(expectedProgram);
|
109
109
|
});
|
110
110
|
it("parses operators", function () {
|
111
|
-
|
112
|
-
|
111
|
+
const program = parse("{ sub }");
|
112
|
+
const expectedProgram = ["sub"];
|
113
113
|
expect(program).toMatchArray(expectedProgram);
|
114
114
|
});
|
115
115
|
it("parses if statements", function () {
|
116
|
-
|
117
|
-
|
116
|
+
const program = parse("{ { 99 } if }");
|
117
|
+
const expectedProgram = [3, "jz", 99];
|
118
118
|
expect(program).toMatchArray(expectedProgram);
|
119
119
|
});
|
120
120
|
it("parses ifelse statements", function () {
|
121
|
-
|
122
|
-
|
121
|
+
const program = parse("{ { 99 } { 44 } ifelse }");
|
122
|
+
const expectedProgram = [5, "jz", 99, 6, "j", 44];
|
123
123
|
expect(program).toMatchArray(expectedProgram);
|
124
124
|
});
|
125
125
|
it("handles missing brackets", function () {
|
@@ -128,346 +128,346 @@ describe("function", function () {
|
|
128
128
|
}).toThrow(new Error("Unexpected symbol: found undefined expected 1."));
|
129
129
|
});
|
130
130
|
it("handles junk after the end", function () {
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
const number = 3.3;
|
132
|
+
const program = parse("{ " + number + " }#");
|
133
|
+
const expectedProgram = [number];
|
134
134
|
expect(program).toMatchArray(expectedProgram);
|
135
135
|
});
|
136
136
|
});
|
137
137
|
describe("PostScriptEvaluator", function () {
|
138
138
|
function evaluate(program) {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
139
|
+
const stream = new _stream.StringStream(program);
|
140
|
+
const parser = new _ps_parser.PostScriptParser(new _ps_parser.PostScriptLexer(stream));
|
141
|
+
const code = parser.parse();
|
142
|
+
const evaluator = new _function.PostScriptEvaluator(code);
|
143
|
+
const output = evaluator.execute();
|
144
144
|
return output;
|
145
145
|
}
|
146
146
|
|
147
147
|
it("pushes stack", function () {
|
148
|
-
|
149
|
-
|
148
|
+
const stack = evaluate("{ 99 }");
|
149
|
+
const expectedStack = [99];
|
150
150
|
expect(stack).toMatchArray(expectedStack);
|
151
151
|
});
|
152
152
|
it("handles if with true", function () {
|
153
|
-
|
154
|
-
|
153
|
+
const stack = evaluate("{ 1 {99} if }");
|
154
|
+
const expectedStack = [99];
|
155
155
|
expect(stack).toMatchArray(expectedStack);
|
156
156
|
});
|
157
157
|
it("handles if with false", function () {
|
158
|
-
|
159
|
-
|
158
|
+
const stack = evaluate("{ 0 {99} if }");
|
159
|
+
const expectedStack = [];
|
160
160
|
expect(stack).toMatchArray(expectedStack);
|
161
161
|
});
|
162
162
|
it("handles ifelse with true", function () {
|
163
|
-
|
164
|
-
|
163
|
+
const stack = evaluate("{ 1 {99} {77} ifelse }");
|
164
|
+
const expectedStack = [99];
|
165
165
|
expect(stack).toMatchArray(expectedStack);
|
166
166
|
});
|
167
167
|
it("handles ifelse with false", function () {
|
168
|
-
|
169
|
-
|
168
|
+
const stack = evaluate("{ 0 {99} {77} ifelse }");
|
169
|
+
const expectedStack = [77];
|
170
170
|
expect(stack).toMatchArray(expectedStack);
|
171
171
|
});
|
172
172
|
it("handles nested if", function () {
|
173
|
-
|
174
|
-
|
173
|
+
const stack = evaluate("{ 1 {1 {77} if} if }");
|
174
|
+
const expectedStack = [77];
|
175
175
|
expect(stack).toMatchArray(expectedStack);
|
176
176
|
});
|
177
177
|
it("abs", function () {
|
178
|
-
|
179
|
-
|
178
|
+
const stack = evaluate("{ -2 abs }");
|
179
|
+
const expectedStack = [2];
|
180
180
|
expect(stack).toMatchArray(expectedStack);
|
181
181
|
});
|
182
182
|
it("adds", function () {
|
183
|
-
|
184
|
-
|
183
|
+
const stack = evaluate("{ 1 2 add }");
|
184
|
+
const expectedStack = [3];
|
185
185
|
expect(stack).toMatchArray(expectedStack);
|
186
186
|
});
|
187
187
|
it("boolean and", function () {
|
188
|
-
|
189
|
-
|
188
|
+
const stack = evaluate("{ true false and }");
|
189
|
+
const expectedStack = [false];
|
190
190
|
expect(stack).toMatchArray(expectedStack);
|
191
191
|
});
|
192
192
|
it("bitwise and", function () {
|
193
|
-
|
194
|
-
|
193
|
+
const stack = evaluate("{ 254 1 and }");
|
194
|
+
const expectedStack = [254 & 1];
|
195
195
|
expect(stack).toMatchArray(expectedStack);
|
196
196
|
});
|
197
197
|
it("calculates the inverse tangent of a number", function () {
|
198
|
-
|
199
|
-
|
198
|
+
const stack = evaluate("{ 90 atan }");
|
199
|
+
const expectedStack = [Math.atan(90)];
|
200
200
|
expect(stack).toMatchArray(expectedStack);
|
201
201
|
});
|
202
202
|
it("handles bitshifting ", function () {
|
203
|
-
|
204
|
-
|
203
|
+
const stack = evaluate("{ 50 2 bitshift }");
|
204
|
+
const expectedStack = [200];
|
205
205
|
expect(stack).toMatchArray(expectedStack);
|
206
206
|
});
|
207
207
|
it("calculates the ceiling value", function () {
|
208
|
-
|
209
|
-
|
208
|
+
const stack = evaluate("{ 9.9 ceiling }");
|
209
|
+
const expectedStack = [10];
|
210
210
|
expect(stack).toMatchArray(expectedStack);
|
211
211
|
});
|
212
212
|
it("copies", function () {
|
213
|
-
|
214
|
-
|
213
|
+
const stack = evaluate("{ 99 98 2 copy }");
|
214
|
+
const expectedStack = [99, 98, 99, 98];
|
215
215
|
expect(stack).toMatchArray(expectedStack);
|
216
216
|
});
|
217
217
|
it("calculates the cosine of a number", function () {
|
218
|
-
|
219
|
-
|
218
|
+
const stack = evaluate("{ 90 cos }");
|
219
|
+
const expectedStack = [Math.cos(90)];
|
220
220
|
expect(stack).toMatchArray(expectedStack);
|
221
221
|
});
|
222
222
|
it("converts to int", function () {
|
223
|
-
|
224
|
-
|
223
|
+
const stack = evaluate("{ 9.9 cvi }");
|
224
|
+
const expectedStack = [9];
|
225
225
|
expect(stack).toMatchArray(expectedStack);
|
226
226
|
});
|
227
227
|
it("converts negatives to int", function () {
|
228
|
-
|
229
|
-
|
228
|
+
const stack = evaluate("{ -9.9 cvi }");
|
229
|
+
const expectedStack = [-9];
|
230
230
|
expect(stack).toMatchArray(expectedStack);
|
231
231
|
});
|
232
232
|
it("converts to real", function () {
|
233
|
-
|
234
|
-
|
233
|
+
const stack = evaluate("{ 55.34 cvr }");
|
234
|
+
const expectedStack = [55.34];
|
235
235
|
expect(stack).toMatchArray(expectedStack);
|
236
236
|
});
|
237
237
|
it("divides", function () {
|
238
|
-
|
239
|
-
|
238
|
+
const stack = evaluate("{ 6 5 div }");
|
239
|
+
const expectedStack = [1.2];
|
240
240
|
expect(stack).toMatchArray(expectedStack);
|
241
241
|
});
|
242
242
|
it("maps division by zero to infinity", function () {
|
243
|
-
|
244
|
-
|
243
|
+
const stack = evaluate("{ 6 0 div }");
|
244
|
+
const expectedStack = [Infinity];
|
245
245
|
expect(stack).toMatchArray(expectedStack);
|
246
246
|
});
|
247
247
|
it("duplicates", function () {
|
248
|
-
|
249
|
-
|
248
|
+
const stack = evaluate("{ 99 dup }");
|
249
|
+
const expectedStack = [99, 99];
|
250
250
|
expect(stack).toMatchArray(expectedStack);
|
251
251
|
});
|
252
252
|
it("accepts an equality", function () {
|
253
|
-
|
254
|
-
|
253
|
+
const stack = evaluate("{ 9 9 eq }");
|
254
|
+
const expectedStack = [true];
|
255
255
|
expect(stack).toMatchArray(expectedStack);
|
256
256
|
});
|
257
257
|
it("rejects an inequality", function () {
|
258
|
-
|
259
|
-
|
258
|
+
const stack = evaluate("{ 9 8 eq }");
|
259
|
+
const expectedStack = [false];
|
260
260
|
expect(stack).toMatchArray(expectedStack);
|
261
261
|
});
|
262
262
|
it("exchanges", function () {
|
263
|
-
|
264
|
-
|
263
|
+
const stack = evaluate("{ 44 99 exch }");
|
264
|
+
const expectedStack = [99, 44];
|
265
265
|
expect(stack).toMatchArray(expectedStack);
|
266
266
|
});
|
267
267
|
it("handles exponentiation", function () {
|
268
|
-
|
269
|
-
|
268
|
+
const stack = evaluate("{ 10 2 exp }");
|
269
|
+
const expectedStack = [100];
|
270
270
|
expect(stack).toMatchArray(expectedStack);
|
271
271
|
});
|
272
272
|
it("pushes false onto the stack", function () {
|
273
|
-
|
274
|
-
|
273
|
+
const stack = evaluate("{ false }");
|
274
|
+
const expectedStack = [false];
|
275
275
|
expect(stack).toMatchArray(expectedStack);
|
276
276
|
});
|
277
277
|
it("calculates the floor value", function () {
|
278
|
-
|
279
|
-
|
278
|
+
const stack = evaluate("{ 9.9 floor }");
|
279
|
+
const expectedStack = [9];
|
280
280
|
expect(stack).toMatchArray(expectedStack);
|
281
281
|
});
|
282
282
|
it("handles greater than or equal to", function () {
|
283
|
-
|
284
|
-
|
283
|
+
const stack = evaluate("{ 10 9 ge }");
|
284
|
+
const expectedStack = [true];
|
285
285
|
expect(stack).toMatchArray(expectedStack);
|
286
286
|
});
|
287
287
|
it("rejects less than for greater than or equal to", function () {
|
288
|
-
|
289
|
-
|
288
|
+
const stack = evaluate("{ 8 9 ge }");
|
289
|
+
const expectedStack = [false];
|
290
290
|
expect(stack).toMatchArray(expectedStack);
|
291
291
|
});
|
292
292
|
it("handles greater than", function () {
|
293
|
-
|
294
|
-
|
293
|
+
const stack = evaluate("{ 10 9 gt }");
|
294
|
+
const expectedStack = [true];
|
295
295
|
expect(stack).toMatchArray(expectedStack);
|
296
296
|
});
|
297
297
|
it("rejects less than or equal for greater than", function () {
|
298
|
-
|
299
|
-
|
298
|
+
const stack = evaluate("{ 9 9 gt }");
|
299
|
+
const expectedStack = [false];
|
300
300
|
expect(stack).toMatchArray(expectedStack);
|
301
301
|
});
|
302
302
|
it("divides to integer", function () {
|
303
|
-
|
304
|
-
|
303
|
+
const stack = evaluate("{ 2 3 idiv }");
|
304
|
+
const expectedStack = [0];
|
305
305
|
expect(stack).toMatchArray(expectedStack);
|
306
306
|
});
|
307
307
|
it("divides to negative integer", function () {
|
308
|
-
|
309
|
-
|
308
|
+
const stack = evaluate("{ -2 3 idiv }");
|
309
|
+
const expectedStack = [0];
|
310
310
|
expect(stack).toMatchArray(expectedStack);
|
311
311
|
});
|
312
312
|
it("duplicates index", function () {
|
313
|
-
|
314
|
-
|
313
|
+
const stack = evaluate("{ 4 3 2 1 2 index }");
|
314
|
+
const expectedStack = [4, 3, 2, 1, 3];
|
315
315
|
expect(stack).toMatchArray(expectedStack);
|
316
316
|
});
|
317
317
|
it("handles less than or equal to", function () {
|
318
|
-
|
319
|
-
|
318
|
+
const stack = evaluate("{ 9 10 le }");
|
319
|
+
const expectedStack = [true];
|
320
320
|
expect(stack).toMatchArray(expectedStack);
|
321
321
|
});
|
322
322
|
it("rejects greater than for less than or equal to", function () {
|
323
|
-
|
324
|
-
|
323
|
+
const stack = evaluate("{ 10 9 le }");
|
324
|
+
const expectedStack = [false];
|
325
325
|
expect(stack).toMatchArray(expectedStack);
|
326
326
|
});
|
327
327
|
it("calculates the natural logarithm", function () {
|
328
|
-
|
329
|
-
|
328
|
+
const stack = evaluate("{ 10 ln }");
|
329
|
+
const expectedStack = [Math.log(10)];
|
330
330
|
expect(stack).toMatchArray(expectedStack);
|
331
331
|
});
|
332
332
|
it("calculates the base 10 logarithm", function () {
|
333
|
-
|
334
|
-
|
333
|
+
const stack = evaluate("{ 100 log }");
|
334
|
+
const expectedStack = [2];
|
335
335
|
expect(stack).toMatchArray(expectedStack);
|
336
336
|
});
|
337
337
|
it("handles less than", function () {
|
338
|
-
|
339
|
-
|
338
|
+
const stack = evaluate("{ 9 10 lt }");
|
339
|
+
const expectedStack = [true];
|
340
340
|
expect(stack).toMatchArray(expectedStack);
|
341
341
|
});
|
342
342
|
it("rejects greater than or equal to for less than", function () {
|
343
|
-
|
344
|
-
|
343
|
+
const stack = evaluate("{ 10 9 lt }");
|
344
|
+
const expectedStack = [false];
|
345
345
|
expect(stack).toMatchArray(expectedStack);
|
346
346
|
});
|
347
347
|
it("performs the modulo operation", function () {
|
348
|
-
|
349
|
-
|
348
|
+
const stack = evaluate("{ 4 3 mod }");
|
349
|
+
const expectedStack = [1];
|
350
350
|
expect(stack).toMatchArray(expectedStack);
|
351
351
|
});
|
352
352
|
it("multiplies two numbers (positive result)", function () {
|
353
|
-
|
354
|
-
|
353
|
+
const stack = evaluate("{ 9 8 mul }");
|
354
|
+
const expectedStack = [72];
|
355
355
|
expect(stack).toMatchArray(expectedStack);
|
356
356
|
});
|
357
357
|
it("multiplies two numbers (negative result)", function () {
|
358
|
-
|
359
|
-
|
358
|
+
const stack = evaluate("{ 9 -8 mul }");
|
359
|
+
const expectedStack = [-72];
|
360
360
|
expect(stack).toMatchArray(expectedStack);
|
361
361
|
});
|
362
362
|
it("accepts an inequality", function () {
|
363
|
-
|
364
|
-
|
363
|
+
const stack = evaluate("{ 9 8 ne }");
|
364
|
+
const expectedStack = [true];
|
365
365
|
expect(stack).toMatchArray(expectedStack);
|
366
366
|
});
|
367
367
|
it("rejects an equality", function () {
|
368
|
-
|
369
|
-
|
368
|
+
const stack = evaluate("{ 9 9 ne }");
|
369
|
+
const expectedStack = [false];
|
370
370
|
expect(stack).toMatchArray(expectedStack);
|
371
371
|
});
|
372
372
|
it("negates", function () {
|
373
|
-
|
374
|
-
|
373
|
+
const stack = evaluate("{ 4.5 neg }");
|
374
|
+
const expectedStack = [-4.5];
|
375
375
|
expect(stack).toMatchArray(expectedStack);
|
376
376
|
});
|
377
377
|
it("boolean not", function () {
|
378
|
-
|
379
|
-
|
378
|
+
const stack = evaluate("{ true not }");
|
379
|
+
const expectedStack = [false];
|
380
380
|
expect(stack).toMatchArray(expectedStack);
|
381
381
|
});
|
382
382
|
it("bitwise not", function () {
|
383
|
-
|
384
|
-
|
383
|
+
const stack = evaluate("{ 12 not }");
|
384
|
+
const expectedStack = [-13];
|
385
385
|
expect(stack).toMatchArray(expectedStack);
|
386
386
|
});
|
387
387
|
it("boolean or", function () {
|
388
|
-
|
389
|
-
|
388
|
+
const stack = evaluate("{ true false or }");
|
389
|
+
const expectedStack = [true];
|
390
390
|
expect(stack).toMatchArray(expectedStack);
|
391
391
|
});
|
392
392
|
it("bitwise or", function () {
|
393
|
-
|
394
|
-
|
393
|
+
const stack = evaluate("{ 254 1 or }");
|
394
|
+
const expectedStack = [254 | 1];
|
395
395
|
expect(stack).toMatchArray(expectedStack);
|
396
396
|
});
|
397
397
|
it("pops stack", function () {
|
398
|
-
|
399
|
-
|
398
|
+
const stack = evaluate("{ 1 2 pop }");
|
399
|
+
const expectedStack = [1];
|
400
400
|
expect(stack).toMatchArray(expectedStack);
|
401
401
|
});
|
402
402
|
it("rolls stack right", function () {
|
403
|
-
|
404
|
-
|
403
|
+
const stack = evaluate("{ 1 3 2 2 4 1 roll }");
|
404
|
+
const expectedStack = [2, 1, 3, 2];
|
405
405
|
expect(stack).toMatchArray(expectedStack);
|
406
406
|
});
|
407
407
|
it("rolls stack left", function () {
|
408
|
-
|
409
|
-
|
408
|
+
const stack = evaluate("{ 1 3 2 2 4 -1 roll }");
|
409
|
+
const expectedStack = [3, 2, 2, 1];
|
410
410
|
expect(stack).toMatchArray(expectedStack);
|
411
411
|
});
|
412
412
|
it("rounds a number", function () {
|
413
|
-
|
414
|
-
|
413
|
+
const stack = evaluate("{ 9.52 round }");
|
414
|
+
const expectedStack = [10];
|
415
415
|
expect(stack).toMatchArray(expectedStack);
|
416
416
|
});
|
417
417
|
it("calculates the sine of a number", function () {
|
418
|
-
|
419
|
-
|
418
|
+
const stack = evaluate("{ 90 sin }");
|
419
|
+
const expectedStack = [Math.sin(90)];
|
420
420
|
expect(stack).toMatchArray(expectedStack);
|
421
421
|
});
|
422
422
|
it("calculates a square root (integer)", function () {
|
423
|
-
|
424
|
-
|
423
|
+
const stack = evaluate("{ 100 sqrt }");
|
424
|
+
const expectedStack = [10];
|
425
425
|
expect(stack).toMatchArray(expectedStack);
|
426
426
|
});
|
427
427
|
it("calculates a square root (float)", function () {
|
428
|
-
|
429
|
-
|
428
|
+
const stack = evaluate("{ 99 sqrt }");
|
429
|
+
const expectedStack = [Math.sqrt(99)];
|
430
430
|
expect(stack).toMatchArray(expectedStack);
|
431
431
|
});
|
432
432
|
it("subtracts (positive result)", function () {
|
433
|
-
|
434
|
-
|
433
|
+
const stack = evaluate("{ 6 4 sub }");
|
434
|
+
const expectedStack = [2];
|
435
435
|
expect(stack).toMatchArray(expectedStack);
|
436
436
|
});
|
437
437
|
it("subtracts (negative result)", function () {
|
438
|
-
|
439
|
-
|
438
|
+
const stack = evaluate("{ 4 6 sub }");
|
439
|
+
const expectedStack = [-2];
|
440
440
|
expect(stack).toMatchArray(expectedStack);
|
441
441
|
});
|
442
442
|
it("pushes true onto the stack", function () {
|
443
|
-
|
444
|
-
|
443
|
+
const stack = evaluate("{ true }");
|
444
|
+
const expectedStack = [true];
|
445
445
|
expect(stack).toMatchArray(expectedStack);
|
446
446
|
});
|
447
447
|
it("truncates a number", function () {
|
448
|
-
|
449
|
-
|
448
|
+
const stack = evaluate("{ 35.004 truncate }");
|
449
|
+
const expectedStack = [35];
|
450
450
|
expect(stack).toMatchArray(expectedStack);
|
451
451
|
});
|
452
452
|
it("calculates an exclusive or value", function () {
|
453
|
-
|
454
|
-
|
453
|
+
const stack = evaluate("{ 3 9 xor }");
|
454
|
+
const expectedStack = [10];
|
455
455
|
expect(stack).toMatchArray(expectedStack);
|
456
456
|
});
|
457
457
|
});
|
458
458
|
describe("PostScriptCompiler", function () {
|
459
459
|
function check(code, domain, range, samples) {
|
460
|
-
|
461
|
-
|
460
|
+
const compiler = new _function.PostScriptCompiler();
|
461
|
+
const compiledCode = compiler.compile(code, domain, range);
|
462
462
|
|
463
463
|
if (samples === null) {
|
464
464
|
expect(compiledCode).toBeNull();
|
465
465
|
} else {
|
466
466
|
expect(compiledCode).not.toBeNull();
|
467
|
-
|
467
|
+
const fn = new Function("src", "srcOffset", "dest", "destOffset", compiledCode);
|
468
468
|
|
469
|
-
for (
|
470
|
-
|
469
|
+
for (let i = 0; i < samples.length; i++) {
|
470
|
+
const out = new Float32Array(samples[i].output.length);
|
471
471
|
fn(samples[i].input, 0, out, 0);
|
472
472
|
expect(Array.prototype.slice.call(out, 0)).toMatchArray(samples[i].output);
|
473
473
|
}
|
@@ -636,9 +636,9 @@ describe("function", function () {
|
|
636
636
|
}]);
|
637
637
|
});
|
638
638
|
it("compile optimized", function () {
|
639
|
-
|
640
|
-
|
641
|
-
|
639
|
+
const compiler = new _function.PostScriptCompiler();
|
640
|
+
const code = [0, "add", 1, 1, 3, -1, "roll", "sub", "sub", 1, "mul"];
|
641
|
+
const compiledCode = compiler.compile(code, [0, 1], [0, 1]);
|
642
642
|
expect(compiledCode).toEqual("dest[destOffset + 0] = Math.max(0, Math.min(1, src[srcOffset + 0]));");
|
643
643
|
});
|
644
644
|
});
|