pdf-codec 1.3.1 → 1.4.0
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 +9 -0
- package/dist/afm-widths-BoeTOK2r.cjs +826 -0
- package/dist/afm-widths-Dxucrg7D.js +779 -0
- package/dist/afm-widths-DyDq56Ph.d.cts +19 -0
- package/dist/afm-widths-DyDq56Ph.d.ts +19 -0
- package/dist/afm-widths.cjs +4 -0
- package/dist/afm-widths.d.cts +2 -0
- package/dist/afm-widths.d.ts +2 -0
- package/dist/afm-widths.js +2 -0
- package/dist/assets/stix-two-math-font.cjs +5 -0
- package/dist/assets/stix-two-math-font.d.cts +4 -0
- package/dist/assets/stix-two-math-font.d.ts +4 -0
- package/dist/assets/stix-two-math-font.js +4 -0
- package/dist/bytes/crc32.cjs +21 -0
- package/dist/bytes/crc32.d.cts +4 -0
- package/dist/bytes/crc32.d.ts +4 -0
- package/dist/bytes/crc32.js +20 -0
- package/dist/bytes/flate.cjs +53 -0
- package/dist/bytes/flate.d.cts +12 -0
- package/dist/bytes/flate.d.ts +12 -0
- package/dist/bytes/flate.js +49 -0
- package/dist/bytes/reader.cjs +60 -0
- package/dist/bytes/reader.d.cts +20 -0
- package/dist/bytes/reader.d.ts +20 -0
- package/dist/bytes/reader.js +58 -0
- package/dist/bytes/writer.cjs +37 -0
- package/dist/bytes/writer.d.cts +13 -0
- package/dist/bytes/writer.d.ts +13 -0
- package/dist/bytes/writer.js +35 -0
- package/dist/cmap.cjs +110 -0
- package/dist/cmap.d.cts +8 -0
- package/dist/cmap.d.ts +8 -0
- package/dist/cmap.js +109 -0
- package/dist/codec.cjs +34 -0
- package/dist/codec.d.cts +167 -0
- package/dist/codec.d.ts +167 -0
- package/dist/codec.js +32 -0
- package/dist/content-read.cjs +126 -0
- package/dist/content-read.d.cts +21 -0
- package/dist/content-read.d.ts +21 -0
- package/dist/content-read.js +125 -0
- package/dist/content-write.cjs +138 -0
- package/dist/content-write.d.cts +24 -0
- package/dist/content-write.d.ts +24 -0
- package/dist/content-write.js +137 -0
- package/dist/diagnostics.cjs +21 -0
- package/dist/diagnostics.d.cts +19 -0
- package/dist/diagnostics.d.ts +19 -0
- package/dist/diagnostics.js +18 -0
- package/dist/document.cjs +162 -0
- package/dist/document.d.cts +12 -0
- package/dist/document.d.ts +12 -0
- package/dist/document.js +161 -0
- package/dist/encoding.cjs +5 -0
- package/dist/encoding.d.cts +6 -0
- package/dist/encoding.d.ts +6 -0
- package/dist/encoding.js +2 -0
- package/dist/filters.cjs +223 -0
- package/dist/filters.d.cts +14 -0
- package/dist/filters.d.ts +14 -0
- package/dist/filters.js +218 -0
- package/dist/font-read.cjs +199 -0
- package/dist/font-read.d.cts +23 -0
- package/dist/font-read.d.ts +23 -0
- package/dist/font-read.js +198 -0
- package/dist/font-style.cjs +35 -0
- package/dist/font-style.d.cts +14 -0
- package/dist/font-style.d.ts +14 -0
- package/dist/font-style.js +34 -0
- package/dist/fonts.cjs +124 -0
- package/dist/fonts.d.cts +15 -0
- package/dist/fonts.d.ts +15 -0
- package/dist/fonts.js +122 -0
- package/dist/formula.cjs +0 -0
- package/dist/formula.d.cts +10 -0
- package/dist/formula.d.ts +10 -0
- package/dist/formula.js +0 -0
- package/dist/image/jpeg-info.cjs +71 -0
- package/dist/image/jpeg-info.d.cts +12 -0
- package/dist/image/jpeg-info.d.ts +12 -0
- package/dist/image/jpeg-info.js +70 -0
- package/dist/image/png-decode.cjs +181 -0
- package/dist/image/png-decode.d.cts +14 -0
- package/dist/image/png-decode.d.ts +14 -0
- package/dist/image/png-decode.js +180 -0
- package/dist/image/png-encode.cjs +64 -0
- package/dist/image/png-encode.d.cts +8 -0
- package/dist/image/png-encode.d.ts +8 -0
- package/dist/image/png-encode.js +63 -0
- package/dist/image/png-filter.cjs +95 -0
- package/dist/image/png-filter.d.cts +6 -0
- package/dist/image/png-filter.d.ts +6 -0
- package/dist/image/png-filter.js +93 -0
- package/dist/images-read.cjs +250 -0
- package/dist/images-read.d.cts +13 -0
- package/dist/images-read.d.ts +13 -0
- package/dist/images-read.js +249 -0
- package/dist/index.cjs +45 -5912
- package/dist/index.d.cts +21 -483
- package/dist/index.d.ts +21 -483
- package/dist/index.js +18 -5885
- package/dist/interpret.cjs +587 -0
- package/dist/interpret.d.cts +84 -0
- package/dist/interpret.d.ts +84 -0
- package/dist/interpret.js +586 -0
- package/dist/lexer.cjs +180 -0
- package/dist/lexer.d.cts +29 -0
- package/dist/lexer.d.ts +29 -0
- package/dist/lexer.js +179 -0
- package/dist/math-cmap.cjs +81 -0
- package/dist/math-cmap.d.cts +6 -0
- package/dist/math-cmap.d.ts +6 -0
- package/dist/math-cmap.js +80 -0
- package/dist/math-content-write.cjs +83 -0
- package/dist/math-content-write.d.cts +11 -0
- package/dist/math-content-write.d.ts +11 -0
- package/dist/math-content-write.js +81 -0
- package/dist/math-font-write.cjs +100 -0
- package/dist/math-font-write.d.cts +19 -0
- package/dist/math-font-write.d.ts +19 -0
- package/dist/math-font-write.js +99 -0
- package/dist/math-font.cjs +103 -0
- package/dist/math-font.d.cts +25 -0
- package/dist/math-font.d.ts +25 -0
- package/dist/math-font.js +102 -0
- package/dist/math-hmtx.cjs +17 -0
- package/dist/math-hmtx.d.cts +8 -0
- package/dist/math-hmtx.d.ts +8 -0
- package/dist/math-hmtx.js +16 -0
- package/dist/math-table.cjs +117 -0
- package/dist/math-table.d.cts +45 -0
- package/dist/math-table.d.ts +45 -0
- package/dist/math-table.js +116 -0
- package/dist/math-types-Ba8qAf1p.d.cts +82 -0
- package/dist/math-types-Ba8qAf1p.d.ts +82 -0
- package/dist/math-types.cjs +0 -0
- package/dist/math-types.d.cts +2 -0
- package/dist/math-types.d.ts +2 -0
- package/dist/math-types.js +0 -0
- package/dist/matrix-B3c2_a2f.d.cts +18 -0
- package/dist/matrix-B3c2_a2f.d.ts +18 -0
- package/dist/matrix.cjs +93 -0
- package/dist/matrix.d.cts +2 -0
- package/dist/matrix.d.ts +2 -0
- package/dist/matrix.js +83 -0
- package/dist/measure.cjs +54 -0
- package/dist/measure.d.cts +20 -0
- package/dist/measure.d.ts +20 -0
- package/dist/measure.js +53 -0
- package/dist/objects.cjs +100 -0
- package/dist/objects.d.cts +58 -0
- package/dist/objects.d.ts +58 -0
- package/dist/objects.js +84 -0
- package/dist/parse.cjs +230 -0
- package/dist/parse.d.cts +13 -0
- package/dist/parse.d.ts +13 -0
- package/dist/parse.js +228 -0
- package/dist/predictors.cjs +64 -0
- package/dist/predictors.d.cts +13 -0
- package/dist/predictors.d.ts +13 -0
- package/dist/predictors.js +62 -0
- package/dist/read.cjs +418 -0
- package/dist/read.d.cts +21 -0
- package/dist/read.d.ts +21 -0
- package/dist/read.js +413 -0
- package/dist/serialize.cjs +69 -0
- package/dist/serialize.d.cts +8 -0
- package/dist/serialize.d.ts +8 -0
- package/dist/serialize.js +66 -0
- package/dist/sfnt.cjs +52 -0
- package/dist/sfnt.d.cts +17 -0
- package/dist/sfnt.d.ts +17 -0
- package/dist/sfnt.js +46 -0
- package/dist/text-layout.cjs +224 -0
- package/dist/text-layout.d.cts +37 -0
- package/dist/text-layout.d.ts +37 -0
- package/dist/text-layout.js +222 -0
- package/dist/util/abort.cjs +7 -0
- package/dist/util/abort.d.cts +4 -0
- package/dist/util/abort.d.ts +4 -0
- package/dist/util/abort.js +6 -0
- package/dist/util/base64.cjs +48 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +46 -0
- package/dist/winansi.cjs +5 -0
- package/dist/winansi.d.cts +20 -0
- package/dist/winansi.d.ts +20 -0
- package/dist/winansi.js +2 -0
- package/dist/write.cjs +421 -0
- package/dist/write.d.cts +16 -0
- package/dist/write.d.ts +16 -0
- package/dist/write.js +419 -0
- package/dist/xref.cjs +325 -0
- package/dist/xref.d.cts +21 -0
- package/dist/xref.d.ts +21 -0
- package/dist/xref.js +324 -0
- package/package.json +9 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/bytes/crc32.ts
|
|
3
|
+
const CRC32_POLYNOMIAL = 3988292384;
|
|
4
|
+
const BYTE_VALUES = 256;
|
|
5
|
+
const BITS_PER_BYTE = 8;
|
|
6
|
+
const CRC32_TABLE = (() => {
|
|
7
|
+
const table = new Uint32Array(BYTE_VALUES);
|
|
8
|
+
for (let n = 0; n < BYTE_VALUES; n++) {
|
|
9
|
+
let c = n;
|
|
10
|
+
for (let k = 0; k < BITS_PER_BYTE; k++) c = (c & 1) === 1 ? CRC32_POLYNOMIAL ^ c >>> 1 : c >>> 1;
|
|
11
|
+
table[n] = c >>> 0;
|
|
12
|
+
}
|
|
13
|
+
return table;
|
|
14
|
+
})();
|
|
15
|
+
function crc32(bytes) {
|
|
16
|
+
let crc = 4294967295;
|
|
17
|
+
for (const byte of bytes) crc = CRC32_TABLE[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
18
|
+
return (crc ^ 4294967295) >>> 0;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.crc32 = crc32;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/bytes/crc32.ts
|
|
2
|
+
const CRC32_POLYNOMIAL = 3988292384;
|
|
3
|
+
const BYTE_VALUES = 256;
|
|
4
|
+
const BITS_PER_BYTE = 8;
|
|
5
|
+
const CRC32_TABLE = (() => {
|
|
6
|
+
const table = new Uint32Array(BYTE_VALUES);
|
|
7
|
+
for (let n = 0; n < BYTE_VALUES; n++) {
|
|
8
|
+
let c = n;
|
|
9
|
+
for (let k = 0; k < BITS_PER_BYTE; k++) c = (c & 1) === 1 ? CRC32_POLYNOMIAL ^ c >>> 1 : c >>> 1;
|
|
10
|
+
table[n] = c >>> 0;
|
|
11
|
+
}
|
|
12
|
+
return table;
|
|
13
|
+
})();
|
|
14
|
+
function crc32(bytes) {
|
|
15
|
+
let crc = 4294967295;
|
|
16
|
+
for (const byte of bytes) crc = CRC32_TABLE[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
17
|
+
return (crc ^ 4294967295) >>> 0;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { crc32 };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_bytes_reader = require("./reader.cjs");
|
|
3
|
+
const require_bytes_writer = require("./writer.cjs");
|
|
4
|
+
let fflate = require("fflate");
|
|
5
|
+
//#region src/bytes/flate.ts
|
|
6
|
+
const MAX_INFLATE_OUTPUT_BYTES = 536870912;
|
|
7
|
+
function deflate(data, level) {
|
|
8
|
+
return (0, fflate.zlibSync)(data, level === void 0 ? void 0 : { level });
|
|
9
|
+
}
|
|
10
|
+
function inflate(data) {
|
|
11
|
+
const out = (0, fflate.unzlibSync)(data);
|
|
12
|
+
if (out.length > 536870912) throw new Error(`inflated output exceeds the ${MAX_INFLATE_OUTPUT_BYTES}-byte limit`);
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
function inflateTolerant(data) {
|
|
16
|
+
try {
|
|
17
|
+
return {
|
|
18
|
+
bytes: inflate(data),
|
|
19
|
+
recovered: false
|
|
20
|
+
};
|
|
21
|
+
} catch {}
|
|
22
|
+
let offset = 0;
|
|
23
|
+
while (offset < data.length && require_bytes_reader.isAsciiWhitespace(data[offset])) offset++;
|
|
24
|
+
if (offset > 0) try {
|
|
25
|
+
return {
|
|
26
|
+
bytes: inflate(data.subarray(offset)),
|
|
27
|
+
recovered: true
|
|
28
|
+
};
|
|
29
|
+
} catch {}
|
|
30
|
+
try {
|
|
31
|
+
return {
|
|
32
|
+
bytes: (0, fflate.inflateSync)(data),
|
|
33
|
+
recovered: true
|
|
34
|
+
};
|
|
35
|
+
} catch {}
|
|
36
|
+
const chunks = [];
|
|
37
|
+
const unzlib = new fflate.Unzlib((chunk) => {
|
|
38
|
+
chunks.push(chunk);
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
unzlib.push(data, false);
|
|
42
|
+
} catch {}
|
|
43
|
+
if (chunks.length === 0) throw new Error("unable to inflate stream: no data could be recovered");
|
|
44
|
+
return {
|
|
45
|
+
bytes: require_bytes_writer.concatBytes(chunks),
|
|
46
|
+
recovered: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.MAX_INFLATE_OUTPUT_BYTES = MAX_INFLATE_OUTPUT_BYTES;
|
|
51
|
+
exports.deflate = deflate;
|
|
52
|
+
exports.inflate = inflate;
|
|
53
|
+
exports.inflateTolerant = inflateTolerant;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/bytes/flate.d.ts
|
|
2
|
+
declare const MAX_INFLATE_OUTPUT_BYTES: number;
|
|
3
|
+
type DeflateLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
4
|
+
declare function deflate(data: Uint8Array<ArrayBuffer>, level?: DeflateLevel): Uint8Array<ArrayBuffer>;
|
|
5
|
+
declare function inflate(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
6
|
+
interface InflateResult {
|
|
7
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
8
|
+
readonly recovered: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function inflateTolerant(data: Uint8Array<ArrayBuffer>): InflateResult;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DeflateLevel, InflateResult, MAX_INFLATE_OUTPUT_BYTES, deflate, inflate, inflateTolerant };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/bytes/flate.d.ts
|
|
2
|
+
declare const MAX_INFLATE_OUTPUT_BYTES: number;
|
|
3
|
+
type DeflateLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
4
|
+
declare function deflate(data: Uint8Array<ArrayBuffer>, level?: DeflateLevel): Uint8Array<ArrayBuffer>;
|
|
5
|
+
declare function inflate(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
6
|
+
interface InflateResult {
|
|
7
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
8
|
+
readonly recovered: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function inflateTolerant(data: Uint8Array<ArrayBuffer>): InflateResult;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DeflateLevel, InflateResult, MAX_INFLATE_OUTPUT_BYTES, deflate, inflate, inflateTolerant };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isAsciiWhitespace } from "./reader.js";
|
|
2
|
+
import { concatBytes } from "./writer.js";
|
|
3
|
+
import { Unzlib, inflateSync, unzlibSync, zlibSync } from "fflate";
|
|
4
|
+
//#region src/bytes/flate.ts
|
|
5
|
+
const MAX_INFLATE_OUTPUT_BYTES = 536870912;
|
|
6
|
+
function deflate(data, level) {
|
|
7
|
+
return zlibSync(data, level === void 0 ? void 0 : { level });
|
|
8
|
+
}
|
|
9
|
+
function inflate(data) {
|
|
10
|
+
const out = unzlibSync(data);
|
|
11
|
+
if (out.length > 536870912) throw new Error(`inflated output exceeds the ${MAX_INFLATE_OUTPUT_BYTES}-byte limit`);
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
function inflateTolerant(data) {
|
|
15
|
+
try {
|
|
16
|
+
return {
|
|
17
|
+
bytes: inflate(data),
|
|
18
|
+
recovered: false
|
|
19
|
+
};
|
|
20
|
+
} catch {}
|
|
21
|
+
let offset = 0;
|
|
22
|
+
while (offset < data.length && isAsciiWhitespace(data[offset])) offset++;
|
|
23
|
+
if (offset > 0) try {
|
|
24
|
+
return {
|
|
25
|
+
bytes: inflate(data.subarray(offset)),
|
|
26
|
+
recovered: true
|
|
27
|
+
};
|
|
28
|
+
} catch {}
|
|
29
|
+
try {
|
|
30
|
+
return {
|
|
31
|
+
bytes: inflateSync(data),
|
|
32
|
+
recovered: true
|
|
33
|
+
};
|
|
34
|
+
} catch {}
|
|
35
|
+
const chunks = [];
|
|
36
|
+
const unzlib = new Unzlib((chunk) => {
|
|
37
|
+
chunks.push(chunk);
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
unzlib.push(data, false);
|
|
41
|
+
} catch {}
|
|
42
|
+
if (chunks.length === 0) throw new Error("unable to inflate stream: no data could be recovered");
|
|
43
|
+
return {
|
|
44
|
+
bytes: concatBytes(chunks),
|
|
45
|
+
recovered: true
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { MAX_INFLATE_OUTPUT_BYTES, deflate, inflate, inflateTolerant };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/bytes/reader.ts
|
|
3
|
+
const ASCII_WHITESPACE_BYTES = /* @__PURE__ */ new Set([
|
|
4
|
+
0,
|
|
5
|
+
9,
|
|
6
|
+
10,
|
|
7
|
+
12,
|
|
8
|
+
13,
|
|
9
|
+
32
|
|
10
|
+
]);
|
|
11
|
+
function isAsciiWhitespace(byte) {
|
|
12
|
+
return byte !== void 0 && ASCII_WHITESPACE_BYTES.has(byte);
|
|
13
|
+
}
|
|
14
|
+
var ByteReader = class {
|
|
15
|
+
bytes;
|
|
16
|
+
position = 0;
|
|
17
|
+
constructor(bytes) {
|
|
18
|
+
this.bytes = bytes;
|
|
19
|
+
}
|
|
20
|
+
get offset() {
|
|
21
|
+
return this.position;
|
|
22
|
+
}
|
|
23
|
+
get length() {
|
|
24
|
+
return this.bytes.length;
|
|
25
|
+
}
|
|
26
|
+
atEnd() {
|
|
27
|
+
return this.position >= this.bytes.length;
|
|
28
|
+
}
|
|
29
|
+
peek(aheadBy = 0) {
|
|
30
|
+
return this.bytes[this.position + aheadBy];
|
|
31
|
+
}
|
|
32
|
+
next() {
|
|
33
|
+
const byte = this.bytes[this.position];
|
|
34
|
+
if (byte !== void 0) this.position++;
|
|
35
|
+
return byte;
|
|
36
|
+
}
|
|
37
|
+
mark() {
|
|
38
|
+
return this.position;
|
|
39
|
+
}
|
|
40
|
+
reset(mark) {
|
|
41
|
+
this.position = mark;
|
|
42
|
+
}
|
|
43
|
+
seek(offset) {
|
|
44
|
+
this.position = offset;
|
|
45
|
+
}
|
|
46
|
+
slice(start, end) {
|
|
47
|
+
return this.bytes.subarray(start, end);
|
|
48
|
+
}
|
|
49
|
+
skipWhitespace() {
|
|
50
|
+
while (isAsciiWhitespace(this.peek())) this.position++;
|
|
51
|
+
}
|
|
52
|
+
matchKeyword(keyword) {
|
|
53
|
+
for (let i = 0; i < keyword.length; i++) if (this.peek(i) !== keyword.charCodeAt(i)) return false;
|
|
54
|
+
this.position += keyword.length;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.ByteReader = ByteReader;
|
|
60
|
+
exports.isAsciiWhitespace = isAsciiWhitespace;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/bytes/reader.d.ts
|
|
2
|
+
declare function isAsciiWhitespace(byte: number | undefined): boolean;
|
|
3
|
+
declare class ByteReader {
|
|
4
|
+
private readonly bytes;
|
|
5
|
+
private position;
|
|
6
|
+
constructor(bytes: Uint8Array<ArrayBuffer>);
|
|
7
|
+
get offset(): number;
|
|
8
|
+
get length(): number;
|
|
9
|
+
atEnd(): boolean;
|
|
10
|
+
peek(aheadBy?: number): number | undefined;
|
|
11
|
+
next(): number | undefined;
|
|
12
|
+
mark(): number;
|
|
13
|
+
reset(mark: number): void;
|
|
14
|
+
seek(offset: number): void;
|
|
15
|
+
slice(start: number, end: number): Uint8Array<ArrayBuffer>;
|
|
16
|
+
skipWhitespace(): void;
|
|
17
|
+
matchKeyword(keyword: string): boolean;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ByteReader, isAsciiWhitespace };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/bytes/reader.d.ts
|
|
2
|
+
declare function isAsciiWhitespace(byte: number | undefined): boolean;
|
|
3
|
+
declare class ByteReader {
|
|
4
|
+
private readonly bytes;
|
|
5
|
+
private position;
|
|
6
|
+
constructor(bytes: Uint8Array<ArrayBuffer>);
|
|
7
|
+
get offset(): number;
|
|
8
|
+
get length(): number;
|
|
9
|
+
atEnd(): boolean;
|
|
10
|
+
peek(aheadBy?: number): number | undefined;
|
|
11
|
+
next(): number | undefined;
|
|
12
|
+
mark(): number;
|
|
13
|
+
reset(mark: number): void;
|
|
14
|
+
seek(offset: number): void;
|
|
15
|
+
slice(start: number, end: number): Uint8Array<ArrayBuffer>;
|
|
16
|
+
skipWhitespace(): void;
|
|
17
|
+
matchKeyword(keyword: string): boolean;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ByteReader, isAsciiWhitespace };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region src/bytes/reader.ts
|
|
2
|
+
const ASCII_WHITESPACE_BYTES = /* @__PURE__ */ new Set([
|
|
3
|
+
0,
|
|
4
|
+
9,
|
|
5
|
+
10,
|
|
6
|
+
12,
|
|
7
|
+
13,
|
|
8
|
+
32
|
|
9
|
+
]);
|
|
10
|
+
function isAsciiWhitespace(byte) {
|
|
11
|
+
return byte !== void 0 && ASCII_WHITESPACE_BYTES.has(byte);
|
|
12
|
+
}
|
|
13
|
+
var ByteReader = class {
|
|
14
|
+
bytes;
|
|
15
|
+
position = 0;
|
|
16
|
+
constructor(bytes) {
|
|
17
|
+
this.bytes = bytes;
|
|
18
|
+
}
|
|
19
|
+
get offset() {
|
|
20
|
+
return this.position;
|
|
21
|
+
}
|
|
22
|
+
get length() {
|
|
23
|
+
return this.bytes.length;
|
|
24
|
+
}
|
|
25
|
+
atEnd() {
|
|
26
|
+
return this.position >= this.bytes.length;
|
|
27
|
+
}
|
|
28
|
+
peek(aheadBy = 0) {
|
|
29
|
+
return this.bytes[this.position + aheadBy];
|
|
30
|
+
}
|
|
31
|
+
next() {
|
|
32
|
+
const byte = this.bytes[this.position];
|
|
33
|
+
if (byte !== void 0) this.position++;
|
|
34
|
+
return byte;
|
|
35
|
+
}
|
|
36
|
+
mark() {
|
|
37
|
+
return this.position;
|
|
38
|
+
}
|
|
39
|
+
reset(mark) {
|
|
40
|
+
this.position = mark;
|
|
41
|
+
}
|
|
42
|
+
seek(offset) {
|
|
43
|
+
this.position = offset;
|
|
44
|
+
}
|
|
45
|
+
slice(start, end) {
|
|
46
|
+
return this.bytes.subarray(start, end);
|
|
47
|
+
}
|
|
48
|
+
skipWhitespace() {
|
|
49
|
+
while (isAsciiWhitespace(this.peek())) this.position++;
|
|
50
|
+
}
|
|
51
|
+
matchKeyword(keyword) {
|
|
52
|
+
for (let i = 0; i < keyword.length; i++) if (this.peek(i) !== keyword.charCodeAt(i)) return false;
|
|
53
|
+
this.position += keyword.length;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { ByteReader, isAsciiWhitespace };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/bytes/writer.ts
|
|
3
|
+
var ByteWriter = class {
|
|
4
|
+
chunks = [];
|
|
5
|
+
byteLength = 0;
|
|
6
|
+
get length() {
|
|
7
|
+
return this.byteLength;
|
|
8
|
+
}
|
|
9
|
+
writeBytes(bytes) {
|
|
10
|
+
if (bytes.length === 0) return;
|
|
11
|
+
this.chunks.push(bytes);
|
|
12
|
+
this.byteLength += bytes.length;
|
|
13
|
+
}
|
|
14
|
+
writeByte(byte) {
|
|
15
|
+
this.writeBytes(new Uint8Array([byte]));
|
|
16
|
+
}
|
|
17
|
+
writeAscii(text) {
|
|
18
|
+
this.writeBytes(new TextEncoder().encode(text));
|
|
19
|
+
}
|
|
20
|
+
toBytes() {
|
|
21
|
+
const out = new Uint8Array(this.byteLength);
|
|
22
|
+
let offset = 0;
|
|
23
|
+
for (const chunk of this.chunks) {
|
|
24
|
+
out.set(chunk, offset);
|
|
25
|
+
offset += chunk.length;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function concatBytes(chunks) {
|
|
31
|
+
const writer = new ByteWriter();
|
|
32
|
+
for (const chunk of chunks) writer.writeBytes(chunk);
|
|
33
|
+
return writer.toBytes();
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.ByteWriter = ByteWriter;
|
|
37
|
+
exports.concatBytes = concatBytes;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/bytes/writer.d.ts
|
|
2
|
+
declare class ByteWriter {
|
|
3
|
+
private readonly chunks;
|
|
4
|
+
private byteLength;
|
|
5
|
+
get length(): number;
|
|
6
|
+
writeBytes(bytes: Uint8Array<ArrayBuffer>): void;
|
|
7
|
+
writeByte(byte: number): void;
|
|
8
|
+
writeAscii(text: string): void;
|
|
9
|
+
toBytes(): Uint8Array<ArrayBuffer>;
|
|
10
|
+
}
|
|
11
|
+
declare function concatBytes(chunks: readonly Uint8Array<ArrayBuffer>[]): Uint8Array<ArrayBuffer>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ByteWriter, concatBytes };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/bytes/writer.d.ts
|
|
2
|
+
declare class ByteWriter {
|
|
3
|
+
private readonly chunks;
|
|
4
|
+
private byteLength;
|
|
5
|
+
get length(): number;
|
|
6
|
+
writeBytes(bytes: Uint8Array<ArrayBuffer>): void;
|
|
7
|
+
writeByte(byte: number): void;
|
|
8
|
+
writeAscii(text: string): void;
|
|
9
|
+
toBytes(): Uint8Array<ArrayBuffer>;
|
|
10
|
+
}
|
|
11
|
+
declare function concatBytes(chunks: readonly Uint8Array<ArrayBuffer>[]): Uint8Array<ArrayBuffer>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ByteWriter, concatBytes };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/bytes/writer.ts
|
|
2
|
+
var ByteWriter = class {
|
|
3
|
+
chunks = [];
|
|
4
|
+
byteLength = 0;
|
|
5
|
+
get length() {
|
|
6
|
+
return this.byteLength;
|
|
7
|
+
}
|
|
8
|
+
writeBytes(bytes) {
|
|
9
|
+
if (bytes.length === 0) return;
|
|
10
|
+
this.chunks.push(bytes);
|
|
11
|
+
this.byteLength += bytes.length;
|
|
12
|
+
}
|
|
13
|
+
writeByte(byte) {
|
|
14
|
+
this.writeBytes(new Uint8Array([byte]));
|
|
15
|
+
}
|
|
16
|
+
writeAscii(text) {
|
|
17
|
+
this.writeBytes(new TextEncoder().encode(text));
|
|
18
|
+
}
|
|
19
|
+
toBytes() {
|
|
20
|
+
const out = new Uint8Array(this.byteLength);
|
|
21
|
+
let offset = 0;
|
|
22
|
+
for (const chunk of this.chunks) {
|
|
23
|
+
out.set(chunk, offset);
|
|
24
|
+
offset += chunk.length;
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function concatBytes(chunks) {
|
|
30
|
+
const writer = new ByteWriter();
|
|
31
|
+
for (const chunk of chunks) writer.writeBytes(chunk);
|
|
32
|
+
return writer.toBytes();
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { ByteWriter, concatBytes };
|
package/dist/cmap.cjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_bytes_reader = require("./bytes/reader.cjs");
|
|
3
|
+
const require_lexer = require("./lexer.cjs");
|
|
4
|
+
//#region src/cmap.ts
|
|
5
|
+
function hexBytesToNumber(bytes) {
|
|
6
|
+
let value = 0;
|
|
7
|
+
for (const byte of bytes) value = value * 256 + byte;
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function decodeUtf16BEString(bytes) {
|
|
11
|
+
const units = [];
|
|
12
|
+
for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) << 8 | (bytes[i + 1] ?? 0));
|
|
13
|
+
return String.fromCharCode(...units);
|
|
14
|
+
}
|
|
15
|
+
function parseToUnicodeCMap(bytes, sink) {
|
|
16
|
+
const reader = new require_bytes_reader.ByteReader(bytes);
|
|
17
|
+
const map = /* @__PURE__ */ new Map();
|
|
18
|
+
for (;;) {
|
|
19
|
+
const token = require_lexer.nextToken(reader);
|
|
20
|
+
if (token === void 0) break;
|
|
21
|
+
if (token.kind === "keyword" && token.value === "beginbfchar") readBfChar(reader, map, sink);
|
|
22
|
+
else if (token.kind === "keyword" && token.value === "beginbfrange") readBfRange(reader, map, sink);
|
|
23
|
+
}
|
|
24
|
+
return { lookup: (code) => map.get(code) };
|
|
25
|
+
}
|
|
26
|
+
function readBfChar(reader, map, sink) {
|
|
27
|
+
for (;;) {
|
|
28
|
+
const srcTok = require_lexer.nextToken(reader);
|
|
29
|
+
if (srcTok === void 0) {
|
|
30
|
+
sink({
|
|
31
|
+
code: "pdf/cmap-truncated",
|
|
32
|
+
severity: "warning",
|
|
33
|
+
message: "bfchar section was truncated before endbfchar"
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (srcTok.kind === "keyword" && srcTok.value === "endbfchar") return;
|
|
38
|
+
if (srcTok.kind !== "hexString") continue;
|
|
39
|
+
const dstTok = require_lexer.nextToken(reader);
|
|
40
|
+
if (dstTok?.kind !== "hexString") {
|
|
41
|
+
sink({
|
|
42
|
+
code: "pdf/cmap-entry-invalid",
|
|
43
|
+
severity: "warning",
|
|
44
|
+
message: "bfchar entry had no valid destination hex string"
|
|
45
|
+
});
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
map.set(hexBytesToNumber(srcTok.value), decodeUtf16BEString(dstTok.value));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function readBfRange(reader, map, sink) {
|
|
52
|
+
for (;;) {
|
|
53
|
+
const loTok = require_lexer.nextToken(reader);
|
|
54
|
+
if (loTok === void 0) {
|
|
55
|
+
sink({
|
|
56
|
+
code: "pdf/cmap-truncated",
|
|
57
|
+
severity: "warning",
|
|
58
|
+
message: "bfrange section was truncated before endbfrange"
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (loTok.kind === "keyword" && loTok.value === "endbfrange") return;
|
|
63
|
+
if (loTok.kind !== "hexString") continue;
|
|
64
|
+
const hiTok = require_lexer.nextToken(reader);
|
|
65
|
+
if (hiTok?.kind !== "hexString") {
|
|
66
|
+
sink({
|
|
67
|
+
code: "pdf/cmap-entry-invalid",
|
|
68
|
+
severity: "warning",
|
|
69
|
+
message: "bfrange entry had no valid high-end hex string"
|
|
70
|
+
});
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const lo = hexBytesToNumber(loTok.value);
|
|
74
|
+
const hi = hexBytesToNumber(hiTok.value);
|
|
75
|
+
const dstTok = require_lexer.nextToken(reader);
|
|
76
|
+
if (dstTok?.kind === "hexString") registerBfRangeSingle(map, lo, hi, dstTok.value);
|
|
77
|
+
else if (dstTok?.kind === "arrayStart") readBfRangeArray(reader, map, lo, sink);
|
|
78
|
+
else sink({
|
|
79
|
+
code: "pdf/cmap-entry-invalid",
|
|
80
|
+
severity: "warning",
|
|
81
|
+
message: "bfrange entry had no valid destination"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function registerBfRangeSingle(map, lo, hi, dstBytes) {
|
|
86
|
+
if (dstBytes.length < 2) return;
|
|
87
|
+
const prefix = decodeUtf16BEString(dstBytes.subarray(0, dstBytes.length - 2));
|
|
88
|
+
const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) << 8 | (dstBytes[dstBytes.length - 1] ?? 0);
|
|
89
|
+
for (let code = lo; code <= hi; code++) map.set(code, prefix + String.fromCharCode(baseUnit + (code - lo)));
|
|
90
|
+
}
|
|
91
|
+
function readBfRangeArray(reader, map, lo, sink) {
|
|
92
|
+
let code = lo;
|
|
93
|
+
for (;;) {
|
|
94
|
+
const token = require_lexer.nextToken(reader);
|
|
95
|
+
if (token === void 0) {
|
|
96
|
+
sink({
|
|
97
|
+
code: "pdf/cmap-truncated",
|
|
98
|
+
severity: "warning",
|
|
99
|
+
message: "bfrange array destination was truncated"
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (token.kind === "arrayEnd") return;
|
|
104
|
+
if (token.kind !== "hexString") continue;
|
|
105
|
+
map.set(code, decodeUtf16BEString(token.value));
|
|
106
|
+
code++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
exports.parseToUnicodeCMap = parseToUnicodeCMap;
|
package/dist/cmap.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
+
//#region src/cmap.d.ts
|
|
3
|
+
interface ToUnicodeCMap {
|
|
4
|
+
lookup(code: number): string | undefined;
|
|
5
|
+
}
|
|
6
|
+
declare function parseToUnicodeCMap(bytes: Uint8Array<ArrayBuffer>, sink: PdfDiagnosticSink): ToUnicodeCMap;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ToUnicodeCMap, parseToUnicodeCMap };
|
package/dist/cmap.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
+
//#region src/cmap.d.ts
|
|
3
|
+
interface ToUnicodeCMap {
|
|
4
|
+
lookup(code: number): string | undefined;
|
|
5
|
+
}
|
|
6
|
+
declare function parseToUnicodeCMap(bytes: Uint8Array<ArrayBuffer>, sink: PdfDiagnosticSink): ToUnicodeCMap;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ToUnicodeCMap, parseToUnicodeCMap };
|
package/dist/cmap.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ByteReader } from "./bytes/reader.js";
|
|
2
|
+
import { nextToken } from "./lexer.js";
|
|
3
|
+
//#region src/cmap.ts
|
|
4
|
+
function hexBytesToNumber(bytes) {
|
|
5
|
+
let value = 0;
|
|
6
|
+
for (const byte of bytes) value = value * 256 + byte;
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
function decodeUtf16BEString(bytes) {
|
|
10
|
+
const units = [];
|
|
11
|
+
for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) << 8 | (bytes[i + 1] ?? 0));
|
|
12
|
+
return String.fromCharCode(...units);
|
|
13
|
+
}
|
|
14
|
+
function parseToUnicodeCMap(bytes, sink) {
|
|
15
|
+
const reader = new ByteReader(bytes);
|
|
16
|
+
const map = /* @__PURE__ */ new Map();
|
|
17
|
+
for (;;) {
|
|
18
|
+
const token = nextToken(reader);
|
|
19
|
+
if (token === void 0) break;
|
|
20
|
+
if (token.kind === "keyword" && token.value === "beginbfchar") readBfChar(reader, map, sink);
|
|
21
|
+
else if (token.kind === "keyword" && token.value === "beginbfrange") readBfRange(reader, map, sink);
|
|
22
|
+
}
|
|
23
|
+
return { lookup: (code) => map.get(code) };
|
|
24
|
+
}
|
|
25
|
+
function readBfChar(reader, map, sink) {
|
|
26
|
+
for (;;) {
|
|
27
|
+
const srcTok = nextToken(reader);
|
|
28
|
+
if (srcTok === void 0) {
|
|
29
|
+
sink({
|
|
30
|
+
code: "pdf/cmap-truncated",
|
|
31
|
+
severity: "warning",
|
|
32
|
+
message: "bfchar section was truncated before endbfchar"
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (srcTok.kind === "keyword" && srcTok.value === "endbfchar") return;
|
|
37
|
+
if (srcTok.kind !== "hexString") continue;
|
|
38
|
+
const dstTok = nextToken(reader);
|
|
39
|
+
if (dstTok?.kind !== "hexString") {
|
|
40
|
+
sink({
|
|
41
|
+
code: "pdf/cmap-entry-invalid",
|
|
42
|
+
severity: "warning",
|
|
43
|
+
message: "bfchar entry had no valid destination hex string"
|
|
44
|
+
});
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
map.set(hexBytesToNumber(srcTok.value), decodeUtf16BEString(dstTok.value));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function readBfRange(reader, map, sink) {
|
|
51
|
+
for (;;) {
|
|
52
|
+
const loTok = nextToken(reader);
|
|
53
|
+
if (loTok === void 0) {
|
|
54
|
+
sink({
|
|
55
|
+
code: "pdf/cmap-truncated",
|
|
56
|
+
severity: "warning",
|
|
57
|
+
message: "bfrange section was truncated before endbfrange"
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (loTok.kind === "keyword" && loTok.value === "endbfrange") return;
|
|
62
|
+
if (loTok.kind !== "hexString") continue;
|
|
63
|
+
const hiTok = nextToken(reader);
|
|
64
|
+
if (hiTok?.kind !== "hexString") {
|
|
65
|
+
sink({
|
|
66
|
+
code: "pdf/cmap-entry-invalid",
|
|
67
|
+
severity: "warning",
|
|
68
|
+
message: "bfrange entry had no valid high-end hex string"
|
|
69
|
+
});
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const lo = hexBytesToNumber(loTok.value);
|
|
73
|
+
const hi = hexBytesToNumber(hiTok.value);
|
|
74
|
+
const dstTok = nextToken(reader);
|
|
75
|
+
if (dstTok?.kind === "hexString") registerBfRangeSingle(map, lo, hi, dstTok.value);
|
|
76
|
+
else if (dstTok?.kind === "arrayStart") readBfRangeArray(reader, map, lo, sink);
|
|
77
|
+
else sink({
|
|
78
|
+
code: "pdf/cmap-entry-invalid",
|
|
79
|
+
severity: "warning",
|
|
80
|
+
message: "bfrange entry had no valid destination"
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function registerBfRangeSingle(map, lo, hi, dstBytes) {
|
|
85
|
+
if (dstBytes.length < 2) return;
|
|
86
|
+
const prefix = decodeUtf16BEString(dstBytes.subarray(0, dstBytes.length - 2));
|
|
87
|
+
const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) << 8 | (dstBytes[dstBytes.length - 1] ?? 0);
|
|
88
|
+
for (let code = lo; code <= hi; code++) map.set(code, prefix + String.fromCharCode(baseUnit + (code - lo)));
|
|
89
|
+
}
|
|
90
|
+
function readBfRangeArray(reader, map, lo, sink) {
|
|
91
|
+
let code = lo;
|
|
92
|
+
for (;;) {
|
|
93
|
+
const token = nextToken(reader);
|
|
94
|
+
if (token === void 0) {
|
|
95
|
+
sink({
|
|
96
|
+
code: "pdf/cmap-truncated",
|
|
97
|
+
severity: "warning",
|
|
98
|
+
message: "bfrange array destination was truncated"
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (token.kind === "arrayEnd") return;
|
|
103
|
+
if (token.kind !== "hexString") continue;
|
|
104
|
+
map.set(code, decodeUtf16BEString(token.value));
|
|
105
|
+
code++;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { parseToUnicodeCMap };
|