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,677 @@
1
+ import { asArray, asName, asNumber, dictGet } from "./objects.js";
2
+ import { IDENTITY_MATRIX, applyMatrix, multiplyMatrices, translationMatrix } from "./matrix.js";
3
+ import { decodeStream } from "./filters.js";
4
+ import { readContentStream } from "./content-read.js";
5
+ import { MarkedContentStack, classifyShape, strokeStyleFromDashArray } from "./interpret-shapes.js";
6
+ import { markedContentProperties, markedContentScopeProps } from "./interpret-marked.js";
7
+ import { COLOR_BLACK } from "document-schema.js";
8
+ //#region src/interpret-colors.ts
9
+ function grayColor(value) {
10
+ return {
11
+ r: value,
12
+ g: value,
13
+ b: value
14
+ };
15
+ }
16
+ function rgbColor(operands) {
17
+ return {
18
+ r: numAt(operands, 0),
19
+ g: numAt(operands, 1),
20
+ b: numAt(operands, 2)
21
+ };
22
+ }
23
+ const CMYK_K_INDEX = 3;
24
+ function cmykColor(operands) {
25
+ const c = numAt(operands, 0);
26
+ const m = numAt(operands, 1);
27
+ const y = numAt(operands, 2);
28
+ const k = numAt(operands, CMYK_K_INDEX);
29
+ return {
30
+ r: (1 - c) * (1 - k),
31
+ g: (1 - m) * (1 - k),
32
+ b: (1 - y) * (1 - k)
33
+ };
34
+ }
35
+ const RGB_COMPONENT_COUNT = 3;
36
+ const CMYK_COMPONENT_COUNT = 4;
37
+ function genericColor(operands) {
38
+ const numericOperands = operands.filter((o) => o.kind === "number");
39
+ if (numericOperands.length === 1) return grayColor(numAt(numericOperands, 0));
40
+ if (numericOperands.length === RGB_COMPONENT_COUNT) return rgbColor(numericOperands);
41
+ if (numericOperands.length === CMYK_COMPONENT_COUNT) return cmykColor(numericOperands);
42
+ }
43
+ //#endregion
44
+ //#region src/interpret.ts
45
+ const MAX_FORM_XOBJECT_DEPTH = 12;
46
+ const FALLBACK_GLYPH_WIDTH_PER_1000 = 500;
47
+ const GLYPH_SPACE_PER_TEXT_SPACE_UNIT = 1e3;
48
+ const ASCII_SPACE = 32;
49
+ const DEFAULT_LINE_WIDTH_PT = 1;
50
+ function initialTextParameters() {
51
+ return {
52
+ fontResourceName: void 0,
53
+ fontSizePt: 0,
54
+ charSpace: 0,
55
+ wordSpace: 0,
56
+ horizScale: 1,
57
+ leading: 0,
58
+ rise: 0
59
+ };
60
+ }
61
+ function defaultTextObjectState() {
62
+ return {
63
+ tm: IDENTITY_MATRIX,
64
+ tlm: IDENTITY_MATRIX
65
+ };
66
+ }
67
+ function computeTrm(gs, text) {
68
+ const fontMatrix = [
69
+ gs.fontSizePt * gs.horizScale,
70
+ 0,
71
+ 0,
72
+ gs.fontSizePt,
73
+ 0,
74
+ gs.rise
75
+ ];
76
+ return multiplyMatrices(multiplyMatrices(fontMatrix, text.tm), gs.ctm);
77
+ }
78
+ function numAt(operands, index) {
79
+ return asNumber(operands[index]) ?? 0;
80
+ }
81
+ const MATRIX_D_INDEX = 3;
82
+ const MATRIX_E_INDEX = 4;
83
+ const MATRIX_F_INDEX = 5;
84
+ function matrixFromOperands(operands) {
85
+ return [
86
+ numAt(operands, 0),
87
+ numAt(operands, 1),
88
+ numAt(operands, 2),
89
+ numAt(operands, MATRIX_D_INDEX),
90
+ numAt(operands, MATRIX_E_INDEX),
91
+ numAt(operands, MATRIX_F_INDEX)
92
+ ];
93
+ }
94
+ const RE_HEIGHT_INDEX = 3;
95
+ const OPERAND_INDEX_3 = 3;
96
+ const OPERAND_INDEX_4 = 4;
97
+ const OPERAND_INDEX_5 = 5;
98
+ const TZ_PERCENT_DIVISOR = 100;
99
+ function interpretContentStream(bytes, resources, context) {
100
+ return runContentStream(bytes, resources, {
101
+ ctm: IDENTITY_MATRIX,
102
+ fillColor: COLOR_BLACK,
103
+ strokeColor: COLOR_BLACK,
104
+ lineWidth: DEFAULT_LINE_WIDTH_PT,
105
+ dashArray: [],
106
+ ...initialTextParameters()
107
+ }, context, 0, new MarkedContentStack());
108
+ }
109
+ function lastPointOf(subpath) {
110
+ const last = subpath.segments[subpath.segments.length - 1];
111
+ return last === void 0 ? {
112
+ x: subpath.startXPt,
113
+ y: subpath.startYPt
114
+ } : {
115
+ x: last.xPt,
116
+ y: last.yPt
117
+ };
118
+ }
119
+ function runContentStream(bytes, resources, initialState, context, depth, markedContent) {
120
+ const items = [];
121
+ const operations = readContentStream(bytes, context.sink);
122
+ const gsStack = [];
123
+ let gs = initialState;
124
+ let text = defaultTextObjectState();
125
+ let pathSubpaths = [];
126
+ let currentSubpath;
127
+ const inScope = (key) => markedContent.inScope(key);
128
+ const pushItem = (item) => {
129
+ if (item.kind === "text") {
130
+ const layer = item.layerName ?? inScope("layerName");
131
+ const actualText = inScope("actualText");
132
+ const alt = inScope("alt");
133
+ const mcid = inScope("mcid");
134
+ items.push({
135
+ ...item,
136
+ ...layer !== void 0 ? { layerName: layer } : {},
137
+ ...actualText !== void 0 ? { actualText } : {},
138
+ ...alt !== void 0 ? { alt } : {},
139
+ ...mcid !== void 0 ? { mcid } : {}
140
+ });
141
+ return;
142
+ }
143
+ const layer = item.layerName ?? inScope("layerName");
144
+ const layerStamped = layer === void 0 ? item : {
145
+ ...item,
146
+ layerName: layer
147
+ };
148
+ const mcid = inScope("mcid");
149
+ items.push(mcid === void 0 ? layerStamped : {
150
+ ...layerStamped,
151
+ mcid
152
+ });
153
+ };
154
+ const finalizeCurrentSubpath = () => {
155
+ if (currentSubpath !== void 0) {
156
+ pathSubpaths.push(currentSubpath);
157
+ currentSubpath = void 0;
158
+ }
159
+ };
160
+ const resetPath = () => {
161
+ pathSubpaths = [];
162
+ currentSubpath = void 0;
163
+ };
164
+ const appendRectSubpath = (operands, ctm) => {
165
+ finalizeCurrentSubpath();
166
+ const x = numAt(operands, 0);
167
+ const y = numAt(operands, 1);
168
+ const w = numAt(operands, 2);
169
+ const h = numAt(operands, RE_HEIGHT_INDEX);
170
+ const p1 = applyMatrix(ctm, {
171
+ x,
172
+ y
173
+ });
174
+ const p2 = applyMatrix(ctm, {
175
+ x: x + w,
176
+ y
177
+ });
178
+ const p3 = applyMatrix(ctm, {
179
+ x: x + w,
180
+ y: y + h
181
+ });
182
+ const p4 = applyMatrix(ctm, {
183
+ x,
184
+ y: y + h
185
+ });
186
+ pathSubpaths.push({
187
+ startXPt: p1.x,
188
+ startYPt: p1.y,
189
+ segments: [
190
+ {
191
+ kind: "line",
192
+ xPt: p2.x,
193
+ yPt: p2.y
194
+ },
195
+ {
196
+ kind: "line",
197
+ xPt: p3.x,
198
+ yPt: p3.y
199
+ },
200
+ {
201
+ kind: "line",
202
+ xPt: p4.x,
203
+ yPt: p4.y
204
+ }
205
+ ],
206
+ closed: true
207
+ });
208
+ };
209
+ const paintFillRuleFor = (operator) => operator.endsWith("*") ? "evenodd" : "nonzero";
210
+ const emitPaint = (operator) => {
211
+ if (operator === "n") {
212
+ resetPath();
213
+ return;
214
+ }
215
+ if ((operator === "s" || operator === "b" || operator === "b*") && currentSubpath !== void 0) currentSubpath.closed = true;
216
+ finalizeCurrentSubpath();
217
+ if (pathSubpaths.length > 0) {
218
+ const isFillOp = operator === "f" || operator === "F" || operator === "f*" || operator === "B" || operator === "B*" || operator === "b" || operator === "b*";
219
+ const isStrokeOp = operator === "S" || operator === "s" || operator === "B" || operator === "B*" || operator === "b" || operator === "b*";
220
+ const paint = {
221
+ fill: isFillOp ? gs.fillColor : void 0,
222
+ stroke: isStrokeOp ? {
223
+ color: gs.strokeColor,
224
+ widthPt: gs.lineWidth
225
+ } : void 0
226
+ };
227
+ const strokeStyle = isStrokeOp ? strokeStyleFromDashArray(gs.dashArray) : void 0;
228
+ pushItem(classifyShape(pathSubpaths, paint, strokeStyle) ?? {
229
+ kind: "path",
230
+ subpaths: pathSubpaths,
231
+ fillRule: paintFillRuleFor(operator),
232
+ ...paint,
233
+ ...strokeStyle !== void 0 ? { style: strokeStyle } : {}
234
+ });
235
+ }
236
+ resetPath();
237
+ };
238
+ const advanceThroughString = (codes) => {
239
+ const fontResourceName = gs.fontResourceName;
240
+ if (fontResourceName === void 0) return;
241
+ let offset = 0;
242
+ while (offset < codes.length) {
243
+ const glyph = context.fontMetrics.glyphAdvance(fontResourceName, resources, codes, offset);
244
+ if (glyph === void 0) context.sink({
245
+ code: "pdf/font-not-resolved",
246
+ severity: "warning",
247
+ message: `could not resolve font resource /${fontResourceName} to compute a glyph advance; assuming a fallback width`
248
+ });
249
+ const widthPer1000 = glyph?.widthPer1000 ?? FALLBACK_GLYPH_WIDTH_PER_1000;
250
+ const byteLength = glyph?.byteLengthConsumed ?? 1;
251
+ const isSingleByteSpace = byteLength === 1 && codes[offset] === ASCII_SPACE;
252
+ const spacing = gs.charSpace + (isSingleByteSpace ? gs.wordSpace : 0);
253
+ const vertical = glyph?.vertical;
254
+ text.tm = vertical === void 0 ? multiplyMatrices(translationMatrix((widthPer1000 / GLYPH_SPACE_PER_TEXT_SPACE_UNIT * gs.fontSizePt + spacing) * gs.horizScale, 0), text.tm) : multiplyMatrices(translationMatrix(0, vertical.displacementPer1000 / GLYPH_SPACE_PER_TEXT_SPACE_UNIT * gs.fontSizePt + spacing), text.tm);
255
+ offset += byteLength;
256
+ }
257
+ };
258
+ const positionVectorOf = (codes) => {
259
+ const fontResourceName = gs.fontResourceName;
260
+ if (fontResourceName === void 0) return;
261
+ const vertical = context.fontMetrics.glyphAdvance(fontResourceName, resources, codes, 0)?.vertical;
262
+ if (vertical === void 0) return;
263
+ return {
264
+ x: vertical.positionXPer1000 / GLYPH_SPACE_PER_TEXT_SPACE_UNIT,
265
+ y: vertical.positionYPer1000 / GLYPH_SPACE_PER_TEXT_SPACE_UNIT
266
+ };
267
+ };
268
+ const showTextArray = (elements) => {
269
+ const fontResourceName = gs.fontResourceName;
270
+ if (fontResourceName === void 0) return;
271
+ const vertical = context.fontMetrics.isVertical(fontResourceName, resources);
272
+ const startMatrix = computeTrm(gs, text);
273
+ const chunks = [];
274
+ let totalLength = 0;
275
+ let firstGlyphPosition;
276
+ for (const el of elements) if (el.kind === "string") {
277
+ firstGlyphPosition ??= vertical ? positionVectorOf(el.bytes) : void 0;
278
+ chunks.push(el.bytes);
279
+ totalLength += el.bytes.length;
280
+ advanceThroughString(el.bytes);
281
+ } else if (el.kind === "number") {
282
+ const adjustment = -(el.value / GLYPH_SPACE_PER_TEXT_SPACE_UNIT) * gs.fontSizePt;
283
+ text.tm = multiplyMatrices(vertical ? translationMatrix(0, adjustment) : translationMatrix(adjustment * gs.horizScale, 0), text.tm);
284
+ }
285
+ if (totalLength === 0) return;
286
+ const combined = new Uint8Array(totalLength);
287
+ let at = 0;
288
+ for (const chunk of chunks) {
289
+ combined.set(chunk, at);
290
+ at += chunk.length;
291
+ }
292
+ const endMatrix = computeTrm(gs, text);
293
+ const shift = firstGlyphPosition === void 0 ? void 0 : translationMatrix(-firstGlyphPosition.x, -firstGlyphPosition.y);
294
+ pushItem({
295
+ kind: "text",
296
+ codes: combined,
297
+ fontResourceName,
298
+ resources,
299
+ startMatrix: shift === void 0 ? startMatrix : multiplyMatrices(shift, startMatrix),
300
+ endMatrix: shift === void 0 ? endMatrix : multiplyMatrices(shift, endMatrix),
301
+ sizePt: gs.fontSizePt,
302
+ color: gs.fillColor,
303
+ ...vertical ? { vertical: true } : {}
304
+ });
305
+ };
306
+ const showText = (textBytes) => {
307
+ showTextArray([{
308
+ kind: "string",
309
+ bytes: textBytes,
310
+ hex: false
311
+ }]);
312
+ };
313
+ const nextLine = () => {
314
+ text.tlm = multiplyMatrices(translationMatrix(0, -gs.leading), text.tlm);
315
+ text.tm = text.tlm;
316
+ };
317
+ const handleDo = (name) => {
318
+ if (name === void 0) return;
319
+ const xobjects = context.resolver.resolveDict(dictGet(resources, "XObject"));
320
+ const xobj = xobjects !== void 0 ? context.resolver.resolve(dictGet(xobjects, name)) : void 0;
321
+ if (xobj?.kind !== "stream") {
322
+ context.sink({
323
+ code: "pdf/xobject-not-resolved",
324
+ severity: "warning",
325
+ message: `XObject resource /${name} did not resolve to a stream`
326
+ });
327
+ return;
328
+ }
329
+ const subtype = asName(dictGet(xobj.dict, "Subtype"));
330
+ const ownLayer = context.layerNameOf?.(dictGet(xobj.dict, "OC"));
331
+ if (subtype === "Image") {
332
+ pushItem({
333
+ kind: "image",
334
+ resourceName: name,
335
+ resources,
336
+ matrix: gs.ctm,
337
+ ...ownLayer !== void 0 ? { layerName: ownLayer } : {}
338
+ });
339
+ return;
340
+ }
341
+ if (subtype === "Form") {
342
+ if (depth >= MAX_FORM_XOBJECT_DEPTH) {
343
+ context.sink({
344
+ code: "pdf/form-recursion-limit",
345
+ severity: "warning",
346
+ message: "form XObject recursion exceeded the depth limit; skipping further nesting"
347
+ });
348
+ return;
349
+ }
350
+ const formMatrixArr = asArray(dictGet(xobj.dict, "Matrix"));
351
+ const formMatrix = formMatrixArr !== void 0 ? matrixFromOperands(formMatrixArr) : IDENTITY_MATRIX;
352
+ const formResources = context.resolver.resolveDict(dictGet(xobj.dict, "Resources")) ?? resources;
353
+ const decoded = decodeStream(xobj.raw, xobj.dict, context.sink);
354
+ const formState = {
355
+ ...gs,
356
+ ctm: multiplyMatrices(formMatrix, gs.ctm)
357
+ };
358
+ const formLayer = ownLayer ?? inScope("layerName");
359
+ const formMcid = dictGet(xobj.dict, "StructParents") !== void 0 ? void 0 : inScope("mcid");
360
+ for (const formItem of runContentStream(decoded.bytes, formResources, formState, context, depth + 1, new MarkedContentStack([{
361
+ ...formLayer !== void 0 ? { layerName: formLayer } : {},
362
+ ...formMcid !== void 0 ? { mcid: formMcid } : {}
363
+ }]))) items.push(formItem);
364
+ }
365
+ };
366
+ for (const token of operations) {
367
+ if (token.kind === "inlineImage") {
368
+ pushItem({
369
+ kind: "inlineImage",
370
+ dict: token.image.dict,
371
+ data: token.image.data,
372
+ matrix: gs.ctm
373
+ });
374
+ continue;
375
+ }
376
+ const { operands, operator } = token.operation;
377
+ switch (operator) {
378
+ case "q":
379
+ gsStack.push(gs);
380
+ break;
381
+ case "Q":
382
+ gs = gsStack.pop() ?? gs;
383
+ break;
384
+ case "cm":
385
+ gs = {
386
+ ...gs,
387
+ ctm: multiplyMatrices(matrixFromOperands(operands), gs.ctm)
388
+ };
389
+ break;
390
+ case "g":
391
+ gs = {
392
+ ...gs,
393
+ fillColor: grayColor(numAt(operands, 0))
394
+ };
395
+ break;
396
+ case "G":
397
+ gs = {
398
+ ...gs,
399
+ strokeColor: grayColor(numAt(operands, 0))
400
+ };
401
+ break;
402
+ case "rg":
403
+ gs = {
404
+ ...gs,
405
+ fillColor: rgbColor(operands)
406
+ };
407
+ break;
408
+ case "RG":
409
+ gs = {
410
+ ...gs,
411
+ strokeColor: rgbColor(operands)
412
+ };
413
+ break;
414
+ case "k":
415
+ gs = {
416
+ ...gs,
417
+ fillColor: cmykColor(operands)
418
+ };
419
+ break;
420
+ case "K":
421
+ gs = {
422
+ ...gs,
423
+ strokeColor: cmykColor(operands)
424
+ };
425
+ break;
426
+ case "sc":
427
+ case "scn": {
428
+ const color = genericColor(operands);
429
+ if (color !== void 0) gs = {
430
+ ...gs,
431
+ fillColor: color
432
+ };
433
+ break;
434
+ }
435
+ case "SC":
436
+ case "SCN": {
437
+ const color = genericColor(operands);
438
+ if (color !== void 0) gs = {
439
+ ...gs,
440
+ strokeColor: color
441
+ };
442
+ break;
443
+ }
444
+ case "re":
445
+ appendRectSubpath(operands, gs.ctm);
446
+ break;
447
+ case "m": {
448
+ finalizeCurrentSubpath();
449
+ const p = applyMatrix(gs.ctm, {
450
+ x: numAt(operands, 0),
451
+ y: numAt(operands, 1)
452
+ });
453
+ currentSubpath = {
454
+ startXPt: p.x,
455
+ startYPt: p.y,
456
+ segments: [],
457
+ closed: false
458
+ };
459
+ break;
460
+ }
461
+ case "l": {
462
+ const p = applyMatrix(gs.ctm, {
463
+ x: numAt(operands, 0),
464
+ y: numAt(operands, 1)
465
+ });
466
+ currentSubpath?.segments.push({
467
+ kind: "line",
468
+ xPt: p.x,
469
+ yPt: p.y
470
+ });
471
+ break;
472
+ }
473
+ case "c": {
474
+ const c1 = applyMatrix(gs.ctm, {
475
+ x: numAt(operands, 0),
476
+ y: numAt(operands, 1)
477
+ });
478
+ const c2 = applyMatrix(gs.ctm, {
479
+ x: numAt(operands, 2),
480
+ y: numAt(operands, OPERAND_INDEX_3)
481
+ });
482
+ const p = applyMatrix(gs.ctm, {
483
+ x: numAt(operands, OPERAND_INDEX_4),
484
+ y: numAt(operands, OPERAND_INDEX_5)
485
+ });
486
+ currentSubpath?.segments.push({
487
+ kind: "cubic",
488
+ c1xPt: c1.x,
489
+ c1yPt: c1.y,
490
+ c2xPt: c2.x,
491
+ c2yPt: c2.y,
492
+ xPt: p.x,
493
+ yPt: p.y
494
+ });
495
+ break;
496
+ }
497
+ case "v":
498
+ if (currentSubpath !== void 0) {
499
+ const cur = lastPointOf(currentSubpath);
500
+ const c2 = applyMatrix(gs.ctm, {
501
+ x: numAt(operands, 0),
502
+ y: numAt(operands, 1)
503
+ });
504
+ const p = applyMatrix(gs.ctm, {
505
+ x: numAt(operands, 2),
506
+ y: numAt(operands, OPERAND_INDEX_3)
507
+ });
508
+ currentSubpath.segments.push({
509
+ kind: "cubic",
510
+ c1xPt: cur.x,
511
+ c1yPt: cur.y,
512
+ c2xPt: c2.x,
513
+ c2yPt: c2.y,
514
+ xPt: p.x,
515
+ yPt: p.y
516
+ });
517
+ }
518
+ break;
519
+ case "y": {
520
+ const c1 = applyMatrix(gs.ctm, {
521
+ x: numAt(operands, 0),
522
+ y: numAt(operands, 1)
523
+ });
524
+ const p = applyMatrix(gs.ctm, {
525
+ x: numAt(operands, 2),
526
+ y: numAt(operands, OPERAND_INDEX_3)
527
+ });
528
+ currentSubpath?.segments.push({
529
+ kind: "cubic",
530
+ c1xPt: c1.x,
531
+ c1yPt: c1.y,
532
+ c2xPt: p.x,
533
+ c2yPt: p.y,
534
+ xPt: p.x,
535
+ yPt: p.y
536
+ });
537
+ break;
538
+ }
539
+ case "h":
540
+ if (currentSubpath !== void 0) currentSubpath.closed = true;
541
+ break;
542
+ case "w":
543
+ gs = {
544
+ ...gs,
545
+ lineWidth: numAt(operands, 0)
546
+ };
547
+ break;
548
+ case "d":
549
+ gs = {
550
+ ...gs,
551
+ dashArray: (asArray(operands[0]) ?? []).map((entry) => asNumber(entry) ?? 0)
552
+ };
553
+ break;
554
+ case "f":
555
+ case "F":
556
+ case "f*":
557
+ case "S":
558
+ case "s":
559
+ case "B":
560
+ case "B*":
561
+ case "b":
562
+ case "b*":
563
+ case "n":
564
+ emitPaint(operator);
565
+ break;
566
+ case "BT":
567
+ text = defaultTextObjectState();
568
+ break;
569
+ case "Tf":
570
+ gs = {
571
+ ...gs,
572
+ fontResourceName: asName(operands[0]),
573
+ fontSizePt: numAt(operands, 1)
574
+ };
575
+ break;
576
+ case "Tc":
577
+ gs = {
578
+ ...gs,
579
+ charSpace: numAt(operands, 0)
580
+ };
581
+ break;
582
+ case "Tw":
583
+ gs = {
584
+ ...gs,
585
+ wordSpace: numAt(operands, 0)
586
+ };
587
+ break;
588
+ case "Tz":
589
+ gs = {
590
+ ...gs,
591
+ horizScale: numAt(operands, 0) / TZ_PERCENT_DIVISOR
592
+ };
593
+ break;
594
+ case "TL":
595
+ gs = {
596
+ ...gs,
597
+ leading: numAt(operands, 0)
598
+ };
599
+ break;
600
+ case "Ts":
601
+ gs = {
602
+ ...gs,
603
+ rise: numAt(operands, 0)
604
+ };
605
+ break;
606
+ case "Td":
607
+ text.tlm = multiplyMatrices(translationMatrix(numAt(operands, 0), numAt(operands, 1)), text.tlm);
608
+ text.tm = text.tlm;
609
+ break;
610
+ case "TD":
611
+ gs = {
612
+ ...gs,
613
+ leading: -numAt(operands, 1)
614
+ };
615
+ text.tlm = multiplyMatrices(translationMatrix(numAt(operands, 0), numAt(operands, 1)), text.tlm);
616
+ text.tm = text.tlm;
617
+ break;
618
+ case "Tm":
619
+ text.tlm = matrixFromOperands(operands);
620
+ text.tm = text.tlm;
621
+ break;
622
+ case "T*":
623
+ nextLine();
624
+ break;
625
+ case "Tj": {
626
+ const str = operands[0];
627
+ if (str?.kind === "string") showText(str.bytes);
628
+ break;
629
+ }
630
+ case "'": {
631
+ nextLine();
632
+ const str = operands[0];
633
+ if (str?.kind === "string") showText(str.bytes);
634
+ break;
635
+ }
636
+ case "\"": {
637
+ gs = {
638
+ ...gs,
639
+ wordSpace: numAt(operands, 0),
640
+ charSpace: numAt(operands, 1)
641
+ };
642
+ nextLine();
643
+ const str = operands[2];
644
+ if (str?.kind === "string") showText(str.bytes);
645
+ break;
646
+ }
647
+ case "TJ": {
648
+ const array = asArray(operands[0]);
649
+ if (array !== void 0) showTextArray(array);
650
+ break;
651
+ }
652
+ case "Do":
653
+ handleDo(asName(operands[0]));
654
+ break;
655
+ case "BDC": {
656
+ const props = markedContentProperties(operands[1], resources, context.resolver);
657
+ const layerName = context.layerNameOf?.(props === void 0 ? void 0 : dictGet(props, "OC"));
658
+ const scopeProps = {
659
+ ...layerName !== void 0 ? { layerName } : {},
660
+ ...markedContentScopeProps(props)
661
+ };
662
+ markedContent.open(depth === 0 ? scopeProps : {
663
+ ...scopeProps,
664
+ mcid: void 0
665
+ });
666
+ break;
667
+ }
668
+ case "BMC":
669
+ markedContent.open({});
670
+ break;
671
+ case "EMC": markedContent.close();
672
+ }
673
+ }
674
+ return items;
675
+ }
676
+ //#endregion
677
+ export { grayColor as a, genericColor as i, numAt as n, rgbColor as o, cmykColor as r, interpretContentStream as t };
@@ -0,0 +1,6 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_interpret = require("./interpret-CqXdXgkY.cjs");
3
+ exports.cmykColor = require_interpret.cmykColor;
4
+ exports.genericColor = require_interpret.genericColor;
5
+ exports.grayColor = require_interpret.grayColor;
6
+ exports.rgbColor = require_interpret.rgbColor;
@@ -0,0 +1,9 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
+ import { Color } from "document-schema.js";
3
+ //#region src/interpret-colors.d.ts
4
+ declare function grayColor(value: number): Color;
5
+ declare function rgbColor(operands: readonly PdfObject[]): Color;
6
+ declare function cmykColor(operands: readonly PdfObject[]): Color;
7
+ declare function genericColor(operands: readonly PdfObject[]): Color | undefined;
8
+ //#endregion
9
+ export { cmykColor, genericColor, grayColor, rgbColor };
@@ -0,0 +1,9 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
2
+ import { Color } from "document-schema.js";
3
+ //#region src/interpret-colors.d.ts
4
+ declare function grayColor(value: number): Color;
5
+ declare function rgbColor(operands: readonly PdfObject[]): Color;
6
+ declare function cmykColor(operands: readonly PdfObject[]): Color;
7
+ declare function genericColor(operands: readonly PdfObject[]): Color | undefined;
8
+ //#endregion
9
+ export { cmykColor, genericColor, grayColor, rgbColor };
@@ -0,0 +1,2 @@
1
+ import { a as grayColor, i as genericColor, o as rgbColor, r as cmykColor } from "./interpret-aWWhdIzr.js";
2
+ export { cmykColor, genericColor, grayColor, rgbColor };