pdf-parser.js 5.2.30 → 5.3.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.
Files changed (189) hide show
  1. package/dist/{afm-widths-BHD2HZIL.cjs → afm-widths-C6U0SQj9.cjs} +5 -1448
  2. package/dist/{afm-widths-B_IGbGky.js → afm-widths-p3UfaXme.js} +3 -1398
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.d.cts +3 -3
  6. package/dist/annotations.d.ts +3 -3
  7. package/dist/attachments.d.cts +2 -2
  8. package/dist/attachments.d.ts +2 -2
  9. package/dist/builtin-encoding.cjs +4 -3
  10. package/dist/builtin-encoding.js +2 -1
  11. package/dist/cmap.d.cts +1 -1
  12. package/dist/cmap.d.ts +1 -1
  13. package/dist/content-read.d.cts +1 -1
  14. package/dist/content-read.d.ts +1 -1
  15. package/dist/content-write.cjs +1 -1
  16. package/dist/content-write.d.cts +1 -1
  17. package/dist/content-write.d.ts +1 -1
  18. package/dist/content-write.js +1 -1
  19. package/dist/diagnostics-C9FxfZ6H.d.cts +22 -0
  20. package/dist/diagnostics-C9FxfZ6H.d.ts +22 -0
  21. package/dist/diagnostics.d.cts +1 -21
  22. package/dist/diagnostics.d.ts +1 -21
  23. package/dist/document.d.cts +1 -1
  24. package/dist/document.d.ts +1 -1
  25. package/dist/{embedded-font-ByD7ZiQS.d.ts → embedded-font-CQZbTTDM.d.ts} +1 -1
  26. package/dist/{embedded-font-DgVBedw6.d.cts → embedded-font-CqePfvrl.d.cts} +1 -1
  27. package/dist/embedded-font-write.d.cts +1 -1
  28. package/dist/embedded-font-write.d.ts +1 -1
  29. package/dist/embedded-font.cjs +2 -2
  30. package/dist/embedded-font.d.cts +1 -1
  31. package/dist/embedded-font.d.ts +1 -1
  32. package/dist/embedded-font.js +2 -2
  33. package/dist/encoding-glyph-unicode.cjs +353 -0
  34. package/dist/encoding-glyph-unicode.d.cts +4 -0
  35. package/dist/encoding-glyph-unicode.d.ts +4 -0
  36. package/dist/encoding-glyph-unicode.js +352 -0
  37. package/dist/encoding-standard-tables.cjs +531 -0
  38. package/dist/encoding-standard-tables.d.cts +7 -0
  39. package/dist/encoding-standard-tables.d.ts +7 -0
  40. package/dist/encoding-standard-tables.js +527 -0
  41. package/dist/encoding-symbol-tables.cjs +533 -0
  42. package/dist/encoding-symbol-tables.d.cts +7 -0
  43. package/dist/encoding-symbol-tables.d.ts +7 -0
  44. package/dist/encoding-symbol-tables.js +529 -0
  45. package/dist/encoding.cjs +1 -9
  46. package/dist/encoding.d.cts +1 -9
  47. package/dist/encoding.d.ts +1 -9
  48. package/dist/encoding.js +2 -2
  49. package/dist/encrypt.d.cts +1 -1
  50. package/dist/encrypt.d.ts +1 -1
  51. package/dist/filters.d.cts +1 -1
  52. package/dist/filters.d.ts +1 -1
  53. package/dist/font-read.cjs +4 -3
  54. package/dist/font-read.d.cts +2 -2
  55. package/dist/font-read.d.ts +2 -2
  56. package/dist/font-read.js +2 -1
  57. package/dist/font-registry.d.cts +1 -1
  58. package/dist/font-registry.d.ts +1 -1
  59. package/dist/form.d.cts +2 -2
  60. package/dist/form.d.ts +2 -2
  61. package/dist/gdef-table-D0Hzn4KD.d.cts +15 -0
  62. package/dist/gdef-table-DL0V8wEZ.d.ts +15 -0
  63. package/dist/gdef-table.d.cts +1 -14
  64. package/dist/gdef-table.d.ts +1 -14
  65. package/dist/glyf-contours.d.cts +12 -1
  66. package/dist/glyf-contours.d.ts +12 -1
  67. package/dist/gsub-context.cjs +13 -0
  68. package/dist/gsub-context.d.cts +34 -0
  69. package/dist/gsub-context.d.ts +34 -0
  70. package/dist/gsub-context.js +2 -0
  71. package/dist/gsub-table-BDpJWqpf.d.ts +52 -0
  72. package/dist/gsub-table-D6niKeLi.js +556 -0
  73. package/dist/gsub-table-DW7Wmi9V.d.cts +52 -0
  74. package/dist/gsub-table-hFfYmf1W.cjs +741 -0
  75. package/dist/gsub-table.cjs +21 -556
  76. package/dist/gsub-table.d.cts +2 -2
  77. package/dist/gsub-table.d.ts +2 -2
  78. package/dist/gsub-table.js +2 -554
  79. package/dist/images-read.d.cts +2 -2
  80. package/dist/images-read.d.ts +2 -2
  81. package/dist/index.cjs +6 -6
  82. package/dist/index.d.cts +2 -2
  83. package/dist/index.d.ts +2 -2
  84. package/dist/index.js +6 -6
  85. package/dist/interpret-CqXdXgkY.cjs +712 -0
  86. package/dist/interpret-aWWhdIzr.js +677 -0
  87. package/dist/interpret-colors.cjs +6 -0
  88. package/dist/interpret-colors.d.cts +9 -0
  89. package/dist/interpret-colors.d.ts +9 -0
  90. package/dist/interpret-colors.js +2 -0
  91. package/dist/interpret-marked.cjs +25 -0
  92. package/dist/interpret-marked.d.cts +11 -0
  93. package/dist/interpret-marked.d.ts +11 -0
  94. package/dist/interpret-marked.js +23 -0
  95. package/dist/interpret-shapes.cjs +212 -0
  96. package/dist/interpret-shapes.d.cts +32 -0
  97. package/dist/interpret-shapes.d.ts +32 -0
  98. package/dist/interpret-shapes.js +199 -0
  99. package/dist/interpret-types.cjs +0 -0
  100. package/dist/interpret-types.d.cts +123 -0
  101. package/dist/interpret-types.d.ts +123 -0
  102. package/dist/interpret-types.js +0 -0
  103. package/dist/interpret.cjs +3 -887
  104. package/dist/interpret.d.cts +5 -116
  105. package/dist/interpret.d.ts +5 -116
  106. package/dist/interpret.js +2 -887
  107. package/dist/math-font.cjs +1 -1
  108. package/dist/math-font.js +1 -1
  109. package/dist/measure.cjs +1 -1
  110. package/dist/measure.js +1 -1
  111. package/dist/names.d.cts +2 -2
  112. package/dist/names.d.ts +2 -2
  113. package/dist/navigation.d.cts +2 -2
  114. package/dist/navigation.d.ts +2 -2
  115. package/dist/optional-content.d.cts +2 -2
  116. package/dist/optional-content.d.ts +2 -2
  117. package/dist/ot-layout-common-BcsGRFBS.d.cts +10 -0
  118. package/dist/ot-layout-common-BcsGRFBS.d.ts +10 -0
  119. package/dist/ot-layout-common.d.cts +1 -9
  120. package/dist/ot-layout-common.d.ts +1 -9
  121. package/dist/parse.d.cts +1 -1
  122. package/dist/parse.d.ts +1 -1
  123. package/dist/predictors.d.cts +1 -1
  124. package/dist/predictors.d.ts +1 -1
  125. package/dist/raster-Cdm3idP_.js +794 -0
  126. package/dist/raster-EG2KYRZ0.cjs +829 -0
  127. package/dist/raster-text.cjs +5 -0
  128. package/dist/raster-text.d.cts +20 -0
  129. package/dist/raster-text.d.ts +20 -0
  130. package/dist/raster-text.js +2 -0
  131. package/dist/raster.cjs +4 -795
  132. package/dist/raster.d.cts +17 -6
  133. package/dist/raster.d.ts +17 -6
  134. package/dist/raster.js +2 -792
  135. package/dist/read-convert.cjs +310 -0
  136. package/dist/read-convert.d.cts +58 -0
  137. package/dist/read-convert.d.ts +58 -0
  138. package/dist/read-convert.js +295 -0
  139. package/dist/read.cjs +5 -293
  140. package/dist/read.d.cts +1 -1
  141. package/dist/read.d.ts +1 -1
  142. package/dist/read.js +4 -292
  143. package/dist/structure.d.cts +2 -2
  144. package/dist/structure.d.ts +2 -2
  145. package/dist/winansi.cjs +1 -1
  146. package/dist/winansi.js +1 -1
  147. package/dist/write-annotations.cjs +132 -0
  148. package/dist/write-annotations.d.cts +29 -0
  149. package/dist/write-annotations.d.ts +29 -0
  150. package/dist/write-annotations.js +121 -0
  151. package/dist/write-font-objects.cjs +76 -0
  152. package/dist/write-font-objects.d.cts +35 -0
  153. package/dist/write-font-objects.d.ts +35 -0
  154. package/dist/write-font-objects.js +75 -0
  155. package/dist/write-form.cjs +91 -0
  156. package/dist/write-form.d.cts +19 -0
  157. package/dist/write-form.d.ts +19 -0
  158. package/dist/write-form.js +89 -0
  159. package/dist/write-images.cjs +148 -0
  160. package/dist/write-images.d.cts +25 -0
  161. package/dist/write-images.d.ts +25 -0
  162. package/dist/write-images.js +140 -0
  163. package/dist/write-outline.cjs +46 -0
  164. package/dist/write-outline.d.cts +18 -0
  165. package/dist/write-outline.d.ts +18 -0
  166. package/dist/write-outline.js +45 -0
  167. package/dist/write-page-emit.cjs +97 -0
  168. package/dist/write-page-emit.d.cts +63 -0
  169. package/dist/write-page-emit.d.ts +63 -0
  170. package/dist/write-page-emit.js +96 -0
  171. package/dist/write-pages.cjs +37 -0
  172. package/dist/write-pages.d.cts +21 -0
  173. package/dist/write-pages.d.ts +21 -0
  174. package/dist/write-pages.js +36 -0
  175. package/dist/write-strings.cjs +41 -0
  176. package/dist/write-strings.d.cts +9 -0
  177. package/dist/write-strings.d.ts +9 -0
  178. package/dist/write-strings.js +37 -0
  179. package/dist/write.cjs +53 -553
  180. package/dist/write.d.cts +1 -1
  181. package/dist/write.d.ts +1 -1
  182. package/dist/write.js +49 -549
  183. package/dist/xref.d.cts +1 -1
  184. package/dist/xref.d.ts +1 -1
  185. package/package.json +1 -1
  186. package/dist/glyf-contours-B1PsI9oA.d.ts +0 -13
  187. package/dist/glyf-contours-NHBpgks-.d.cts +0 -13
  188. package/dist/gsub-table-Bm9kSMzk.d.cts +0 -16
  189. package/dist/gsub-table-CdfESH2-.d.ts +0 -16
@@ -0,0 +1,140 @@
1
+ import { pdfArray, pdfBool, pdfDict, pdfName, pdfNum } from "./objects.js";
2
+ import { deflate } from "./bytes/flate.js";
3
+ import { encodeCcittFax } from "./image/ccitt-encode.js";
4
+ import { decodePng } from "./image/png-decode.js";
5
+ import { readJpegInfo as readJpegInfo$1 } from "./image/jpeg-info.js";
6
+ import { base64ToBytes } from "byte-codec";
7
+ //#region src/write-images.ts
8
+ const BITS_PER_BYTE = 8;
9
+ const BYTE_SHIFT = Math.log2(8);
10
+ const BYTE_MASK = 255;
11
+ const PACKED_BIT_MSB_MASK = 128;
12
+ const BIT_INDEX_MASK = 7;
13
+ const JPEG_COMPONENTS_CMYK = 4;
14
+ function prepareJpegImage(bytes) {
15
+ const info = readJpegInfo$1(bytes);
16
+ const colorSpace = info.components === 1 ? "DeviceGray" : info.components === JPEG_COMPONENTS_CMYK ? "DeviceCMYK" : "DeviceRGB";
17
+ const entries = /* @__PURE__ */ new Map([
18
+ ["Type", pdfName("XObject")],
19
+ ["Subtype", pdfName("Image")],
20
+ ["Width", pdfNum(info.width)],
21
+ ["Height", pdfNum(info.height)],
22
+ ["ColorSpace", pdfName(colorSpace)],
23
+ ["BitsPerComponent", pdfNum(info.precision)],
24
+ ["Filter", pdfName("DCTDecode")]
25
+ ]);
26
+ if (info.components === JPEG_COMPONENTS_CMYK && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", pdfArray([
27
+ 1,
28
+ 0,
29
+ 1,
30
+ 0,
31
+ 1,
32
+ 0,
33
+ 1,
34
+ 0
35
+ ].map((n) => pdfNum(n))));
36
+ return {
37
+ dict: pdfDict(entries),
38
+ raw: bytes
39
+ };
40
+ }
41
+ function pngImageDict(width, height, colorSpace, compress) {
42
+ const entries = /* @__PURE__ */ new Map([
43
+ ["Type", pdfName("XObject")],
44
+ ["Subtype", pdfName("Image")],
45
+ ["Width", pdfNum(width)],
46
+ ["Height", pdfNum(height)],
47
+ ["ColorSpace", pdfName(colorSpace)],
48
+ ["BitsPerComponent", pdfNum(8)]
49
+ ]);
50
+ if (compress) entries.set("Filter", pdfName("FlateDecode"));
51
+ return pdfDict(entries);
52
+ }
53
+ function packBilevel(raw) {
54
+ const rowBytes = raw.width + BIT_INDEX_MASK >> BYTE_SHIFT;
55
+ const packed = new Uint8Array(rowBytes * raw.height);
56
+ const view = new DataView(packed.buffer);
57
+ for (let index = 0; index < raw.data.length; index++) {
58
+ const sample = raw.data[index];
59
+ if (sample !== 0 && sample !== 255) return;
60
+ if (sample === 255) {
61
+ const x = index % raw.width;
62
+ const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> BYTE_SHIFT);
63
+ view.setUint8(byteIndex, view.getUint8(byteIndex) | PACKED_BIT_MSB_MASK >> (x & BIT_INDEX_MASK));
64
+ }
65
+ }
66
+ return packed;
67
+ }
68
+ function preparePngImage(bytes, compress) {
69
+ const raw = decodePng(bytes);
70
+ const colorSpace = raw.channels === 1 ? "DeviceGray" : "DeviceRGB";
71
+ if (compress && raw.channels === 1 && raw.alpha === void 0) {
72
+ const bilevel = packBilevel(raw);
73
+ if (bilevel !== void 0) {
74
+ const flate = deflate(raw.data);
75
+ const g4 = encodeCcittFax(bilevel, {
76
+ columns: raw.width,
77
+ rows: raw.height,
78
+ maxBytes: flate.length
79
+ });
80
+ if (g4 !== void 0) return {
81
+ dict: pdfDict(/* @__PURE__ */ new Map([
82
+ ["Type", pdfName("XObject")],
83
+ ["Subtype", pdfName("Image")],
84
+ ["Width", pdfNum(raw.width)],
85
+ ["Height", pdfNum(raw.height)],
86
+ ["ColorSpace", pdfName("DeviceGray")],
87
+ ["BitsPerComponent", pdfNum(1)],
88
+ ["Filter", pdfName("CCITTFaxDecode")],
89
+ ["DecodeParms", pdfDict(/* @__PURE__ */ new Map([
90
+ ["K", pdfNum(-1)],
91
+ ["Columns", pdfNum(raw.width)],
92
+ ["Rows", pdfNum(raw.height)],
93
+ ["BlackIs1", pdfBool(false)]
94
+ ]))]
95
+ ])),
96
+ raw: g4,
97
+ alpha: void 0
98
+ };
99
+ return {
100
+ dict: pngImageDict(raw.width, raw.height, colorSpace, true),
101
+ raw: flate,
102
+ alpha: void 0
103
+ };
104
+ }
105
+ }
106
+ return {
107
+ dict: pngImageDict(raw.width, raw.height, colorSpace, compress),
108
+ raw: compress ? deflate(raw.data) : raw.data,
109
+ alpha: raw.alpha === void 0 ? void 0 : {
110
+ dict: pngImageDict(raw.width, raw.height, "DeviceGray", compress),
111
+ raw: compress ? deflate(raw.alpha) : raw.alpha
112
+ }
113
+ };
114
+ }
115
+ function preparePassthroughImage(asset, original, compress) {
116
+ const png = preparePngImage(base64ToBytes(asset.base64), compress);
117
+ const entries = /* @__PURE__ */ new Map([
118
+ ["Type", pdfName("XObject")],
119
+ ["Subtype", pdfName("Image")],
120
+ ["Width", pdfNum(asset.widthPx)],
121
+ ["Height", pdfNum(asset.heightPx)],
122
+ ["Filter", pdfName(original.filter === "jbig2" ? "JBIG2Decode" : "JPXDecode")]
123
+ ]);
124
+ if (original.filter === "jbig2") {
125
+ entries.set("ColorSpace", pdfName("DeviceGray"));
126
+ entries.set("BitsPerComponent", pdfNum(1));
127
+ }
128
+ return {
129
+ dict: pdfDict(entries),
130
+ raw: base64ToBytes(original.base64),
131
+ alpha: png.alpha
132
+ };
133
+ }
134
+ function prepareImage(asset, compress) {
135
+ if (asset.original !== void 0) return preparePassthroughImage(asset, asset.original, compress);
136
+ const bytes = base64ToBytes(asset.base64);
137
+ return asset.format === "jpeg" ? prepareJpegImage(bytes) : preparePngImage(bytes, compress);
138
+ }
139
+ //#endregion
140
+ export { BITS_PER_BYTE, BYTE_MASK, packBilevel, pngImageDict, prepareImage, prepareJpegImage, preparePassthroughImage, preparePngImage };
@@ -0,0 +1,46 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_objects = require("./objects.cjs");
3
+ const require_write_annotations = require("./write-annotations.cjs");
4
+ //#region src/write-outline.ts
5
+ function emitOutlineObjects(state) {
6
+ const { objects, outlineItemNums, outlineRootNum, doc, pageAllocs } = state;
7
+ if (outlineRootNum !== void 0) {
8
+ let itemCursor = 0;
9
+ const emitItems = (items, parentNum) => {
10
+ const siblingNums = [];
11
+ let prevNum;
12
+ for (const item of items) {
13
+ const ownNum = outlineItemNums[itemCursor];
14
+ itemCursor += 1;
15
+ siblingNums.push(ownNum);
16
+ const childNums = emitItems(item.children, ownNum);
17
+ const entries = [["Title", require_objects.pdfLiteralString(new TextEncoder().encode(item.title))], ["Parent", require_objects.pdfRef(parentNum, 0)]];
18
+ if (item.destination !== void 0) entries.push(["Dest", require_objects.pdfArray(require_write_annotations.resolveDestinationArray(doc, pageAllocs, item.destination, `outline item "${item.title}"`))]);
19
+ if (prevNum !== void 0) entries.push(["Prev", require_objects.pdfRef(prevNum, 0)]);
20
+ if (siblingNums.length < items.length) entries.push(["Next", require_objects.pdfRef(outlineItemNums[itemCursor], 0)]);
21
+ if (childNums.length > 0) {
22
+ entries.push(["First", require_objects.pdfRef(childNums[0], 0)]);
23
+ entries.push(["Last", require_objects.pdfRef(childNums[childNums.length - 1], 0)]);
24
+ entries.push(["Count", require_objects.pdfNum(childNums.length)]);
25
+ }
26
+ objects.push({
27
+ num: ownNum,
28
+ value: require_objects.pdfDict(Object.fromEntries(entries))
29
+ });
30
+ prevNum = ownNum;
31
+ }
32
+ return siblingNums;
33
+ };
34
+ const topLevelNums = emitItems(doc.outline ?? [], outlineRootNum);
35
+ objects.push({
36
+ num: outlineRootNum,
37
+ value: require_objects.pdfDict({
38
+ Type: require_objects.pdfName("Outlines"),
39
+ First: require_objects.pdfRef(topLevelNums[0], 0),
40
+ Last: require_objects.pdfRef(topLevelNums[topLevelNums.length - 1], 0)
41
+ })
42
+ });
43
+ }
44
+ }
45
+ //#endregion
46
+ exports.emitOutlineObjects = emitOutlineObjects;
@@ -0,0 +1,18 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
+ import { LayoutDocument } from "./layout.cjs";
3
+ //#region src/write-outline.d.ts
4
+ interface OutlineEmitState {
5
+ readonly objects: {
6
+ num: number;
7
+ value: PdfObject;
8
+ }[];
9
+ readonly outlineItemNums: readonly number[];
10
+ readonly outlineRootNum: number | undefined;
11
+ readonly doc: LayoutDocument;
12
+ readonly pageAllocs: readonly {
13
+ pageNum: number;
14
+ }[];
15
+ }
16
+ declare function emitOutlineObjects(state: OutlineEmitState): void;
17
+ //#endregion
18
+ export { OutlineEmitState, emitOutlineObjects };
@@ -0,0 +1,18 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
2
+ import { LayoutDocument } from "./layout.js";
3
+ //#region src/write-outline.d.ts
4
+ interface OutlineEmitState {
5
+ readonly objects: {
6
+ num: number;
7
+ value: PdfObject;
8
+ }[];
9
+ readonly outlineItemNums: readonly number[];
10
+ readonly outlineRootNum: number | undefined;
11
+ readonly doc: LayoutDocument;
12
+ readonly pageAllocs: readonly {
13
+ pageNum: number;
14
+ }[];
15
+ }
16
+ declare function emitOutlineObjects(state: OutlineEmitState): void;
17
+ //#endregion
18
+ export { OutlineEmitState, emitOutlineObjects };
@@ -0,0 +1,45 @@
1
+ import { pdfArray, pdfDict, pdfLiteralString, pdfName, pdfNum, pdfRef } from "./objects.js";
2
+ import { resolveDestinationArray } from "./write-annotations.js";
3
+ //#region src/write-outline.ts
4
+ function emitOutlineObjects(state) {
5
+ const { objects, outlineItemNums, outlineRootNum, doc, pageAllocs } = state;
6
+ if (outlineRootNum !== void 0) {
7
+ let itemCursor = 0;
8
+ const emitItems = (items, parentNum) => {
9
+ const siblingNums = [];
10
+ let prevNum;
11
+ for (const item of items) {
12
+ const ownNum = outlineItemNums[itemCursor];
13
+ itemCursor += 1;
14
+ siblingNums.push(ownNum);
15
+ const childNums = emitItems(item.children, ownNum);
16
+ const entries = [["Title", pdfLiteralString(new TextEncoder().encode(item.title))], ["Parent", pdfRef(parentNum, 0)]];
17
+ if (item.destination !== void 0) entries.push(["Dest", pdfArray(resolveDestinationArray(doc, pageAllocs, item.destination, `outline item "${item.title}"`))]);
18
+ if (prevNum !== void 0) entries.push(["Prev", pdfRef(prevNum, 0)]);
19
+ if (siblingNums.length < items.length) entries.push(["Next", pdfRef(outlineItemNums[itemCursor], 0)]);
20
+ if (childNums.length > 0) {
21
+ entries.push(["First", pdfRef(childNums[0], 0)]);
22
+ entries.push(["Last", pdfRef(childNums[childNums.length - 1], 0)]);
23
+ entries.push(["Count", pdfNum(childNums.length)]);
24
+ }
25
+ objects.push({
26
+ num: ownNum,
27
+ value: pdfDict(Object.fromEntries(entries))
28
+ });
29
+ prevNum = ownNum;
30
+ }
31
+ return siblingNums;
32
+ };
33
+ const topLevelNums = emitItems(doc.outline ?? [], outlineRootNum);
34
+ objects.push({
35
+ num: outlineRootNum,
36
+ value: pdfDict({
37
+ Type: pdfName("Outlines"),
38
+ First: pdfRef(topLevelNums[0], 0),
39
+ Last: pdfRef(topLevelNums[topLevelNums.length - 1], 0)
40
+ })
41
+ });
42
+ }
43
+ }
44
+ //#endregion
45
+ export { emitOutlineObjects };
@@ -0,0 +1,97 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_objects = require("./objects.cjs");
3
+ const require_bytes_writer = require("./bytes/writer.cjs");
4
+ const require_bytes_flate = require("./bytes/flate.cjs");
5
+ const require_util_abort = require("./util/abort.cjs");
6
+ const require_write_annotations = require("./write-annotations.cjs");
7
+ const require_math_content_write = require("./math-content-write.cjs");
8
+ const require_content_write = require("./content-write.cjs");
9
+ const require_font_registry = require("./font-registry.cjs");
10
+ //#region src/write-page-emit.ts
11
+ function emitPageObjects(s) {
12
+ const { doc, options, objects, compress, measurer, registry, fontAllocs, embeddedAllocs, imageAllocs, layerNumByName, formulas, mathFontAlloc, mathFont, pageAllocs, pagesNum, resourcesDict, widgetAnnotsByPage } = s;
13
+ const markedStructureByPage = /* @__PURE__ */ new Map();
14
+ const formulasByPage = /* @__PURE__ */ new Map();
15
+ for (const formula of formulas) {
16
+ const forPage = formulasByPage.get(formula.pageIndex);
17
+ if (forPage === void 0) formulasByPage.set(formula.pageIndex, [formula]);
18
+ else forPage.push(formula);
19
+ }
20
+ const context = {
21
+ measurer,
22
+ resolveFont: (font) => {
23
+ const resolved = require_font_registry.resolveFaceWithRegistry(registry, font);
24
+ if (resolved.kind === "embedded") {
25
+ const alloc = embeddedAllocs.get(resolved.face);
26
+ if (alloc === void 0) throw new Error(`embedded font "${resolved.face.postScriptName}" was not pre-allocated — this is a writePdf internal invariant violation`);
27
+ return {
28
+ kind: "embedded",
29
+ resourceName: alloc.resourceName,
30
+ face: resolved.face
31
+ };
32
+ }
33
+ const alloc = fontAllocs.get(resolved.standardName);
34
+ if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated — this is a writePdf internal invariant violation`);
35
+ return {
36
+ kind: "standard",
37
+ resourceName: alloc.resourceName,
38
+ standardName: resolved.standardName
39
+ };
40
+ },
41
+ resolveImage: (imageId) => {
42
+ const alloc = imageAllocs.get(imageId);
43
+ if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated — this is a writePdf internal invariant violation`);
44
+ return { resourceName: alloc.resourceName };
45
+ }
46
+ };
47
+ doc.pages.forEach((page, pageIndex) => {
48
+ require_util_abort.throwIfAborted(options.signal);
49
+ const { pageNum, contentsNum } = pageAllocs[pageIndex];
50
+ let pageMcid = 0;
51
+ const pageContext = {
52
+ ...context,
53
+ nextMcid: () => pageMcid++,
54
+ layerObjectNumberOf: (name) => layerNumByName.get(name)
55
+ };
56
+ const { bytes: contentBytes, substitutions, missingGlyphs, markedStructure } = require_content_write.writeContentStream(page.items, pageContext);
57
+ if (markedStructure.length > 0) markedStructureByPage.set(pageIndex, [...markedStructure]);
58
+ for (const substitution of substitutions) options.onSubstitution?.(substitution, { pageIndex });
59
+ for (const missing of missingGlyphs) options.onMissingGlyph?.(missing, { pageIndex });
60
+ const pageFormulas = formulasByPage.get(pageIndex);
61
+ const formulaBytes = pageFormulas === void 0 || mathFontAlloc === void 0 || mathFont === void 0 ? void 0 : require_math_content_write.writeFormulaContentStream(pageFormulas, {
62
+ font: mathFont.font,
63
+ resourceName: mathFontAlloc.resourceName
64
+ });
65
+ const combinedContentBytes = formulaBytes === void 0 ? contentBytes : require_bytes_writer.concatBytes([contentBytes, formulaBytes]);
66
+ const finalContentBytes = compress ? require_bytes_flate.deflate(combinedContentBytes) : combinedContentBytes;
67
+ const contentsDict = require_objects.pdfDict(compress ? { Filter: require_objects.pdfName("FlateDecode") } : {});
68
+ objects.push({
69
+ num: contentsNum,
70
+ value: require_objects.pdfStream(contentsDict, finalContentBytes)
71
+ });
72
+ const annots = [...page.items.filter(require_write_annotations.isLinkItem).map((link) => require_write_annotations.buildLinkAnnotDict(link)), ...page.items.filter(require_write_annotations.isInternalLinkItem).map((link) => require_write_annotations.buildInternalLinkAnnotDict(link, doc, pageAllocs))];
73
+ if (page.notes !== void 0 && page.notes.length > 0) annots.push(require_write_annotations.buildNotesAnnotDict(page.notes));
74
+ annots.push(...widgetAnnotsByPage.get(pageIndex) ?? []);
75
+ const pageEntries = /* @__PURE__ */ new Map([
76
+ ["Type", require_objects.pdfName("Page")],
77
+ ["Parent", require_objects.pdfRef(pagesNum, 0)],
78
+ ["MediaBox", require_objects.pdfArray([
79
+ 0,
80
+ 0,
81
+ page.widthPt,
82
+ page.heightPt
83
+ ].map((n) => require_objects.pdfNum(n)))],
84
+ ["Resources", resourcesDict],
85
+ ["Contents", require_objects.pdfRef(contentsNum, 0)]
86
+ ]);
87
+ if (annots.length > 0) pageEntries.set("Annots", require_objects.pdfArray(annots));
88
+ if (markedStructureByPage.has(pageIndex)) pageEntries.set("StructParents", require_objects.pdfNum(pageIndex));
89
+ objects.push({
90
+ num: pageNum,
91
+ value: require_objects.pdfDict(pageEntries)
92
+ });
93
+ });
94
+ return markedStructureByPage;
95
+ }
96
+ //#endregion
97
+ exports.emitPageObjects = emitPageObjects;
@@ -0,0 +1,63 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
+ import { LayoutDocument } from "./layout.cjs";
3
+ import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CqePfvrl.cjs";
4
+ import { WinAnsiSubstitution } from "./winansi.cjs";
5
+ import { FontRegistry } from "./font-registry.cjs";
6
+ import { LoadedMathFont } from "./math-font.cjs";
7
+ import { createFontMeasurer } from "./measure.cjs";
8
+ import { PositionedFormula } from "document-schema.js";
9
+ //#region src/write-page-emit.d.ts
10
+ interface PdfObjectSink {
11
+ num: number;
12
+ value: PdfObject;
13
+ }
14
+ interface WritePdfPageOptions {
15
+ readonly signal?: AbortSignal;
16
+ readonly onSubstitution?: (substitution: WinAnsiSubstitution, context: {
17
+ readonly pageIndex: number;
18
+ }) => void;
19
+ readonly onMissingGlyph?: (missing: EmbeddedFaceSubstitution, context: {
20
+ readonly pageIndex: number;
21
+ }) => void;
22
+ }
23
+ interface PageEmitState {
24
+ readonly doc: LayoutDocument;
25
+ readonly options: WritePdfPageOptions;
26
+ readonly objects: PdfObjectSink[];
27
+ readonly compress: boolean;
28
+ readonly measurer: ReturnType<typeof createFontMeasurer>;
29
+ readonly registry: FontRegistry | undefined;
30
+ readonly fontAllocs: ReadonlyMap<string, {
31
+ resourceName: string;
32
+ fontNum: number;
33
+ descNum: number;
34
+ objNum?: number;
35
+ objNums?: readonly number[];
36
+ }>;
37
+ readonly embeddedAllocs: ReadonlyMap<EmbeddedFace, {
38
+ resourceName: string;
39
+ }>;
40
+ readonly imageAllocs: ReadonlyMap<string, {
41
+ resourceName: string;
42
+ [extra: string]: unknown;
43
+ }>;
44
+ readonly layerNumByName: ReadonlyMap<string, number>;
45
+ readonly formulas: readonly PositionedFormula[];
46
+ readonly mathFontAlloc: {
47
+ resourceName: string;
48
+ } | undefined;
49
+ readonly mathFont: LoadedMathFont | undefined;
50
+ readonly pageAllocs: readonly {
51
+ pageNum: number;
52
+ contentsNum: number;
53
+ }[];
54
+ readonly pagesNum: number;
55
+ readonly resourcesDict: PdfObject;
56
+ readonly widgetAnnotsByPage: ReadonlyMap<number, PdfObject[]>;
57
+ }
58
+ declare function emitPageObjects(s: PageEmitState): Map<number, {
59
+ mcid: number;
60
+ structureId: string;
61
+ }[]>;
62
+ //#endregion
63
+ export { PageEmitState, PdfObjectSink, WritePdfPageOptions, emitPageObjects };
@@ -0,0 +1,63 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
2
+ import { LayoutDocument } from "./layout.js";
3
+ import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CQZbTTDM.js";
4
+ import { WinAnsiSubstitution } from "./winansi.js";
5
+ import { FontRegistry } from "./font-registry.js";
6
+ import { LoadedMathFont } from "./math-font.js";
7
+ import { createFontMeasurer } from "./measure.js";
8
+ import { PositionedFormula } from "document-schema.js";
9
+ //#region src/write-page-emit.d.ts
10
+ interface PdfObjectSink {
11
+ num: number;
12
+ value: PdfObject;
13
+ }
14
+ interface WritePdfPageOptions {
15
+ readonly signal?: AbortSignal;
16
+ readonly onSubstitution?: (substitution: WinAnsiSubstitution, context: {
17
+ readonly pageIndex: number;
18
+ }) => void;
19
+ readonly onMissingGlyph?: (missing: EmbeddedFaceSubstitution, context: {
20
+ readonly pageIndex: number;
21
+ }) => void;
22
+ }
23
+ interface PageEmitState {
24
+ readonly doc: LayoutDocument;
25
+ readonly options: WritePdfPageOptions;
26
+ readonly objects: PdfObjectSink[];
27
+ readonly compress: boolean;
28
+ readonly measurer: ReturnType<typeof createFontMeasurer>;
29
+ readonly registry: FontRegistry | undefined;
30
+ readonly fontAllocs: ReadonlyMap<string, {
31
+ resourceName: string;
32
+ fontNum: number;
33
+ descNum: number;
34
+ objNum?: number;
35
+ objNums?: readonly number[];
36
+ }>;
37
+ readonly embeddedAllocs: ReadonlyMap<EmbeddedFace, {
38
+ resourceName: string;
39
+ }>;
40
+ readonly imageAllocs: ReadonlyMap<string, {
41
+ resourceName: string;
42
+ [extra: string]: unknown;
43
+ }>;
44
+ readonly layerNumByName: ReadonlyMap<string, number>;
45
+ readonly formulas: readonly PositionedFormula[];
46
+ readonly mathFontAlloc: {
47
+ resourceName: string;
48
+ } | undefined;
49
+ readonly mathFont: LoadedMathFont | undefined;
50
+ readonly pageAllocs: readonly {
51
+ pageNum: number;
52
+ contentsNum: number;
53
+ }[];
54
+ readonly pagesNum: number;
55
+ readonly resourcesDict: PdfObject;
56
+ readonly widgetAnnotsByPage: ReadonlyMap<number, PdfObject[]>;
57
+ }
58
+ declare function emitPageObjects(s: PageEmitState): Map<number, {
59
+ mcid: number;
60
+ structureId: string;
61
+ }[]>;
62
+ //#endregion
63
+ export { PageEmitState, PdfObjectSink, WritePdfPageOptions, emitPageObjects };
@@ -0,0 +1,96 @@
1
+ import { pdfArray, pdfDict, pdfName, pdfNum, pdfRef, pdfStream } from "./objects.js";
2
+ import { concatBytes } from "./bytes/writer.js";
3
+ import { deflate } from "./bytes/flate.js";
4
+ import { throwIfAborted } from "./util/abort.js";
5
+ import { buildInternalLinkAnnotDict, buildLinkAnnotDict, buildNotesAnnotDict, isInternalLinkItem, isLinkItem } from "./write-annotations.js";
6
+ import { writeFormulaContentStream } from "./math-content-write.js";
7
+ import { writeContentStream } from "./content-write.js";
8
+ import { resolveFaceWithRegistry } from "./font-registry.js";
9
+ //#region src/write-page-emit.ts
10
+ function emitPageObjects(s) {
11
+ const { doc, options, objects, compress, measurer, registry, fontAllocs, embeddedAllocs, imageAllocs, layerNumByName, formulas, mathFontAlloc, mathFont, pageAllocs, pagesNum, resourcesDict, widgetAnnotsByPage } = s;
12
+ const markedStructureByPage = /* @__PURE__ */ new Map();
13
+ const formulasByPage = /* @__PURE__ */ new Map();
14
+ for (const formula of formulas) {
15
+ const forPage = formulasByPage.get(formula.pageIndex);
16
+ if (forPage === void 0) formulasByPage.set(formula.pageIndex, [formula]);
17
+ else forPage.push(formula);
18
+ }
19
+ const context = {
20
+ measurer,
21
+ resolveFont: (font) => {
22
+ const resolved = resolveFaceWithRegistry(registry, font);
23
+ if (resolved.kind === "embedded") {
24
+ const alloc = embeddedAllocs.get(resolved.face);
25
+ if (alloc === void 0) throw new Error(`embedded font "${resolved.face.postScriptName}" was not pre-allocated — this is a writePdf internal invariant violation`);
26
+ return {
27
+ kind: "embedded",
28
+ resourceName: alloc.resourceName,
29
+ face: resolved.face
30
+ };
31
+ }
32
+ const alloc = fontAllocs.get(resolved.standardName);
33
+ if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated — this is a writePdf internal invariant violation`);
34
+ return {
35
+ kind: "standard",
36
+ resourceName: alloc.resourceName,
37
+ standardName: resolved.standardName
38
+ };
39
+ },
40
+ resolveImage: (imageId) => {
41
+ const alloc = imageAllocs.get(imageId);
42
+ if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated — this is a writePdf internal invariant violation`);
43
+ return { resourceName: alloc.resourceName };
44
+ }
45
+ };
46
+ doc.pages.forEach((page, pageIndex) => {
47
+ throwIfAborted(options.signal);
48
+ const { pageNum, contentsNum } = pageAllocs[pageIndex];
49
+ let pageMcid = 0;
50
+ const pageContext = {
51
+ ...context,
52
+ nextMcid: () => pageMcid++,
53
+ layerObjectNumberOf: (name) => layerNumByName.get(name)
54
+ };
55
+ const { bytes: contentBytes, substitutions, missingGlyphs, markedStructure } = writeContentStream(page.items, pageContext);
56
+ if (markedStructure.length > 0) markedStructureByPage.set(pageIndex, [...markedStructure]);
57
+ for (const substitution of substitutions) options.onSubstitution?.(substitution, { pageIndex });
58
+ for (const missing of missingGlyphs) options.onMissingGlyph?.(missing, { pageIndex });
59
+ const pageFormulas = formulasByPage.get(pageIndex);
60
+ const formulaBytes = pageFormulas === void 0 || mathFontAlloc === void 0 || mathFont === void 0 ? void 0 : writeFormulaContentStream(pageFormulas, {
61
+ font: mathFont.font,
62
+ resourceName: mathFontAlloc.resourceName
63
+ });
64
+ const combinedContentBytes = formulaBytes === void 0 ? contentBytes : concatBytes([contentBytes, formulaBytes]);
65
+ const finalContentBytes = compress ? deflate(combinedContentBytes) : combinedContentBytes;
66
+ const contentsDict = pdfDict(compress ? { Filter: pdfName("FlateDecode") } : {});
67
+ objects.push({
68
+ num: contentsNum,
69
+ value: pdfStream(contentsDict, finalContentBytes)
70
+ });
71
+ const annots = [...page.items.filter(isLinkItem).map((link) => buildLinkAnnotDict(link)), ...page.items.filter(isInternalLinkItem).map((link) => buildInternalLinkAnnotDict(link, doc, pageAllocs))];
72
+ if (page.notes !== void 0 && page.notes.length > 0) annots.push(buildNotesAnnotDict(page.notes));
73
+ annots.push(...widgetAnnotsByPage.get(pageIndex) ?? []);
74
+ const pageEntries = /* @__PURE__ */ new Map([
75
+ ["Type", pdfName("Page")],
76
+ ["Parent", pdfRef(pagesNum, 0)],
77
+ ["MediaBox", pdfArray([
78
+ 0,
79
+ 0,
80
+ page.widthPt,
81
+ page.heightPt
82
+ ].map((n) => pdfNum(n)))],
83
+ ["Resources", resourcesDict],
84
+ ["Contents", pdfRef(contentsNum, 0)]
85
+ ]);
86
+ if (annots.length > 0) pageEntries.set("Annots", pdfArray(annots));
87
+ if (markedStructureByPage.has(pageIndex)) pageEntries.set("StructParents", pdfNum(pageIndex));
88
+ objects.push({
89
+ num: pageNum,
90
+ value: pdfDict(pageEntries)
91
+ });
92
+ });
93
+ return markedStructureByPage;
94
+ }
95
+ //#endregion
96
+ export { emitPageObjects };
@@ -0,0 +1,37 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_objects = require("./objects.cjs");
3
+ //#region src/write-pages.ts
4
+ function emitStructParentTree(state) {
5
+ const { objects, structElementNumById, markedStructureByPage, structureRoots, structRootNum, structParentTreeNum } = state;
6
+ if (structRootNum !== void 0 && structParentTreeNum !== void 0) {
7
+ const nums = [];
8
+ for (const [pageIndex, marks] of markedStructureByPage) {
9
+ const maxMcid = Math.max(...marks.map((mark) => mark.mcid));
10
+ const byMcid = Array.from({ length: maxMcid + 1 }, (_, mcid) => {
11
+ const mark = marks.find((candidate) => candidate.mcid === mcid);
12
+ const elementNum = mark === void 0 ? void 0 : structElementNumById.get(mark.structureId);
13
+ return elementNum === void 0 ? require_objects.pdfNull() : require_objects.pdfRef(elementNum, 0);
14
+ });
15
+ nums.push(require_objects.pdfNum(pageIndex), require_objects.pdfArray(byMcid));
16
+ }
17
+ objects.push({
18
+ num: structParentTreeNum,
19
+ value: require_objects.pdfDict({ Nums: require_objects.pdfArray(nums) })
20
+ });
21
+ const rootEntries = [
22
+ ["Type", require_objects.pdfName("StructTreeRoot")],
23
+ ["K", require_objects.pdfArray(structureRoots.map((element) => {
24
+ const num = structElementNumById.get(element.id);
25
+ if (num === void 0) throw new Error(`structure element "${element.id}" was not allocated — this is a writePdf internal invariant violation`);
26
+ return require_objects.pdfRef(num, 0);
27
+ }))],
28
+ ["ParentTree", require_objects.pdfRef(structParentTreeNum, 0)]
29
+ ];
30
+ objects.push({
31
+ num: structRootNum,
32
+ value: require_objects.pdfDict(Object.fromEntries(rootEntries))
33
+ });
34
+ }
35
+ }
36
+ //#endregion
37
+ exports.emitStructParentTree = emitStructParentTree;
@@ -0,0 +1,21 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
+ //#region src/write-pages.d.ts
3
+ interface StructParentTreeState {
4
+ readonly objects: {
5
+ num: number;
6
+ value: PdfObject;
7
+ }[];
8
+ readonly structElementNumById: ReadonlyMap<string, number>;
9
+ readonly markedStructureByPage: ReadonlyMap<number, readonly {
10
+ mcid: number;
11
+ structureId: string;
12
+ }[]>;
13
+ readonly structureRoots: readonly {
14
+ id: string;
15
+ }[];
16
+ readonly structRootNum: number | undefined;
17
+ readonly structParentTreeNum: number | undefined;
18
+ }
19
+ declare function emitStructParentTree(state: StructParentTreeState): void;
20
+ //#endregion
21
+ export { StructParentTreeState, emitStructParentTree };
@@ -0,0 +1,21 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
2
+ //#region src/write-pages.d.ts
3
+ interface StructParentTreeState {
4
+ readonly objects: {
5
+ num: number;
6
+ value: PdfObject;
7
+ }[];
8
+ readonly structElementNumById: ReadonlyMap<string, number>;
9
+ readonly markedStructureByPage: ReadonlyMap<number, readonly {
10
+ mcid: number;
11
+ structureId: string;
12
+ }[]>;
13
+ readonly structureRoots: readonly {
14
+ id: string;
15
+ }[];
16
+ readonly structRootNum: number | undefined;
17
+ readonly structParentTreeNum: number | undefined;
18
+ }
19
+ declare function emitStructParentTree(state: StructParentTreeState): void;
20
+ //#endregion
21
+ export { StructParentTreeState, emitStructParentTree };