pdf-parser.js 3.0.8 → 4.5.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/README.md +105 -54
- package/dist/{afm-widths-Dxucrg7D.js → afm-widths-BTu0IDp2.cjs} +1517 -4
- package/dist/{afm-widths-DyDq56Ph.d.cts → afm-widths-CneRyu5l.d.cts} +1 -1
- package/dist/{afm-widths-DyDq56Ph.d.ts → afm-widths-CneRyu5l.d.ts} +1 -1
- package/dist/{afm-widths-BoeTOK2r.cjs → afm-widths-De_QMWgC.js} +1416 -51
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.d.cts +1 -1
- package/dist/afm-widths.d.ts +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.cjs +104 -0
- package/dist/annotations.d.cts +9 -0
- package/dist/annotations.d.ts +9 -0
- package/dist/annotations.js +103 -0
- package/dist/attachments.cjs +65 -0
- package/dist/attachments.d.cts +8 -0
- package/dist/attachments.d.ts +8 -0
- package/dist/attachments.js +64 -0
- package/dist/builtin-encoding.cjs +221 -0
- package/dist/builtin-encoding.d.cts +8 -0
- package/dist/builtin-encoding.d.ts +8 -0
- package/dist/builtin-encoding.js +220 -0
- package/dist/bytes/flate.cjs +1 -1
- package/dist/bytes/flate.js +1 -1
- package/dist/cff.cjs +14 -0
- package/dist/cff.d.cts +4 -1
- package/dist/cff.d.ts +4 -1
- package/dist/cff.js +12 -1
- package/dist/cmap-table.cjs +76 -13
- package/dist/cmap-table.d.cts +9 -1
- package/dist/cmap-table.d.ts +9 -1
- package/dist/cmap-table.js +77 -15
- package/dist/codec.cjs +1 -1
- package/dist/codec.d.cts +134 -0
- package/dist/codec.d.ts +134 -0
- package/dist/codec.js +1 -1
- package/dist/content-read.cjs +1 -1
- package/dist/content-read.d.cts +3 -3
- package/dist/content-read.d.ts +3 -3
- package/dist/content-read.js +1 -1
- package/dist/content-write.cjs +32 -10
- package/dist/content-write.d.cts +12 -5
- package/dist/content-write.d.ts +12 -5
- package/dist/content-write.js +32 -10
- package/dist/crypto/random.cjs +9 -0
- package/dist/crypto/random.d.cts +4 -0
- package/dist/crypto/random.d.ts +4 -0
- package/dist/crypto/random.js +8 -0
- package/dist/diagnostics.d.cts +1 -1
- package/dist/diagnostics.d.ts +1 -1
- package/dist/document.cjs +12 -3
- package/dist/document.d.cts +3 -1
- package/dist/document.d.ts +3 -1
- package/dist/document.js +12 -3
- package/dist/{embedded-font-fREdbxnr.d.ts → embedded-font-B4p9a3O3.d.ts} +3 -1
- package/dist/{embedded-font-BU6Jgcof.d.cts → embedded-font-oc65VGlr.d.cts} +3 -1
- package/dist/embedded-font-write.cjs +1 -1
- package/dist/embedded-font-write.d.cts +3 -3
- package/dist/embedded-font-write.d.ts +3 -3
- package/dist/embedded-font-write.js +1 -1
- package/dist/embedded-font.cjs +46 -15
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +46 -15
- package/dist/encoding.cjs +10 -1
- package/dist/encoding.d.cts +10 -1
- package/dist/encoding.d.ts +10 -1
- package/dist/encoding.js +2 -2
- package/dist/encrypt-write.cjs +234 -0
- package/dist/encrypt-write.d.cts +31 -0
- package/dist/encrypt-write.d.ts +31 -0
- package/dist/encrypt-write.js +231 -0
- package/dist/encrypt.cjs +51 -21
- package/dist/encrypt.d.cts +19 -3
- package/dist/encrypt.d.ts +19 -3
- package/dist/encrypt.js +36 -22
- package/dist/filters.cjs +18 -14
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/filters.js +18 -14
- package/dist/font-read.cjs +68 -13
- package/dist/font-read.d.cts +1 -1
- package/dist/font-read.d.ts +1 -1
- package/dist/font-read.js +69 -14
- package/dist/font-registry.cjs +1 -1
- package/dist/font-registry.d.cts +4 -4
- package/dist/font-registry.d.ts +4 -4
- package/dist/font-registry.js +1 -1
- package/dist/font-substitutes.d.cts +1 -1
- package/dist/font-substitutes.d.ts +1 -1
- package/dist/font-tables.cjs +31 -0
- package/dist/font-tables.d.cts +3 -1
- package/dist/font-tables.d.ts +3 -1
- package/dist/font-tables.js +31 -2
- package/dist/fonts.d.cts +2 -2
- package/dist/fonts.d.ts +2 -2
- package/dist/form.cjs +138 -0
- package/dist/form.d.cts +9 -0
- package/dist/form.d.ts +9 -0
- package/dist/form.js +137 -0
- package/dist/gsub-table-BRTQ8EUW.d.ts +10 -0
- package/dist/gsub-table-URczLd85.d.cts +10 -0
- package/dist/gsub-table.cjs +225 -0
- package/dist/gsub-table.d.cts +2 -0
- package/dist/gsub-table.d.ts +2 -0
- package/dist/gsub-table.js +224 -0
- package/dist/image/ccitt-encode.cjs +119 -0
- package/dist/image/ccitt-encode.d.cts +9 -0
- package/dist/image/ccitt-encode.d.ts +9 -0
- package/dist/image/ccitt-encode.js +118 -0
- package/dist/image/ccitt.cjs +3 -0
- package/dist/image/ccitt.d.cts +4 -1
- package/dist/image/ccitt.d.ts +4 -1
- package/dist/image/ccitt.js +1 -1
- package/dist/image/jbig2-bitmap.d.cts +1 -1
- package/dist/image/jbig2-bitmap.d.ts +1 -1
- package/dist/image/jbig2.cjs +3 -1
- package/dist/image/jbig2.js +3 -1
- package/dist/image/jp2-boxes.d.cts +1 -1
- package/dist/image/jp2-boxes.d.ts +1 -1
- package/dist/image/jpeg2000-codestream.d.cts +3 -3
- package/dist/image/jpeg2000-codestream.d.ts +3 -3
- package/dist/image/jpeg2000-t1.d.cts +1 -1
- package/dist/image/jpeg2000-t1.d.ts +1 -1
- package/dist/image/jpeg2000.cjs +1 -0
- package/dist/image/jpeg2000.d.cts +3 -0
- package/dist/image/jpeg2000.d.ts +3 -0
- package/dist/image/jpeg2000.js +1 -0
- package/dist/image/png-decode.cjs +1 -1
- package/dist/image/png-decode.js +1 -1
- package/dist/image/png-filter.d.cts +1 -1
- package/dist/image/png-filter.d.ts +1 -1
- package/dist/images-read.cjs +18 -12
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/images-read.js +15 -9
- package/dist/index.cjs +17 -4
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +6 -5
- package/dist/interpret.cjs +178 -56
- package/dist/interpret.d.cts +27 -12
- package/dist/interpret.d.ts +27 -12
- package/dist/interpret.js +178 -56
- package/dist/layout.cjs +149 -2
- package/dist/layout.d.cts +394 -1
- package/dist/layout.d.ts +394 -1
- package/dist/layout.js +140 -4
- package/dist/lexer.d.cts +9 -9
- package/dist/lexer.d.ts +9 -9
- package/dist/math-content-write.cjs +1 -1
- package/dist/math-content-write.js +1 -1
- package/dist/math-font-write.cjs +1 -1
- package/dist/math-font-write.d.cts +1 -1
- package/dist/math-font-write.d.ts +1 -1
- package/dist/math-font-write.js +1 -1
- package/dist/math-font.cjs +2 -2
- package/dist/math-font.d.cts +1 -1
- package/dist/math-font.d.ts +1 -1
- package/dist/math-font.js +2 -2
- package/dist/{math-stretch-a_rHNRvc.d.ts → math-stretch-BbC2o4Br.d.ts} +1 -1
- package/dist/{math-stretch-E26z6byT.d.cts → math-stretch-C2JanDAz.d.cts} +1 -1
- package/dist/math-stretch.d.cts +1 -1
- package/dist/math-stretch.d.ts +1 -1
- package/dist/measure.cjs +1 -1
- package/dist/measure.d.cts +1 -1
- package/dist/measure.d.ts +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.cjs +41 -0
- package/dist/names.d.cts +11 -0
- package/dist/names.d.ts +11 -0
- package/dist/names.js +40 -0
- package/dist/navigation.cjs +210 -0
- package/dist/navigation.d.cts +18 -0
- package/dist/navigation.d.ts +18 -0
- package/dist/navigation.js +207 -0
- package/dist/notes-annotation-author.cjs +5 -0
- package/dist/notes-annotation-author.d.cts +4 -0
- package/dist/notes-annotation-author.d.ts +4 -0
- package/dist/notes-annotation-author.js +4 -0
- package/dist/objects-B7HdMeWS.d.cts +59 -0
- package/dist/objects-B7HdMeWS.d.ts +59 -0
- package/dist/objects.d.cts +1 -58
- package/dist/objects.d.ts +1 -58
- package/dist/optional-content.cjs +63 -0
- package/dist/optional-content.d.cts +12 -0
- package/dist/optional-content.d.ts +12 -0
- package/dist/optional-content.js +62 -0
- package/dist/parse.cjs +1 -1
- package/dist/parse.d.cts +2 -2
- package/dist/parse.d.ts +2 -2
- package/dist/parse.js +1 -1
- package/dist/pdf-text.cjs +21 -0
- package/dist/pdf-text.d.cts +5 -0
- package/dist/pdf-text.d.ts +5 -0
- package/dist/pdf-text.js +19 -0
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/read.cjs +287 -72
- package/dist/read.d.cts +2 -4
- package/dist/read.d.ts +2 -4
- package/dist/read.js +284 -67
- package/dist/serialize.cjs +5 -1
- package/dist/serialize.d.cts +3 -2
- package/dist/serialize.d.ts +3 -2
- package/dist/serialize.js +5 -2
- package/dist/sfnt-subset.cjs +10 -3
- package/dist/sfnt-subset.d.cts +1 -1
- package/dist/sfnt-subset.d.ts +1 -1
- package/dist/sfnt-subset.js +10 -3
- package/dist/structure.cjs +184 -0
- package/dist/structure.d.cts +12 -0
- package/dist/structure.d.ts +12 -0
- package/dist/structure.js +183 -0
- package/dist/tounicode.cjs +8 -3
- package/dist/tounicode.d.cts +2 -2
- package/dist/tounicode.d.ts +2 -2
- package/dist/tounicode.js +8 -3
- package/dist/util/base64.cjs +4 -4
- package/dist/util/base64.js +4 -4
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.d.cts +1 -1
- package/dist/winansi.d.ts +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write.cjs +464 -21
- package/dist/write.d.cts +4 -3
- package/dist/write.d.ts +4 -3
- package/dist/write.js +464 -20
- package/dist/xmp.cjs +46 -0
- package/dist/xmp.d.cts +14 -0
- package/dist/xmp.d.ts +14 -0
- package/dist/xmp.js +45 -0
- package/dist/xref.cjs +2 -2
- package/dist/xref.d.cts +3 -3
- package/dist/xref.d.ts +3 -3
- package/dist/xref.js +2 -2
- package/package.json +46 -31
- package/dist/image/png-encode.cjs +0 -64
- package/dist/image/png-encode.d.cts +0 -8
- package/dist/image/png-encode.d.ts +0 -8
- package/dist/image/png-encode.js +0 -63
package/dist/afm-widths.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_afm_widths = require("./afm-widths-
|
|
2
|
+
const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
|
|
3
3
|
exports.STANDARD_METRICS = require_afm_widths.STANDARD_METRICS;
|
|
4
4
|
exports.widthOfCode = require_afm_widths.widthOfCode;
|
package/dist/afm-widths.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as widthOfCode, n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-
|
|
1
|
+
import { i as widthOfCode, n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-CneRyu5l.cjs";
|
|
2
2
|
export { FontMetrics, STANDARD_METRICS, StandardFontName, widthOfCode };
|
package/dist/afm-widths.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as widthOfCode, n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-
|
|
1
|
+
import { i as widthOfCode, n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-CneRyu5l.js";
|
|
2
2
|
export { FontMetrics, STANDARD_METRICS, StandardFontName, widthOfCode };
|
package/dist/afm-widths.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-
|
|
1
|
+
import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-De_QMWgC.js";
|
|
2
2
|
export { STANDARD_METRICS, widthOfCode };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./notes-annotation-author.cjs");
|
|
3
|
+
const require_objects = require("./objects.cjs");
|
|
4
|
+
const require_pdf_text = require("./pdf-text.cjs");
|
|
5
|
+
const require_serialize = require("./serialize.cjs");
|
|
6
|
+
const require_matrix = require("./matrix.cjs");
|
|
7
|
+
//#region src/annotations.ts
|
|
8
|
+
const SEMANTIC_SUBTYPES = /* @__PURE__ */ new Set([
|
|
9
|
+
"Text",
|
|
10
|
+
"FreeText",
|
|
11
|
+
"Highlight",
|
|
12
|
+
"Underline",
|
|
13
|
+
"StrikeOut",
|
|
14
|
+
"Squiggly"
|
|
15
|
+
]);
|
|
16
|
+
const OWNED_ELSEWHERE_SUBTYPES = /* @__PURE__ */ new Set([
|
|
17
|
+
"Link",
|
|
18
|
+
"FileAttachment",
|
|
19
|
+
"Widget",
|
|
20
|
+
"Popup"
|
|
21
|
+
]);
|
|
22
|
+
function readPageAnnotations(page, pageMatrix, resolver, sink) {
|
|
23
|
+
const annotsArr = require_objects.asArray(require_objects.dictGet(page, "Annots"));
|
|
24
|
+
if (annotsArr === void 0) return [];
|
|
25
|
+
const annotations = [];
|
|
26
|
+
for (const annotRef of annotsArr) {
|
|
27
|
+
const annot = resolver.resolveDict(annotRef);
|
|
28
|
+
if (annot === void 0) continue;
|
|
29
|
+
const subtype = require_objects.asName(require_objects.dictGet(annot, "Subtype"));
|
|
30
|
+
if (subtype === void 0 || OWNED_ELSEWHERE_SUBTYPES.has(subtype)) continue;
|
|
31
|
+
if (subtype === "Text" && annotString(annot, "T") === "documents.js:notes") continue;
|
|
32
|
+
const rectArr = require_objects.asArray(require_objects.dictGet(annot, "Rect"));
|
|
33
|
+
if (rectArr === void 0) {
|
|
34
|
+
sink({
|
|
35
|
+
code: "pdf/annotation-missing-rect",
|
|
36
|
+
severity: "warning",
|
|
37
|
+
message: `a /${subtype} annotation carries no /Rect; skipping it`
|
|
38
|
+
});
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const x1 = require_objects.asNumber(rectArr[0]) ?? 0;
|
|
42
|
+
const y1 = require_objects.asNumber(rectArr[1]) ?? 0;
|
|
43
|
+
const x2 = require_objects.asNumber(rectArr[2]) ?? 0;
|
|
44
|
+
const y2 = require_objects.asNumber(rectArr[3]) ?? 0;
|
|
45
|
+
const p1 = require_matrix.applyMatrix(pageMatrix, {
|
|
46
|
+
x: Math.min(x1, x2),
|
|
47
|
+
y: Math.min(y1, y2)
|
|
48
|
+
});
|
|
49
|
+
const p2 = require_matrix.applyMatrix(pageMatrix, {
|
|
50
|
+
x: Math.max(x1, x2),
|
|
51
|
+
y: Math.max(y1, y2)
|
|
52
|
+
});
|
|
53
|
+
const contents = annotString(annot, "Contents");
|
|
54
|
+
const author = annotString(annot, "T");
|
|
55
|
+
const modifiedIso = require_pdf_text.parsePdfDate(annotString(annot, "M"));
|
|
56
|
+
annotations.push({
|
|
57
|
+
subtype,
|
|
58
|
+
xPt: Math.min(p1.x, p2.x),
|
|
59
|
+
yPt: Math.min(p1.y, p2.y),
|
|
60
|
+
widthPt: Math.abs(p2.x - p1.x),
|
|
61
|
+
heightPt: Math.abs(p2.y - p1.y),
|
|
62
|
+
...contents !== void 0 ? { contents } : {},
|
|
63
|
+
...author !== void 0 ? { author } : {},
|
|
64
|
+
...modifiedIso !== void 0 ? { modifiedIso } : {},
|
|
65
|
+
...SEMANTIC_SUBTYPES.has(subtype) ? markupFields(annot, pageMatrix) : { source: {
|
|
66
|
+
format: "pdf",
|
|
67
|
+
xml: require_serialize.serializeObjectToText(annot)
|
|
68
|
+
} }
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return annotations;
|
|
72
|
+
}
|
|
73
|
+
function annotString(annot, key) {
|
|
74
|
+
const obj = require_objects.dictGet(annot, key);
|
|
75
|
+
return obj?.kind === "string" ? require_pdf_text.decodePdfString(obj.bytes) : void 0;
|
|
76
|
+
}
|
|
77
|
+
function markupFields(annot, pageMatrix) {
|
|
78
|
+
const quadPoints = require_objects.asArray(require_objects.dictGet(annot, "QuadPoints"));
|
|
79
|
+
if (quadPoints === void 0 || quadPoints.length < 8 || quadPoints.length % 8 !== 0) return {};
|
|
80
|
+
const quads = [];
|
|
81
|
+
for (let i = 0; i < quadPoints.length; i += 8) {
|
|
82
|
+
const corner = (index) => {
|
|
83
|
+
const x = require_objects.asNumber(quadPoints[i + index * 2]) ?? 0;
|
|
84
|
+
const y = require_objects.asNumber(quadPoints[i + index * 2 + 1]) ?? 0;
|
|
85
|
+
const transformed = require_matrix.applyMatrix(pageMatrix, {
|
|
86
|
+
x,
|
|
87
|
+
y
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
xPt: transformed.x,
|
|
91
|
+
yPt: transformed.y
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
quads.push([
|
|
95
|
+
corner(0),
|
|
96
|
+
corner(1),
|
|
97
|
+
corner(2),
|
|
98
|
+
corner(3)
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
return { quads };
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
exports.readPageAnnotations = readPageAnnotations;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
+
import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
|
|
3
|
+
import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
|
|
4
|
+
import { PdfObjectResolver } from "./interpret.cjs";
|
|
5
|
+
import { LayoutAnnotation } from "./layout.cjs";
|
|
6
|
+
//#region src/annotations.d.ts
|
|
7
|
+
declare function readPageAnnotations(page: PdfDict, pageMatrix: Matrix, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutAnnotation[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { readPageAnnotations };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
+
import { r as Matrix } from "./matrix-B7_SBKQ5.js";
|
|
3
|
+
import { n as PdfDict } from "./objects-B7HdMeWS.js";
|
|
4
|
+
import { PdfObjectResolver } from "./interpret.js";
|
|
5
|
+
import { LayoutAnnotation } from "./layout.js";
|
|
6
|
+
//#region src/annotations.d.ts
|
|
7
|
+
declare function readPageAnnotations(page: PdfDict, pageMatrix: Matrix, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutAnnotation[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { readPageAnnotations };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import "./notes-annotation-author.js";
|
|
2
|
+
import { asArray, asName, asNumber, dictGet } from "./objects.js";
|
|
3
|
+
import { decodePdfString, parsePdfDate } from "./pdf-text.js";
|
|
4
|
+
import { serializeObjectToText } from "./serialize.js";
|
|
5
|
+
import { applyMatrix } from "./matrix.js";
|
|
6
|
+
//#region src/annotations.ts
|
|
7
|
+
const SEMANTIC_SUBTYPES = /* @__PURE__ */ new Set([
|
|
8
|
+
"Text",
|
|
9
|
+
"FreeText",
|
|
10
|
+
"Highlight",
|
|
11
|
+
"Underline",
|
|
12
|
+
"StrikeOut",
|
|
13
|
+
"Squiggly"
|
|
14
|
+
]);
|
|
15
|
+
const OWNED_ELSEWHERE_SUBTYPES = /* @__PURE__ */ new Set([
|
|
16
|
+
"Link",
|
|
17
|
+
"FileAttachment",
|
|
18
|
+
"Widget",
|
|
19
|
+
"Popup"
|
|
20
|
+
]);
|
|
21
|
+
function readPageAnnotations(page, pageMatrix, resolver, sink) {
|
|
22
|
+
const annotsArr = asArray(dictGet(page, "Annots"));
|
|
23
|
+
if (annotsArr === void 0) return [];
|
|
24
|
+
const annotations = [];
|
|
25
|
+
for (const annotRef of annotsArr) {
|
|
26
|
+
const annot = resolver.resolveDict(annotRef);
|
|
27
|
+
if (annot === void 0) continue;
|
|
28
|
+
const subtype = asName(dictGet(annot, "Subtype"));
|
|
29
|
+
if (subtype === void 0 || OWNED_ELSEWHERE_SUBTYPES.has(subtype)) continue;
|
|
30
|
+
if (subtype === "Text" && annotString(annot, "T") === "documents.js:notes") continue;
|
|
31
|
+
const rectArr = asArray(dictGet(annot, "Rect"));
|
|
32
|
+
if (rectArr === void 0) {
|
|
33
|
+
sink({
|
|
34
|
+
code: "pdf/annotation-missing-rect",
|
|
35
|
+
severity: "warning",
|
|
36
|
+
message: `a /${subtype} annotation carries no /Rect; skipping it`
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const x1 = asNumber(rectArr[0]) ?? 0;
|
|
41
|
+
const y1 = asNumber(rectArr[1]) ?? 0;
|
|
42
|
+
const x2 = asNumber(rectArr[2]) ?? 0;
|
|
43
|
+
const y2 = asNumber(rectArr[3]) ?? 0;
|
|
44
|
+
const p1 = applyMatrix(pageMatrix, {
|
|
45
|
+
x: Math.min(x1, x2),
|
|
46
|
+
y: Math.min(y1, y2)
|
|
47
|
+
});
|
|
48
|
+
const p2 = applyMatrix(pageMatrix, {
|
|
49
|
+
x: Math.max(x1, x2),
|
|
50
|
+
y: Math.max(y1, y2)
|
|
51
|
+
});
|
|
52
|
+
const contents = annotString(annot, "Contents");
|
|
53
|
+
const author = annotString(annot, "T");
|
|
54
|
+
const modifiedIso = parsePdfDate(annotString(annot, "M"));
|
|
55
|
+
annotations.push({
|
|
56
|
+
subtype,
|
|
57
|
+
xPt: Math.min(p1.x, p2.x),
|
|
58
|
+
yPt: Math.min(p1.y, p2.y),
|
|
59
|
+
widthPt: Math.abs(p2.x - p1.x),
|
|
60
|
+
heightPt: Math.abs(p2.y - p1.y),
|
|
61
|
+
...contents !== void 0 ? { contents } : {},
|
|
62
|
+
...author !== void 0 ? { author } : {},
|
|
63
|
+
...modifiedIso !== void 0 ? { modifiedIso } : {},
|
|
64
|
+
...SEMANTIC_SUBTYPES.has(subtype) ? markupFields(annot, pageMatrix) : { source: {
|
|
65
|
+
format: "pdf",
|
|
66
|
+
xml: serializeObjectToText(annot)
|
|
67
|
+
} }
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return annotations;
|
|
71
|
+
}
|
|
72
|
+
function annotString(annot, key) {
|
|
73
|
+
const obj = dictGet(annot, key);
|
|
74
|
+
return obj?.kind === "string" ? decodePdfString(obj.bytes) : void 0;
|
|
75
|
+
}
|
|
76
|
+
function markupFields(annot, pageMatrix) {
|
|
77
|
+
const quadPoints = asArray(dictGet(annot, "QuadPoints"));
|
|
78
|
+
if (quadPoints === void 0 || quadPoints.length < 8 || quadPoints.length % 8 !== 0) return {};
|
|
79
|
+
const quads = [];
|
|
80
|
+
for (let i = 0; i < quadPoints.length; i += 8) {
|
|
81
|
+
const corner = (index) => {
|
|
82
|
+
const x = asNumber(quadPoints[i + index * 2]) ?? 0;
|
|
83
|
+
const y = asNumber(quadPoints[i + index * 2 + 1]) ?? 0;
|
|
84
|
+
const transformed = applyMatrix(pageMatrix, {
|
|
85
|
+
x,
|
|
86
|
+
y
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
xPt: transformed.x,
|
|
90
|
+
yPt: transformed.y
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
quads.push([
|
|
94
|
+
corner(0),
|
|
95
|
+
corner(1),
|
|
96
|
+
corner(2),
|
|
97
|
+
corner(3)
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
return { quads };
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { readPageAnnotations };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_objects = require("./objects.cjs");
|
|
3
|
+
const require_pdf_text = require("./pdf-text.cjs");
|
|
4
|
+
const require_filters = require("./filters.cjs");
|
|
5
|
+
const require_names = require("./names.cjs");
|
|
6
|
+
const require_util_base64 = require("./util/base64.cjs");
|
|
7
|
+
//#region src/attachments.ts
|
|
8
|
+
function readAttachments(catalog, pages, resolver, sink) {
|
|
9
|
+
const attachments = [];
|
|
10
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11
|
+
const collect = (filespecRef) => {
|
|
12
|
+
const filespec = resolver.resolveDict(filespecRef);
|
|
13
|
+
if (filespec === void 0) return;
|
|
14
|
+
const name = filespecName(filespec);
|
|
15
|
+
if (name === void 0 || seen.has(name)) return;
|
|
16
|
+
const attachment = readFilespec(name, filespec, resolver, sink);
|
|
17
|
+
if (attachment !== void 0) {
|
|
18
|
+
seen.add(name);
|
|
19
|
+
attachments.push(attachment);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const namesRoot = resolver.resolveDict(require_objects.dictGet(catalog, "Names"));
|
|
23
|
+
for (const entry of require_names.walkNameTree(namesRoot === void 0 ? void 0 : require_objects.dictGet(namesRoot, "EmbeddedFiles"), resolver, sink)) collect(entry.value);
|
|
24
|
+
for (const page of pages) {
|
|
25
|
+
const annots = require_objects.asArray(require_objects.dictGet(page, "Annots"));
|
|
26
|
+
if (annots === void 0) continue;
|
|
27
|
+
for (const annotRef of annots) {
|
|
28
|
+
const annot = resolver.resolveDict(annotRef);
|
|
29
|
+
if (annot !== void 0 && require_objects.asName(require_objects.dictGet(annot, "Subtype")) === "FileAttachment") collect(require_objects.dictGet(annot, "FS"));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const af = require_objects.asArray(resolver.resolve(require_objects.dictGet(catalog, "AF")));
|
|
33
|
+
if (af !== void 0) for (const filespecRef of af) collect(filespecRef);
|
|
34
|
+
return attachments;
|
|
35
|
+
}
|
|
36
|
+
function filespecName(filespec) {
|
|
37
|
+
for (const key of ["UF", "F"]) {
|
|
38
|
+
const obj = require_objects.dictGet(filespec, key);
|
|
39
|
+
if (obj?.kind === "string") return require_pdf_text.decodePdfString(obj.bytes);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function readFilespec(name, filespec, resolver, sink) {
|
|
43
|
+
const ef = resolver.resolveDict(require_objects.dictGet(filespec, "EF"));
|
|
44
|
+
if (ef === void 0) return;
|
|
45
|
+
for (const key of ["F", "UF"]) {
|
|
46
|
+
const streamObj = resolver.resolve(require_objects.dictGet(ef, key));
|
|
47
|
+
if (streamObj?.kind !== "stream") continue;
|
|
48
|
+
const decoded = require_filters.decodeStream(streamObj.raw, streamObj.dict, sink);
|
|
49
|
+
const descObj = require_objects.dictGet(filespec, "Desc");
|
|
50
|
+
const subtype = require_objects.asName(require_objects.dictGet(streamObj.dict, "Subtype"));
|
|
51
|
+
return {
|
|
52
|
+
name,
|
|
53
|
+
...descObj?.kind === "string" ? { description: require_pdf_text.decodePdfString(descObj.bytes) } : {},
|
|
54
|
+
...subtype !== void 0 ? { mimeType: subtype } : {},
|
|
55
|
+
base64: require_util_base64.bytesToBase64(decoded.bytes)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
sink({
|
|
59
|
+
code: "pdf/embedded-file-missing-stream",
|
|
60
|
+
severity: "warning",
|
|
61
|
+
message: "a filespec declares /EF but neither /F nor /UF resolves to an embedded stream"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.readAttachments = readAttachments;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
+
import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
|
|
3
|
+
import { PdfObjectResolver } from "./interpret.cjs";
|
|
4
|
+
import { LayoutAttachment } from "./layout.cjs";
|
|
5
|
+
//#region src/attachments.d.ts
|
|
6
|
+
declare function readAttachments(catalog: PdfDict, pages: readonly PdfDict[], resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutAttachment[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { readAttachments };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
+
import { n as PdfDict } from "./objects-B7HdMeWS.js";
|
|
3
|
+
import { PdfObjectResolver } from "./interpret.js";
|
|
4
|
+
import { LayoutAttachment } from "./layout.js";
|
|
5
|
+
//#region src/attachments.d.ts
|
|
6
|
+
declare function readAttachments(catalog: PdfDict, pages: readonly PdfDict[], resolver: PdfObjectResolver, sink: PdfDiagnosticSink): LayoutAttachment[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { readAttachments };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { asArray, asName, dictGet } from "./objects.js";
|
|
2
|
+
import { decodePdfString } from "./pdf-text.js";
|
|
3
|
+
import { decodeStream } from "./filters.js";
|
|
4
|
+
import { walkNameTree } from "./names.js";
|
|
5
|
+
import { bytesToBase64 } from "./util/base64.js";
|
|
6
|
+
//#region src/attachments.ts
|
|
7
|
+
function readAttachments(catalog, pages, resolver, sink) {
|
|
8
|
+
const attachments = [];
|
|
9
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10
|
+
const collect = (filespecRef) => {
|
|
11
|
+
const filespec = resolver.resolveDict(filespecRef);
|
|
12
|
+
if (filespec === void 0) return;
|
|
13
|
+
const name = filespecName(filespec);
|
|
14
|
+
if (name === void 0 || seen.has(name)) return;
|
|
15
|
+
const attachment = readFilespec(name, filespec, resolver, sink);
|
|
16
|
+
if (attachment !== void 0) {
|
|
17
|
+
seen.add(name);
|
|
18
|
+
attachments.push(attachment);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const namesRoot = resolver.resolveDict(dictGet(catalog, "Names"));
|
|
22
|
+
for (const entry of walkNameTree(namesRoot === void 0 ? void 0 : dictGet(namesRoot, "EmbeddedFiles"), resolver, sink)) collect(entry.value);
|
|
23
|
+
for (const page of pages) {
|
|
24
|
+
const annots = asArray(dictGet(page, "Annots"));
|
|
25
|
+
if (annots === void 0) continue;
|
|
26
|
+
for (const annotRef of annots) {
|
|
27
|
+
const annot = resolver.resolveDict(annotRef);
|
|
28
|
+
if (annot !== void 0 && asName(dictGet(annot, "Subtype")) === "FileAttachment") collect(dictGet(annot, "FS"));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const af = asArray(resolver.resolve(dictGet(catalog, "AF")));
|
|
32
|
+
if (af !== void 0) for (const filespecRef of af) collect(filespecRef);
|
|
33
|
+
return attachments;
|
|
34
|
+
}
|
|
35
|
+
function filespecName(filespec) {
|
|
36
|
+
for (const key of ["UF", "F"]) {
|
|
37
|
+
const obj = dictGet(filespec, key);
|
|
38
|
+
if (obj?.kind === "string") return decodePdfString(obj.bytes);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function readFilespec(name, filespec, resolver, sink) {
|
|
42
|
+
const ef = resolver.resolveDict(dictGet(filespec, "EF"));
|
|
43
|
+
if (ef === void 0) return;
|
|
44
|
+
for (const key of ["F", "UF"]) {
|
|
45
|
+
const streamObj = resolver.resolve(dictGet(ef, key));
|
|
46
|
+
if (streamObj?.kind !== "stream") continue;
|
|
47
|
+
const decoded = decodeStream(streamObj.raw, streamObj.dict, sink);
|
|
48
|
+
const descObj = dictGet(filespec, "Desc");
|
|
49
|
+
const subtype = asName(dictGet(streamObj.dict, "Subtype"));
|
|
50
|
+
return {
|
|
51
|
+
name,
|
|
52
|
+
...descObj?.kind === "string" ? { description: decodePdfString(descObj.bytes) } : {},
|
|
53
|
+
...subtype !== void 0 ? { mimeType: subtype } : {},
|
|
54
|
+
base64: bytesToBase64(decoded.bytes)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
sink({
|
|
58
|
+
code: "pdf/embedded-file-missing-stream",
|
|
59
|
+
severity: "warning",
|
|
60
|
+
message: "a filespec declares /EF but neither /F nor /UF resolves to an embedded stream"
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { readAttachments };
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
|
|
3
|
+
const require_sfnt = require("./sfnt.cjs");
|
|
4
|
+
const require_cff = require("./cff.cjs");
|
|
5
|
+
const require_cmap_table = require("./cmap-table.cjs");
|
|
6
|
+
const require_font_tables = require("./font-tables.cjs");
|
|
7
|
+
//#region src/builtin-encoding.ts
|
|
8
|
+
function isPrivateUse(codePoint) {
|
|
9
|
+
return codePoint >= 57344 && codePoint <= 63743 || codePoint >= 983040 && codePoint <= 1048573 || codePoint >= 1048576 && codePoint <= 1114109;
|
|
10
|
+
}
|
|
11
|
+
function encodingFromSources(sources) {
|
|
12
|
+
const { codeToGlyphId, codeToName, glyphIdToName, glyphIdToUnicode } = sources;
|
|
13
|
+
const glyphUnicode = (glyphId) => {
|
|
14
|
+
const name = glyphIdToName?.(glyphId);
|
|
15
|
+
return (name !== void 0 ? require_afm_widths.glyphNameToUnicode(name) : void 0) ?? glyphIdToUnicode?.(glyphId);
|
|
16
|
+
};
|
|
17
|
+
const codeUnicode = (code) => {
|
|
18
|
+
const name = codeToName?.(code);
|
|
19
|
+
if (name !== void 0) {
|
|
20
|
+
const named = require_afm_widths.glyphNameToUnicode(name);
|
|
21
|
+
if (named !== void 0) return named;
|
|
22
|
+
}
|
|
23
|
+
const glyphId = codeToGlyphId?.(code);
|
|
24
|
+
return glyphId === void 0 ? void 0 : glyphUnicode(glyphId);
|
|
25
|
+
};
|
|
26
|
+
return codeToName !== void 0 || codeToGlyphId !== void 0 || glyphIdToName !== void 0 || glyphIdToUnicode !== void 0 ? {
|
|
27
|
+
codeToUnicode: codeUnicode,
|
|
28
|
+
glyphIdToUnicode: glyphUnicode
|
|
29
|
+
} : void 0;
|
|
30
|
+
}
|
|
31
|
+
const SYMBOL_CMAP_CODE_BASE = 61440;
|
|
32
|
+
function symbolSubtable(subtables) {
|
|
33
|
+
return subtables.find((s) => s.platformId === 3 && s.encodingId === 0) ?? subtables.find((s) => s.platformId === 1 && s.encodingId === 0);
|
|
34
|
+
}
|
|
35
|
+
function unicodeSubtable(subtables) {
|
|
36
|
+
return subtables.find((s) => s.platformId === 3 && s.encodingId === 10) ?? subtables.find((s) => s.platformId === 3 && s.encodingId === 1) ?? subtables.find((s) => s.platformId === 0);
|
|
37
|
+
}
|
|
38
|
+
function invertUnicodeSubtable(subtable) {
|
|
39
|
+
let inverse;
|
|
40
|
+
return (glyphId) => {
|
|
41
|
+
if (inverse === void 0) {
|
|
42
|
+
const built = /* @__PURE__ */ new Map();
|
|
43
|
+
subtable.forEachMapping((code, mappedGlyphId) => {
|
|
44
|
+
if (!isPrivateUse(code) && !built.has(mappedGlyphId)) built.set(mappedGlyphId, code);
|
|
45
|
+
});
|
|
46
|
+
inverse = built;
|
|
47
|
+
}
|
|
48
|
+
return inverse.get(glyphId);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function trueTypeSources(font) {
|
|
52
|
+
const subtables = require_cmap_table.readCmapSubtables(font);
|
|
53
|
+
const symbol = symbolSubtable(subtables);
|
|
54
|
+
const unicode = unicodeSubtable(subtables);
|
|
55
|
+
return {
|
|
56
|
+
codeToGlyphId: symbol !== void 0 ? (code) => symbol.lookup(SYMBOL_CMAP_CODE_BASE | code) ?? symbol.lookup(code) : unicode !== void 0 ? (code) => unicode.lookup(SYMBOL_CMAP_CODE_BASE | code) : void 0,
|
|
57
|
+
glyphIdToName: require_font_tables.parsePostGlyphNames(font),
|
|
58
|
+
glyphIdToUnicode: unicode !== void 0 ? invertUnicodeSubtable(unicode) : void 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const CFF_HEADER_SIZE = 4;
|
|
62
|
+
const CFF_MAJOR_VERSION = 1;
|
|
63
|
+
const CFF_PREDEFINED_CHARSET_ISO_ADOBE = 0;
|
|
64
|
+
const CFF_PREDEFINED_ENCODING_STANDARD = 0;
|
|
65
|
+
const CFF_ENCODING_FORMAT_MASK = 127;
|
|
66
|
+
const CFF_ENCODING_SUPPLEMENT_FLAG = 128;
|
|
67
|
+
function readCffCharset(bytes, offset, glyphCount) {
|
|
68
|
+
const sidByGlyph = /* @__PURE__ */ new Map();
|
|
69
|
+
if (offset === CFF_PREDEFINED_CHARSET_ISO_ADOBE) {
|
|
70
|
+
for (let glyphId = 1; glyphId < glyphCount; glyphId++) sidByGlyph.set(glyphId, glyphId);
|
|
71
|
+
return sidByGlyph;
|
|
72
|
+
}
|
|
73
|
+
if (offset < CFF_HEADER_SIZE || !require_sfnt.hasBytes(bytes, offset, 1)) return;
|
|
74
|
+
const format = require_sfnt.u8(bytes, offset);
|
|
75
|
+
let cursor = offset + 1;
|
|
76
|
+
if (format === 0) {
|
|
77
|
+
for (let glyphId = 1; glyphId < glyphCount; glyphId++) {
|
|
78
|
+
if (!require_sfnt.hasBytes(bytes, cursor, 2)) return sidByGlyph;
|
|
79
|
+
sidByGlyph.set(glyphId, require_sfnt.u16(bytes, cursor));
|
|
80
|
+
cursor += 2;
|
|
81
|
+
}
|
|
82
|
+
return sidByGlyph;
|
|
83
|
+
}
|
|
84
|
+
if (format !== 1 && format !== 2) return;
|
|
85
|
+
const nLeftSize = format === 1 ? 1 : 2;
|
|
86
|
+
let glyphId = 1;
|
|
87
|
+
while (glyphId < glyphCount) {
|
|
88
|
+
if (!require_sfnt.hasBytes(bytes, cursor, 2 + nLeftSize)) return sidByGlyph;
|
|
89
|
+
const firstSid = require_sfnt.u16(bytes, cursor);
|
|
90
|
+
const nLeft = format === 1 ? require_sfnt.u8(bytes, cursor + 2) : require_sfnt.u16(bytes, cursor + 2);
|
|
91
|
+
for (let i = 0; i <= nLeft && glyphId < glyphCount; i++) {
|
|
92
|
+
sidByGlyph.set(glyphId, firstSid + i);
|
|
93
|
+
glyphId++;
|
|
94
|
+
}
|
|
95
|
+
cursor += 2 + nLeftSize;
|
|
96
|
+
}
|
|
97
|
+
return sidByGlyph;
|
|
98
|
+
}
|
|
99
|
+
function readCffEncoding(bytes, offset, glyphCount, glyphBySid) {
|
|
100
|
+
if (offset < CFF_HEADER_SIZE || !require_sfnt.hasBytes(bytes, offset, 2)) return;
|
|
101
|
+
const formatByte = require_sfnt.u8(bytes, offset);
|
|
102
|
+
const format = formatByte & CFF_ENCODING_FORMAT_MASK;
|
|
103
|
+
const glyphByCode = /* @__PURE__ */ new Map();
|
|
104
|
+
let cursor = offset + 1;
|
|
105
|
+
if (format === 0) {
|
|
106
|
+
const nCodes = require_sfnt.u8(bytes, cursor);
|
|
107
|
+
cursor += 1;
|
|
108
|
+
for (let i = 0; i < nCodes; i++) {
|
|
109
|
+
if (!require_sfnt.hasBytes(bytes, cursor, 1)) return glyphByCode;
|
|
110
|
+
const glyphId = i + 1;
|
|
111
|
+
if (glyphId < glyphCount) glyphByCode.set(require_sfnt.u8(bytes, cursor), glyphId);
|
|
112
|
+
cursor += 1;
|
|
113
|
+
}
|
|
114
|
+
} else if (format === 1) {
|
|
115
|
+
const nRanges = require_sfnt.u8(bytes, cursor);
|
|
116
|
+
cursor += 1;
|
|
117
|
+
let glyphId = 1;
|
|
118
|
+
for (let i = 0; i < nRanges; i++) {
|
|
119
|
+
if (!require_sfnt.hasBytes(bytes, cursor, 2)) return glyphByCode;
|
|
120
|
+
const first = require_sfnt.u8(bytes, cursor);
|
|
121
|
+
const nLeft = require_sfnt.u8(bytes, cursor + 1);
|
|
122
|
+
for (let j = 0; j <= nLeft && glyphId < glyphCount; j++) {
|
|
123
|
+
glyphByCode.set(first + j, glyphId);
|
|
124
|
+
glyphId++;
|
|
125
|
+
}
|
|
126
|
+
cursor += 2;
|
|
127
|
+
}
|
|
128
|
+
} else return;
|
|
129
|
+
if ((formatByte & CFF_ENCODING_SUPPLEMENT_FLAG) !== 0) {
|
|
130
|
+
if (!require_sfnt.hasBytes(bytes, cursor, 1)) return glyphByCode;
|
|
131
|
+
const nSups = require_sfnt.u8(bytes, cursor);
|
|
132
|
+
cursor += 1;
|
|
133
|
+
for (let i = 0; i < nSups; i++) {
|
|
134
|
+
if (!require_sfnt.hasBytes(bytes, cursor, 3)) return glyphByCode;
|
|
135
|
+
const glyphId = glyphBySid.get(require_sfnt.u16(bytes, cursor + 1));
|
|
136
|
+
if (glyphId !== void 0) glyphByCode.set(require_sfnt.u8(bytes, cursor), glyphId);
|
|
137
|
+
cursor += 3;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return glyphByCode;
|
|
141
|
+
}
|
|
142
|
+
function cffSources(bytes, predefinedEncodingApplies) {
|
|
143
|
+
if (!require_sfnt.hasBytes(bytes, 0, CFF_HEADER_SIZE)) return;
|
|
144
|
+
const headerSize = require_sfnt.u8(bytes, 2);
|
|
145
|
+
if (require_sfnt.u8(bytes, 0) !== CFF_MAJOR_VERSION || headerSize < CFF_HEADER_SIZE) return;
|
|
146
|
+
const nameIndex = require_cff.readCffIndex(bytes, headerSize);
|
|
147
|
+
if (nameIndex === void 0) return;
|
|
148
|
+
const topDictIndex = require_cff.readCffIndex(bytes, nameIndex.endOffset);
|
|
149
|
+
const topDictBytes = topDictIndex?.entry(0);
|
|
150
|
+
if (topDictIndex === void 0 || topDictBytes === void 0) return;
|
|
151
|
+
const topDict = require_cff.parseCffDict(topDictBytes);
|
|
152
|
+
if (topDict === void 0 || topDict.has(1230)) return;
|
|
153
|
+
const stringIndex = require_cff.readCffIndex(bytes, topDictIndex.endOffset);
|
|
154
|
+
const charStringsOffset = topDict.get(17)?.[0];
|
|
155
|
+
const glyphCount = charStringsOffset === void 0 ? void 0 : require_cff.readCffIndex(bytes, charStringsOffset)?.count;
|
|
156
|
+
if (glyphCount === void 0) return;
|
|
157
|
+
const sidByGlyph = readCffCharset(bytes, topDict.get(15)?.[0] ?? CFF_PREDEFINED_CHARSET_ISO_ADOBE, glyphCount);
|
|
158
|
+
const glyphIdToName = sidByGlyph === void 0 ? void 0 : (glyphId) => {
|
|
159
|
+
const sid = sidByGlyph.get(glyphId);
|
|
160
|
+
return sid === void 0 ? void 0 : require_cff.cffStringForSid(sid, stringIndex);
|
|
161
|
+
};
|
|
162
|
+
const encodingOffset = topDict.get(16)?.[0] ?? CFF_PREDEFINED_ENCODING_STANDARD;
|
|
163
|
+
if (encodingOffset === CFF_PREDEFINED_ENCODING_STANDARD) return predefinedEncodingApplies ? {
|
|
164
|
+
codeToName: require_afm_widths.standardGlyphName,
|
|
165
|
+
glyphIdToName
|
|
166
|
+
} : { glyphIdToName };
|
|
167
|
+
const glyphBySid = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const [glyphId, sid] of sidByGlyph ?? []) if (!glyphBySid.has(sid)) glyphBySid.set(sid, glyphId);
|
|
169
|
+
const glyphByCode = readCffEncoding(bytes, encodingOffset, glyphCount, glyphBySid);
|
|
170
|
+
return glyphByCode === void 0 ? { glyphIdToName } : {
|
|
171
|
+
codeToGlyphId: (code) => glyphByCode.get(code),
|
|
172
|
+
glyphIdToName
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function matchesAscii(bytes, offset, text) {
|
|
176
|
+
for (let i = 0; i < text.length; i++) if (bytes[offset + i] !== text.charCodeAt(i)) return false;
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
const TYPE1_CLEARTEXT_TERMINATOR = "eexec";
|
|
180
|
+
const PFB_SEGMENT_MARKER = 128;
|
|
181
|
+
const PFB_SEGMENT_HEADER_SIZE = 6;
|
|
182
|
+
const POSTSCRIPT_MAGIC = "%!";
|
|
183
|
+
function type1Sources(bytes) {
|
|
184
|
+
const start = bytes[0] === PFB_SEGMENT_MARKER ? PFB_SEGMENT_HEADER_SIZE : 0;
|
|
185
|
+
if (!matchesAscii(bytes, start, POSTSCRIPT_MAGIC)) return;
|
|
186
|
+
let cleartextEnd = bytes.length;
|
|
187
|
+
for (let i = start; i + 5 <= bytes.length; i++) if (matchesAscii(bytes, i, TYPE1_CLEARTEXT_TERMINATOR)) {
|
|
188
|
+
cleartextEnd = i;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
let header = "";
|
|
192
|
+
for (let i = start; i < cleartextEnd; i++) header += String.fromCharCode(bytes[i] ?? 0);
|
|
193
|
+
if (!header.includes("/Encoding")) return;
|
|
194
|
+
if (/\/Encoding\s+StandardEncoding\s+def/.test(header)) return { codeToName: require_afm_widths.standardGlyphName };
|
|
195
|
+
const nameByCode = /* @__PURE__ */ new Map();
|
|
196
|
+
for (const match of header.matchAll(/dup\s+(\d+)\s*\/([^\s/[\]{}<>()%]+)\s+put/g)) {
|
|
197
|
+
const code = Number(match[1]);
|
|
198
|
+
const name = match[2];
|
|
199
|
+
if (name !== void 0 && Number.isInteger(code)) nameByCode.set(code, name);
|
|
200
|
+
}
|
|
201
|
+
return nameByCode.size === 0 ? void 0 : { codeToName: (code) => nameByCode.get(code) };
|
|
202
|
+
}
|
|
203
|
+
function readFontProgramEncoding(program) {
|
|
204
|
+
const font = require_sfnt.parseSfnt(program);
|
|
205
|
+
if (font !== void 0) {
|
|
206
|
+
const cff = require_sfnt.sfntTableBytes(font, "CFF ");
|
|
207
|
+
const container = trueTypeSources(font);
|
|
208
|
+
const outlines = cff === void 0 ? void 0 : cffSources(cff, false);
|
|
209
|
+
return encodingFromSources({
|
|
210
|
+
codeToGlyphId: container.codeToGlyphId ?? outlines?.codeToGlyphId,
|
|
211
|
+
glyphIdToName: container.glyphIdToName ?? outlines?.glyphIdToName,
|
|
212
|
+
glyphIdToUnicode: container.glyphIdToUnicode
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const cff = cffSources(program, true);
|
|
216
|
+
if (cff !== void 0) return encodingFromSources(cff);
|
|
217
|
+
const type1 = type1Sources(program);
|
|
218
|
+
return type1 === void 0 ? void 0 : encodingFromSources(type1);
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
exports.readFontProgramEncoding = readFontProgramEncoding;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/builtin-encoding.d.ts
|
|
2
|
+
interface BuiltinEncoding {
|
|
3
|
+
codeToUnicode(code: number): number | undefined;
|
|
4
|
+
glyphIdToUnicode(glyphId: number): number | undefined;
|
|
5
|
+
}
|
|
6
|
+
declare function readFontProgramEncoding(program: Uint8Array<ArrayBuffer>): BuiltinEncoding | undefined;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { BuiltinEncoding, readFontProgramEncoding };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/builtin-encoding.d.ts
|
|
2
|
+
interface BuiltinEncoding {
|
|
3
|
+
codeToUnicode(code: number): number | undefined;
|
|
4
|
+
glyphIdToUnicode(glyphId: number): number | undefined;
|
|
5
|
+
}
|
|
6
|
+
declare function readFontProgramEncoding(program: Uint8Array<ArrayBuffer>): BuiltinEncoding | undefined;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { BuiltinEncoding, readFontProgramEncoding };
|