pdf-codec 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -12
- package/dist/content-write.cjs +2 -3
- package/dist/content-write.js +1 -2
- package/dist/crypto/aes.cjs +166 -0
- package/dist/crypto/aes.d.cts +6 -0
- package/dist/crypto/aes.d.ts +6 -0
- package/dist/crypto/aes.js +163 -0
- package/dist/crypto/md5.cjs +215 -0
- package/dist/crypto/md5.d.cts +4 -0
- package/dist/crypto/md5.d.ts +4 -0
- package/dist/crypto/md5.js +214 -0
- package/dist/crypto/rc4.cjs +29 -0
- package/dist/crypto/rc4.d.cts +4 -0
- package/dist/crypto/rc4.d.ts +4 -0
- package/dist/crypto/rc4.js +28 -0
- package/dist/crypto/sha2.cjs +261 -0
- package/dist/crypto/sha2.d.cts +6 -0
- package/dist/crypto/sha2.d.ts +6 -0
- package/dist/crypto/sha2.js +258 -0
- package/dist/diagnostics.cjs +7 -0
- package/dist/diagnostics.d.cts +4 -1
- package/dist/diagnostics.d.ts +4 -1
- package/dist/diagnostics.js +7 -1
- package/dist/document.cjs +38 -2
- package/dist/document.js +38 -2
- package/dist/encrypt.cjs +264 -0
- package/dist/encrypt.d.cts +11 -0
- package/dist/encrypt.d.ts +11 -0
- package/dist/encrypt.js +263 -0
- package/dist/filters.cjs +19 -1
- package/dist/filters.js +19 -1
- package/dist/image/ccitt.cjs +488 -0
- package/dist/image/ccitt.d.cts +17 -0
- package/dist/image/ccitt.d.ts +17 -0
- package/dist/image/ccitt.js +487 -0
- package/dist/images-read.cjs +1 -4
- package/dist/images-read.js +2 -5
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/interpret.cjs +173 -38
- package/dist/interpret.d.cts +27 -10
- package/dist/interpret.d.ts +27 -10
- package/dist/interpret.js +174 -39
- package/dist/math-font-write.cjs +1 -1
- package/dist/math-font-write.js +1 -1
- package/dist/{matrix-B3c2_a2f.d.cts → matrix-BHzJESll.d.cts} +2 -1
- package/dist/{matrix-B3c2_a2f.d.ts → matrix-BHzJESll.d.ts} +2 -1
- package/dist/matrix.cjs +2 -0
- package/dist/matrix.d.cts +2 -2
- package/dist/matrix.d.ts +2 -2
- package/dist/matrix.js +2 -1
- package/dist/objects.cjs +4 -0
- package/dist/objects.d.cts +2 -1
- package/dist/objects.d.ts +2 -1
- package/dist/objects.js +4 -1
- package/dist/read.cjs +43 -4
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +43 -4
- package/dist/write.cjs +1 -1
- package/dist/write.js +1 -1
- package/package.json +1 -1
package/dist/interpret.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { asArray, asName, asNumber, dictGet } from "./objects.js";
|
|
2
2
|
import { decodeStream } from "./filters.js";
|
|
3
|
-
import { IDENTITY_MATRIX, applyMatrix, multiplyMatrices, translationMatrix } from "./matrix.js";
|
|
3
|
+
import { BEZIER_KAPPA, IDENTITY_MATRIX, applyMatrix, multiplyMatrices, translationMatrix } from "./matrix.js";
|
|
4
4
|
import { readContentStream } from "./content-read.js";
|
|
5
5
|
import { COLOR_BLACK } from "document-schema.js";
|
|
6
6
|
//#region src/interpret.ts
|
|
@@ -75,26 +75,176 @@ function matrixFromOperands(operands) {
|
|
|
75
75
|
numAt(operands, 5)
|
|
76
76
|
];
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const SHAPE_ABS_TOLERANCE_PT = .001;
|
|
79
|
+
const SHAPE_REL_TOLERANCE = 1e-4;
|
|
80
|
+
function shapeTolerance(extentPt) {
|
|
81
|
+
return Math.max(SHAPE_ABS_TOLERANCE_PT, Math.abs(extentPt) * SHAPE_REL_TOLERANCE);
|
|
80
82
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
83
|
+
function nearlyEqual(a, b, tolerance) {
|
|
84
|
+
return Math.abs(a - b) <= tolerance;
|
|
85
|
+
}
|
|
86
|
+
function nearlyEqualPoints(a, b, tolerance) {
|
|
87
|
+
return nearlyEqual(a.x, b.x, tolerance) && nearlyEqual(a.y, b.y, tolerance);
|
|
88
|
+
}
|
|
89
|
+
function boundsOf(points) {
|
|
90
|
+
const xs = points.map((p) => p.x);
|
|
91
|
+
const ys = points.map((p) => p.y);
|
|
92
|
+
return {
|
|
93
|
+
minX: Math.min(...xs),
|
|
94
|
+
minY: Math.min(...ys),
|
|
95
|
+
maxX: Math.max(...xs),
|
|
96
|
+
maxY: Math.max(...ys)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function closedPolygonCorners(subpath) {
|
|
100
|
+
if (!subpath.closed) return;
|
|
101
|
+
const corners = [{
|
|
102
|
+
x: subpath.startXPt,
|
|
103
|
+
y: subpath.startYPt
|
|
104
|
+
}];
|
|
105
|
+
for (const segment of subpath.segments) {
|
|
106
|
+
if (segment.kind !== "line") return;
|
|
107
|
+
corners.push({
|
|
108
|
+
x: segment.xPt,
|
|
109
|
+
y: segment.yPt
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const first = corners[0];
|
|
113
|
+
const last = corners[corners.length - 1];
|
|
114
|
+
if (first === void 0 || last === void 0 || corners.length < 2) return;
|
|
115
|
+
const bounds = boundsOf(corners);
|
|
116
|
+
if (nearlyEqualPoints(first, last, shapeTolerance(Math.max(bounds.maxX - bounds.minX, bounds.maxY - bounds.minY)))) corners.pop();
|
|
117
|
+
return corners;
|
|
118
|
+
}
|
|
119
|
+
function detectRect(subpath, paint) {
|
|
120
|
+
const corners = closedPolygonCorners(subpath);
|
|
121
|
+
if (corners?.length !== 4) return;
|
|
122
|
+
const { minX, minY, maxX, maxY } = boundsOf(corners);
|
|
123
|
+
const widthPt = maxX - minX;
|
|
124
|
+
const heightPt = maxY - minY;
|
|
125
|
+
const tolX = shapeTolerance(widthPt);
|
|
126
|
+
const tolY = shapeTolerance(heightPt);
|
|
127
|
+
if (widthPt <= tolX || heightPt <= tolY) return;
|
|
128
|
+
for (const corner of corners) {
|
|
129
|
+
if (!nearlyEqual(corner.x, minX, tolX) && !nearlyEqual(corner.x, maxX, tolX)) return;
|
|
130
|
+
if (!nearlyEqual(corner.y, minY, tolY) && !nearlyEqual(corner.y, maxY, tolY)) return;
|
|
131
|
+
}
|
|
132
|
+
for (let i = 0; i < corners.length; i += 1) {
|
|
133
|
+
const from = corners[i];
|
|
134
|
+
const to = corners[(i + 1) % corners.length];
|
|
135
|
+
if (from === void 0 || to === void 0) return;
|
|
136
|
+
if (nearlyEqual(from.x, to.x, tolX) === nearlyEqual(from.y, to.y, tolY)) return;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
kind: "rect",
|
|
140
|
+
xPt: minX,
|
|
141
|
+
yPt: minY,
|
|
142
|
+
widthPt,
|
|
143
|
+
heightPt,
|
|
144
|
+
fill: paint.fill,
|
|
145
|
+
stroke: paint.stroke
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function cardinalExtremeOf(point, center, rx, ry, tolX, tolY) {
|
|
149
|
+
if (nearlyEqual(point.y, center.y, tolY)) {
|
|
150
|
+
if (nearlyEqual(point.x, center.x + rx, tolX)) return "right";
|
|
151
|
+
if (nearlyEqual(point.x, center.x - rx, tolX)) return "left";
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (nearlyEqual(point.x, center.x, tolX)) {
|
|
155
|
+
if (nearlyEqual(point.y, center.y + ry, tolY)) return "top";
|
|
156
|
+
if (nearlyEqual(point.y, center.y - ry, tolY)) return "bottom";
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function expectedEllipseControl(atExtreme, atExtremeKind, otherEnd, center, kx, ky) {
|
|
160
|
+
if (atExtremeKind === "right" || atExtremeKind === "left") return {
|
|
161
|
+
x: atExtreme.x,
|
|
162
|
+
y: center.y + Math.sign(otherEnd.y - center.y) * ky
|
|
163
|
+
};
|
|
164
|
+
return {
|
|
165
|
+
x: center.x + Math.sign(otherEnd.x - center.x) * kx,
|
|
166
|
+
y: atExtreme.y
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function detectEllipse(subpath, paint) {
|
|
170
|
+
const segments = subpath.segments;
|
|
171
|
+
if (!subpath.closed || segments.length !== 4 || segments.some((segment) => segment.kind !== "cubic")) return;
|
|
172
|
+
const start = {
|
|
173
|
+
x: subpath.startXPt,
|
|
174
|
+
y: subpath.startYPt
|
|
175
|
+
};
|
|
176
|
+
const onCurve = [start];
|
|
177
|
+
for (const segment of segments.slice(0, 3)) onCurve.push({
|
|
178
|
+
x: segment.xPt,
|
|
179
|
+
y: segment.yPt
|
|
180
|
+
});
|
|
181
|
+
const { minX, minY, maxX, maxY } = boundsOf(onCurve);
|
|
182
|
+
const rx = (maxX - minX) / 2;
|
|
183
|
+
const ry = (maxY - minY) / 2;
|
|
184
|
+
const center = {
|
|
185
|
+
x: (minX + maxX) / 2,
|
|
186
|
+
y: (minY + maxY) / 2
|
|
187
|
+
};
|
|
188
|
+
const tolX = shapeTolerance(rx);
|
|
189
|
+
const tolY = shapeTolerance(ry);
|
|
190
|
+
if (rx <= tolX || ry <= tolY) return;
|
|
191
|
+
const finalSegment = segments[3];
|
|
192
|
+
if (finalSegment === void 0 || !nearlyEqualPoints({
|
|
193
|
+
x: finalSegment.xPt,
|
|
194
|
+
y: finalSegment.yPt
|
|
195
|
+
}, start, Math.max(tolX, tolY))) return;
|
|
196
|
+
const extremes = onCurve.map((point) => cardinalExtremeOf(point, center, rx, ry, tolX, tolY));
|
|
197
|
+
if (extremes.some((extreme) => extreme === void 0) || new Set(extremes).size !== 4) return;
|
|
198
|
+
const kx = rx * BEZIER_KAPPA;
|
|
199
|
+
const ky = ry * BEZIER_KAPPA;
|
|
200
|
+
const controlTolerance = Math.max(tolX, tolY);
|
|
201
|
+
for (let i = 0; i < 4; i += 1) {
|
|
202
|
+
const segment = segments[i];
|
|
203
|
+
const from = onCurve[i];
|
|
204
|
+
const fromKind = extremes[i];
|
|
205
|
+
const to = onCurve[(i + 1) % 4];
|
|
206
|
+
const toKind = extremes[(i + 1) % 4];
|
|
207
|
+
if (segment?.kind !== "cubic" || from === void 0 || to === void 0 || fromKind === void 0 || toKind === void 0) return;
|
|
208
|
+
const expectedC1 = expectedEllipseControl(from, fromKind, to, center, kx, ky);
|
|
209
|
+
const expectedC2 = expectedEllipseControl(to, toKind, from, center, kx, ky);
|
|
210
|
+
if (!nearlyEqualPoints({
|
|
211
|
+
x: segment.c1xPt,
|
|
212
|
+
y: segment.c1yPt
|
|
213
|
+
}, expectedC1, controlTolerance)) return;
|
|
214
|
+
if (!nearlyEqualPoints({
|
|
215
|
+
x: segment.c2xPt,
|
|
216
|
+
y: segment.c2yPt
|
|
217
|
+
}, expectedC2, controlTolerance)) return;
|
|
218
|
+
}
|
|
91
219
|
return {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
220
|
+
kind: "ellipse",
|
|
221
|
+
xPt: minX,
|
|
222
|
+
yPt: minY,
|
|
223
|
+
widthPt: maxX - minX,
|
|
224
|
+
heightPt: maxY - minY,
|
|
225
|
+
fill: paint.fill,
|
|
226
|
+
stroke: paint.stroke
|
|
96
227
|
};
|
|
97
228
|
}
|
|
229
|
+
function detectLine(subpath, paint) {
|
|
230
|
+
const segment = subpath.segments[0];
|
|
231
|
+
if (subpath.closed || subpath.segments.length !== 1 || segment?.kind !== "line") return;
|
|
232
|
+
if (paint.fill !== void 0 || paint.stroke === void 0) return;
|
|
233
|
+
return {
|
|
234
|
+
kind: "line",
|
|
235
|
+
x1Pt: subpath.startXPt,
|
|
236
|
+
y1Pt: subpath.startYPt,
|
|
237
|
+
x2Pt: segment.xPt,
|
|
238
|
+
y2Pt: segment.yPt,
|
|
239
|
+
color: paint.stroke.color,
|
|
240
|
+
widthPt: paint.stroke.widthPt
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function classifyShape(subpaths, paint) {
|
|
244
|
+
const subpath = subpaths[0];
|
|
245
|
+
if (subpaths.length !== 1 || subpath === void 0) return;
|
|
246
|
+
return detectRect(subpath, paint) ?? detectEllipse(subpath, paint) ?? detectLine(subpath, paint);
|
|
247
|
+
}
|
|
98
248
|
function interpretContentStream(bytes, resources, context) {
|
|
99
249
|
const items = [];
|
|
100
250
|
runContentStream(bytes, resources, {
|
|
@@ -120,7 +270,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
120
270
|
const gsStack = [];
|
|
121
271
|
let gs = initialState;
|
|
122
272
|
let ts = defaultTextState();
|
|
123
|
-
let pendingRect;
|
|
124
273
|
let pathSubpaths = [];
|
|
125
274
|
let currentSubpath;
|
|
126
275
|
const finalizeCurrentSubpath = () => {
|
|
@@ -130,7 +279,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
130
279
|
}
|
|
131
280
|
};
|
|
132
281
|
const resetPath = () => {
|
|
133
|
-
pendingRect = void 0;
|
|
134
282
|
pathSubpaths = [];
|
|
135
283
|
currentSubpath = void 0;
|
|
136
284
|
};
|
|
@@ -186,28 +334,22 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
186
334
|
return;
|
|
187
335
|
}
|
|
188
336
|
if ((operator === "s" || operator === "b" || operator === "b*") && currentSubpath !== void 0) currentSubpath.closed = true;
|
|
189
|
-
if ((operator === "f" || operator === "F" || operator === "f*") && currentSubpath === void 0 && pathSubpaths.length === 1 && pendingRect !== void 0) {
|
|
190
|
-
items.push({
|
|
191
|
-
kind: "rect",
|
|
192
|
-
...pendingRect,
|
|
193
|
-
color: gs.fillColor
|
|
194
|
-
});
|
|
195
|
-
resetPath();
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
337
|
finalizeCurrentSubpath();
|
|
199
338
|
if (pathSubpaths.length > 0) {
|
|
200
339
|
const isFillOp = operator === "f" || operator === "F" || operator === "f*" || operator === "B" || operator === "B*" || operator === "b" || operator === "b*";
|
|
201
340
|
const isStrokeOp = operator === "S" || operator === "s" || operator === "B" || operator === "B*" || operator === "b" || operator === "b*";
|
|
202
|
-
|
|
203
|
-
kind: "path",
|
|
204
|
-
subpaths: pathSubpaths,
|
|
205
|
-
fillRule: paintFillRuleFor(operator),
|
|
341
|
+
const paint = {
|
|
206
342
|
fill: isFillOp ? gs.fillColor : void 0,
|
|
207
343
|
stroke: isStrokeOp ? {
|
|
208
344
|
color: gs.strokeColor,
|
|
209
345
|
widthPt: gs.lineWidth
|
|
210
346
|
} : void 0
|
|
347
|
+
};
|
|
348
|
+
items.push(classifyShape(pathSubpaths, paint) ?? {
|
|
349
|
+
kind: "path",
|
|
350
|
+
subpaths: pathSubpaths,
|
|
351
|
+
fillRule: paintFillRuleFor(operator),
|
|
352
|
+
...paint
|
|
211
353
|
});
|
|
212
354
|
}
|
|
213
355
|
resetPath();
|
|
@@ -394,7 +536,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
394
536
|
break;
|
|
395
537
|
}
|
|
396
538
|
case "re":
|
|
397
|
-
pendingRect = rectFromOperands(operands, gs.ctm);
|
|
398
539
|
appendRectSubpath(operands, gs.ctm);
|
|
399
540
|
break;
|
|
400
541
|
case "m": {
|
|
@@ -409,7 +550,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
409
550
|
segments: [],
|
|
410
551
|
closed: false
|
|
411
552
|
};
|
|
412
|
-
pendingRect = void 0;
|
|
413
553
|
break;
|
|
414
554
|
}
|
|
415
555
|
case "l": {
|
|
@@ -422,7 +562,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
422
562
|
xPt: p.x,
|
|
423
563
|
yPt: p.y
|
|
424
564
|
});
|
|
425
|
-
pendingRect = void 0;
|
|
426
565
|
break;
|
|
427
566
|
}
|
|
428
567
|
case "c": {
|
|
@@ -447,7 +586,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
447
586
|
xPt: p.x,
|
|
448
587
|
yPt: p.y
|
|
449
588
|
});
|
|
450
|
-
pendingRect = void 0;
|
|
451
589
|
break;
|
|
452
590
|
}
|
|
453
591
|
case "v":
|
|
@@ -471,7 +609,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
471
609
|
yPt: p.y
|
|
472
610
|
});
|
|
473
611
|
}
|
|
474
|
-
pendingRect = void 0;
|
|
475
612
|
break;
|
|
476
613
|
case "y": {
|
|
477
614
|
const c1 = applyMatrix(gs.ctm, {
|
|
@@ -491,12 +628,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
491
628
|
xPt: p.x,
|
|
492
629
|
yPt: p.y
|
|
493
630
|
});
|
|
494
|
-
pendingRect = void 0;
|
|
495
631
|
break;
|
|
496
632
|
}
|
|
497
633
|
case "h":
|
|
498
634
|
if (currentSubpath !== void 0) currentSubpath.closed = true;
|
|
499
|
-
pendingRect = void 0;
|
|
500
635
|
break;
|
|
501
636
|
case "w":
|
|
502
637
|
gs = {
|
package/dist/math-font-write.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_bytes_flate = require("./bytes/flate.cjs");
|
|
3
2
|
const require_objects = require("./objects.cjs");
|
|
3
|
+
const require_bytes_flate = require("./bytes/flate.cjs");
|
|
4
4
|
//#region src/math-font-write.ts
|
|
5
5
|
const FLAG_SYMBOLIC = 4;
|
|
6
6
|
const NOMINAL_STEM_V = 80;
|
package/dist/math-font-write.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { deflate } from "./bytes/flate.js";
|
|
2
1
|
import { pdfArray, pdfDict, pdfHexString, pdfName, pdfNum, pdfStream } from "./objects.js";
|
|
2
|
+
import { deflate } from "./bytes/flate.js";
|
|
3
3
|
//#region src/math-font-write.ts
|
|
4
4
|
const FLAG_SYMBOLIC = 4;
|
|
5
5
|
const NOMINAL_STEM_V = 80;
|
|
@@ -9,10 +9,11 @@ interface Point {
|
|
|
9
9
|
declare function applyMatrix(m: Matrix, point: Point): Point;
|
|
10
10
|
declare function translationMatrix(x: number, y: number): Matrix;
|
|
11
11
|
declare function scaleMatrix(sx: number, sy: number): Matrix;
|
|
12
|
+
declare const BEZIER_KAPPA = 0.5522847498;
|
|
12
13
|
declare function rotationMatrix(degrees: number): Matrix;
|
|
13
14
|
declare function matrixScaleX(m: Matrix): number;
|
|
14
15
|
declare function matrixScaleY(m: Matrix): number;
|
|
15
16
|
declare function matrixRotationDegrees(m: Matrix): number;
|
|
16
17
|
declare function rotatePointAboutCenter(point: Point, center: Point, degrees: number): Point;
|
|
17
18
|
//#endregion
|
|
18
|
-
export {
|
|
19
|
+
export { applyMatrix as a, matrixScaleY as c, rotationMatrix as d, scaleMatrix as f, Point as i, multiplyMatrices as l, IDENTITY_MATRIX as n, matrixRotationDegrees as o, translationMatrix as p, Matrix as r, matrixScaleX as s, BEZIER_KAPPA as t, rotatePointAboutCenter as u };
|
|
@@ -9,10 +9,11 @@ interface Point {
|
|
|
9
9
|
declare function applyMatrix(m: Matrix, point: Point): Point;
|
|
10
10
|
declare function translationMatrix(x: number, y: number): Matrix;
|
|
11
11
|
declare function scaleMatrix(sx: number, sy: number): Matrix;
|
|
12
|
+
declare const BEZIER_KAPPA = 0.5522847498;
|
|
12
13
|
declare function rotationMatrix(degrees: number): Matrix;
|
|
13
14
|
declare function matrixScaleX(m: Matrix): number;
|
|
14
15
|
declare function matrixScaleY(m: Matrix): number;
|
|
15
16
|
declare function matrixRotationDegrees(m: Matrix): number;
|
|
16
17
|
declare function rotatePointAboutCenter(point: Point, center: Point, degrees: number): Point;
|
|
17
18
|
//#endregion
|
|
18
|
-
export {
|
|
19
|
+
export { applyMatrix as a, matrixScaleY as c, rotationMatrix as d, scaleMatrix as f, Point as i, multiplyMatrices as l, IDENTITY_MATRIX as n, matrixRotationDegrees as o, translationMatrix as p, Matrix as r, matrixScaleX as s, BEZIER_KAPPA as t, rotatePointAboutCenter as u };
|
package/dist/matrix.cjs
CHANGED
|
@@ -47,6 +47,7 @@ function scaleMatrix(sx, sy) {
|
|
|
47
47
|
0
|
|
48
48
|
];
|
|
49
49
|
}
|
|
50
|
+
const BEZIER_KAPPA = .5522847498;
|
|
50
51
|
function rotationMatrix(degrees) {
|
|
51
52
|
const radians = degrees * Math.PI / 180;
|
|
52
53
|
const cos = Math.cos(radians);
|
|
@@ -81,6 +82,7 @@ function rotatePointAboutCenter(point, center, degrees) {
|
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
84
|
//#endregion
|
|
85
|
+
exports.BEZIER_KAPPA = BEZIER_KAPPA;
|
|
84
86
|
exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
|
|
85
87
|
exports.applyMatrix = applyMatrix;
|
|
86
88
|
exports.matrixRotationDegrees = matrixRotationDegrees;
|
package/dist/matrix.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
|
1
|
+
import { a as applyMatrix, c as matrixScaleY, d as rotationMatrix, f as scaleMatrix, i as Point, l as multiplyMatrices, n as IDENTITY_MATRIX, o as matrixRotationDegrees, p as translationMatrix, r as Matrix, s as matrixScaleX, t as BEZIER_KAPPA, u as rotatePointAboutCenter } from "./matrix-BHzJESll.cjs";
|
|
2
|
+
export { BEZIER_KAPPA, IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
package/dist/matrix.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
|
1
|
+
import { a as applyMatrix, c as matrixScaleY, d as rotationMatrix, f as scaleMatrix, i as Point, l as multiplyMatrices, n as IDENTITY_MATRIX, o as matrixRotationDegrees, p as translationMatrix, r as Matrix, s as matrixScaleX, t as BEZIER_KAPPA, u as rotatePointAboutCenter } from "./matrix-BHzJESll.js";
|
|
2
|
+
export { BEZIER_KAPPA, IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
package/dist/matrix.js
CHANGED
|
@@ -46,6 +46,7 @@ function scaleMatrix(sx, sy) {
|
|
|
46
46
|
0
|
|
47
47
|
];
|
|
48
48
|
}
|
|
49
|
+
const BEZIER_KAPPA = .5522847498;
|
|
49
50
|
function rotationMatrix(degrees) {
|
|
50
51
|
const radians = degrees * Math.PI / 180;
|
|
51
52
|
const cos = Math.cos(radians);
|
|
@@ -80,4 +81,4 @@ function rotatePointAboutCenter(point, center, degrees) {
|
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
//#endregion
|
|
83
|
-
export { IDENTITY_MATRIX, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
|
84
|
+
export { BEZIER_KAPPA, IDENTITY_MATRIX, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
package/dist/objects.cjs
CHANGED
|
@@ -70,6 +70,9 @@ function asNumber(obj) {
|
|
|
70
70
|
function asName(obj) {
|
|
71
71
|
return obj?.kind === "name" ? obj.name : void 0;
|
|
72
72
|
}
|
|
73
|
+
function asBool(obj) {
|
|
74
|
+
return obj?.kind === "bool" ? obj.value : void 0;
|
|
75
|
+
}
|
|
73
76
|
function asArray(obj) {
|
|
74
77
|
return obj?.kind === "array" ? obj.items : void 0;
|
|
75
78
|
}
|
|
@@ -83,6 +86,7 @@ function dictGet(dict, key) {
|
|
|
83
86
|
}
|
|
84
87
|
//#endregion
|
|
85
88
|
exports.asArray = asArray;
|
|
89
|
+
exports.asBool = asBool;
|
|
86
90
|
exports.asDict = asDict;
|
|
87
91
|
exports.asName = asName;
|
|
88
92
|
exports.asNumber = asNumber;
|
package/dist/objects.d.cts
CHANGED
|
@@ -51,8 +51,9 @@ declare function pdfRef(num: number, gen: number): PdfObject;
|
|
|
51
51
|
declare function isName(obj: PdfObject | undefined, name: string): boolean;
|
|
52
52
|
declare function asNumber(obj: PdfObject | undefined): number | undefined;
|
|
53
53
|
declare function asName(obj: PdfObject | undefined): string | undefined;
|
|
54
|
+
declare function asBool(obj: PdfObject | undefined): boolean | undefined;
|
|
54
55
|
declare function asArray(obj: PdfObject | undefined): PdfObject[] | undefined;
|
|
55
56
|
declare function asDict(obj: PdfObject | undefined): PdfDict | undefined;
|
|
56
57
|
declare function dictGet(dict: PdfDict, key: string): PdfObject | undefined;
|
|
57
58
|
//#endregion
|
|
58
|
-
export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
|
59
|
+
export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asBool, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
package/dist/objects.d.ts
CHANGED
|
@@ -51,8 +51,9 @@ declare function pdfRef(num: number, gen: number): PdfObject;
|
|
|
51
51
|
declare function isName(obj: PdfObject | undefined, name: string): boolean;
|
|
52
52
|
declare function asNumber(obj: PdfObject | undefined): number | undefined;
|
|
53
53
|
declare function asName(obj: PdfObject | undefined): string | undefined;
|
|
54
|
+
declare function asBool(obj: PdfObject | undefined): boolean | undefined;
|
|
54
55
|
declare function asArray(obj: PdfObject | undefined): PdfObject[] | undefined;
|
|
55
56
|
declare function asDict(obj: PdfObject | undefined): PdfDict | undefined;
|
|
56
57
|
declare function dictGet(dict: PdfDict, key: string): PdfObject | undefined;
|
|
57
58
|
//#endregion
|
|
58
|
-
export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
|
59
|
+
export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asBool, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
package/dist/objects.js
CHANGED
|
@@ -69,6 +69,9 @@ function asNumber(obj) {
|
|
|
69
69
|
function asName(obj) {
|
|
70
70
|
return obj?.kind === "name" ? obj.name : void 0;
|
|
71
71
|
}
|
|
72
|
+
function asBool(obj) {
|
|
73
|
+
return obj?.kind === "bool" ? obj.value : void 0;
|
|
74
|
+
}
|
|
72
75
|
function asArray(obj) {
|
|
73
76
|
return obj?.kind === "array" ? obj.items : void 0;
|
|
74
77
|
}
|
|
@@ -81,4 +84,4 @@ function dictGet(dict, key) {
|
|
|
81
84
|
return dict.entries.get(key);
|
|
82
85
|
}
|
|
83
86
|
//#endregion
|
|
84
|
-
export { asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
|
87
|
+
export { asArray, asBool, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
package/dist/read.cjs
CHANGED
|
@@ -169,6 +169,8 @@ function readPage(page, resolver, fontResolver, images, imageIdCache, sink) {
|
|
|
169
169
|
function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
|
|
170
170
|
if (item.kind === "text") return convertText(item, pageMatrix, fontResolver);
|
|
171
171
|
if (item.kind === "rect") return convertRect(item, pageMatrix);
|
|
172
|
+
if (item.kind === "ellipse") return convertEllipse(item, pageMatrix);
|
|
173
|
+
if (item.kind === "line") return convertLine(item, pageMatrix);
|
|
172
174
|
if (item.kind === "path") return convertPath(item, pageMatrix);
|
|
173
175
|
if (item.kind === "image") return convertImage(item, pageMatrix, images, imageIdCache, resolver, sink);
|
|
174
176
|
return convertInlineImage(item, pageMatrix, images, resolver, sink);
|
|
@@ -199,7 +201,13 @@ function convertText(item, pageMatrix, fontResolver) {
|
|
|
199
201
|
rotationDeg: rotationDeg !== 0 ? rotationDeg : void 0
|
|
200
202
|
};
|
|
201
203
|
}
|
|
202
|
-
function
|
|
204
|
+
function paintFields(paint) {
|
|
205
|
+
return {
|
|
206
|
+
...paint.fill !== void 0 ? { fill: paint.fill } : {},
|
|
207
|
+
...paint.stroke !== void 0 ? { stroke: paint.stroke } : {}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function transformBox(item, pageMatrix) {
|
|
203
211
|
const p1 = require_matrix.applyMatrix(pageMatrix, {
|
|
204
212
|
x: item.xPt,
|
|
205
213
|
y: item.yPt
|
|
@@ -209,12 +217,43 @@ function convertRect(item, pageMatrix) {
|
|
|
209
217
|
y: item.yPt + item.heightPt
|
|
210
218
|
});
|
|
211
219
|
return {
|
|
212
|
-
kind: "rect",
|
|
213
220
|
xPt: Math.min(p1.x, p2.x),
|
|
214
221
|
yPt: Math.min(p1.y, p2.y),
|
|
215
222
|
widthPt: Math.abs(p2.x - p1.x),
|
|
216
|
-
heightPt: Math.abs(p2.y - p1.y)
|
|
217
|
-
|
|
223
|
+
heightPt: Math.abs(p2.y - p1.y)
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function convertRect(item, pageMatrix) {
|
|
227
|
+
return {
|
|
228
|
+
kind: "rect",
|
|
229
|
+
...transformBox(item, pageMatrix),
|
|
230
|
+
...paintFields(item)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function convertEllipse(item, pageMatrix) {
|
|
234
|
+
return {
|
|
235
|
+
kind: "ellipse",
|
|
236
|
+
...transformBox(item, pageMatrix),
|
|
237
|
+
...paintFields(item)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function convertLine(item, pageMatrix) {
|
|
241
|
+
const p1 = require_matrix.applyMatrix(pageMatrix, {
|
|
242
|
+
x: item.x1Pt,
|
|
243
|
+
y: item.y1Pt
|
|
244
|
+
});
|
|
245
|
+
const p2 = require_matrix.applyMatrix(pageMatrix, {
|
|
246
|
+
x: item.x2Pt,
|
|
247
|
+
y: item.y2Pt
|
|
248
|
+
});
|
|
249
|
+
return {
|
|
250
|
+
kind: "line",
|
|
251
|
+
x1Pt: p1.x,
|
|
252
|
+
y1Pt: p1.y,
|
|
253
|
+
x2Pt: p2.x,
|
|
254
|
+
y2Pt: p2.y,
|
|
255
|
+
color: item.color,
|
|
256
|
+
widthPt: item.widthPt
|
|
218
257
|
};
|
|
219
258
|
}
|
|
220
259
|
function transformSubpath(subpath, pageMatrix) {
|
package/dist/read.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { r as Matrix } from "./matrix-BHzJESll.cjs";
|
|
3
3
|
import { LayoutDocument } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
package/dist/read.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
-
import {
|
|
2
|
+
import { r as Matrix } from "./matrix-BHzJESll.js";
|
|
3
3
|
import { LayoutDocument } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
package/dist/read.js
CHANGED
|
@@ -168,6 +168,8 @@ function readPage(page, resolver, fontResolver, images, imageIdCache, sink) {
|
|
|
168
168
|
function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
|
|
169
169
|
if (item.kind === "text") return convertText(item, pageMatrix, fontResolver);
|
|
170
170
|
if (item.kind === "rect") return convertRect(item, pageMatrix);
|
|
171
|
+
if (item.kind === "ellipse") return convertEllipse(item, pageMatrix);
|
|
172
|
+
if (item.kind === "line") return convertLine(item, pageMatrix);
|
|
171
173
|
if (item.kind === "path") return convertPath(item, pageMatrix);
|
|
172
174
|
if (item.kind === "image") return convertImage(item, pageMatrix, images, imageIdCache, resolver, sink);
|
|
173
175
|
return convertInlineImage(item, pageMatrix, images, resolver, sink);
|
|
@@ -198,7 +200,13 @@ function convertText(item, pageMatrix, fontResolver) {
|
|
|
198
200
|
rotationDeg: rotationDeg !== 0 ? rotationDeg : void 0
|
|
199
201
|
};
|
|
200
202
|
}
|
|
201
|
-
function
|
|
203
|
+
function paintFields(paint) {
|
|
204
|
+
return {
|
|
205
|
+
...paint.fill !== void 0 ? { fill: paint.fill } : {},
|
|
206
|
+
...paint.stroke !== void 0 ? { stroke: paint.stroke } : {}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function transformBox(item, pageMatrix) {
|
|
202
210
|
const p1 = applyMatrix(pageMatrix, {
|
|
203
211
|
x: item.xPt,
|
|
204
212
|
y: item.yPt
|
|
@@ -208,12 +216,43 @@ function convertRect(item, pageMatrix) {
|
|
|
208
216
|
y: item.yPt + item.heightPt
|
|
209
217
|
});
|
|
210
218
|
return {
|
|
211
|
-
kind: "rect",
|
|
212
219
|
xPt: Math.min(p1.x, p2.x),
|
|
213
220
|
yPt: Math.min(p1.y, p2.y),
|
|
214
221
|
widthPt: Math.abs(p2.x - p1.x),
|
|
215
|
-
heightPt: Math.abs(p2.y - p1.y)
|
|
216
|
-
|
|
222
|
+
heightPt: Math.abs(p2.y - p1.y)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function convertRect(item, pageMatrix) {
|
|
226
|
+
return {
|
|
227
|
+
kind: "rect",
|
|
228
|
+
...transformBox(item, pageMatrix),
|
|
229
|
+
...paintFields(item)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function convertEllipse(item, pageMatrix) {
|
|
233
|
+
return {
|
|
234
|
+
kind: "ellipse",
|
|
235
|
+
...transformBox(item, pageMatrix),
|
|
236
|
+
...paintFields(item)
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function convertLine(item, pageMatrix) {
|
|
240
|
+
const p1 = applyMatrix(pageMatrix, {
|
|
241
|
+
x: item.x1Pt,
|
|
242
|
+
y: item.y1Pt
|
|
243
|
+
});
|
|
244
|
+
const p2 = applyMatrix(pageMatrix, {
|
|
245
|
+
x: item.x2Pt,
|
|
246
|
+
y: item.y2Pt
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
kind: "line",
|
|
250
|
+
x1Pt: p1.x,
|
|
251
|
+
y1Pt: p1.y,
|
|
252
|
+
x2Pt: p2.x,
|
|
253
|
+
y2Pt: p2.y,
|
|
254
|
+
color: item.color,
|
|
255
|
+
widthPt: item.widthPt
|
|
217
256
|
};
|
|
218
257
|
}
|
|
219
258
|
function transformSubpath(subpath, pageMatrix) {
|
package/dist/write.cjs
CHANGED
|
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_afm_widths = require("./afm-widths-BoeTOK2r.cjs");
|
|
3
3
|
const require_util_base64 = require("./util/base64.cjs");
|
|
4
4
|
const require_bytes_writer = require("./bytes/writer.cjs");
|
|
5
|
-
const require_bytes_flate = require("./bytes/flate.cjs");
|
|
6
5
|
const require_objects = require("./objects.cjs");
|
|
6
|
+
const require_bytes_flate = require("./bytes/flate.cjs");
|
|
7
7
|
const require_util_abort = require("./util/abort.cjs");
|
|
8
8
|
const require_fonts = require("./fonts.cjs");
|
|
9
9
|
const require_image_jpeg_info = require("./image/jpeg-info.cjs");
|
package/dist/write.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as winAnsiGlyphName, n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-Dxucrg7D.js";
|
|
2
2
|
import { base64ToBytes } from "./util/base64.js";
|
|
3
3
|
import { ByteWriter, concatBytes } from "./bytes/writer.js";
|
|
4
|
-
import { deflate } from "./bytes/flate.js";
|
|
5
4
|
import { pdfArray, pdfDict, pdfHexString, pdfName, pdfNum, pdfRef, pdfStream } from "./objects.js";
|
|
5
|
+
import { deflate } from "./bytes/flate.js";
|
|
6
6
|
import { throwIfAborted } from "./util/abort.js";
|
|
7
7
|
import { resolveStandardFont } from "./fonts.js";
|
|
8
8
|
import { readJpegInfo } from "./image/jpeg-info.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-codec",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on document-schema.js's LayoutDocument pivot and Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|