pdf-codec.js 5.2.26 → 5.2.28
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/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
- package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.cjs +5 -3
- package/dist/annotations.d.cts +2 -2
- package/dist/annotations.d.ts +2 -2
- package/dist/annotations.js +5 -3
- package/dist/attachments.d.cts +2 -2
- package/dist/attachments.d.ts +2 -2
- package/dist/builtin-encoding.cjs +17 -6
- package/dist/builtin-encoding.js +17 -6
- package/dist/bytes/crc32.cjs +5 -3
- package/dist/bytes/crc32.js +5 -3
- package/dist/bytes/flate.cjs +0 -1
- package/dist/bytes/flate.js +0 -1
- package/dist/cff-bounds.cjs +73 -45
- package/dist/cff-bounds.js +73 -45
- package/dist/cff.cjs +13 -6
- package/dist/cff.js +13 -6
- package/dist/cmap-table.cjs +54 -26
- package/dist/cmap-table.js +54 -26
- package/dist/cmap.cjs +5 -3
- package/dist/cmap.js +5 -3
- package/dist/content-read.d.cts +1 -1
- package/dist/content-read.d.ts +1 -1
- package/dist/content-write.cjs +21 -14
- package/dist/content-write.d.cts +2 -2
- package/dist/content-write.d.ts +2 -2
- package/dist/content-write.js +21 -14
- package/dist/crypto/aes.cjs +76 -55
- package/dist/crypto/aes.js +76 -55
- package/dist/crypto/md5.cjs +345 -149
- package/dist/crypto/md5.js +345 -149
- package/dist/crypto/rc4.cjs +5 -4
- package/dist/crypto/rc4.js +5 -4
- package/dist/crypto/sha2.cjs +92 -43
- package/dist/crypto/sha2.js +92 -43
- package/dist/document.cjs +17 -11
- package/dist/document.d.cts +1 -1
- package/dist/document.d.ts +1 -1
- package/dist/document.js +17 -11
- package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
- package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
- package/dist/embedded-font-write.d.cts +2 -2
- package/dist/embedded-font-write.d.ts +2 -2
- package/dist/embedded-font.cjs +4 -2
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +4 -2
- package/dist/encoding.cjs +1 -1
- package/dist/encoding.js +1 -1
- package/dist/encrypt-write.cjs +25 -21
- package/dist/encrypt-write.d.cts +1 -1
- package/dist/encrypt-write.d.ts +1 -1
- package/dist/encrypt-write.js +25 -21
- package/dist/encrypt.cjs +43 -64
- package/dist/encrypt.d.cts +1 -1
- package/dist/encrypt.d.ts +1 -1
- package/dist/encrypt.js +43 -64
- package/dist/filters.cjs +46 -26
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/filters.js +46 -26
- package/dist/font-face.cjs +2 -1
- package/dist/font-face.js +2 -1
- package/dist/font-read.cjs +12 -6
- package/dist/font-read.d.cts +1 -1
- package/dist/font-read.d.ts +1 -1
- package/dist/font-read.js +12 -6
- package/dist/font-registry.d.cts +3 -3
- package/dist/font-registry.d.ts +3 -3
- package/dist/font-tables.cjs +55 -28
- package/dist/font-tables.js +55 -28
- package/dist/form.cjs +13 -8
- package/dist/form.d.cts +2 -2
- package/dist/form.d.ts +2 -2
- package/dist/form.js +13 -8
- package/dist/gdef-table.cjs +6 -3
- package/dist/gdef-table.js +6 -3
- package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
- package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
- package/dist/glyf-contours.cjs +3 -1
- package/dist/glyf-contours.d.cts +1 -1
- package/dist/glyf-contours.d.ts +1 -1
- package/dist/glyf-contours.js +3 -1
- package/dist/glyf.cjs +22 -11
- package/dist/glyf.js +22 -11
- package/dist/gpos-table.cjs +37 -19
- package/dist/gpos-table.js +37 -19
- package/dist/gsub-table.cjs +40 -25
- package/dist/gsub-table.js +40 -25
- package/dist/hmtx-table.cjs +5 -3
- package/dist/hmtx-table.js +5 -3
- package/dist/image/ccitt-encode.cjs +8 -5
- package/dist/image/ccitt-encode.js +8 -5
- package/dist/image/ccitt.cjs +801 -209
- package/dist/image/ccitt.js +801 -209
- package/dist/image/jbig2-arith.cjs +340 -306
- package/dist/image/jbig2-arith.js +340 -306
- package/dist/image/jbig2-bitmap.cjs +8 -5
- package/dist/image/jbig2-bitmap.js +8 -5
- package/dist/image/jbig2-generic.cjs +240 -69
- package/dist/image/jbig2-generic.js +240 -69
- package/dist/image/jbig2-text.cjs +4 -2
- package/dist/image/jbig2-text.js +4 -2
- package/dist/image/jbig2.cjs +69 -31
- package/dist/image/jbig2.js +69 -31
- package/dist/image/jp2-boxes.cjs +52 -27
- package/dist/image/jp2-boxes.js +52 -27
- package/dist/image/jpeg-info.cjs +29 -24
- package/dist/image/jpeg-info.js +29 -24
- package/dist/image/jpeg2000-codestream.cjs +61 -32
- package/dist/image/jpeg2000-codestream.js +61 -32
- package/dist/image/jpeg2000-dwt.cjs +2 -1
- package/dist/image/jpeg2000-dwt.js +2 -1
- package/dist/image/jpeg2000-t1.cjs +21 -11
- package/dist/image/jpeg2000-t1.js +21 -11
- package/dist/image/jpeg2000-t2.cjs +12 -5
- package/dist/image/jpeg2000-t2.js +12 -5
- package/dist/image/jpeg2000-tagtree.cjs +8 -4
- package/dist/image/jpeg2000-tagtree.js +8 -4
- package/dist/image/jpeg2000.cjs +11 -6
- package/dist/image/jpeg2000.js +11 -6
- package/dist/image/png-decode.cjs +62 -39
- package/dist/image/png-decode.d.cts +3 -2
- package/dist/image/png-decode.d.ts +3 -2
- package/dist/image/png-decode.js +62 -39
- package/dist/image/png-filter.cjs +23 -15
- package/dist/image/png-filter.js +23 -15
- package/dist/images-read.cjs +41 -36
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/images-read.js +41 -36
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interpret.cjs +68 -40
- package/dist/interpret.d.cts +1 -1
- package/dist/interpret.d.ts +1 -1
- package/dist/interpret.js +68 -40
- package/dist/lexer.cjs +86 -51
- package/dist/lexer.js +86 -51
- package/dist/math-content-write.cjs +9 -5
- package/dist/math-content-write.js +9 -5
- package/dist/math-font-write.cjs +2 -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 +2 -1
- package/dist/math-font.cjs +16 -7
- package/dist/math-font.js +16 -7
- package/dist/math-table.cjs +25 -13
- package/dist/math-table.js +25 -13
- package/dist/matrix.cjs +3 -2
- package/dist/matrix.js +3 -2
- package/dist/measure.cjs +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.cjs +7 -7
- package/dist/names.d.cts +2 -2
- package/dist/names.d.ts +2 -2
- package/dist/names.js +7 -7
- package/dist/navigation.cjs +16 -12
- package/dist/navigation.d.cts +4 -4
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.js +16 -12
- package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
- package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
- package/dist/objects.d.cts +1 -1
- package/dist/objects.d.ts +1 -1
- package/dist/optional-content.d.cts +2 -2
- package/dist/optional-content.d.ts +2 -2
- package/dist/ot-layout-common.cjs +22 -15
- package/dist/ot-layout-common.js +22 -15
- package/dist/parse.cjs +7 -5
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +7 -5
- package/dist/pdf-text.cjs +5 -2
- package/dist/pdf-text.js +5 -2
- package/dist/predictors.cjs +14 -9
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/predictors.js +14 -9
- package/dist/raster.cjs +30 -19
- package/dist/raster.d.cts +8 -8
- package/dist/raster.d.ts +8 -8
- package/dist/raster.js +30 -19
- package/dist/read.cjs +29 -16
- package/dist/read.js +29 -16
- package/dist/serialize.cjs +6 -2
- package/dist/serialize.d.cts +1 -1
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.js +6 -2
- package/dist/sfnt-subset.cjs +25 -13
- package/dist/sfnt-subset.d.cts +1 -1
- package/dist/sfnt-subset.d.ts +1 -1
- package/dist/sfnt-subset.js +25 -13
- package/dist/sfnt.cjs +20 -10
- package/dist/sfnt.js +20 -10
- package/dist/structure.d.cts +2 -2
- package/dist/structure.d.ts +2 -2
- package/dist/text-group.cjs +0 -1
- package/dist/text-group.js +0 -1
- package/dist/text-layout.d.cts +1 -1
- package/dist/text-layout.d.ts +1 -1
- package/dist/tounicode.cjs +4 -2
- package/dist/tounicode.d.cts +1 -1
- package/dist/tounicode.d.ts +1 -1
- package/dist/tounicode.js +4 -2
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write.cjs +20 -12
- package/dist/write.d.cts +1 -1
- package/dist/write.d.ts +1 -1
- package/dist/write.js +20 -12
- package/dist/xref.cjs +5 -2
- package/dist/xref.d.cts +1 -1
- package/dist/xref.d.ts +1 -1
- package/dist/xref.js +5 -2
- package/package.json +1 -1
package/dist/interpret.js
CHANGED
|
@@ -7,6 +7,8 @@ import { COLOR_BLACK } from "document-schema.js";
|
|
|
7
7
|
//#region src/interpret.ts
|
|
8
8
|
const MAX_FORM_XOBJECT_DEPTH = 12;
|
|
9
9
|
const FALLBACK_GLYPH_WIDTH_PER_1000 = 500;
|
|
10
|
+
const GLYPH_SPACE_PER_TEXT_SPACE_UNIT = 1e3;
|
|
11
|
+
const ASCII_SPACE = 32;
|
|
10
12
|
const DEFAULT_LINE_WIDTH_PT = 1;
|
|
11
13
|
function initialTextParameters() {
|
|
12
14
|
return {
|
|
@@ -71,31 +73,37 @@ function rgbColor(operands) {
|
|
|
71
73
|
b: numAt(operands, 2)
|
|
72
74
|
};
|
|
73
75
|
}
|
|
76
|
+
const CMYK_K_INDEX = 3;
|
|
74
77
|
function cmykColor(operands) {
|
|
75
78
|
const c = numAt(operands, 0);
|
|
76
79
|
const m = numAt(operands, 1);
|
|
77
80
|
const y = numAt(operands, 2);
|
|
78
|
-
const k = numAt(operands,
|
|
81
|
+
const k = numAt(operands, CMYK_K_INDEX);
|
|
79
82
|
return {
|
|
80
83
|
r: (1 - c) * (1 - k),
|
|
81
84
|
g: (1 - m) * (1 - k),
|
|
82
85
|
b: (1 - y) * (1 - k)
|
|
83
86
|
};
|
|
84
87
|
}
|
|
88
|
+
const RGB_COMPONENT_COUNT = 3;
|
|
89
|
+
const CMYK_COMPONENT_COUNT = 4;
|
|
85
90
|
function genericColor(operands) {
|
|
86
91
|
const numericOperands = operands.filter((o) => o.kind === "number");
|
|
87
92
|
if (numericOperands.length === 1) return grayColor(numAt(numericOperands, 0));
|
|
88
|
-
if (numericOperands.length ===
|
|
89
|
-
if (numericOperands.length ===
|
|
93
|
+
if (numericOperands.length === RGB_COMPONENT_COUNT) return rgbColor(numericOperands);
|
|
94
|
+
if (numericOperands.length === CMYK_COMPONENT_COUNT) return cmykColor(numericOperands);
|
|
90
95
|
}
|
|
96
|
+
const MATRIX_D_INDEX = 3;
|
|
97
|
+
const MATRIX_E_INDEX = 4;
|
|
98
|
+
const MATRIX_F_INDEX = 5;
|
|
91
99
|
function matrixFromOperands(operands) {
|
|
92
100
|
return [
|
|
93
101
|
numAt(operands, 0),
|
|
94
102
|
numAt(operands, 1),
|
|
95
103
|
numAt(operands, 2),
|
|
96
|
-
numAt(operands,
|
|
97
|
-
numAt(operands,
|
|
98
|
-
numAt(operands,
|
|
104
|
+
numAt(operands, MATRIX_D_INDEX),
|
|
105
|
+
numAt(operands, MATRIX_E_INDEX),
|
|
106
|
+
numAt(operands, MATRIX_F_INDEX)
|
|
99
107
|
];
|
|
100
108
|
}
|
|
101
109
|
const SHAPE_ABS_TOLERANCE_PT = .001;
|
|
@@ -139,9 +147,10 @@ function closedPolygonCorners(subpath) {
|
|
|
139
147
|
if (nearlyEqualPoints(first, last, shapeTolerance(Math.max(bounds.maxX - bounds.minX, bounds.maxY - bounds.minY)))) corners.pop();
|
|
140
148
|
return corners;
|
|
141
149
|
}
|
|
150
|
+
const RECTANGLE_CORNER_COUNT = 4;
|
|
142
151
|
function detectRect(subpath, paint) {
|
|
143
152
|
const corners = closedPolygonCorners(subpath);
|
|
144
|
-
if (corners?.length !==
|
|
153
|
+
if (corners?.length !== RECTANGLE_CORNER_COUNT) return;
|
|
145
154
|
const { minX, minY, maxX, maxY } = boundsOf(corners);
|
|
146
155
|
const widthPt = maxX - minX;
|
|
147
156
|
const heightPt = maxY - minY;
|
|
@@ -189,9 +198,10 @@ function expectedEllipseControl(atExtreme, atExtremeKind, otherEnd, center, kx,
|
|
|
189
198
|
y: atExtreme.y
|
|
190
199
|
};
|
|
191
200
|
}
|
|
201
|
+
const ELLIPSE_SEGMENT_COUNT = 4;
|
|
192
202
|
function detectEllipse(subpath, paint) {
|
|
193
203
|
const segments = subpath.segments;
|
|
194
|
-
if (!subpath.closed || segments.length !==
|
|
204
|
+
if (!subpath.closed || segments.length !== ELLIPSE_SEGMENT_COUNT || segments.some((segment) => segment.kind !== "cubic")) return;
|
|
195
205
|
const start = {
|
|
196
206
|
x: subpath.startXPt,
|
|
197
207
|
y: subpath.startYPt
|
|
@@ -217,16 +227,16 @@ function detectEllipse(subpath, paint) {
|
|
|
217
227
|
y: finalSegment.yPt
|
|
218
228
|
}, start, Math.max(tolX, tolY))) return;
|
|
219
229
|
const extremes = onCurve.map((point) => cardinalExtremeOf(point, center, rx, ry, tolX, tolY));
|
|
220
|
-
if (extremes.some((extreme) => extreme === void 0) || new Set(extremes).size !==
|
|
230
|
+
if (extremes.some((extreme) => extreme === void 0) || new Set(extremes).size !== ELLIPSE_SEGMENT_COUNT) return;
|
|
221
231
|
const kx = rx * BEZIER_KAPPA;
|
|
222
232
|
const ky = ry * BEZIER_KAPPA;
|
|
223
233
|
const controlTolerance = Math.max(tolX, tolY);
|
|
224
|
-
for (let i = 0; i <
|
|
234
|
+
for (let i = 0; i < ELLIPSE_SEGMENT_COUNT; i += 1) {
|
|
225
235
|
const segment = segments[i];
|
|
226
236
|
const from = onCurve[i];
|
|
227
237
|
const fromKind = extremes[i];
|
|
228
|
-
const to = onCurve[(i + 1) %
|
|
229
|
-
const toKind = extremes[(i + 1) %
|
|
238
|
+
const to = onCurve[(i + 1) % ELLIPSE_SEGMENT_COUNT];
|
|
239
|
+
const toKind = extremes[(i + 1) % ELLIPSE_SEGMENT_COUNT];
|
|
230
240
|
if (segment?.kind !== "cubic" || from === void 0 || to === void 0 || fromKind === void 0 || toKind === void 0) return;
|
|
231
241
|
const expectedC1 = expectedEllipseControl(from, fromKind, to, center, kx, ky);
|
|
232
242
|
const expectedC2 = expectedEllipseControl(to, toKind, from, center, kx, ky);
|
|
@@ -273,17 +283,38 @@ function classifyShape(subpaths, paint, style) {
|
|
|
273
283
|
if (subpaths.length !== 1 || subpath === void 0) return;
|
|
274
284
|
return detectRect(subpath, paint) ?? detectEllipse(subpath, paint) ?? detectLine(subpath, paint, style);
|
|
275
285
|
}
|
|
286
|
+
var MarkedContentStack = class {
|
|
287
|
+
#frames;
|
|
288
|
+
constructor(seed = []) {
|
|
289
|
+
this.#frames = [...seed];
|
|
290
|
+
}
|
|
291
|
+
open(frame) {
|
|
292
|
+
this.#frames.push(frame);
|
|
293
|
+
}
|
|
294
|
+
close() {
|
|
295
|
+
this.#frames.pop();
|
|
296
|
+
}
|
|
297
|
+
inScope(key) {
|
|
298
|
+
for (let i = this.#frames.length - 1; i >= 0; i--) {
|
|
299
|
+
const frame = this.#frames[i];
|
|
300
|
+
if (frame !== void 0 && key in frame) return frame[key];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
const RE_HEIGHT_INDEX = 3;
|
|
305
|
+
const OPERAND_INDEX_3 = 3;
|
|
306
|
+
const OPERAND_INDEX_4 = 4;
|
|
307
|
+
const OPERAND_INDEX_5 = 5;
|
|
308
|
+
const TZ_PERCENT_DIVISOR = 100;
|
|
276
309
|
function interpretContentStream(bytes, resources, context) {
|
|
277
|
-
|
|
278
|
-
runContentStream(bytes, resources, {
|
|
310
|
+
return runContentStream(bytes, resources, {
|
|
279
311
|
ctm: IDENTITY_MATRIX,
|
|
280
312
|
fillColor: COLOR_BLACK,
|
|
281
313
|
strokeColor: COLOR_BLACK,
|
|
282
314
|
lineWidth: DEFAULT_LINE_WIDTH_PT,
|
|
283
315
|
dashArray: [],
|
|
284
316
|
...initialTextParameters()
|
|
285
|
-
}, context,
|
|
286
|
-
return items;
|
|
317
|
+
}, context, 0, new MarkedContentStack());
|
|
287
318
|
}
|
|
288
319
|
function lastPointOf(subpath) {
|
|
289
320
|
const last = subpath.segments[subpath.segments.length - 1];
|
|
@@ -295,19 +326,15 @@ function lastPointOf(subpath) {
|
|
|
295
326
|
y: last.yPt
|
|
296
327
|
};
|
|
297
328
|
}
|
|
298
|
-
function runContentStream(bytes, resources, initialState, context,
|
|
329
|
+
function runContentStream(bytes, resources, initialState, context, depth, markedContent) {
|
|
330
|
+
const items = [];
|
|
299
331
|
const operations = readContentStream(bytes, context.sink);
|
|
300
332
|
const gsStack = [];
|
|
301
333
|
let gs = initialState;
|
|
302
334
|
let text = defaultTextObjectState();
|
|
303
335
|
let pathSubpaths = [];
|
|
304
336
|
let currentSubpath;
|
|
305
|
-
const inScope = (key) =>
|
|
306
|
-
for (let i = markedContent.length - 1; i >= 0; i--) {
|
|
307
|
-
const frame = markedContent[i];
|
|
308
|
-
if (frame !== void 0 && key in frame) return frame[key];
|
|
309
|
-
}
|
|
310
|
-
};
|
|
337
|
+
const inScope = (key) => markedContent.inScope(key);
|
|
311
338
|
const pushItem = (item) => {
|
|
312
339
|
if (item.kind === "text") {
|
|
313
340
|
const layer = item.layerName ?? inScope("layerName");
|
|
@@ -349,7 +376,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
349
376
|
const x = numAt(operands, 0);
|
|
350
377
|
const y = numAt(operands, 1);
|
|
351
378
|
const w = numAt(operands, 2);
|
|
352
|
-
const h = numAt(operands,
|
|
379
|
+
const h = numAt(operands, RE_HEIGHT_INDEX);
|
|
353
380
|
const p1 = applyMatrix(ctm, {
|
|
354
381
|
x,
|
|
355
382
|
y
|
|
@@ -431,10 +458,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
431
458
|
});
|
|
432
459
|
const widthPer1000 = glyph?.widthPer1000 ?? FALLBACK_GLYPH_WIDTH_PER_1000;
|
|
433
460
|
const byteLength = glyph?.byteLengthConsumed ?? 1;
|
|
434
|
-
const isSingleByteSpace = byteLength === 1 && codes[offset] ===
|
|
461
|
+
const isSingleByteSpace = byteLength === 1 && codes[offset] === ASCII_SPACE;
|
|
435
462
|
const spacing = gs.charSpace + (isSingleByteSpace ? gs.wordSpace : 0);
|
|
436
463
|
const vertical = glyph?.vertical;
|
|
437
|
-
text.tm = vertical === void 0 ? multiplyMatrices(translationMatrix((widthPer1000 /
|
|
464
|
+
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);
|
|
438
465
|
offset += byteLength;
|
|
439
466
|
}
|
|
440
467
|
};
|
|
@@ -444,8 +471,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
444
471
|
const vertical = context.fontMetrics.glyphAdvance(fontResourceName, resources, codes, 0)?.vertical;
|
|
445
472
|
if (vertical === void 0) return;
|
|
446
473
|
return {
|
|
447
|
-
x: vertical.positionXPer1000 /
|
|
448
|
-
y: vertical.positionYPer1000 /
|
|
474
|
+
x: vertical.positionXPer1000 / GLYPH_SPACE_PER_TEXT_SPACE_UNIT,
|
|
475
|
+
y: vertical.positionYPer1000 / GLYPH_SPACE_PER_TEXT_SPACE_UNIT
|
|
449
476
|
};
|
|
450
477
|
};
|
|
451
478
|
const showTextArray = (elements) => {
|
|
@@ -462,7 +489,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
462
489
|
totalLength += el.bytes.length;
|
|
463
490
|
advanceThroughString(el.bytes);
|
|
464
491
|
} else if (el.kind === "number") {
|
|
465
|
-
const adjustment = -(el.value /
|
|
492
|
+
const adjustment = -(el.value / GLYPH_SPACE_PER_TEXT_SPACE_UNIT) * gs.fontSizePt;
|
|
466
493
|
text.tm = multiplyMatrices(vertical ? translationMatrix(0, adjustment) : translationMatrix(adjustment * gs.horizScale, 0), text.tm);
|
|
467
494
|
}
|
|
468
495
|
if (totalLength === 0) return;
|
|
@@ -540,10 +567,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
540
567
|
};
|
|
541
568
|
const formLayer = ownLayer ?? inScope("layerName");
|
|
542
569
|
const formMcid = dictGet(xobj.dict, "StructParents") !== void 0 ? void 0 : inScope("mcid");
|
|
543
|
-
runContentStream(decoded.bytes, formResources, formState, context,
|
|
570
|
+
for (const formItem of runContentStream(decoded.bytes, formResources, formState, context, depth + 1, new MarkedContentStack([{
|
|
544
571
|
...formLayer !== void 0 ? { layerName: formLayer } : {},
|
|
545
572
|
...formMcid !== void 0 ? { mcid: formMcid } : {}
|
|
546
|
-
}]);
|
|
573
|
+
}]))) items.push(formItem);
|
|
547
574
|
}
|
|
548
575
|
};
|
|
549
576
|
for (const token of operations) {
|
|
@@ -660,11 +687,11 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
660
687
|
});
|
|
661
688
|
const c2 = applyMatrix(gs.ctm, {
|
|
662
689
|
x: numAt(operands, 2),
|
|
663
|
-
y: numAt(operands,
|
|
690
|
+
y: numAt(operands, OPERAND_INDEX_3)
|
|
664
691
|
});
|
|
665
692
|
const p = applyMatrix(gs.ctm, {
|
|
666
|
-
x: numAt(operands,
|
|
667
|
-
y: numAt(operands,
|
|
693
|
+
x: numAt(operands, OPERAND_INDEX_4),
|
|
694
|
+
y: numAt(operands, OPERAND_INDEX_5)
|
|
668
695
|
});
|
|
669
696
|
currentSubpath?.segments.push({
|
|
670
697
|
kind: "cubic",
|
|
@@ -686,7 +713,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
686
713
|
});
|
|
687
714
|
const p = applyMatrix(gs.ctm, {
|
|
688
715
|
x: numAt(operands, 2),
|
|
689
|
-
y: numAt(operands,
|
|
716
|
+
y: numAt(operands, OPERAND_INDEX_3)
|
|
690
717
|
});
|
|
691
718
|
currentSubpath.segments.push({
|
|
692
719
|
kind: "cubic",
|
|
@@ -706,7 +733,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
706
733
|
});
|
|
707
734
|
const p = applyMatrix(gs.ctm, {
|
|
708
735
|
x: numAt(operands, 2),
|
|
709
|
-
y: numAt(operands,
|
|
736
|
+
y: numAt(operands, OPERAND_INDEX_3)
|
|
710
737
|
});
|
|
711
738
|
currentSubpath?.segments.push({
|
|
712
739
|
kind: "cubic",
|
|
@@ -771,7 +798,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
771
798
|
case "Tz":
|
|
772
799
|
gs = {
|
|
773
800
|
...gs,
|
|
774
|
-
horizScale: numAt(operands, 0) /
|
|
801
|
+
horizScale: numAt(operands, 0) / TZ_PERCENT_DIVISOR
|
|
775
802
|
};
|
|
776
803
|
break;
|
|
777
804
|
case "TL":
|
|
@@ -842,18 +869,19 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
842
869
|
...layerName !== void 0 ? { layerName } : {},
|
|
843
870
|
...markedContentScopeProps(props)
|
|
844
871
|
};
|
|
845
|
-
markedContent.
|
|
872
|
+
markedContent.open(depth === 0 ? scopeProps : {
|
|
846
873
|
...scopeProps,
|
|
847
874
|
mcid: void 0
|
|
848
875
|
});
|
|
849
876
|
break;
|
|
850
877
|
}
|
|
851
878
|
case "BMC":
|
|
852
|
-
markedContent.
|
|
879
|
+
markedContent.open({});
|
|
853
880
|
break;
|
|
854
|
-
case "EMC": markedContent.
|
|
881
|
+
case "EMC": markedContent.close();
|
|
855
882
|
}
|
|
856
883
|
}
|
|
884
|
+
return items;
|
|
857
885
|
}
|
|
858
886
|
//#endregion
|
|
859
887
|
export { interpretContentStream };
|
package/dist/lexer.cjs
CHANGED
|
@@ -1,44 +1,79 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_bytes_reader = require("./bytes/reader.cjs");
|
|
3
3
|
//#region src/lexer.ts
|
|
4
|
+
const LEFT_PAREN = 40;
|
|
5
|
+
const RIGHT_PAREN = 41;
|
|
6
|
+
const LESS_THAN = 60;
|
|
7
|
+
const GREATER_THAN = 62;
|
|
8
|
+
const LEFT_BRACKET = 91;
|
|
9
|
+
const RIGHT_BRACKET = 93;
|
|
10
|
+
const LEFT_BRACE = 123;
|
|
11
|
+
const RIGHT_BRACE = 125;
|
|
12
|
+
const SOLIDUS = 47;
|
|
13
|
+
const PERCENT_SIGN = 37;
|
|
14
|
+
const REVERSE_SOLIDUS = 92;
|
|
15
|
+
const NUMBER_SIGN = 35;
|
|
16
|
+
const PLUS_SIGN = 43;
|
|
17
|
+
const MINUS_SIGN = 45;
|
|
18
|
+
const FULL_STOP = 46;
|
|
19
|
+
const LINE_FEED = 10;
|
|
20
|
+
const CARRIAGE_RETURN = 13;
|
|
21
|
+
const HORIZONTAL_TAB = 9;
|
|
22
|
+
const BACKSPACE = 8;
|
|
23
|
+
const FORM_FEED = 12;
|
|
24
|
+
const DIGIT_ZERO = 48;
|
|
25
|
+
const DIGIT_SEVEN = 55;
|
|
26
|
+
const DIGIT_NINE = 57;
|
|
27
|
+
const UPPER_A = 65;
|
|
28
|
+
const UPPER_F = 70;
|
|
29
|
+
const LOWER_A = 97;
|
|
30
|
+
const LOWER_B = 98;
|
|
31
|
+
const LOWER_F = 102;
|
|
32
|
+
const LOWER_N = 110;
|
|
33
|
+
const LOWER_R = 114;
|
|
34
|
+
const LOWER_T = 116;
|
|
35
|
+
const HEX_DIGIT_ALPHA_OFFSET = 10;
|
|
36
|
+
const HEX_RADIX = 16;
|
|
37
|
+
const OCTAL_RADIX = 8;
|
|
38
|
+
const BYTE_MASK = 255;
|
|
4
39
|
const DELIMITER_BYTES = /* @__PURE__ */ new Set([
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
40
|
+
LEFT_PAREN,
|
|
41
|
+
RIGHT_PAREN,
|
|
42
|
+
LESS_THAN,
|
|
43
|
+
GREATER_THAN,
|
|
44
|
+
LEFT_BRACKET,
|
|
45
|
+
RIGHT_BRACKET,
|
|
46
|
+
LEFT_BRACE,
|
|
47
|
+
RIGHT_BRACE,
|
|
48
|
+
SOLIDUS,
|
|
49
|
+
PERCENT_SIGN
|
|
15
50
|
]);
|
|
16
51
|
function isRegularByte(byte) {
|
|
17
52
|
return !require_bytes_reader.isAsciiWhitespace(byte) && !DELIMITER_BYTES.has(byte);
|
|
18
53
|
}
|
|
19
54
|
function isDigit(byte) {
|
|
20
|
-
return byte !== void 0 && byte >=
|
|
55
|
+
return byte !== void 0 && byte >= DIGIT_ZERO && byte <= DIGIT_NINE;
|
|
21
56
|
}
|
|
22
57
|
function isHexDigit(byte) {
|
|
23
|
-
return byte !== void 0 && (byte >=
|
|
58
|
+
return byte !== void 0 && (byte >= DIGIT_ZERO && byte <= DIGIT_NINE || byte >= UPPER_A && byte <= UPPER_F || byte >= LOWER_A && byte <= LOWER_F);
|
|
24
59
|
}
|
|
25
60
|
function hexDigitValue(byte) {
|
|
26
|
-
if (byte >=
|
|
27
|
-
if (byte >=
|
|
28
|
-
return byte -
|
|
61
|
+
if (byte >= DIGIT_ZERO && byte <= DIGIT_NINE) return byte - DIGIT_ZERO;
|
|
62
|
+
if (byte >= UPPER_A && byte <= UPPER_F) return byte - UPPER_A + HEX_DIGIT_ALPHA_OFFSET;
|
|
63
|
+
return byte - LOWER_A + HEX_DIGIT_ALPHA_OFFSET;
|
|
29
64
|
}
|
|
30
65
|
function skipWhitespaceAndComments(reader) {
|
|
31
66
|
for (;;) {
|
|
32
67
|
reader.skipWhitespace();
|
|
33
|
-
if (reader.peek() !==
|
|
34
|
-
while (!reader.atEnd() && reader.peek() !==
|
|
68
|
+
if (reader.peek() !== PERCENT_SIGN) return;
|
|
69
|
+
while (!reader.atEnd() && reader.peek() !== LINE_FEED && reader.peek() !== CARRIAGE_RETURN) reader.next();
|
|
35
70
|
}
|
|
36
71
|
}
|
|
37
72
|
function readNumberToken(reader) {
|
|
38
73
|
const start = reader.offset;
|
|
39
|
-
if (reader.peek() ===
|
|
74
|
+
if (reader.peek() === PLUS_SIGN || reader.peek() === MINUS_SIGN) reader.next();
|
|
40
75
|
while (isDigit(reader.peek())) reader.next();
|
|
41
|
-
if (reader.peek() ===
|
|
76
|
+
if (reader.peek() === FULL_STOP) {
|
|
42
77
|
reader.next();
|
|
43
78
|
while (isDigit(reader.peek())) reader.next();
|
|
44
79
|
}
|
|
@@ -54,11 +89,11 @@ function readNameToken(reader) {
|
|
|
54
89
|
for (;;) {
|
|
55
90
|
const byte = reader.peek();
|
|
56
91
|
if (byte === void 0 || !isRegularByte(byte)) break;
|
|
57
|
-
if (byte ===
|
|
92
|
+
if (byte === NUMBER_SIGN && isHexDigit(reader.peek(1)) && isHexDigit(reader.peek(2))) {
|
|
58
93
|
reader.next();
|
|
59
94
|
const hi = hexDigitValue(reader.next());
|
|
60
95
|
const lo = hexDigitValue(reader.next());
|
|
61
|
-
bytes.push(hi *
|
|
96
|
+
bytes.push(hi * HEX_RADIX + lo);
|
|
62
97
|
} else bytes.push(reader.next());
|
|
63
98
|
}
|
|
64
99
|
return {
|
|
@@ -73,38 +108,38 @@ function readLiteralStringToken(reader) {
|
|
|
73
108
|
for (;;) {
|
|
74
109
|
const byte = reader.next();
|
|
75
110
|
if (byte === void 0) break;
|
|
76
|
-
if (byte ===
|
|
111
|
+
if (byte === REVERSE_SOLIDUS) {
|
|
77
112
|
const esc = reader.next();
|
|
78
113
|
if (esc === void 0) break;
|
|
79
|
-
if (esc ===
|
|
80
|
-
else if (esc ===
|
|
81
|
-
else if (esc ===
|
|
82
|
-
else if (esc ===
|
|
83
|
-
else if (esc ===
|
|
84
|
-
else if (esc ===
|
|
85
|
-
else if (esc ===
|
|
86
|
-
if (reader.peek() ===
|
|
87
|
-
} else if (esc ===
|
|
88
|
-
let value = esc -
|
|
89
|
-
for (let i = 0; i < 2 && reader.peek() !== void 0 && reader.peek() >=
|
|
90
|
-
bytes.push(value &
|
|
114
|
+
if (esc === LOWER_N) bytes.push(LINE_FEED);
|
|
115
|
+
else if (esc === LOWER_R) bytes.push(CARRIAGE_RETURN);
|
|
116
|
+
else if (esc === LOWER_T) bytes.push(HORIZONTAL_TAB);
|
|
117
|
+
else if (esc === LOWER_B) bytes.push(BACKSPACE);
|
|
118
|
+
else if (esc === LOWER_F) bytes.push(FORM_FEED);
|
|
119
|
+
else if (esc === LEFT_PAREN || esc === RIGHT_PAREN || esc === REVERSE_SOLIDUS) bytes.push(esc);
|
|
120
|
+
else if (esc === CARRIAGE_RETURN) {
|
|
121
|
+
if (reader.peek() === LINE_FEED) reader.next();
|
|
122
|
+
} else if (esc === LINE_FEED) {} else if (esc >= DIGIT_ZERO && esc <= DIGIT_SEVEN) {
|
|
123
|
+
let value = esc - DIGIT_ZERO;
|
|
124
|
+
for (let i = 0; i < 2 && reader.peek() !== void 0 && reader.peek() >= DIGIT_ZERO && reader.peek() <= DIGIT_SEVEN; i++) value = value * OCTAL_RADIX + (reader.next() - DIGIT_ZERO);
|
|
125
|
+
bytes.push(value & BYTE_MASK);
|
|
91
126
|
} else bytes.push(esc);
|
|
92
127
|
continue;
|
|
93
128
|
}
|
|
94
|
-
if (byte ===
|
|
129
|
+
if (byte === LEFT_PAREN) {
|
|
95
130
|
depth++;
|
|
96
131
|
bytes.push(byte);
|
|
97
132
|
continue;
|
|
98
133
|
}
|
|
99
|
-
if (byte ===
|
|
134
|
+
if (byte === RIGHT_PAREN) {
|
|
100
135
|
depth--;
|
|
101
136
|
if (depth === 0) break;
|
|
102
137
|
bytes.push(byte);
|
|
103
138
|
continue;
|
|
104
139
|
}
|
|
105
|
-
if (byte ===
|
|
106
|
-
if (reader.peek() ===
|
|
107
|
-
bytes.push(
|
|
140
|
+
if (byte === CARRIAGE_RETURN) {
|
|
141
|
+
if (reader.peek() === LINE_FEED) reader.next();
|
|
142
|
+
bytes.push(LINE_FEED);
|
|
108
143
|
continue;
|
|
109
144
|
}
|
|
110
145
|
bytes.push(byte);
|
|
@@ -119,12 +154,12 @@ function readHexStringToken(reader) {
|
|
|
119
154
|
const digits = [];
|
|
120
155
|
for (;;) {
|
|
121
156
|
const byte = reader.next();
|
|
122
|
-
if (byte === void 0 || byte ===
|
|
157
|
+
if (byte === void 0 || byte === GREATER_THAN) break;
|
|
123
158
|
if (isHexDigit(byte)) digits.push(hexDigitValue(byte));
|
|
124
159
|
}
|
|
125
160
|
if (digits.length % 2 === 1) digits.push(0);
|
|
126
161
|
const bytes = new Uint8Array(digits.length / 2);
|
|
127
|
-
for (let i = 0; i < bytes.length; i++) bytes[i] = digits[i * 2] *
|
|
162
|
+
for (let i = 0; i < bytes.length; i++) bytes[i] = digits[i * 2] * HEX_RADIX + digits[i * 2 + 1];
|
|
128
163
|
return {
|
|
129
164
|
kind: "hexString",
|
|
130
165
|
value: bytes
|
|
@@ -142,18 +177,18 @@ function nextToken(reader) {
|
|
|
142
177
|
skipWhitespaceAndComments(reader);
|
|
143
178
|
const byte = reader.peek();
|
|
144
179
|
if (byte === void 0) return;
|
|
145
|
-
if (byte ===
|
|
146
|
-
if (byte ===
|
|
147
|
-
if (byte ===
|
|
148
|
-
if (reader.peek(1) ===
|
|
180
|
+
if (byte === SOLIDUS) return readNameToken(reader);
|
|
181
|
+
if (byte === LEFT_PAREN) return readLiteralStringToken(reader);
|
|
182
|
+
if (byte === LESS_THAN) {
|
|
183
|
+
if (reader.peek(1) === LESS_THAN) {
|
|
149
184
|
reader.next();
|
|
150
185
|
reader.next();
|
|
151
186
|
return { kind: "dictStart" };
|
|
152
187
|
}
|
|
153
188
|
return readHexStringToken(reader);
|
|
154
189
|
}
|
|
155
|
-
if (byte ===
|
|
156
|
-
if (reader.peek(1) ===
|
|
190
|
+
if (byte === GREATER_THAN) {
|
|
191
|
+
if (reader.peek(1) === GREATER_THAN) {
|
|
157
192
|
reader.next();
|
|
158
193
|
reader.next();
|
|
159
194
|
return { kind: "dictEnd" };
|
|
@@ -161,19 +196,19 @@ function nextToken(reader) {
|
|
|
161
196
|
reader.next();
|
|
162
197
|
return nextToken(reader);
|
|
163
198
|
}
|
|
164
|
-
if (byte ===
|
|
199
|
+
if (byte === LEFT_BRACKET) {
|
|
165
200
|
reader.next();
|
|
166
201
|
return { kind: "arrayStart" };
|
|
167
202
|
}
|
|
168
|
-
if (byte ===
|
|
203
|
+
if (byte === RIGHT_BRACKET) {
|
|
169
204
|
reader.next();
|
|
170
205
|
return { kind: "arrayEnd" };
|
|
171
206
|
}
|
|
172
|
-
if (byte ===
|
|
207
|
+
if (byte === LEFT_BRACE || byte === RIGHT_BRACE) {
|
|
173
208
|
reader.next();
|
|
174
209
|
return nextToken(reader);
|
|
175
210
|
}
|
|
176
|
-
if (byte ===
|
|
211
|
+
if (byte === PLUS_SIGN || byte === MINUS_SIGN || byte === FULL_STOP || isDigit(byte)) return readNumberToken(reader);
|
|
177
212
|
return readKeywordToken(reader);
|
|
178
213
|
}
|
|
179
214
|
//#endregion
|