@syzlm/ofdparser 0.0.1
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/.babelrc +14 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +18 -0
- package/.prettierrc.json +9 -0
- package/dist/OFD.d.ts +8 -0
- package/dist/Pages.d.ts +7 -0
- package/dist/RootDocumnet.d.ts +1 -0
- package/dist/bundle.cjs.js +64123 -0
- package/dist/bundle.esm.js +64115 -0
- package/dist/bundle.iife.js +14743 -0
- package/dist/bundle.umd.js +64045 -0
- package/dist/constant/index.d.ts +7 -0
- package/dist/constant.d.ts +6 -0
- package/dist/core/ofd-core/Annotations/AnnotationsXml.d.ts +16 -0
- package/dist/core/ofd-core/Asn.1Utils.d.ts +47 -0
- package/dist/core/ofd-core/Documents/DocumentResXml.d.ts +15 -0
- package/dist/core/ofd-core/Documents/DocumnetXml.d.ts +25 -0
- package/dist/core/ofd-core/Documents/PublicResXml.d.ts +15 -0
- package/dist/core/ofd-core/OFDElement.d.ts +232 -0
- package/dist/core/ofd-core/Ofd/OFDXml.d.ts +19 -0
- package/dist/core/ofd-core/Pages/PageXml.d.ts +20 -0
- package/dist/core/ofd-core/Signatures/Signatures.d.ts +20 -0
- package/dist/core/ofd-core/TemplatePages/TemplatePages.d.ts +20 -0
- package/dist/core/ofd-core/constant.d.ts +29 -0
- package/dist/core/ofd-core/utils.d.ts +21 -0
- package/dist/dicom/dicom.d.ts +15 -0
- package/dist/dicom/index.d.ts +1 -0
- package/dist/errors/ErrorHandle.d.ts +6 -0
- package/dist/errors/ErrorMsg.d.ts +16 -0
- package/dist/errors/FetchErrors.d.ts +4 -0
- package/dist/errors/MimeError.d.ts +4 -0
- package/dist/errors/OFDErrors.d.ts +4 -0
- package/dist/errors/UnzipErrors.d.ts +4 -0
- package/dist/errors/XmlErrors.d.ts +4 -0
- package/dist/errors/error-msg.d.ts +9 -0
- package/dist/es.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/lib/ParseFile.d.ts +7 -0
- package/dist/lib/UnitCoversion.d.ts +31 -0
- package/dist/lib/asn1/Asn.1.d.ts +34 -0
- package/dist/lib/asn1/Stream.d.ts +27 -0
- package/dist/lib/asn1/asn1.d.ts +4 -0
- package/dist/lib/asn1/base64.d.ts +4 -0
- package/dist/lib/asn1/hex.d.ts +5 -0
- package/dist/lib/asn1/index.d.ts +5 -0
- package/dist/lib/asn1/int10.d.ts +34 -0
- package/dist/lib/asn1/oids.d.ts +2 -0
- package/dist/lib/asn1/string-cut.d.ts +2 -0
- package/dist/lib/decode-html.d.ts +7 -0
- package/dist/lib/fetch.d.ts +17 -0
- package/dist/lib/is-element.d.ts +5 -0
- package/dist/lib/load-files.d.ts +3 -0
- package/dist/lib/load-opentype.d.ts +34 -0
- package/dist/lib/load-script.d.ts +1 -0
- package/dist/lib/mime.d.ts +8 -0
- package/dist/lib/read-buffer.d.ts +2 -0
- package/dist/lib/toFixeds.d.ts +7 -0
- package/dist/libs/Asn.1Utils.d.ts +47 -0
- package/dist/libs/asn1/Asn.1.d.ts +34 -0
- package/dist/libs/asn1/Stream.d.ts +27 -0
- package/dist/libs/asn1/asn1.d.ts +4 -0
- package/dist/libs/asn1/base64.d.ts +4 -0
- package/dist/libs/asn1/hex.d.ts +5 -0
- package/dist/libs/asn1/index.d.ts +5 -0
- package/dist/libs/asn1/int10.d.ts +34 -0
- package/dist/libs/asn1/oids.d.ts +2 -0
- package/dist/libs/asn1/string-cut.d.ts +2 -0
- package/dist/libs/decode-html.d.ts +7 -0
- package/dist/libs/fetch.d.ts +17 -0
- package/dist/libs/mime.d.ts +8 -0
- package/dist/libs/ofdArray.d.ts +10 -0
- package/dist/libs/ofdImageObject.d.ts +9 -0
- package/dist/libs/ofdLayer.d.ts +3 -0
- package/dist/libs/ofdName.d.ts +17 -0
- package/dist/libs/ofdPathObject.d.ts +11 -0
- package/dist/libs/ofdTextObject.d.ts +6 -0
- package/dist/libs/parseAnnotation.d.ts +5 -0
- package/dist/libs/parseColor.d.ts +5 -0
- package/dist/libs/parsePageArea.d.ts +17 -0
- package/dist/libs/parser-elements.d.ts +8 -0
- package/dist/libs/parserElements.d.ts +8 -0
- package/dist/libs/pipeExtensions.d.ts +4 -0
- package/dist/libs/read-buffer.d.ts +2 -0
- package/dist/main.d.ts +15 -0
- package/dist/ofd/ConverterDpi.d.ts +16 -0
- package/dist/ofd/index.d.ts +1 -0
- package/dist/ofd/ofd-utils.d.ts +137 -0
- package/dist/ofd/ofd.d.ts +35 -0
- package/dist/ofd/parse-ofd.d.ts +18 -0
- package/dist/ofd/render.d.ts +18 -0
- package/dist/ofd/svg-image.d.ts +12 -0
- package/dist/ofd/svg-path.d.ts +5 -0
- package/dist/ofd/svg-text.d.ts +8 -0
- package/dist/ofd.parse.d.ts +6 -0
- package/dist/ofd.xml.d.ts +1 -0
- package/dist/ofdParse.d.ts +6 -0
- package/dist/pipe/annotations.d.ts +13 -0
- package/dist/pipe/attachments.d.ts +13 -0
- package/dist/pipe/commonData.d.ts +18 -0
- package/dist/pipe/customTags.d.ts +14 -0
- package/dist/pipe/extensions.d.ts +14 -0
- package/dist/pipe/output.d.ts +7 -0
- package/dist/pipe/pages.d.ts +13 -0
- package/dist/pipe/permissions.d.ts +14 -0
- package/dist/pipe/pipeline.d.ts +63 -0
- package/dist/pipe/startPipe.d.ts +11 -0
- package/dist/xml/index.d.ts +2 -0
- package/dist/xml/render.d.ts +6 -0
- package/dist/xml/xml.d.ts +18 -0
- package/package.json +47 -0
- package/public/index.html +75 -0
- package/public/opentype.min.js +2 -0
- package/rollup.config.dev.mjs +47 -0
- package/rollup.config.mjs +70 -0
- package/src/constant/index.ts +13 -0
- package/src/core/ofd-core/Annotations/Annotation.km +206 -0
- package/src/core/ofd-core/Annotations/Annotations.km +59 -0
- package/src/core/ofd-core/Annotations/Annotations.md +13 -0
- package/src/core/ofd-core/Annotations/AnnotationsXml.ts +114 -0
- package/src/core/ofd-core/Asn.1Utils.ts +225 -0
- package/src/core/ofd-core/Documents/DocumentResXml.ts +55 -0
- package/src/core/ofd-core/Documents/Documnet.km +862 -0
- package/src/core/ofd-core/Documents/DocumnetXml.ts +118 -0
- package/src/core/ofd-core/Documents/Documnets.md +296 -0
- package/src/core/ofd-core/Documents/PublicResXml.ts +63 -0
- package/src/core/ofd-core/Documents//345/233/276/345/261/202/346/270/262/346/237/223/351/241/272/345/272/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25022/347/272/277/346/235/241/350/277/236/346/216/245/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25023/347/272/277/346/235/241/350/231/232/347/272/277/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25023/347/273/223/345/220/210/347/202/271/351/225/277/345/272/246.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25024/347/272/277/346/235/241/347/253/257/347/202/271/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//351/241/265/350/276/271/347/225/214/345/261/202/346/254/241/347/273/223/346/236/204.png +0 -0
- package/src/core/ofd-core/OFDElement.ts +724 -0
- package/src/core/ofd-core/Ofd/CT_DocInfo.km +197 -0
- package/src/core/ofd-core/Ofd/OFD.km +114 -0
- package/src/core/ofd-core/Ofd/OFD.md +99 -0
- package/src/core/ofd-core/Ofd/OFDXml.ts +69 -0
- package/src/core/ofd-core/Pages/PAGE.md +40 -0
- package/src/core/ofd-core/Pages/PageXml.ts +59 -0
- package/src/core/ofd-core/Signatures/Signature.km +308 -0
- package/src/core/ofd-core/Signatures/Signature.md +21 -0
- package/src/core/ofd-core/Signatures/Signatures.km +315 -0
- package/src/core/ofd-core/Signatures/Signatures.md +24 -0
- package/src/core/ofd-core/Signatures/Signatures.ts +247 -0
- package/src/core/ofd-core/TemplatePages/TemplatePages.ts +56 -0
- package/src/core/ofd-core/asn.md +60 -0
- package/src/core/ofd-core/constant.ts +35 -0
- package/src/core/ofd-core/index.d.ts +867 -0
- package/src/core/ofd-core/utils.ts +86 -0
- package/src/dicom/dicom.ts +42 -0
- package/src/dicom/index.ts +1 -0
- package/src/errors/ErrorHandle.ts +14 -0
- package/src/errors/FetchErrors.ts +8 -0
- package/src/errors/MimeError.ts +9 -0
- package/src/errors/OFDErrors.ts +11 -0
- package/src/errors/UnzipErrors.ts +9 -0
- package/src/errors/XmlErrors.ts +11 -0
- package/src/errors/error-msg.ts +17 -0
- package/src/es.ts +3 -0
- package/src/global.d.ts +7 -0
- package/src/index.ts +7 -0
- package/src/lib/ParseFile.ts +12 -0
- package/src/lib/README.md +69 -0
- package/src/lib/UnitCoversion.ts +55 -0
- package/src/lib/asn1/Asn.1.ts +284 -0
- package/src/lib/asn1/README.md +1 -0
- package/src/lib/asn1/Stream.ts +314 -0
- package/src/lib/asn1/asn1.ts +120 -0
- package/src/lib/asn1/base64.ts +97 -0
- package/src/lib/asn1/hex.ts +60 -0
- package/src/lib/asn1/index.ts +5 -0
- package/src/lib/asn1/int10.ts +103 -0
- package/src/lib/asn1/oids.ts +6164 -0
- package/src/lib/asn1/string-cut.ts +8 -0
- package/src/lib/decode-html.ts +37 -0
- package/src/lib/fetch.ts +70 -0
- package/src/lib/is-element.ts +13 -0
- package/src/lib/jbig/README.md +1 -0
- package/src/lib/jbig/arithmetic_decoder.js +184 -0
- package/src/lib/jbig/base_stream.js +117 -0
- package/src/lib/jbig/ccitt.js +1068 -0
- package/src/lib/jbig/ccitt_stream.js +60 -0
- package/src/lib/jbig/compatibility.js +108 -0
- package/src/lib/jbig/core_utils.js +591 -0
- package/src/lib/jbig/decode_stream.js +184 -0
- package/src/lib/jbig/is_node.js +28 -0
- package/src/lib/jbig/jbig2.js +2582 -0
- package/src/lib/jbig/jbig2_stream.js +78 -0
- package/src/lib/jbig/primitives.js +441 -0
- package/src/lib/jbig/stream.js +101 -0
- package/src/lib/jbig/util.js +1231 -0
- package/src/lib/load-files.ts +26 -0
- package/src/lib/load-opentype.ts +161 -0
- package/src/lib/load-script.ts +33 -0
- package/src/lib/mime.ts +97 -0
- package/src/lib/read-buffer.ts +19 -0
- package/src/lib/toFixeds.ts +56 -0
- package/src/ofd/ConverterDpi.ts +35 -0
- package/src/ofd/OFD.md +38 -0
- package/src/ofd/TODO.md +10 -0
- package/src/ofd/index.ts +1 -0
- package/src/ofd/ofd-utils.ts +627 -0
- package/src/ofd/ofd.demo.md +12 -0
- package/src/ofd/ofd.ts +200 -0
- package/src/ofd/ofdxml.km +162 -0
- package/src/ofd/parse-ofd.ts +103 -0
- package/src/ofd/render.ts +393 -0
- package/src/ofd/svg-image.ts +318 -0
- package/src/ofd/svg-path.ts +283 -0
- package/src/ofd/svg-text.ts +272 -0
- package/src/xml/index.ts +3 -0
- package/src/xml/render.ts +171 -0
- package/src/xml/xml.ts +136 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,78 @@
|
|
|
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 { BaseStream } from './base_stream.js';
|
|
17
|
+
import { DecodeStream } from './decode_stream.js';
|
|
18
|
+
import { Dict } from './primitives.js';
|
|
19
|
+
import { Jbig2Image } from './jbig2.js';
|
|
20
|
+
import { shadow } from './util.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* For JBIG2's we use a library to decode these images and
|
|
24
|
+
* the stream behaves like all the other DecodeStreams.
|
|
25
|
+
*/
|
|
26
|
+
class Jbig2Stream extends DecodeStream {
|
|
27
|
+
constructor(stream, maybeLength, params) {
|
|
28
|
+
super(maybeLength);
|
|
29
|
+
|
|
30
|
+
this.stream = stream;
|
|
31
|
+
this.dict = stream.dict;
|
|
32
|
+
this.maybeLength = maybeLength;
|
|
33
|
+
this.params = params;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get bytes() {
|
|
37
|
+
// If `this.maybeLength` is null, we'll get the entire stream.
|
|
38
|
+
return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
|
|
39
|
+
}
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
ensureBuffer(requested) {
|
|
42
|
+
// No-op, since `this.readBlock` will always parse the entire image and
|
|
43
|
+
// directly insert all of its data into `this.buffer`.
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
readBlock() {
|
|
47
|
+
if (this.eof) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const jbig2Image = new Jbig2Image();
|
|
51
|
+
|
|
52
|
+
const chunks = [];
|
|
53
|
+
if (this.params instanceof Dict) {
|
|
54
|
+
const globalsStream = this.params.get('JBIG2Globals');
|
|
55
|
+
if (globalsStream instanceof BaseStream) {
|
|
56
|
+
const globals = globalsStream.getBytes();
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
chunks.push({ data: globals, start: 0, end: globals.length });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
chunks.push({ data: this.bytes, start: 0, end: this.bytes.length });
|
|
62
|
+
const data = jbig2Image.parseChunks(chunks);
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
const dataLength = data.length;
|
|
65
|
+
|
|
66
|
+
// JBIG2 had black as 1 and white as 0, inverting the colors
|
|
67
|
+
for (let i = 0; i < dataLength; i++) {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
data[i] ^= 0xff;
|
|
70
|
+
}
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
this.buffer = data;
|
|
73
|
+
this.bufferLength = dataLength;
|
|
74
|
+
this.eof = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { Jbig2Stream };
|
|
@@ -0,0 +1,441 @@
|
|
|
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 './util.js';
|
|
17
|
+
|
|
18
|
+
const CIRCULAR_REF = Symbol('CIRCULAR_REF');
|
|
19
|
+
const EOF = Symbol('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
|
+
// if (
|
|
28
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
29
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
30
|
+
// typeof name !== 'string'
|
|
31
|
+
// ) {
|
|
32
|
+
// unreachable('Name: The "name" must be a string.');
|
|
33
|
+
// }
|
|
34
|
+
this.name = name;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static get(name) {
|
|
38
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
39
|
+
return nameCache[name] || (nameCache[name] = new Name(name));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static _clearCache() {
|
|
43
|
+
nameCache = Object.create(null);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return Name;
|
|
48
|
+
})();
|
|
49
|
+
|
|
50
|
+
const Cmd = (function CmdClosure() {
|
|
51
|
+
let cmdCache = Object.create(null);
|
|
52
|
+
|
|
53
|
+
// eslint-disable-next-line no-shadow
|
|
54
|
+
class Cmd {
|
|
55
|
+
constructor(cmd) {
|
|
56
|
+
// if (
|
|
57
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
58
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
59
|
+
// typeof cmd !== 'string'
|
|
60
|
+
// ) {
|
|
61
|
+
// unreachable('Cmd: The "cmd" must be a string.');
|
|
62
|
+
// }
|
|
63
|
+
this.cmd = cmd;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static get(cmd) {
|
|
67
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
68
|
+
return cmdCache[cmd] || (cmdCache[cmd] = new Cmd(cmd));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static _clearCache() {
|
|
72
|
+
cmdCache = Object.create(null);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return Cmd;
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
const nonSerializable = function nonSerializableClosure() {
|
|
80
|
+
return nonSerializable; // Creating closure on some variable.
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
class Dict {
|
|
84
|
+
constructor(xref = null) {
|
|
85
|
+
// Map should only be used internally, use functions below to access.
|
|
86
|
+
this._map = Object.create(null);
|
|
87
|
+
this.xref = xref;
|
|
88
|
+
this.objId = null;
|
|
89
|
+
this.suppressEncryption = false;
|
|
90
|
+
this.__nonSerializable__ = nonSerializable; // Disable cloning of the Dict.
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
assignXref(newXref) {
|
|
94
|
+
this.xref = newXref;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get size() {
|
|
98
|
+
return Object.keys(this._map).length;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Automatically dereferences Ref objects.
|
|
102
|
+
get(key1, key2, key3) {
|
|
103
|
+
let value = this._map[key1];
|
|
104
|
+
if (value === undefined && key2 !== undefined) {
|
|
105
|
+
// if (
|
|
106
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
107
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
108
|
+
// key2.length < key1.length
|
|
109
|
+
// ) {
|
|
110
|
+
// unreachable('Dict.get: Expected keys to be ordered by length.');
|
|
111
|
+
// }
|
|
112
|
+
value = this._map[key2];
|
|
113
|
+
if (value === undefined && key3 !== undefined) {
|
|
114
|
+
// if (
|
|
115
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
116
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
117
|
+
// key3.length < key2.length
|
|
118
|
+
// ) {
|
|
119
|
+
// unreachable('Dict.get: Expected keys to be ordered by length.');
|
|
120
|
+
// }
|
|
121
|
+
value = this._map[key3];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (value instanceof Ref && this.xref) {
|
|
125
|
+
return this.xref.fetch(value, this.suppressEncryption);
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Same as get(), but returns a promise and uses fetchIfRefAsync().
|
|
131
|
+
async getAsync(key1, key2, key3) {
|
|
132
|
+
let value = this._map[key1];
|
|
133
|
+
if (value === undefined && key2 !== undefined) {
|
|
134
|
+
// if (
|
|
135
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
136
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
137
|
+
// key2.length < key1.length
|
|
138
|
+
// ) {
|
|
139
|
+
// unreachable('Dict.getAsync: Expected keys to be ordered by length.');
|
|
140
|
+
// }
|
|
141
|
+
value = this._map[key2];
|
|
142
|
+
if (value === undefined && key3 !== undefined) {
|
|
143
|
+
// if (
|
|
144
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
145
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
146
|
+
// key3.length < key2.length
|
|
147
|
+
// ) {
|
|
148
|
+
// unreachable('Dict.getAsync: Expected keys to be ordered by length.');
|
|
149
|
+
// }
|
|
150
|
+
value = this._map[key3];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (value instanceof Ref && this.xref) {
|
|
154
|
+
return this.xref.fetchAsync(value, this.suppressEncryption);
|
|
155
|
+
}
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Same as get(), but dereferences all elements if the result is an Array.
|
|
160
|
+
getArray(key1, key2, key3) {
|
|
161
|
+
let value = this._map[key1];
|
|
162
|
+
if (value === undefined && key2 !== undefined) {
|
|
163
|
+
// if (
|
|
164
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
165
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
166
|
+
// key2.length < key1.length
|
|
167
|
+
// ) {
|
|
168
|
+
// unreachable('Dict.getArray: Expected keys to be ordered by length.');
|
|
169
|
+
// }
|
|
170
|
+
value = this._map[key2];
|
|
171
|
+
if (value === undefined && key3 !== undefined) {
|
|
172
|
+
// if (
|
|
173
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
174
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
175
|
+
// key3.length < key2.length
|
|
176
|
+
// ) {
|
|
177
|
+
// unreachable('Dict.getArray: Expected keys to be ordered by length.');
|
|
178
|
+
// }
|
|
179
|
+
value = this._map[key3];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (value instanceof Ref && this.xref) {
|
|
183
|
+
value = this.xref.fetch(value, this.suppressEncryption);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (Array.isArray(value)) {
|
|
187
|
+
value = value.slice(); // Ensure that we don't modify the Dict data.
|
|
188
|
+
for (let i = 0, ii = value.length; i < ii; i++) {
|
|
189
|
+
if (value[i] instanceof Ref && this.xref) {
|
|
190
|
+
value[i] = this.xref.fetch(value[i], this.suppressEncryption);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// No dereferencing.
|
|
198
|
+
getRaw(key) {
|
|
199
|
+
return this._map[key];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
getKeys() {
|
|
203
|
+
return Object.keys(this._map);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// No dereferencing.
|
|
207
|
+
getRawValues() {
|
|
208
|
+
return Object.values(this._map);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
set(key, value) {
|
|
212
|
+
// if (
|
|
213
|
+
// typeof PDFJSDev === 'undefined' ||
|
|
214
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')
|
|
215
|
+
// ) {
|
|
216
|
+
// if (typeof key !== 'string') {
|
|
217
|
+
// unreachable('Dict.set: The "key" must be a string.');
|
|
218
|
+
// } else if (value === undefined) {
|
|
219
|
+
// unreachable('Dict.set: The "value" cannot be undefined.');
|
|
220
|
+
// }
|
|
221
|
+
// }
|
|
222
|
+
this._map[key] = value;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
has(key) {
|
|
226
|
+
return this._map[key] !== undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
forEach(callback) {
|
|
230
|
+
for (const key in this._map) {
|
|
231
|
+
callback(key, this.get(key));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
static get empty() {
|
|
236
|
+
const emptyDict = new Dict(null);
|
|
237
|
+
|
|
238
|
+
emptyDict.set = (key, value) => {
|
|
239
|
+
unreachable('Should not call `set` on the empty dictionary.');
|
|
240
|
+
};
|
|
241
|
+
return shadow(this, 'empty', emptyDict);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static merge({ xref, dictArray, mergeSubDicts = false }) {
|
|
245
|
+
const mergedDict = new Dict(xref),
|
|
246
|
+
properties = new Map();
|
|
247
|
+
|
|
248
|
+
for (const dict of dictArray) {
|
|
249
|
+
if (!(dict instanceof Dict)) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
for (const [key, value] of Object.entries(dict._map)) {
|
|
253
|
+
let property = properties.get(key);
|
|
254
|
+
if (property === undefined) {
|
|
255
|
+
property = [];
|
|
256
|
+
properties.set(key, property);
|
|
257
|
+
} else if (!mergeSubDicts || !(value instanceof Dict)) {
|
|
258
|
+
// Ignore additional entries, if either:
|
|
259
|
+
// - This is a "shallow" merge, where only the first element matters.
|
|
260
|
+
// - The value is *not* a `Dict`, since other types cannot be merged.
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
property.push(value);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
for (const [name, values] of properties) {
|
|
267
|
+
if (values.length === 1 || !(values[0] instanceof Dict)) {
|
|
268
|
+
mergedDict._map[name] = values[0];
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const subDict = new Dict(xref);
|
|
272
|
+
|
|
273
|
+
for (const dict of values) {
|
|
274
|
+
for (const [key, value] of Object.entries(dict._map)) {
|
|
275
|
+
if (subDict._map[key] === undefined) {
|
|
276
|
+
subDict._map[key] = value;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (subDict.size > 0) {
|
|
281
|
+
mergedDict._map[name] = subDict;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
properties.clear();
|
|
285
|
+
|
|
286
|
+
return mergedDict.size > 0 ? mergedDict : Dict.empty;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const Ref = (function RefClosure() {
|
|
291
|
+
let refCache = Object.create(null);
|
|
292
|
+
|
|
293
|
+
// eslint-disable-next-line no-shadow
|
|
294
|
+
class Ref {
|
|
295
|
+
constructor(num, gen) {
|
|
296
|
+
this.num = num;
|
|
297
|
+
this.gen = gen;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
toString() {
|
|
301
|
+
// This function is hot, so we make the string as compact as possible.
|
|
302
|
+
// |this.gen| is almost always zero, so we treat that case specially.
|
|
303
|
+
if (this.gen === 0) {
|
|
304
|
+
return `${this.num}R`;
|
|
305
|
+
}
|
|
306
|
+
return `${this.num}R${this.gen}`;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
static get(num, gen) {
|
|
310
|
+
const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
|
|
311
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
312
|
+
return refCache[key] || (refCache[key] = new Ref(num, gen));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
static _clearCache() {
|
|
316
|
+
refCache = Object.create(null);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return Ref;
|
|
321
|
+
})();
|
|
322
|
+
|
|
323
|
+
// The reference is identified by number and generation.
|
|
324
|
+
// This structure stores only one instance of the reference.
|
|
325
|
+
class RefSet {
|
|
326
|
+
constructor(parent = null) {
|
|
327
|
+
// if (
|
|
328
|
+
// (typeof PDFJSDev === 'undefined' ||
|
|
329
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')) &&
|
|
330
|
+
// parent &&
|
|
331
|
+
// !(parent instanceof RefSet)
|
|
332
|
+
// ) {
|
|
333
|
+
// unreachable('RefSet: Invalid "parent" value.');
|
|
334
|
+
// }
|
|
335
|
+
// @ts-ignore
|
|
336
|
+
this._set = new Set(parent && parent._set);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
has(ref) {
|
|
340
|
+
return this._set.has(ref.toString());
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
put(ref) {
|
|
344
|
+
this._set.add(ref.toString());
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
remove(ref) {
|
|
348
|
+
this._set.delete(ref.toString());
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
[Symbol.iterator]() {
|
|
352
|
+
return this._set.values();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
clear() {
|
|
356
|
+
this._set.clear();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
class RefSetCache {
|
|
361
|
+
constructor() {
|
|
362
|
+
this._map = new Map();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
get size() {
|
|
366
|
+
return this._map.size;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
get(ref) {
|
|
370
|
+
return this._map.get(ref.toString());
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
has(ref) {
|
|
374
|
+
return this._map.has(ref.toString());
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
put(ref, obj) {
|
|
378
|
+
this._map.set(ref.toString(), obj);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
putAlias(ref, aliasRef) {
|
|
382
|
+
this._map.set(ref.toString(), this.get(aliasRef));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
[Symbol.iterator]() {
|
|
386
|
+
return this._map.values();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
clear() {
|
|
390
|
+
this._map.clear();
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function isName(v, name) {
|
|
395
|
+
return v instanceof Name && (name === undefined || v.name === name);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function isCmd(v, cmd) {
|
|
399
|
+
return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function isDict(v, type) {
|
|
403
|
+
return (
|
|
404
|
+
v instanceof Dict && (type === undefined || isName(v.get('Type'), type))
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function isRefsEqual(v1, v2) {
|
|
409
|
+
// if (
|
|
410
|
+
// typeof PDFJSDev === 'undefined' ||
|
|
411
|
+
// PDFJSDev.test('!PRODUCTION || TESTING')
|
|
412
|
+
// ) {
|
|
413
|
+
// assert(
|
|
414
|
+
// v1 instanceof Ref && v2 instanceof Ref,
|
|
415
|
+
// 'isRefsEqual: Both parameters should be `Ref`s.'
|
|
416
|
+
// );
|
|
417
|
+
// }
|
|
418
|
+
return v1.num === v2.num && v1.gen === v2.gen;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function clearPrimitiveCaches() {
|
|
422
|
+
Cmd._clearCache();
|
|
423
|
+
Name._clearCache();
|
|
424
|
+
Ref._clearCache();
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export {
|
|
428
|
+
CIRCULAR_REF,
|
|
429
|
+
clearPrimitiveCaches,
|
|
430
|
+
Cmd,
|
|
431
|
+
Dict,
|
|
432
|
+
EOF,
|
|
433
|
+
isCmd,
|
|
434
|
+
isDict,
|
|
435
|
+
isName,
|
|
436
|
+
isRefsEqual,
|
|
437
|
+
Name,
|
|
438
|
+
Ref,
|
|
439
|
+
RefSet,
|
|
440
|
+
RefSetCache
|
|
441
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
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 { BaseStream } from './base_stream.js';
|
|
17
|
+
import { stringToBytes } from './util.js';
|
|
18
|
+
|
|
19
|
+
class Stream extends BaseStream {
|
|
20
|
+
constructor(arrayBuffer, start, length, dict) {
|
|
21
|
+
super();
|
|
22
|
+
|
|
23
|
+
this.bytes =
|
|
24
|
+
arrayBuffer instanceof Uint8Array
|
|
25
|
+
? arrayBuffer
|
|
26
|
+
: new Uint8Array(arrayBuffer);
|
|
27
|
+
this.start = start || 0;
|
|
28
|
+
this.pos = this.start;
|
|
29
|
+
this.end = start + length || this.bytes.length;
|
|
30
|
+
this.dict = dict;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
get length() {
|
|
35
|
+
return this.end - this.start;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
get isEmpty() {
|
|
40
|
+
return this.length === 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getByte() {
|
|
44
|
+
if (this.pos >= this.end) {
|
|
45
|
+
return -1;
|
|
46
|
+
}
|
|
47
|
+
return this.bytes[this.pos++];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getBytes(length) {
|
|
51
|
+
const bytes = this.bytes;
|
|
52
|
+
const pos = this.pos;
|
|
53
|
+
const strEnd = this.end;
|
|
54
|
+
|
|
55
|
+
if (!length) {
|
|
56
|
+
return bytes.subarray(pos, strEnd);
|
|
57
|
+
}
|
|
58
|
+
let end = pos + length;
|
|
59
|
+
if (end > strEnd) {
|
|
60
|
+
end = strEnd;
|
|
61
|
+
}
|
|
62
|
+
this.pos = end;
|
|
63
|
+
return bytes.subarray(pos, end);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getByteRange(begin, end) {
|
|
67
|
+
if (begin < 0) {
|
|
68
|
+
begin = 0;
|
|
69
|
+
}
|
|
70
|
+
if (end > this.end) {
|
|
71
|
+
end = this.end;
|
|
72
|
+
}
|
|
73
|
+
return this.bytes.subarray(begin, end);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
reset() {
|
|
77
|
+
this.pos = this.start;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
moveStart() {
|
|
81
|
+
this.start = this.pos;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
makeSubStream(start, length, dict = null) {
|
|
85
|
+
return new Stream(this.bytes.buffer, start, length, dict);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class StringStream extends Stream {
|
|
90
|
+
constructor(str) {
|
|
91
|
+
super(stringToBytes(str));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
class NullStream extends Stream {
|
|
96
|
+
constructor() {
|
|
97
|
+
super(new Uint8Array(0));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { NullStream, Stream, StringStream };
|