@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.4
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.
- package/README.md +1 -1
- package/package.json +33 -18
- package/{src/display → pdfjs/dist}/display_utils.js +344 -139
- package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
- package/pdfjs/dist/get.js +1857 -0
- package/pdfjs/dist/index.js +767 -0
- package/pdfjs/dist/l10n_utils.js +140 -0
- package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
- package/{src/display → pdfjs/dist}/network.js +149 -87
- package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
- package/{src/display → pdfjs/dist}/node_stream.js +133 -98
- package/pdfjs/dist/pdf.js +12778 -0
- package/pdfjs/dist/pdf_link_service.js +638 -0
- package/pdfjs/dist/pdf_rendering_queue.js +199 -0
- package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
- package/pdfjs/dist/pdf_viewer.js +3598 -0
- package/pdfjs/dist/typeof.js +100 -0
- package/pdfjs/dist/ui_utils.js +1033 -0
- package/{src/shared → pdfjs/dist}/util.js +301 -287
- package/pdfjs/dist/worker.js +62813 -0
- package/src/vcf-pdf-viewer.js +77 -27
- package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
- package/theme/material/vcf-pdf-viewer.js +2 -2
- package/src/core/.eslintrc +0 -13
- package/src/core/annotation.js +0 -2948
- package/src/core/arithmetic_decoder.js +0 -182
- package/src/core/ascii_85_stream.js +0 -98
- package/src/core/ascii_hex_stream.js +0 -79
- package/src/core/base_stream.js +0 -110
- package/src/core/bidi.js +0 -438
- package/src/core/calibri_factors.js +0 -308
- package/src/core/catalog.js +0 -1459
- package/src/core/ccitt.js +0 -1062
- package/src/core/ccitt_stream.js +0 -60
- package/src/core/cff_font.js +0 -116
- package/src/core/cff_parser.js +0 -1949
- package/src/core/charsets.js +0 -119
- package/src/core/chunked_stream.js +0 -557
- package/src/core/cmap.js +0 -1039
- package/src/core/colorspace.js +0 -1533
- package/src/core/core_utils.js +0 -464
- package/src/core/crypto.js +0 -1900
- package/src/core/decode_stream.js +0 -170
- package/src/core/decrypt_stream.js +0 -59
- package/src/core/default_appearance.js +0 -99
- package/src/core/document.js +0 -1456
- package/src/core/encodings.js +0 -301
- package/src/core/evaluator.js +0 -4601
- package/src/core/file_spec.js +0 -108
- package/src/core/flate_stream.js +0 -402
- package/src/core/font_renderer.js +0 -882
- package/src/core/fonts.js +0 -3260
- package/src/core/fonts_utils.js +0 -221
- package/src/core/function.js +0 -1257
- package/src/core/glyf.js +0 -706
- package/src/core/glyphlist.js +0 -4558
- package/src/core/helvetica_factors.js +0 -353
- package/src/core/image.js +0 -802
- package/src/core/image_utils.js +0 -291
- package/src/core/jbig2.js +0 -2572
- package/src/core/jbig2_stream.js +0 -73
- package/src/core/jpeg_stream.js +0 -105
- package/src/core/jpg.js +0 -1416
- package/src/core/jpx.js +0 -2343
- package/src/core/jpx_stream.js +0 -87
- package/src/core/liberationsans_widths.js +0 -221
- package/src/core/lzw_stream.js +0 -150
- package/src/core/metadata_parser.js +0 -146
- package/src/core/metrics.js +0 -2970
- package/src/core/murmurhash3.js +0 -139
- package/src/core/myriadpro_factors.js +0 -290
- package/src/core/name_number_tree.js +0 -153
- package/src/core/object_loader.js +0 -149
- package/src/core/opentype_file_builder.js +0 -154
- package/src/core/operator_list.js +0 -734
- package/src/core/parser.js +0 -1416
- package/src/core/pattern.js +0 -985
- package/src/core/pdf_manager.js +0 -217
- package/src/core/predictor_stream.js +0 -238
- package/src/core/primitives.js +0 -402
- package/src/core/ps_parser.js +0 -272
- package/src/core/run_length_stream.js +0 -61
- package/src/core/segoeui_factors.js +0 -308
- package/src/core/standard_fonts.js +0 -817
- package/src/core/stream.js +0 -103
- package/src/core/struct_tree.js +0 -335
- package/src/core/to_unicode_map.js +0 -103
- package/src/core/type1_font.js +0 -421
- package/src/core/type1_parser.js +0 -776
- package/src/core/unicode.js +0 -1649
- package/src/core/worker.js +0 -848
- package/src/core/worker_stream.js +0 -135
- package/src/core/writer.js +0 -278
- package/src/core/xfa/bind.js +0 -652
- package/src/core/xfa/builder.js +0 -207
- package/src/core/xfa/config.js +0 -1926
- package/src/core/xfa/connection_set.js +0 -202
- package/src/core/xfa/data.js +0 -82
- package/src/core/xfa/datasets.js +0 -76
- package/src/core/xfa/factory.js +0 -111
- package/src/core/xfa/fonts.js +0 -181
- package/src/core/xfa/formcalc_lexer.js +0 -385
- package/src/core/xfa/formcalc_parser.js +0 -1340
- package/src/core/xfa/html_utils.js +0 -639
- package/src/core/xfa/layout.js +0 -383
- package/src/core/xfa/locale_set.js +0 -345
- package/src/core/xfa/namespaces.js +0 -81
- package/src/core/xfa/parser.js +0 -184
- package/src/core/xfa/setup.js +0 -38
- package/src/core/xfa/signature.js +0 -40
- package/src/core/xfa/som.js +0 -338
- package/src/core/xfa/stylesheet.js +0 -40
- package/src/core/xfa/template.js +0 -6260
- package/src/core/xfa/text.js +0 -290
- package/src/core/xfa/unknown.js +0 -29
- package/src/core/xfa/utils.js +0 -217
- package/src/core/xfa/xdp.js +0 -59
- package/src/core/xfa/xfa_object.js +0 -1130
- package/src/core/xfa/xhtml.js +0 -543
- package/src/core/xfa_fonts.js +0 -208
- package/src/core/xml_parser.js +0 -507
- package/src/core/xref.js +0 -899
- package/src/display/annotation_layer.js +0 -2107
- package/src/display/annotation_storage.js +0 -113
- package/src/display/api.js +0 -3292
- package/src/display/base_factory.js +0 -180
- package/src/display/canvas.js +0 -2828
- package/src/display/font_loader.js +0 -484
- package/src/display/metadata.js +0 -41
- package/src/display/network_utils.js +0 -100
- package/src/display/node_utils.js +0 -83
- package/src/display/optional_content_config.js +0 -189
- package/src/display/pattern_helper.js +0 -659
- package/src/display/svg.js +0 -1709
- package/src/display/text_layer.js +0 -847
- package/src/display/transport_stream.js +0 -303
- package/src/display/worker_options.js +0 -40
- package/src/display/xfa_layer.js +0 -204
- package/src/doc_helper.js +0 -25
- package/src/images/logo.svg +0 -41
- package/src/interfaces.js +0 -169
- package/src/license_header.js +0 -14
- package/src/license_header_libre.js +0 -21
- package/src/pdf.image_decoders.js +0 -46
- package/src/pdf.js +0 -146
- package/src/pdf.sandbox.external.js +0 -181
- package/src/pdf.sandbox.js +0 -151
- package/src/pdf.scripting.js +0 -25
- package/src/pdf.worker.entry.js +0 -19
- package/src/pdf.worker.js +0 -23
- package/src/scripting_api/aform.js +0 -608
- package/src/scripting_api/app.js +0 -621
- package/src/scripting_api/color.js +0 -129
- package/src/scripting_api/common.js +0 -58
- package/src/scripting_api/console.js +0 -38
- package/src/scripting_api/constants.js +0 -208
- package/src/scripting_api/doc.js +0 -1195
- package/src/scripting_api/error.js +0 -23
- package/src/scripting_api/event.js +0 -232
- package/src/scripting_api/field.js +0 -620
- package/src/scripting_api/fullscreen.js +0 -145
- package/src/scripting_api/initialization.js +0 -223
- package/src/scripting_api/pdf_object.js +0 -24
- package/src/scripting_api/print_params.js +0 -146
- package/src/scripting_api/proxy.js +0 -139
- package/src/scripting_api/thermometer.js +0 -69
- package/src/scripting_api/util.js +0 -581
- package/src/shared/.eslintrc +0 -13
- package/src/shared/cffStandardStrings.js +0 -311
- package/src/shared/compatibility.js +0 -114
- package/src/shared/fonts_utils.js +0 -429
- package/src/shared/is_node.js +0 -27
- package/src/shared/scripting_utils.js +0 -85
- package/src/worker_loader.js +0 -32
package/src/core/primitives.js
DELETED
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
/* Copyright 2012 Mozilla Foundation
|
|
2
|
-
*
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { assert, shadow, unreachable } from "../shared/util.js";
|
|
17
|
-
import { BaseStream } from "./base_stream.js";
|
|
18
|
-
|
|
19
|
-
const EOF = {};
|
|
20
|
-
|
|
21
|
-
const Name = (function NameClosure() {
|
|
22
|
-
let nameCache = Object.create(null);
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line no-shadow
|
|
25
|
-
class Name {
|
|
26
|
-
constructor(name) {
|
|
27
|
-
this.name = name;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static get(name) {
|
|
31
|
-
const nameValue = nameCache[name];
|
|
32
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
33
|
-
return nameValue ? nameValue : (nameCache[name] = new Name(name));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static _clearCache() {
|
|
37
|
-
nameCache = Object.create(null);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return Name;
|
|
42
|
-
})();
|
|
43
|
-
|
|
44
|
-
const Cmd = (function CmdClosure() {
|
|
45
|
-
let cmdCache = Object.create(null);
|
|
46
|
-
|
|
47
|
-
// eslint-disable-next-line no-shadow
|
|
48
|
-
class Cmd {
|
|
49
|
-
constructor(cmd) {
|
|
50
|
-
this.cmd = cmd;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static get(cmd) {
|
|
54
|
-
const cmdValue = cmdCache[cmd];
|
|
55
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
56
|
-
return cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static _clearCache() {
|
|
60
|
-
cmdCache = Object.create(null);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return Cmd;
|
|
65
|
-
})();
|
|
66
|
-
|
|
67
|
-
const nonSerializable = function nonSerializableClosure() {
|
|
68
|
-
return nonSerializable; // Creating closure on some variable.
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
class Dict {
|
|
72
|
-
constructor(xref = null) {
|
|
73
|
-
// Map should only be used internally, use functions below to access.
|
|
74
|
-
this._map = Object.create(null);
|
|
75
|
-
this.xref = xref;
|
|
76
|
-
this.objId = null;
|
|
77
|
-
this.suppressEncryption = false;
|
|
78
|
-
this.__nonSerializable__ = nonSerializable; // Disable cloning of the Dict.
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
assignXref(newXref) {
|
|
82
|
-
this.xref = newXref;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get size() {
|
|
86
|
-
return Object.keys(this._map).length;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Automatically dereferences Ref objects.
|
|
90
|
-
get(key1, key2, key3) {
|
|
91
|
-
let value = this._map[key1];
|
|
92
|
-
if (value === undefined && key2 !== undefined) {
|
|
93
|
-
value = this._map[key2];
|
|
94
|
-
if (value === undefined && key3 !== undefined) {
|
|
95
|
-
value = this._map[key3];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (value instanceof Ref && this.xref) {
|
|
99
|
-
return this.xref.fetch(value, this.suppressEncryption);
|
|
100
|
-
}
|
|
101
|
-
return value;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Same as get(), but returns a promise and uses fetchIfRefAsync().
|
|
105
|
-
async getAsync(key1, key2, key3) {
|
|
106
|
-
let value = this._map[key1];
|
|
107
|
-
if (value === undefined && key2 !== undefined) {
|
|
108
|
-
value = this._map[key2];
|
|
109
|
-
if (value === undefined && key3 !== undefined) {
|
|
110
|
-
value = this._map[key3];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (value instanceof Ref && this.xref) {
|
|
114
|
-
return this.xref.fetchAsync(value, this.suppressEncryption);
|
|
115
|
-
}
|
|
116
|
-
return value;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Same as get(), but dereferences all elements if the result is an Array.
|
|
120
|
-
getArray(key1, key2, key3) {
|
|
121
|
-
let value = this._map[key1];
|
|
122
|
-
if (value === undefined && key2 !== undefined) {
|
|
123
|
-
value = this._map[key2];
|
|
124
|
-
if (value === undefined && key3 !== undefined) {
|
|
125
|
-
value = this._map[key3];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (value instanceof Ref && this.xref) {
|
|
129
|
-
value = this.xref.fetch(value, this.suppressEncryption);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (Array.isArray(value)) {
|
|
133
|
-
value = value.slice(); // Ensure that we don't modify the Dict data.
|
|
134
|
-
for (let i = 0, ii = value.length; i < ii; i++) {
|
|
135
|
-
if (value[i] instanceof Ref && this.xref) {
|
|
136
|
-
value[i] = this.xref.fetch(value[i], this.suppressEncryption);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return value;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// No dereferencing.
|
|
144
|
-
getRaw(key) {
|
|
145
|
-
return this._map[key];
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
getKeys() {
|
|
149
|
-
return Object.keys(this._map);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// No dereferencing.
|
|
153
|
-
getRawValues() {
|
|
154
|
-
return Object.values(this._map);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
set(key, value) {
|
|
158
|
-
if (
|
|
159
|
-
(typeof PDFJSDev === "undefined" ||
|
|
160
|
-
PDFJSDev.test("!PRODUCTION || TESTING")) &&
|
|
161
|
-
value === undefined
|
|
162
|
-
) {
|
|
163
|
-
unreachable('Dict.set: The "value" cannot be undefined.');
|
|
164
|
-
}
|
|
165
|
-
this._map[key] = value;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
has(key) {
|
|
169
|
-
return this._map[key] !== undefined;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
forEach(callback) {
|
|
173
|
-
for (const key in this._map) {
|
|
174
|
-
callback(key, this.get(key));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
static get empty() {
|
|
179
|
-
const emptyDict = new Dict(null);
|
|
180
|
-
|
|
181
|
-
emptyDict.set = (key, value) => {
|
|
182
|
-
unreachable("Should not call `set` on the empty dictionary.");
|
|
183
|
-
};
|
|
184
|
-
return shadow(this, "empty", emptyDict);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
static merge({ xref, dictArray, mergeSubDicts = false }) {
|
|
188
|
-
const mergedDict = new Dict(xref),
|
|
189
|
-
properties = new Map();
|
|
190
|
-
|
|
191
|
-
for (const dict of dictArray) {
|
|
192
|
-
if (!(dict instanceof Dict)) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
for (const [key, value] of Object.entries(dict._map)) {
|
|
196
|
-
let property = properties.get(key);
|
|
197
|
-
if (property === undefined) {
|
|
198
|
-
property = [];
|
|
199
|
-
properties.set(key, property);
|
|
200
|
-
} else if (!mergeSubDicts) {
|
|
201
|
-
continue; // Ignore additional entries for a "shallow" merge.
|
|
202
|
-
}
|
|
203
|
-
property.push(value);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
for (const [name, values] of properties) {
|
|
207
|
-
if (values.length === 1 || !(values[0] instanceof Dict)) {
|
|
208
|
-
mergedDict._map[name] = values[0];
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
const subDict = new Dict(xref);
|
|
212
|
-
|
|
213
|
-
for (const dict of values) {
|
|
214
|
-
if (!(dict instanceof Dict)) {
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
for (const [key, value] of Object.entries(dict._map)) {
|
|
218
|
-
if (subDict._map[key] === undefined) {
|
|
219
|
-
subDict._map[key] = value;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (subDict.size > 0) {
|
|
224
|
-
mergedDict._map[name] = subDict;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
properties.clear();
|
|
228
|
-
|
|
229
|
-
return mergedDict.size > 0 ? mergedDict : Dict.empty;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const Ref = (function RefClosure() {
|
|
234
|
-
let refCache = Object.create(null);
|
|
235
|
-
|
|
236
|
-
// eslint-disable-next-line no-shadow
|
|
237
|
-
class Ref {
|
|
238
|
-
constructor(num, gen) {
|
|
239
|
-
this.num = num;
|
|
240
|
-
this.gen = gen;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
toString() {
|
|
244
|
-
// This function is hot, so we make the string as compact as possible.
|
|
245
|
-
// |this.gen| is almost always zero, so we treat that case specially.
|
|
246
|
-
if (this.gen === 0) {
|
|
247
|
-
return `${this.num}R`;
|
|
248
|
-
}
|
|
249
|
-
return `${this.num}R${this.gen}`;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
static get(num, gen) {
|
|
253
|
-
const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
|
|
254
|
-
const refValue = refCache[key];
|
|
255
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
256
|
-
return refValue ? refValue : (refCache[key] = new Ref(num, gen));
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
static _clearCache() {
|
|
260
|
-
refCache = Object.create(null);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return Ref;
|
|
265
|
-
})();
|
|
266
|
-
|
|
267
|
-
// The reference is identified by number and generation.
|
|
268
|
-
// This structure stores only one instance of the reference.
|
|
269
|
-
class RefSet {
|
|
270
|
-
constructor(parent = null) {
|
|
271
|
-
if (
|
|
272
|
-
(typeof PDFJSDev === "undefined" ||
|
|
273
|
-
PDFJSDev.test("!PRODUCTION || TESTING")) &&
|
|
274
|
-
parent &&
|
|
275
|
-
!(parent instanceof RefSet)
|
|
276
|
-
) {
|
|
277
|
-
unreachable('RefSet: Invalid "parent" value.');
|
|
278
|
-
}
|
|
279
|
-
this._set = new Set(parent && parent._set);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
has(ref) {
|
|
283
|
-
return this._set.has(ref.toString());
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
put(ref) {
|
|
287
|
-
this._set.add(ref.toString());
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
remove(ref) {
|
|
291
|
-
this._set.delete(ref.toString());
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
forEach(callback) {
|
|
295
|
-
for (const ref of this._set.values()) {
|
|
296
|
-
callback(ref);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
clear() {
|
|
301
|
-
this._set.clear();
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
class RefSetCache {
|
|
306
|
-
constructor() {
|
|
307
|
-
this._map = new Map();
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
get size() {
|
|
311
|
-
return this._map.size;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
get(ref) {
|
|
315
|
-
return this._map.get(ref.toString());
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
has(ref) {
|
|
319
|
-
return this._map.has(ref.toString());
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
put(ref, obj) {
|
|
323
|
-
this._map.set(ref.toString(), obj);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
putAlias(ref, aliasRef) {
|
|
327
|
-
this._map.set(ref.toString(), this.get(aliasRef));
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
forEach(callback) {
|
|
331
|
-
for (const value of this._map.values()) {
|
|
332
|
-
callback(value);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
clear() {
|
|
337
|
-
this._map.clear();
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
function isEOF(v) {
|
|
342
|
-
return v === EOF;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function isName(v, name) {
|
|
346
|
-
return v instanceof Name && (name === undefined || v.name === name);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function isCmd(v, cmd) {
|
|
350
|
-
return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function isDict(v, type) {
|
|
354
|
-
return (
|
|
355
|
-
v instanceof Dict && (type === undefined || isName(v.get("Type"), type))
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function isRef(v) {
|
|
360
|
-
return v instanceof Ref;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function isRefsEqual(v1, v2) {
|
|
364
|
-
if (
|
|
365
|
-
typeof PDFJSDev === "undefined" ||
|
|
366
|
-
PDFJSDev.test("!PRODUCTION || TESTING")
|
|
367
|
-
) {
|
|
368
|
-
assert(
|
|
369
|
-
v1 instanceof Ref && v2 instanceof Ref,
|
|
370
|
-
"isRefsEqual: Both parameters should be `Ref`s."
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
return v1.num === v2.num && v1.gen === v2.gen;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
function isStream(v) {
|
|
377
|
-
return v instanceof BaseStream;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
function clearPrimitiveCaches() {
|
|
381
|
-
Cmd._clearCache();
|
|
382
|
-
Name._clearCache();
|
|
383
|
-
Ref._clearCache();
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
export {
|
|
387
|
-
clearPrimitiveCaches,
|
|
388
|
-
Cmd,
|
|
389
|
-
Dict,
|
|
390
|
-
EOF,
|
|
391
|
-
isCmd,
|
|
392
|
-
isDict,
|
|
393
|
-
isEOF,
|
|
394
|
-
isName,
|
|
395
|
-
isRef,
|
|
396
|
-
isRefsEqual,
|
|
397
|
-
isStream,
|
|
398
|
-
Name,
|
|
399
|
-
Ref,
|
|
400
|
-
RefSet,
|
|
401
|
-
RefSetCache,
|
|
402
|
-
};
|
package/src/core/ps_parser.js
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
/* Copyright 2014 Mozilla Foundation
|
|
2
|
-
*
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { FormatError, shadow } from "../shared/util.js";
|
|
17
|
-
import { EOF } from "./primitives.js";
|
|
18
|
-
import { isWhiteSpace } from "./core_utils.js";
|
|
19
|
-
|
|
20
|
-
class PostScriptParser {
|
|
21
|
-
constructor(lexer) {
|
|
22
|
-
this.lexer = lexer;
|
|
23
|
-
this.operators = [];
|
|
24
|
-
this.token = null;
|
|
25
|
-
this.prev = null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
nextToken() {
|
|
29
|
-
this.prev = this.token;
|
|
30
|
-
this.token = this.lexer.getToken();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
accept(type) {
|
|
34
|
-
if (this.token.type === type) {
|
|
35
|
-
this.nextToken();
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
expect(type) {
|
|
42
|
-
if (this.accept(type)) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
throw new FormatError(
|
|
46
|
-
`Unexpected symbol: found ${this.token.type} expected ${type}.`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
parse() {
|
|
51
|
-
this.nextToken();
|
|
52
|
-
this.expect(PostScriptTokenTypes.LBRACE);
|
|
53
|
-
this.parseBlock();
|
|
54
|
-
this.expect(PostScriptTokenTypes.RBRACE);
|
|
55
|
-
return this.operators;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
parseBlock() {
|
|
59
|
-
while (true) {
|
|
60
|
-
if (this.accept(PostScriptTokenTypes.NUMBER)) {
|
|
61
|
-
this.operators.push(this.prev.value);
|
|
62
|
-
} else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
|
|
63
|
-
this.operators.push(this.prev.value);
|
|
64
|
-
} else if (this.accept(PostScriptTokenTypes.LBRACE)) {
|
|
65
|
-
this.parseCondition();
|
|
66
|
-
} else {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
parseCondition() {
|
|
73
|
-
// Add two place holders that will be updated later
|
|
74
|
-
const conditionLocation = this.operators.length;
|
|
75
|
-
this.operators.push(null, null);
|
|
76
|
-
|
|
77
|
-
this.parseBlock();
|
|
78
|
-
this.expect(PostScriptTokenTypes.RBRACE);
|
|
79
|
-
if (this.accept(PostScriptTokenTypes.IF)) {
|
|
80
|
-
// The true block is right after the 'if' so it just falls through on true
|
|
81
|
-
// else it jumps and skips the true block.
|
|
82
|
-
this.operators[conditionLocation] = this.operators.length;
|
|
83
|
-
this.operators[conditionLocation + 1] = "jz";
|
|
84
|
-
} else if (this.accept(PostScriptTokenTypes.LBRACE)) {
|
|
85
|
-
const jumpLocation = this.operators.length;
|
|
86
|
-
this.operators.push(null, null);
|
|
87
|
-
const endOfTrue = this.operators.length;
|
|
88
|
-
this.parseBlock();
|
|
89
|
-
this.expect(PostScriptTokenTypes.RBRACE);
|
|
90
|
-
this.expect(PostScriptTokenTypes.IFELSE);
|
|
91
|
-
// The jump is added at the end of the true block to skip the false block.
|
|
92
|
-
this.operators[jumpLocation] = this.operators.length;
|
|
93
|
-
this.operators[jumpLocation + 1] = "j";
|
|
94
|
-
|
|
95
|
-
this.operators[conditionLocation] = endOfTrue;
|
|
96
|
-
this.operators[conditionLocation + 1] = "jz";
|
|
97
|
-
} else {
|
|
98
|
-
throw new FormatError("PS Function: error parsing conditional.");
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const PostScriptTokenTypes = {
|
|
104
|
-
LBRACE: 0,
|
|
105
|
-
RBRACE: 1,
|
|
106
|
-
NUMBER: 2,
|
|
107
|
-
OPERATOR: 3,
|
|
108
|
-
IF: 4,
|
|
109
|
-
IFELSE: 5,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
class PostScriptToken {
|
|
113
|
-
static get opCache() {
|
|
114
|
-
return shadow(this, "opCache", Object.create(null));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
constructor(type, value) {
|
|
118
|
-
this.type = type;
|
|
119
|
-
this.value = value;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
static getOperator(op) {
|
|
123
|
-
const opValue = PostScriptToken.opCache[op];
|
|
124
|
-
if (opValue) {
|
|
125
|
-
return opValue;
|
|
126
|
-
}
|
|
127
|
-
return (PostScriptToken.opCache[op] = new PostScriptToken(
|
|
128
|
-
PostScriptTokenTypes.OPERATOR,
|
|
129
|
-
op
|
|
130
|
-
));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
static get LBRACE() {
|
|
134
|
-
return shadow(
|
|
135
|
-
this,
|
|
136
|
-
"LBRACE",
|
|
137
|
-
new PostScriptToken(PostScriptTokenTypes.LBRACE, "{")
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
static get RBRACE() {
|
|
142
|
-
return shadow(
|
|
143
|
-
this,
|
|
144
|
-
"RBRACE",
|
|
145
|
-
new PostScriptToken(PostScriptTokenTypes.RBRACE, "}")
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
static get IF() {
|
|
150
|
-
return shadow(
|
|
151
|
-
this,
|
|
152
|
-
"IF",
|
|
153
|
-
new PostScriptToken(PostScriptTokenTypes.IF, "IF")
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
static get IFELSE() {
|
|
158
|
-
return shadow(
|
|
159
|
-
this,
|
|
160
|
-
"IFELSE",
|
|
161
|
-
new PostScriptToken(PostScriptTokenTypes.IFELSE, "IFELSE")
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
class PostScriptLexer {
|
|
167
|
-
constructor(stream) {
|
|
168
|
-
this.stream = stream;
|
|
169
|
-
this.nextChar();
|
|
170
|
-
|
|
171
|
-
this.strBuf = [];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
nextChar() {
|
|
175
|
-
return (this.currentChar = this.stream.getByte());
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
getToken() {
|
|
179
|
-
let comment = false;
|
|
180
|
-
let ch = this.currentChar;
|
|
181
|
-
|
|
182
|
-
// skip comments
|
|
183
|
-
while (true) {
|
|
184
|
-
if (ch < 0) {
|
|
185
|
-
return EOF;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (comment) {
|
|
189
|
-
if (ch === 0x0a || ch === 0x0d) {
|
|
190
|
-
comment = false;
|
|
191
|
-
}
|
|
192
|
-
} else if (ch === /* '%' = */ 0x25) {
|
|
193
|
-
comment = true;
|
|
194
|
-
} else if (!isWhiteSpace(ch)) {
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
ch = this.nextChar();
|
|
198
|
-
}
|
|
199
|
-
switch (ch | 0) {
|
|
200
|
-
case 0x30: // '0'
|
|
201
|
-
case 0x31: // '1'
|
|
202
|
-
case 0x32: // '2'
|
|
203
|
-
case 0x33: // '3'
|
|
204
|
-
case 0x34: // '4'
|
|
205
|
-
case 0x35: // '5'
|
|
206
|
-
case 0x36: // '6'
|
|
207
|
-
case 0x37: // '7'
|
|
208
|
-
case 0x38: // '8'
|
|
209
|
-
case 0x39: // '9'
|
|
210
|
-
case 0x2b: // '+'
|
|
211
|
-
case 0x2d: // '-'
|
|
212
|
-
case 0x2e: // '.'
|
|
213
|
-
return new PostScriptToken(
|
|
214
|
-
PostScriptTokenTypes.NUMBER,
|
|
215
|
-
this.getNumber()
|
|
216
|
-
);
|
|
217
|
-
case 0x7b: // '{'
|
|
218
|
-
this.nextChar();
|
|
219
|
-
return PostScriptToken.LBRACE;
|
|
220
|
-
case 0x7d: // '}'
|
|
221
|
-
this.nextChar();
|
|
222
|
-
return PostScriptToken.RBRACE;
|
|
223
|
-
}
|
|
224
|
-
// operator
|
|
225
|
-
const strBuf = this.strBuf;
|
|
226
|
-
strBuf.length = 0;
|
|
227
|
-
strBuf[0] = String.fromCharCode(ch);
|
|
228
|
-
|
|
229
|
-
while (
|
|
230
|
-
(ch = this.nextChar()) >= 0 &&
|
|
231
|
-
((ch >= /* 'A' = */ 0x41 && ch <= /* 'Z' = */ 0x5a) ||
|
|
232
|
-
(ch >= /* 'a' = */ 0x61 && ch <= /* 'z' = */ 0x7a))
|
|
233
|
-
) {
|
|
234
|
-
strBuf.push(String.fromCharCode(ch));
|
|
235
|
-
}
|
|
236
|
-
const str = strBuf.join("");
|
|
237
|
-
switch (str.toLowerCase()) {
|
|
238
|
-
case "if":
|
|
239
|
-
return PostScriptToken.IF;
|
|
240
|
-
case "ifelse":
|
|
241
|
-
return PostScriptToken.IFELSE;
|
|
242
|
-
default:
|
|
243
|
-
return PostScriptToken.getOperator(str);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
getNumber() {
|
|
248
|
-
let ch = this.currentChar;
|
|
249
|
-
const strBuf = this.strBuf;
|
|
250
|
-
strBuf.length = 0;
|
|
251
|
-
strBuf[0] = String.fromCharCode(ch);
|
|
252
|
-
|
|
253
|
-
while ((ch = this.nextChar()) >= 0) {
|
|
254
|
-
if (
|
|
255
|
-
(ch >= /* '0' = */ 0x30 && ch <= /* '9' = */ 0x39) ||
|
|
256
|
-
ch === /* '-' = */ 0x2d ||
|
|
257
|
-
ch === /* '.' = */ 0x2e
|
|
258
|
-
) {
|
|
259
|
-
strBuf.push(String.fromCharCode(ch));
|
|
260
|
-
} else {
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
const value = parseFloat(strBuf.join(""));
|
|
265
|
-
if (isNaN(value)) {
|
|
266
|
-
throw new FormatError(`Invalid floating point number: ${value}`);
|
|
267
|
-
}
|
|
268
|
-
return value;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export { PostScriptLexer, PostScriptParser };
|