pdf-parser.js 4.8.9 → 4.8.11
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/cff-probe.cjs +1 -1
- package/dist/cff-probe.js +1 -1
- package/dist/crypto/rc4.cjs +4 -5
- package/dist/crypto/rc4.js +4 -5
- package/dist/crypto/sha2.cjs +10 -10
- package/dist/crypto/sha2.js +10 -10
- package/dist/encrypt-write.cjs +0 -1
- package/dist/encrypt-write.js +0 -1
- package/dist/glyf-contours-OSdG6Edr.d.ts +13 -0
- package/dist/glyf-contours-zRQbj-Yp.d.cts +13 -0
- package/dist/glyf-contours.d.cts +1 -12
- package/dist/glyf-contours.d.ts +1 -12
- package/dist/glyf-nXC-IDRW.d.cts +33 -0
- package/dist/glyf-vMGtP1pb.d.ts +33 -0
- package/dist/glyf.d.cts +1 -32
- package/dist/glyf.d.ts +1 -32
- package/dist/math-content-write.cjs +3 -6
- package/dist/math-content-write.js +3 -6
- package/dist/navigation.cjs +0 -8
- package/dist/navigation.js +0 -8
- package/dist/raster.cjs +34 -41
- package/dist/raster.d.cts +21 -1
- package/dist/raster.d.ts +21 -1
- package/dist/raster.js +32 -42
- package/dist/read.cjs +1 -1
- package/dist/read.js +1 -1
- package/dist/serialize.cjs +1 -5
- package/dist/serialize.js +1 -5
- package/package.json +2 -2
package/dist/cff-probe.cjs
CHANGED
|
@@ -17,7 +17,7 @@ function probeCff(bytes) {
|
|
|
17
17
|
const headerSize = require_sfnt.u8(bytes, CFF_HEADER_SIZE_OFFSET);
|
|
18
18
|
if (majorVersion !== CFF_MAJOR_VERSION || headerSize < CFF_HEADER_SIZE) return;
|
|
19
19
|
const nameIndex = require_cff.readCffIndex(bytes, headerSize);
|
|
20
|
-
if (nameIndex === void 0
|
|
20
|
+
if (nameIndex === void 0) return;
|
|
21
21
|
const nameBytes = nameIndex.entry(0);
|
|
22
22
|
if (nameBytes === void 0) return;
|
|
23
23
|
const topDictBytes = require_cff.readCffIndex(bytes, nameIndex.endOffset)?.entry(0);
|
package/dist/cff-probe.js
CHANGED
|
@@ -16,7 +16,7 @@ function probeCff(bytes) {
|
|
|
16
16
|
const headerSize = u8(bytes, CFF_HEADER_SIZE_OFFSET);
|
|
17
17
|
if (majorVersion !== CFF_MAJOR_VERSION || headerSize < CFF_HEADER_SIZE) return;
|
|
18
18
|
const nameIndex = readCffIndex(bytes, headerSize);
|
|
19
|
-
if (nameIndex === void 0
|
|
19
|
+
if (nameIndex === void 0) return;
|
|
20
20
|
const nameBytes = nameIndex.entry(0);
|
|
21
21
|
if (nameBytes === void 0) return;
|
|
22
22
|
const topDictBytes = readCffIndex(bytes, nameIndex.endOffset)?.entry(0);
|
package/dist/crypto/rc4.cjs
CHANGED
|
@@ -2,8 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
//#region src/crypto/rc4.ts
|
|
3
3
|
const STATE_SIZE = 256;
|
|
4
4
|
function rc4(key, data) {
|
|
5
|
-
const state =
|
|
6
|
-
for (let i = 0; i < STATE_SIZE; i++) state[i] = i;
|
|
5
|
+
const state = Uint8Array.from({ length: STATE_SIZE }, (_, i) => i);
|
|
7
6
|
if (key.length === 0) return Uint8Array.from(data);
|
|
8
7
|
let j = 0;
|
|
9
8
|
for (let i = 0; i < STATE_SIZE; i++) {
|
|
@@ -15,14 +14,14 @@ function rc4(key, data) {
|
|
|
15
14
|
const out = new Uint8Array(data.length);
|
|
16
15
|
let x = 0;
|
|
17
16
|
let y = 0;
|
|
18
|
-
|
|
17
|
+
data.forEach((byte, n) => {
|
|
19
18
|
x = x + 1 & 255;
|
|
20
19
|
y = y + state[x] & 255;
|
|
21
20
|
const swap = state[x];
|
|
22
21
|
state[x] = state[y];
|
|
23
22
|
state[y] = swap;
|
|
24
|
-
out[n] =
|
|
25
|
-
}
|
|
23
|
+
out[n] = byte ^ state[state[x] + state[y] & 255];
|
|
24
|
+
});
|
|
26
25
|
return out;
|
|
27
26
|
}
|
|
28
27
|
//#endregion
|
package/dist/crypto/rc4.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
//#region src/crypto/rc4.ts
|
|
2
2
|
const STATE_SIZE = 256;
|
|
3
3
|
function rc4(key, data) {
|
|
4
|
-
const state =
|
|
5
|
-
for (let i = 0; i < STATE_SIZE; i++) state[i] = i;
|
|
4
|
+
const state = Uint8Array.from({ length: STATE_SIZE }, (_, i) => i);
|
|
6
5
|
if (key.length === 0) return Uint8Array.from(data);
|
|
7
6
|
let j = 0;
|
|
8
7
|
for (let i = 0; i < STATE_SIZE; i++) {
|
|
@@ -14,14 +13,14 @@ function rc4(key, data) {
|
|
|
14
13
|
const out = new Uint8Array(data.length);
|
|
15
14
|
let x = 0;
|
|
16
15
|
let y = 0;
|
|
17
|
-
|
|
16
|
+
data.forEach((byte, n) => {
|
|
18
17
|
x = x + 1 & 255;
|
|
19
18
|
y = y + state[x] & 255;
|
|
20
19
|
const swap = state[x];
|
|
21
20
|
state[x] = state[y];
|
|
22
21
|
state[y] = swap;
|
|
23
|
-
out[n] =
|
|
24
|
-
}
|
|
22
|
+
out[n] = byte ^ state[state[x] + state[y] & 255];
|
|
23
|
+
});
|
|
25
24
|
return out;
|
|
26
25
|
}
|
|
27
26
|
//#endregion
|
package/dist/crypto/sha2.cjs
CHANGED
|
@@ -118,7 +118,7 @@ function padBigEndian(bytes, blockBytes, lengthBytes) {
|
|
|
118
118
|
padded.set(bytes);
|
|
119
119
|
padded[bytes.length] = 128;
|
|
120
120
|
let bitLength = bytes.length * 8;
|
|
121
|
-
for (let i = 0; i < lengthBytes
|
|
121
|
+
for (let i = 0; i < lengthBytes; i++) {
|
|
122
122
|
padded[paddedLength - 1 - i] = bitLength % 256;
|
|
123
123
|
bitLength = Math.floor(bitLength / 256);
|
|
124
124
|
}
|
|
@@ -132,17 +132,18 @@ function sha256(bytes) {
|
|
|
132
132
|
const state = Uint32Array.from(H256);
|
|
133
133
|
const w = new Uint32Array(SHA256_ROUNDS);
|
|
134
134
|
for (let offset = 0; offset < padded.length; offset += SHA256_BLOCK_BYTES) {
|
|
135
|
-
|
|
135
|
+
w.set(Array.from({ length: WORDS_PER_BLOCK }, (_, t) => {
|
|
136
136
|
const at = offset + t * 4;
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
137
|
+
return (padded[at] << 24 | padded[at + 1] << 16 | padded[at + 2] << 8 | padded[at + 3]) >>> 0;
|
|
138
|
+
}));
|
|
139
|
+
Array.from({ length: SHA256_ROUNDS }, (_, t) => {
|
|
140
|
+
if (t < WORDS_PER_BLOCK) return;
|
|
140
141
|
const x = w[t - 15];
|
|
141
142
|
const y = w[t - 2];
|
|
142
143
|
const s0 = rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3;
|
|
143
144
|
const s1 = rotr32(y, 17) ^ rotr32(y, 19) ^ y >>> 10;
|
|
144
145
|
w[t] = w[t - 16] + s0 + w[t - 7] + s1 >>> 0;
|
|
145
|
-
}
|
|
146
|
+
});
|
|
146
147
|
let a = state[0];
|
|
147
148
|
let b = state[1];
|
|
148
149
|
let c = state[2];
|
|
@@ -175,16 +176,15 @@ function sha256(bytes) {
|
|
|
175
176
|
g,
|
|
176
177
|
h
|
|
177
178
|
];
|
|
178
|
-
|
|
179
|
+
state.set(state.map((value, i) => value + next[i] >>> 0));
|
|
179
180
|
}
|
|
180
181
|
const digest = new Uint8Array(state.length * 4);
|
|
181
|
-
|
|
182
|
-
const word = state[i];
|
|
182
|
+
state.forEach((word, i) => {
|
|
183
183
|
digest[i * 4] = word >>> 24 & 255;
|
|
184
184
|
digest[i * 4 + 1] = word >>> 16 & 255;
|
|
185
185
|
digest[i * 4 + 2] = word >>> 8 & 255;
|
|
186
186
|
digest[i * 4 + 3] = word & 255;
|
|
187
|
-
}
|
|
187
|
+
});
|
|
188
188
|
return digest;
|
|
189
189
|
}
|
|
190
190
|
function readWord32(bytes, offset) {
|
package/dist/crypto/sha2.js
CHANGED
|
@@ -117,7 +117,7 @@ function padBigEndian(bytes, blockBytes, lengthBytes) {
|
|
|
117
117
|
padded.set(bytes);
|
|
118
118
|
padded[bytes.length] = 128;
|
|
119
119
|
let bitLength = bytes.length * 8;
|
|
120
|
-
for (let i = 0; i < lengthBytes
|
|
120
|
+
for (let i = 0; i < lengthBytes; i++) {
|
|
121
121
|
padded[paddedLength - 1 - i] = bitLength % 256;
|
|
122
122
|
bitLength = Math.floor(bitLength / 256);
|
|
123
123
|
}
|
|
@@ -131,17 +131,18 @@ function sha256(bytes) {
|
|
|
131
131
|
const state = Uint32Array.from(H256);
|
|
132
132
|
const w = new Uint32Array(SHA256_ROUNDS);
|
|
133
133
|
for (let offset = 0; offset < padded.length; offset += SHA256_BLOCK_BYTES) {
|
|
134
|
-
|
|
134
|
+
w.set(Array.from({ length: WORDS_PER_BLOCK }, (_, t) => {
|
|
135
135
|
const at = offset + t * 4;
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
136
|
+
return (padded[at] << 24 | padded[at + 1] << 16 | padded[at + 2] << 8 | padded[at + 3]) >>> 0;
|
|
137
|
+
}));
|
|
138
|
+
Array.from({ length: SHA256_ROUNDS }, (_, t) => {
|
|
139
|
+
if (t < WORDS_PER_BLOCK) return;
|
|
139
140
|
const x = w[t - 15];
|
|
140
141
|
const y = w[t - 2];
|
|
141
142
|
const s0 = rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3;
|
|
142
143
|
const s1 = rotr32(y, 17) ^ rotr32(y, 19) ^ y >>> 10;
|
|
143
144
|
w[t] = w[t - 16] + s0 + w[t - 7] + s1 >>> 0;
|
|
144
|
-
}
|
|
145
|
+
});
|
|
145
146
|
let a = state[0];
|
|
146
147
|
let b = state[1];
|
|
147
148
|
let c = state[2];
|
|
@@ -174,16 +175,15 @@ function sha256(bytes) {
|
|
|
174
175
|
g,
|
|
175
176
|
h
|
|
176
177
|
];
|
|
177
|
-
|
|
178
|
+
state.set(state.map((value, i) => value + next[i] >>> 0));
|
|
178
179
|
}
|
|
179
180
|
const digest = new Uint8Array(state.length * 4);
|
|
180
|
-
|
|
181
|
-
const word = state[i];
|
|
181
|
+
state.forEach((word, i) => {
|
|
182
182
|
digest[i * 4] = word >>> 24 & 255;
|
|
183
183
|
digest[i * 4 + 1] = word >>> 16 & 255;
|
|
184
184
|
digest[i * 4 + 2] = word >>> 8 & 255;
|
|
185
185
|
digest[i * 4 + 3] = word & 255;
|
|
186
|
-
}
|
|
186
|
+
});
|
|
187
187
|
return digest;
|
|
188
188
|
}
|
|
189
189
|
function readWord32(bytes, offset) {
|
package/dist/encrypt-write.cjs
CHANGED
|
@@ -94,7 +94,6 @@ function encryptAes(key, data) {
|
|
|
94
94
|
return require_bytes_writer.concatBytes([iv, require_crypto_aes.aesCbcEncrypt(key, iv, padded)]);
|
|
95
95
|
}
|
|
96
96
|
function applyEncryptMethod(method, fileKey, perObjectKeys, bytes, num, gen) {
|
|
97
|
-
if (method === "identity") return bytes;
|
|
98
97
|
const key = perObjectKeys ? require_encrypt.objectKey(fileKey, num, gen, method) : fileKey;
|
|
99
98
|
return method === "rc4" ? require_crypto_rc4.rc4(key, bytes) : encryptAes(key, bytes);
|
|
100
99
|
}
|
package/dist/encrypt-write.js
CHANGED
|
@@ -93,7 +93,6 @@ function encryptAes(key, data) {
|
|
|
93
93
|
return concatBytes([iv, aesCbcEncrypt(key, iv, padded)]);
|
|
94
94
|
}
|
|
95
95
|
function applyEncryptMethod(method, fileKey, perObjectKeys, bytes, num, gen) {
|
|
96
|
-
if (method === "identity") return bytes;
|
|
97
96
|
const key = perObjectKeys ? objectKey(fileKey, num, gen, method) : fileKey;
|
|
98
97
|
return method === "rc4" ? rc4(key, bytes) : encryptAes(key, bytes);
|
|
99
98
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { r as GlyfTable } from "./glyf-vMGtP1pb.js";
|
|
2
|
+
//#region src/glyf-contours.d.ts
|
|
3
|
+
interface GlyphContourPoint {
|
|
4
|
+
readonly x: number;
|
|
5
|
+
readonly y: number;
|
|
6
|
+
readonly onCurve: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface GlyphOutline {
|
|
9
|
+
readonly contours: readonly (readonly GlyphContourPoint[])[];
|
|
10
|
+
}
|
|
11
|
+
declare function decodeGlyphOutline(glyf: GlyfTable, glyphId: number): GlyphOutline | undefined;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { GlyphOutline as n, decodeGlyphOutline as r, GlyphContourPoint as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { r as GlyfTable } from "./glyf-nXC-IDRW.cjs";
|
|
2
|
+
//#region src/glyf-contours.d.ts
|
|
3
|
+
interface GlyphContourPoint {
|
|
4
|
+
readonly x: number;
|
|
5
|
+
readonly y: number;
|
|
6
|
+
readonly onCurve: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface GlyphOutline {
|
|
9
|
+
readonly contours: readonly (readonly GlyphContourPoint[])[];
|
|
10
|
+
}
|
|
11
|
+
declare function decodeGlyphOutline(glyf: GlyfTable, glyphId: number): GlyphOutline | undefined;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { GlyphOutline as n, decodeGlyphOutline as r, GlyphContourPoint as t };
|
package/dist/glyf-contours.d.cts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/glyf-contours.d.ts
|
|
3
|
-
interface GlyphContourPoint {
|
|
4
|
-
readonly x: number;
|
|
5
|
-
readonly y: number;
|
|
6
|
-
readonly onCurve: boolean;
|
|
7
|
-
}
|
|
8
|
-
interface GlyphOutline {
|
|
9
|
-
readonly contours: readonly (readonly GlyphContourPoint[])[];
|
|
10
|
-
}
|
|
11
|
-
declare function decodeGlyphOutline(glyf: GlyfTable, glyphId: number): GlyphOutline | undefined;
|
|
12
|
-
//#endregion
|
|
1
|
+
import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-zRQbj-Yp.cjs";
|
|
13
2
|
export { GlyphContourPoint, GlyphOutline, decodeGlyphOutline };
|
package/dist/glyf-contours.d.ts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/glyf-contours.d.ts
|
|
3
|
-
interface GlyphContourPoint {
|
|
4
|
-
readonly x: number;
|
|
5
|
-
readonly y: number;
|
|
6
|
-
readonly onCurve: boolean;
|
|
7
|
-
}
|
|
8
|
-
interface GlyphOutline {
|
|
9
|
-
readonly contours: readonly (readonly GlyphContourPoint[])[];
|
|
10
|
-
}
|
|
11
|
-
declare function decodeGlyphOutline(glyf: GlyfTable, glyphId: number): GlyphOutline | undefined;
|
|
12
|
-
//#endregion
|
|
1
|
+
import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-OSdG6Edr.js";
|
|
13
2
|
export { GlyphContourPoint, GlyphOutline, decodeGlyphOutline };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
|
|
2
|
+
import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
|
|
3
|
+
//#region src/glyf.d.ts
|
|
4
|
+
interface GlyphHeader {
|
|
5
|
+
readonly numberOfContours: number;
|
|
6
|
+
readonly xMin: number;
|
|
7
|
+
readonly yMin: number;
|
|
8
|
+
readonly xMax: number;
|
|
9
|
+
readonly yMax: number;
|
|
10
|
+
}
|
|
11
|
+
interface CompositeComponent {
|
|
12
|
+
readonly flags: number;
|
|
13
|
+
readonly glyphIndex: number;
|
|
14
|
+
readonly argument1: number;
|
|
15
|
+
readonly argument2: number;
|
|
16
|
+
readonly argsAreXyValues: boolean;
|
|
17
|
+
readonly transform: readonly [number, number, number, number] | undefined;
|
|
18
|
+
}
|
|
19
|
+
interface GlyfTable {
|
|
20
|
+
readonly numGlyphs: number;
|
|
21
|
+
glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
|
|
22
|
+
glyphHeader(glyphId: number): GlyphHeader | undefined;
|
|
23
|
+
compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
|
|
24
|
+
glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
|
|
25
|
+
}
|
|
26
|
+
interface GlyfOptions {
|
|
27
|
+
readonly numGlyphs: number;
|
|
28
|
+
readonly indexToLocFormat: 0 | 1;
|
|
29
|
+
}
|
|
30
|
+
declare function parseLoca(font: SfntFont, options: GlyfOptions): readonly number[] | undefined;
|
|
31
|
+
declare function parseGlyf(font: SfntFont, options: GlyfOptions): GlyfTable | undefined;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { parseGlyf as a, GlyphHeader as i, GlyfOptions as n, parseLoca as o, GlyfTable as r, CompositeComponent as t };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
|
|
2
|
+
import { t as SfntFont } from "./sfnt-V08bb5ut.js";
|
|
3
|
+
//#region src/glyf.d.ts
|
|
4
|
+
interface GlyphHeader {
|
|
5
|
+
readonly numberOfContours: number;
|
|
6
|
+
readonly xMin: number;
|
|
7
|
+
readonly yMin: number;
|
|
8
|
+
readonly xMax: number;
|
|
9
|
+
readonly yMax: number;
|
|
10
|
+
}
|
|
11
|
+
interface CompositeComponent {
|
|
12
|
+
readonly flags: number;
|
|
13
|
+
readonly glyphIndex: number;
|
|
14
|
+
readonly argument1: number;
|
|
15
|
+
readonly argument2: number;
|
|
16
|
+
readonly argsAreXyValues: boolean;
|
|
17
|
+
readonly transform: readonly [number, number, number, number] | undefined;
|
|
18
|
+
}
|
|
19
|
+
interface GlyfTable {
|
|
20
|
+
readonly numGlyphs: number;
|
|
21
|
+
glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
|
|
22
|
+
glyphHeader(glyphId: number): GlyphHeader | undefined;
|
|
23
|
+
compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
|
|
24
|
+
glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
|
|
25
|
+
}
|
|
26
|
+
interface GlyfOptions {
|
|
27
|
+
readonly numGlyphs: number;
|
|
28
|
+
readonly indexToLocFormat: 0 | 1;
|
|
29
|
+
}
|
|
30
|
+
declare function parseLoca(font: SfntFont, options: GlyfOptions): readonly number[] | undefined;
|
|
31
|
+
declare function parseGlyf(font: SfntFont, options: GlyfOptions): GlyfTable | undefined;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { parseGlyf as a, GlyphHeader as i, GlyfOptions as n, parseLoca as o, GlyfTable as r, CompositeComponent as t };
|
package/dist/glyf.d.cts
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
|
|
3
|
-
//#region src/glyf.d.ts
|
|
4
|
-
interface GlyphHeader {
|
|
5
|
-
readonly numberOfContours: number;
|
|
6
|
-
readonly xMin: number;
|
|
7
|
-
readonly yMin: number;
|
|
8
|
-
readonly xMax: number;
|
|
9
|
-
readonly yMax: number;
|
|
10
|
-
}
|
|
11
|
-
interface CompositeComponent {
|
|
12
|
-
readonly flags: number;
|
|
13
|
-
readonly glyphIndex: number;
|
|
14
|
-
readonly argument1: number;
|
|
15
|
-
readonly argument2: number;
|
|
16
|
-
readonly argsAreXyValues: boolean;
|
|
17
|
-
readonly transform: readonly [number, number, number, number] | undefined;
|
|
18
|
-
}
|
|
19
|
-
interface GlyfTable {
|
|
20
|
-
readonly numGlyphs: number;
|
|
21
|
-
glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
|
|
22
|
-
glyphHeader(glyphId: number): GlyphHeader | undefined;
|
|
23
|
-
compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
|
|
24
|
-
glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
|
|
25
|
-
}
|
|
26
|
-
interface GlyfOptions {
|
|
27
|
-
readonly numGlyphs: number;
|
|
28
|
-
readonly indexToLocFormat: 0 | 1;
|
|
29
|
-
}
|
|
30
|
-
declare function parseLoca(font: SfntFont, options: GlyfOptions): readonly number[] | undefined;
|
|
31
|
-
declare function parseGlyf(font: SfntFont, options: GlyfOptions): GlyfTable | undefined;
|
|
32
|
-
//#endregion
|
|
1
|
+
import { a as parseGlyf, i as GlyphHeader, n as GlyfOptions, o as parseLoca, r as GlyfTable, t as CompositeComponent } from "./glyf-nXC-IDRW.cjs";
|
|
33
2
|
export { CompositeComponent, GlyfOptions, GlyfTable, GlyphHeader, parseGlyf, parseLoca };
|
package/dist/glyf.d.ts
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as SfntFont } from "./sfnt-V08bb5ut.js";
|
|
3
|
-
//#region src/glyf.d.ts
|
|
4
|
-
interface GlyphHeader {
|
|
5
|
-
readonly numberOfContours: number;
|
|
6
|
-
readonly xMin: number;
|
|
7
|
-
readonly yMin: number;
|
|
8
|
-
readonly xMax: number;
|
|
9
|
-
readonly yMax: number;
|
|
10
|
-
}
|
|
11
|
-
interface CompositeComponent {
|
|
12
|
-
readonly flags: number;
|
|
13
|
-
readonly glyphIndex: number;
|
|
14
|
-
readonly argument1: number;
|
|
15
|
-
readonly argument2: number;
|
|
16
|
-
readonly argsAreXyValues: boolean;
|
|
17
|
-
readonly transform: readonly [number, number, number, number] | undefined;
|
|
18
|
-
}
|
|
19
|
-
interface GlyfTable {
|
|
20
|
-
readonly numGlyphs: number;
|
|
21
|
-
glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
|
|
22
|
-
glyphHeader(glyphId: number): GlyphHeader | undefined;
|
|
23
|
-
compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
|
|
24
|
-
glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
|
|
25
|
-
}
|
|
26
|
-
interface GlyfOptions {
|
|
27
|
-
readonly numGlyphs: number;
|
|
28
|
-
readonly indexToLocFormat: 0 | 1;
|
|
29
|
-
}
|
|
30
|
-
declare function parseLoca(font: SfntFont, options: GlyfOptions): readonly number[] | undefined;
|
|
31
|
-
declare function parseGlyf(font: SfntFont, options: GlyfOptions): GlyfTable | undefined;
|
|
32
|
-
//#endregion
|
|
1
|
+
import { a as parseGlyf, i as GlyphHeader, n as GlyfOptions, o as parseLoca, r as GlyfTable, t as CompositeComponent } from "./glyf-vMGtP1pb.js";
|
|
33
2
|
export { CompositeComponent, GlyfOptions, GlyfTable, GlyphHeader, parseGlyf, parseLoca };
|
|
@@ -44,15 +44,12 @@ function cidBytes(glyphId) {
|
|
|
44
44
|
return new Uint8Array([glyphId >> 8 & 255, glyphId & 255]);
|
|
45
45
|
}
|
|
46
46
|
function utf16BeWithBom(text) {
|
|
47
|
-
const bytes =
|
|
48
|
-
bytes[0] = 254;
|
|
49
|
-
bytes[1] = 255;
|
|
47
|
+
const bytes = [254, 255];
|
|
50
48
|
for (let i = 0; i < text.length; i++) {
|
|
51
49
|
const unit = text.charCodeAt(i);
|
|
52
|
-
bytes
|
|
53
|
-
bytes[3 + i * 2] = unit & 255;
|
|
50
|
+
bytes.push(unit >> 8 & 255, unit & 255);
|
|
54
51
|
}
|
|
55
|
-
return bytes;
|
|
52
|
+
return new Uint8Array(bytes);
|
|
56
53
|
}
|
|
57
54
|
function writeAssembledGlyphs(writer, positioned, item, ctx) {
|
|
58
55
|
if (item.placements.length === 0) return;
|
|
@@ -43,15 +43,12 @@ function cidBytes(glyphId) {
|
|
|
43
43
|
return new Uint8Array([glyphId >> 8 & 255, glyphId & 255]);
|
|
44
44
|
}
|
|
45
45
|
function utf16BeWithBom(text) {
|
|
46
|
-
const bytes =
|
|
47
|
-
bytes[0] = 254;
|
|
48
|
-
bytes[1] = 255;
|
|
46
|
+
const bytes = [254, 255];
|
|
49
47
|
for (let i = 0; i < text.length; i++) {
|
|
50
48
|
const unit = text.charCodeAt(i);
|
|
51
|
-
bytes
|
|
52
|
-
bytes[3 + i * 2] = unit & 255;
|
|
49
|
+
bytes.push(unit >> 8 & 255, unit & 255);
|
|
53
50
|
}
|
|
54
|
-
return bytes;
|
|
51
|
+
return new Uint8Array(bytes);
|
|
55
52
|
}
|
|
56
53
|
function writeAssembledGlyphs(writer, positioned, item, ctx) {
|
|
57
54
|
if (item.placements.length === 0) return;
|
package/dist/navigation.cjs
CHANGED
|
@@ -114,14 +114,6 @@ function createDestinationRegistry(catalog, resolver, pageIndex, sink) {
|
|
|
114
114
|
};
|
|
115
115
|
const destsDict = resolver.resolveDict(require_objects.dictGet(catalog, "Dests"));
|
|
116
116
|
if (destsDict !== void 0) for (const [name, value] of destsDict.entries) {
|
|
117
|
-
if (byName.has(name)) {
|
|
118
|
-
sink({
|
|
119
|
-
code: "pdf/destination-duplicate",
|
|
120
|
-
severity: "warning",
|
|
121
|
-
message: `destination name "${name}" is declared more than once; keeping the first`
|
|
122
|
-
});
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
117
|
const parsed = parseDestination(value, resolver, pageIndex, sink);
|
|
126
118
|
if (parsed !== void 0) add(name, parsed);
|
|
127
119
|
}
|
package/dist/navigation.js
CHANGED
|
@@ -113,14 +113,6 @@ function createDestinationRegistry(catalog, resolver, pageIndex, sink) {
|
|
|
113
113
|
};
|
|
114
114
|
const destsDict = resolver.resolveDict(dictGet(catalog, "Dests"));
|
|
115
115
|
if (destsDict !== void 0) for (const [name, value] of destsDict.entries) {
|
|
116
|
-
if (byName.has(name)) {
|
|
117
|
-
sink({
|
|
118
|
-
code: "pdf/destination-duplicate",
|
|
119
|
-
severity: "warning",
|
|
120
|
-
message: `destination name "${name}" is declared more than once; keeping the first`
|
|
121
|
-
});
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
116
|
const parsed = parseDestination(value, resolver, pageIndex, sink);
|
|
125
117
|
if (parsed !== void 0) add(name, parsed);
|
|
126
118
|
}
|
package/dist/raster.cjs
CHANGED
|
@@ -17,7 +17,6 @@ const require_read = require("./read.cjs");
|
|
|
17
17
|
const require_glyf = require("./glyf.cjs");
|
|
18
18
|
const require_glyf_contours = require("./glyf-contours.cjs");
|
|
19
19
|
//#region src/raster.ts
|
|
20
|
-
const FALLBACK_GLYPH_WIDTH_PER_1000 = 500;
|
|
21
20
|
function regionPixels(extentPt, scale) {
|
|
22
21
|
return Math.max(1, Math.ceil(extentPt * scale - 1e-9));
|
|
23
22
|
}
|
|
@@ -46,7 +45,7 @@ function renderPdfPage(pdfBytes, pageIndex, options, rasteriser) {
|
|
|
46
45
|
cropBox = mediaBox;
|
|
47
46
|
}
|
|
48
47
|
const rotation = require_read.normalizeRotation(require_objects.asNumber(require_objects.dictGet(page, "Rotate")));
|
|
49
|
-
const rotationResult = require_read.pageRotationTransform(rotation,
|
|
48
|
+
const rotationResult = require_read.pageRotationTransform(rotation, 0, 0);
|
|
50
49
|
const visibleRect = rotatedRectBounds(cropBox, rotationResult.matrix);
|
|
51
50
|
const pageWidthPt = visibleRect.maxX - visibleRect.minX;
|
|
52
51
|
const pageHeightPt = visibleRect.maxY - visibleRect.minY;
|
|
@@ -483,7 +482,7 @@ function openEmbeddedProgram(descriptorOwner, resolver) {
|
|
|
483
482
|
const stream = resolver.resolve(require_objects.dictGet(descriptor, key));
|
|
484
483
|
if (stream?.kind !== "stream") continue;
|
|
485
484
|
const bytes = require_filters.decodeStream(stream.raw, stream.dict, require_diagnostics.NOOP_DIAGNOSTIC_SINK).bytes;
|
|
486
|
-
if (bytes
|
|
485
|
+
if (bytes[0] === 1 && bytes[1] === 0 && bytes[2] === 4) return { kind: "cff" };
|
|
487
486
|
const sfnt = require_sfnt.parseSfnt(bytes);
|
|
488
487
|
if (sfnt === void 0) continue;
|
|
489
488
|
if (sfnt.tables.has("CFF ")) return { kind: "cff" };
|
|
@@ -499,10 +498,8 @@ function openEmbeddedProgram(descriptorOwner, resolver) {
|
|
|
499
498
|
kind: "glyf",
|
|
500
499
|
sfnt,
|
|
501
500
|
face: {
|
|
502
|
-
composite: false,
|
|
503
501
|
glyf,
|
|
504
|
-
unitsPerEm: head.unitsPerEm
|
|
505
|
-
glyphIdOf: () => void 0
|
|
502
|
+
unitsPerEm: head.unitsPerEm
|
|
506
503
|
}
|
|
507
504
|
};
|
|
508
505
|
}
|
|
@@ -574,17 +571,15 @@ function buildTextOutlineFace(fontDict, resolver, fontResolver, fontResourceName
|
|
|
574
571
|
const entries = [];
|
|
575
572
|
for (let i = 0; i + 1 < decodedBytes.length; i += 2) entries.push(decodedBytes[i] << 8 | decodedBytes[i + 1]);
|
|
576
573
|
return {
|
|
577
|
-
composite: true,
|
|
578
574
|
glyf: program.face.glyf,
|
|
579
575
|
unitsPerEm: program.face.unitsPerEm,
|
|
580
576
|
glyphIdOf: (codes, offset) => {
|
|
581
577
|
const cid = codes[offset] << 8 | codes[offset + 1];
|
|
582
|
-
return
|
|
578
|
+
return entries[cid];
|
|
583
579
|
}
|
|
584
580
|
};
|
|
585
581
|
}
|
|
586
582
|
return {
|
|
587
|
-
composite: true,
|
|
588
583
|
glyf: program.face.glyf,
|
|
589
584
|
unitsPerEm: program.face.unitsPerEm,
|
|
590
585
|
glyphIdOf: (codes, offset) => codes[offset] << 8 | codes[offset + 1]
|
|
@@ -606,7 +601,6 @@ function buildTextOutlineFace(fontDict, resolver, fontResolver, fontResourceName
|
|
|
606
601
|
return;
|
|
607
602
|
}
|
|
608
603
|
return {
|
|
609
|
-
composite: false,
|
|
610
604
|
glyf: program.face.glyf,
|
|
611
605
|
unitsPerEm: program.face.unitsPerEm,
|
|
612
606
|
glyphIdOf: (codes, offset) => {
|
|
@@ -624,14 +618,13 @@ function buildTextOutlineFace(fontDict, resolver, fontResolver, fontResourceName
|
|
|
624
618
|
function drawTextRun(item, fontResolver, resolver, outlineFaces, interpretToDeviceMatrix, rasteriser, sink) {
|
|
625
619
|
const face = resolveTextOutlineFace(item.fontResourceName, item.resources, resolver, fontResolver, outlineFaces, sink);
|
|
626
620
|
if (face === void 0) return;
|
|
627
|
-
const composite = face.composite;
|
|
628
621
|
const placements = [];
|
|
629
622
|
let offset = 0;
|
|
630
623
|
let cumulative = 0;
|
|
631
624
|
while (offset < item.codes.length) {
|
|
632
625
|
const advance = fontResolver.metrics.glyphAdvance(item.fontResourceName, item.resources, item.codes, offset);
|
|
633
|
-
const widthPer1000 = advance
|
|
634
|
-
const byteLength = advance
|
|
626
|
+
const widthPer1000 = advance.widthPer1000;
|
|
627
|
+
const byteLength = advance.byteLengthConsumed;
|
|
635
628
|
placements.push({
|
|
636
629
|
glyphId: face.glyphIdOf(item.codes, offset),
|
|
637
630
|
advance: cumulative
|
|
@@ -660,20 +653,23 @@ function drawTextRun(item, fontResolver, resolver, outlineFaces, interpretToDevi
|
|
|
660
653
|
for (const placement of placements) {
|
|
661
654
|
if (placement.glyphId === void 0) continue;
|
|
662
655
|
const outline = require_glyf_contours.decodeGlyphOutline(face.glyf, placement.glyphId);
|
|
663
|
-
if (outline === void 0
|
|
656
|
+
if (outline === void 0) continue;
|
|
664
657
|
const trm = require_matrix.multiplyMatrices(require_matrix.translationMatrix(placement.advance * correction, 0), item.startMatrix);
|
|
665
|
-
|
|
666
|
-
if (subpaths.length === 0) continue;
|
|
667
|
-
rasteriser.draw({
|
|
668
|
-
kind: "path",
|
|
669
|
-
subpaths,
|
|
670
|
-
fill: {
|
|
671
|
-
color: item.color,
|
|
672
|
-
fillRule: "nonzero"
|
|
673
|
-
}
|
|
674
|
-
});
|
|
658
|
+
drawGlyphOutline(outline, require_matrix.multiplyMatrices(glyphScale, require_matrix.multiplyMatrices(trm, interpretToDeviceMatrix)), item.color, rasteriser);
|
|
675
659
|
}
|
|
676
660
|
}
|
|
661
|
+
function drawGlyphOutline(outline, glyphMatrix, color, rasteriser) {
|
|
662
|
+
const subpaths = glyphOutlineSubpaths(outline, glyphMatrix);
|
|
663
|
+
if (subpaths.length === 0) return;
|
|
664
|
+
rasteriser.draw({
|
|
665
|
+
kind: "path",
|
|
666
|
+
subpaths,
|
|
667
|
+
fill: {
|
|
668
|
+
color,
|
|
669
|
+
fillRule: "nonzero"
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}
|
|
677
673
|
function glyphOutlineSubpaths(outline, matrix) {
|
|
678
674
|
const subpaths = [];
|
|
679
675
|
for (const contour of outline.contours) {
|
|
@@ -684,8 +680,9 @@ function glyphOutlineSubpaths(outline, matrix) {
|
|
|
684
680
|
y: point.y,
|
|
685
681
|
onCurve: point.onCurve
|
|
686
682
|
}));
|
|
687
|
-
const
|
|
688
|
-
|
|
683
|
+
const hasLeadingOnCurvePoint = firstOn >= 0;
|
|
684
|
+
const ordered = hasLeadingOnCurvePoint ? [...contourPoints.slice(firstOn), ...contourPoints.slice(0, firstOn)] : contourPoints;
|
|
685
|
+
let current = hasLeadingOnCurvePoint ? {
|
|
689
686
|
x: contourPoints[firstOn].x,
|
|
690
687
|
y: contourPoints[firstOn].y
|
|
691
688
|
} : {
|
|
@@ -734,27 +731,20 @@ function glyphOutlineSubpaths(outline, matrix) {
|
|
|
734
731
|
pendingOffCurve = point;
|
|
735
732
|
}
|
|
736
733
|
if (pendingOffCurve !== void 0) emitQuad(current, pendingOffCurve, start);
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
});
|
|
745
|
-
}
|
|
734
|
+
const startPx = require_matrix.applyMatrix(matrix, start);
|
|
735
|
+
subpaths.push({
|
|
736
|
+
startXPx: startPx.x,
|
|
737
|
+
startYPx: startPx.y,
|
|
738
|
+
segments,
|
|
739
|
+
closed: true
|
|
740
|
+
});
|
|
746
741
|
}
|
|
747
742
|
return subpaths;
|
|
748
743
|
}
|
|
749
|
-
const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
|
|
750
744
|
const HEADER_SEARCH_WINDOW = 1024;
|
|
751
745
|
function hasPdfHeader(bytes) {
|
|
752
746
|
const window = bytes.subarray(0, Math.min(HEADER_SEARCH_WINDOW, bytes.length));
|
|
753
|
-
|
|
754
|
-
for (let j = 0; j < PDF_HEADER_BYTES.length; j++) if (window[i + j] !== PDF_HEADER_BYTES[j]) continue outer;
|
|
755
|
-
return true;
|
|
756
|
-
}
|
|
757
|
-
return false;
|
|
747
|
+
return new TextDecoder("latin1").decode(window).includes("%PDF-");
|
|
758
748
|
}
|
|
759
749
|
function readDeclaredPageBox(page, key) {
|
|
760
750
|
const arr = require_objects.asArray(require_objects.dictGet(page, key));
|
|
@@ -813,4 +803,7 @@ function readPageContentBytes(page, resolver, sink) {
|
|
|
813
803
|
return /* @__PURE__ */ new Uint8Array(0);
|
|
814
804
|
}
|
|
815
805
|
//#endregion
|
|
806
|
+
exports.drawGlyphOutline = drawGlyphOutline;
|
|
807
|
+
exports.flattenCubic = flattenCubic;
|
|
808
|
+
exports.glyphOutlineSubpaths = glyphOutlineSubpaths;
|
|
816
809
|
exports.renderPdfPage = renderPdfPage;
|
package/dist/raster.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
+
import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
|
|
3
|
+
import { n as GlyphOutline } from "./glyf-contours-zRQbj-Yp.cjs";
|
|
2
4
|
import { Color } from "document-schema.js";
|
|
3
5
|
//#region src/raster.d.ts
|
|
4
6
|
type RasterMatrix = readonly [number, number, number, number, number, number];
|
|
@@ -79,5 +81,23 @@ interface RenderPdfPageOptions {
|
|
|
79
81
|
readonly signal?: AbortSignal;
|
|
80
82
|
}
|
|
81
83
|
declare function renderPdfPage(pdfBytes: Uint8Array<ArrayBuffer>, pageIndex: number, options: RenderPdfPageOptions, rasteriser: PageRasteriser): Uint8Array<ArrayBuffer> | Promise<Uint8Array<ArrayBuffer>>;
|
|
84
|
+
declare function flattenCubic(p0: {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
}, c1: {
|
|
88
|
+
x: number;
|
|
89
|
+
y: number;
|
|
90
|
+
}, c2: {
|
|
91
|
+
x: number;
|
|
92
|
+
y: number;
|
|
93
|
+
}, p1: {
|
|
94
|
+
x: number;
|
|
95
|
+
y: number;
|
|
96
|
+
}): readonly {
|
|
97
|
+
x: number;
|
|
98
|
+
y: number;
|
|
99
|
+
}[];
|
|
100
|
+
declare function drawGlyphOutline(outline: GlyphOutline, glyphMatrix: Matrix, color: Color, rasteriser: PageRasteriser): void;
|
|
101
|
+
declare function glyphOutlineSubpaths(outline: GlyphOutline, matrix: Matrix): readonly RasterSubpath[];
|
|
82
102
|
//#endregion
|
|
83
|
-
export { PageRasteriser, RasterDrawOp, RasterFillRectOp, RasterFillSpec, RasterImageOp, RasterMatrix, RasterPageGeometry, RasterPathOp, RasterPathSegment, RasterRegionPt, RasterStrokeSpec, RasterSubpath, RenderPdfPageOptions, renderPdfPage };
|
|
103
|
+
export { PageRasteriser, RasterDrawOp, RasterFillRectOp, RasterFillSpec, RasterImageOp, RasterMatrix, RasterPageGeometry, RasterPathOp, RasterPathSegment, RasterRegionPt, RasterStrokeSpec, RasterSubpath, RenderPdfPageOptions, drawGlyphOutline, flattenCubic, glyphOutlineSubpaths, renderPdfPage };
|
package/dist/raster.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
+
import { r as Matrix } from "./matrix-B7_SBKQ5.js";
|
|
3
|
+
import { n as GlyphOutline } from "./glyf-contours-OSdG6Edr.js";
|
|
2
4
|
import { Color } from "document-schema.js";
|
|
3
5
|
//#region src/raster.d.ts
|
|
4
6
|
type RasterMatrix = readonly [number, number, number, number, number, number];
|
|
@@ -79,5 +81,23 @@ interface RenderPdfPageOptions {
|
|
|
79
81
|
readonly signal?: AbortSignal;
|
|
80
82
|
}
|
|
81
83
|
declare function renderPdfPage(pdfBytes: Uint8Array<ArrayBuffer>, pageIndex: number, options: RenderPdfPageOptions, rasteriser: PageRasteriser): Uint8Array<ArrayBuffer> | Promise<Uint8Array<ArrayBuffer>>;
|
|
84
|
+
declare function flattenCubic(p0: {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
}, c1: {
|
|
88
|
+
x: number;
|
|
89
|
+
y: number;
|
|
90
|
+
}, c2: {
|
|
91
|
+
x: number;
|
|
92
|
+
y: number;
|
|
93
|
+
}, p1: {
|
|
94
|
+
x: number;
|
|
95
|
+
y: number;
|
|
96
|
+
}): readonly {
|
|
97
|
+
x: number;
|
|
98
|
+
y: number;
|
|
99
|
+
}[];
|
|
100
|
+
declare function drawGlyphOutline(outline: GlyphOutline, glyphMatrix: Matrix, color: Color, rasteriser: PageRasteriser): void;
|
|
101
|
+
declare function glyphOutlineSubpaths(outline: GlyphOutline, matrix: Matrix): readonly RasterSubpath[];
|
|
82
102
|
//#endregion
|
|
83
|
-
export { PageRasteriser, RasterDrawOp, RasterFillRectOp, RasterFillSpec, RasterImageOp, RasterMatrix, RasterPageGeometry, RasterPathOp, RasterPathSegment, RasterRegionPt, RasterStrokeSpec, RasterSubpath, RenderPdfPageOptions, renderPdfPage };
|
|
103
|
+
export { PageRasteriser, RasterDrawOp, RasterFillRectOp, RasterFillSpec, RasterImageOp, RasterMatrix, RasterPageGeometry, RasterPathOp, RasterPathSegment, RasterRegionPt, RasterStrokeSpec, RasterSubpath, RenderPdfPageOptions, drawGlyphOutline, flattenCubic, glyphOutlineSubpaths, renderPdfPage };
|
package/dist/raster.js
CHANGED
|
@@ -16,7 +16,6 @@ import { normalizeRotation, pageRotationTransform } from "./read.js";
|
|
|
16
16
|
import { parseGlyf } from "./glyf.js";
|
|
17
17
|
import { decodeGlyphOutline } from "./glyf-contours.js";
|
|
18
18
|
//#region src/raster.ts
|
|
19
|
-
const FALLBACK_GLYPH_WIDTH_PER_1000 = 500;
|
|
20
19
|
function regionPixels(extentPt, scale) {
|
|
21
20
|
return Math.max(1, Math.ceil(extentPt * scale - 1e-9));
|
|
22
21
|
}
|
|
@@ -45,7 +44,7 @@ function renderPdfPage(pdfBytes, pageIndex, options, rasteriser) {
|
|
|
45
44
|
cropBox = mediaBox;
|
|
46
45
|
}
|
|
47
46
|
const rotation = normalizeRotation(asNumber(dictGet(page, "Rotate")));
|
|
48
|
-
const rotationResult = pageRotationTransform(rotation,
|
|
47
|
+
const rotationResult = pageRotationTransform(rotation, 0, 0);
|
|
49
48
|
const visibleRect = rotatedRectBounds(cropBox, rotationResult.matrix);
|
|
50
49
|
const pageWidthPt = visibleRect.maxX - visibleRect.minX;
|
|
51
50
|
const pageHeightPt = visibleRect.maxY - visibleRect.minY;
|
|
@@ -482,7 +481,7 @@ function openEmbeddedProgram(descriptorOwner, resolver) {
|
|
|
482
481
|
const stream = resolver.resolve(dictGet(descriptor, key));
|
|
483
482
|
if (stream?.kind !== "stream") continue;
|
|
484
483
|
const bytes = decodeStream(stream.raw, stream.dict, NOOP_DIAGNOSTIC_SINK).bytes;
|
|
485
|
-
if (bytes
|
|
484
|
+
if (bytes[0] === 1 && bytes[1] === 0 && bytes[2] === 4) return { kind: "cff" };
|
|
486
485
|
const sfnt = parseSfnt(bytes);
|
|
487
486
|
if (sfnt === void 0) continue;
|
|
488
487
|
if (sfnt.tables.has("CFF ")) return { kind: "cff" };
|
|
@@ -498,10 +497,8 @@ function openEmbeddedProgram(descriptorOwner, resolver) {
|
|
|
498
497
|
kind: "glyf",
|
|
499
498
|
sfnt,
|
|
500
499
|
face: {
|
|
501
|
-
composite: false,
|
|
502
500
|
glyf,
|
|
503
|
-
unitsPerEm: head.unitsPerEm
|
|
504
|
-
glyphIdOf: () => void 0
|
|
501
|
+
unitsPerEm: head.unitsPerEm
|
|
505
502
|
}
|
|
506
503
|
};
|
|
507
504
|
}
|
|
@@ -573,17 +570,15 @@ function buildTextOutlineFace(fontDict, resolver, fontResolver, fontResourceName
|
|
|
573
570
|
const entries = [];
|
|
574
571
|
for (let i = 0; i + 1 < decodedBytes.length; i += 2) entries.push(decodedBytes[i] << 8 | decodedBytes[i + 1]);
|
|
575
572
|
return {
|
|
576
|
-
composite: true,
|
|
577
573
|
glyf: program.face.glyf,
|
|
578
574
|
unitsPerEm: program.face.unitsPerEm,
|
|
579
575
|
glyphIdOf: (codes, offset) => {
|
|
580
576
|
const cid = codes[offset] << 8 | codes[offset + 1];
|
|
581
|
-
return
|
|
577
|
+
return entries[cid];
|
|
582
578
|
}
|
|
583
579
|
};
|
|
584
580
|
}
|
|
585
581
|
return {
|
|
586
|
-
composite: true,
|
|
587
582
|
glyf: program.face.glyf,
|
|
588
583
|
unitsPerEm: program.face.unitsPerEm,
|
|
589
584
|
glyphIdOf: (codes, offset) => codes[offset] << 8 | codes[offset + 1]
|
|
@@ -605,7 +600,6 @@ function buildTextOutlineFace(fontDict, resolver, fontResolver, fontResourceName
|
|
|
605
600
|
return;
|
|
606
601
|
}
|
|
607
602
|
return {
|
|
608
|
-
composite: false,
|
|
609
603
|
glyf: program.face.glyf,
|
|
610
604
|
unitsPerEm: program.face.unitsPerEm,
|
|
611
605
|
glyphIdOf: (codes, offset) => {
|
|
@@ -623,14 +617,13 @@ function buildTextOutlineFace(fontDict, resolver, fontResolver, fontResourceName
|
|
|
623
617
|
function drawTextRun(item, fontResolver, resolver, outlineFaces, interpretToDeviceMatrix, rasteriser, sink) {
|
|
624
618
|
const face = resolveTextOutlineFace(item.fontResourceName, item.resources, resolver, fontResolver, outlineFaces, sink);
|
|
625
619
|
if (face === void 0) return;
|
|
626
|
-
const composite = face.composite;
|
|
627
620
|
const placements = [];
|
|
628
621
|
let offset = 0;
|
|
629
622
|
let cumulative = 0;
|
|
630
623
|
while (offset < item.codes.length) {
|
|
631
624
|
const advance = fontResolver.metrics.glyphAdvance(item.fontResourceName, item.resources, item.codes, offset);
|
|
632
|
-
const widthPer1000 = advance
|
|
633
|
-
const byteLength = advance
|
|
625
|
+
const widthPer1000 = advance.widthPer1000;
|
|
626
|
+
const byteLength = advance.byteLengthConsumed;
|
|
634
627
|
placements.push({
|
|
635
628
|
glyphId: face.glyphIdOf(item.codes, offset),
|
|
636
629
|
advance: cumulative
|
|
@@ -659,20 +652,23 @@ function drawTextRun(item, fontResolver, resolver, outlineFaces, interpretToDevi
|
|
|
659
652
|
for (const placement of placements) {
|
|
660
653
|
if (placement.glyphId === void 0) continue;
|
|
661
654
|
const outline = decodeGlyphOutline(face.glyf, placement.glyphId);
|
|
662
|
-
if (outline === void 0
|
|
655
|
+
if (outline === void 0) continue;
|
|
663
656
|
const trm = multiplyMatrices(translationMatrix(placement.advance * correction, 0), item.startMatrix);
|
|
664
|
-
|
|
665
|
-
if (subpaths.length === 0) continue;
|
|
666
|
-
rasteriser.draw({
|
|
667
|
-
kind: "path",
|
|
668
|
-
subpaths,
|
|
669
|
-
fill: {
|
|
670
|
-
color: item.color,
|
|
671
|
-
fillRule: "nonzero"
|
|
672
|
-
}
|
|
673
|
-
});
|
|
657
|
+
drawGlyphOutline(outline, multiplyMatrices(glyphScale, multiplyMatrices(trm, interpretToDeviceMatrix)), item.color, rasteriser);
|
|
674
658
|
}
|
|
675
659
|
}
|
|
660
|
+
function drawGlyphOutline(outline, glyphMatrix, color, rasteriser) {
|
|
661
|
+
const subpaths = glyphOutlineSubpaths(outline, glyphMatrix);
|
|
662
|
+
if (subpaths.length === 0) return;
|
|
663
|
+
rasteriser.draw({
|
|
664
|
+
kind: "path",
|
|
665
|
+
subpaths,
|
|
666
|
+
fill: {
|
|
667
|
+
color,
|
|
668
|
+
fillRule: "nonzero"
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
}
|
|
676
672
|
function glyphOutlineSubpaths(outline, matrix) {
|
|
677
673
|
const subpaths = [];
|
|
678
674
|
for (const contour of outline.contours) {
|
|
@@ -683,8 +679,9 @@ function glyphOutlineSubpaths(outline, matrix) {
|
|
|
683
679
|
y: point.y,
|
|
684
680
|
onCurve: point.onCurve
|
|
685
681
|
}));
|
|
686
|
-
const
|
|
687
|
-
|
|
682
|
+
const hasLeadingOnCurvePoint = firstOn >= 0;
|
|
683
|
+
const ordered = hasLeadingOnCurvePoint ? [...contourPoints.slice(firstOn), ...contourPoints.slice(0, firstOn)] : contourPoints;
|
|
684
|
+
let current = hasLeadingOnCurvePoint ? {
|
|
688
685
|
x: contourPoints[firstOn].x,
|
|
689
686
|
y: contourPoints[firstOn].y
|
|
690
687
|
} : {
|
|
@@ -733,27 +730,20 @@ function glyphOutlineSubpaths(outline, matrix) {
|
|
|
733
730
|
pendingOffCurve = point;
|
|
734
731
|
}
|
|
735
732
|
if (pendingOffCurve !== void 0) emitQuad(current, pendingOffCurve, start);
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
});
|
|
744
|
-
}
|
|
733
|
+
const startPx = applyMatrix(matrix, start);
|
|
734
|
+
subpaths.push({
|
|
735
|
+
startXPx: startPx.x,
|
|
736
|
+
startYPx: startPx.y,
|
|
737
|
+
segments,
|
|
738
|
+
closed: true
|
|
739
|
+
});
|
|
745
740
|
}
|
|
746
741
|
return subpaths;
|
|
747
742
|
}
|
|
748
|
-
const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
|
|
749
743
|
const HEADER_SEARCH_WINDOW = 1024;
|
|
750
744
|
function hasPdfHeader(bytes) {
|
|
751
745
|
const window = bytes.subarray(0, Math.min(HEADER_SEARCH_WINDOW, bytes.length));
|
|
752
|
-
|
|
753
|
-
for (let j = 0; j < PDF_HEADER_BYTES.length; j++) if (window[i + j] !== PDF_HEADER_BYTES[j]) continue outer;
|
|
754
|
-
return true;
|
|
755
|
-
}
|
|
756
|
-
return false;
|
|
746
|
+
return new TextDecoder("latin1").decode(window).includes("%PDF-");
|
|
757
747
|
}
|
|
758
748
|
function readDeclaredPageBox(page, key) {
|
|
759
749
|
const arr = asArray(dictGet(page, key));
|
|
@@ -812,4 +802,4 @@ function readPageContentBytes(page, resolver, sink) {
|
|
|
812
802
|
return /* @__PURE__ */ new Uint8Array(0);
|
|
813
803
|
}
|
|
814
804
|
//#endregion
|
|
815
|
-
export { renderPdfPage };
|
|
805
|
+
export { drawGlyphOutline, flattenCubic, glyphOutlineSubpaths, renderPdfPage };
|
package/dist/read.cjs
CHANGED
|
@@ -288,7 +288,7 @@ function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache,
|
|
|
288
288
|
});
|
|
289
289
|
cropBox = mediaBox;
|
|
290
290
|
}
|
|
291
|
-
const rotationResult = pageRotationTransform(normalizeRotation(require_objects.asNumber(require_objects.dictGet(page, "Rotate"))),
|
|
291
|
+
const rotationResult = pageRotationTransform(normalizeRotation(require_objects.asNumber(require_objects.dictGet(page, "Rotate"))), 0, 0);
|
|
292
292
|
const visibleRect = rotatedRectBounds(cropBox, rotationResult.matrix);
|
|
293
293
|
const widthPt = visibleRect.maxX - visibleRect.minX;
|
|
294
294
|
const heightPt = visibleRect.maxY - visibleRect.minY;
|
package/dist/read.js
CHANGED
|
@@ -287,7 +287,7 @@ function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache,
|
|
|
287
287
|
});
|
|
288
288
|
cropBox = mediaBox;
|
|
289
289
|
}
|
|
290
|
-
const rotationResult = pageRotationTransform(normalizeRotation(asNumber(dictGet(page, "Rotate"))),
|
|
290
|
+
const rotationResult = pageRotationTransform(normalizeRotation(asNumber(dictGet(page, "Rotate"))), 0, 0);
|
|
291
291
|
const visibleRect = rotatedRectBounds(cropBox, rotationResult.matrix);
|
|
292
292
|
const widthPt = visibleRect.maxX - visibleRect.minX;
|
|
293
293
|
const heightPt = visibleRect.maxY - visibleRect.minY;
|
package/dist/serialize.cjs
CHANGED
|
@@ -6,13 +6,9 @@ const NUMBER_DECIMAL_PLACES = 4;
|
|
|
6
6
|
const NUMBER_EPSILON = 10 ** -4;
|
|
7
7
|
function formatNumber(n) {
|
|
8
8
|
if (Math.abs(n) < NUMBER_EPSILON) return "0";
|
|
9
|
-
|
|
10
|
-
if (formatted.includes(".")) formatted = formatted.replace(/0+$/, "").replace(/\.$/, "");
|
|
11
|
-
return formatted === "-0" ? "0" : formatted;
|
|
9
|
+
return n.toFixed(NUMBER_DECIMAL_PLACES).replace(/0+$/, "").replace(/\.$/, "");
|
|
12
10
|
}
|
|
13
|
-
const NAME_ESCAPE_PATTERN = /[^!-~]|[#()<>[\]{}/%]/;
|
|
14
11
|
function escapeName(name) {
|
|
15
|
-
if (!NAME_ESCAPE_PATTERN.test(name)) return name;
|
|
16
12
|
let out = "";
|
|
17
13
|
for (const ch of name) {
|
|
18
14
|
const code = ch.codePointAt(0);
|
package/dist/serialize.js
CHANGED
|
@@ -5,13 +5,9 @@ const NUMBER_DECIMAL_PLACES = 4;
|
|
|
5
5
|
const NUMBER_EPSILON = 10 ** -4;
|
|
6
6
|
function formatNumber(n) {
|
|
7
7
|
if (Math.abs(n) < NUMBER_EPSILON) return "0";
|
|
8
|
-
|
|
9
|
-
if (formatted.includes(".")) formatted = formatted.replace(/0+$/, "").replace(/\.$/, "");
|
|
10
|
-
return formatted === "-0" ? "0" : formatted;
|
|
8
|
+
return n.toFixed(NUMBER_DECIMAL_PLACES).replace(/0+$/, "").replace(/\.$/, "");
|
|
11
9
|
}
|
|
12
|
-
const NAME_ESCAPE_PATTERN = /[^!-~]|[#()<>[\]{}/%]/;
|
|
13
10
|
function escapeName(name) {
|
|
14
|
-
if (!NAME_ESCAPE_PATTERN.test(name)) return name;
|
|
15
11
|
let out = "";
|
|
16
12
|
for (const ch of name) {
|
|
17
13
|
const code = ch.codePointAt(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-parser.js",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.11",
|
|
4
4
|
"description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
],
|
|
73
73
|
"license": "MIT",
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"byte-codec": "1.5.
|
|
75
|
+
"byte-codec": "1.5.8",
|
|
76
76
|
"document-schema.js": "7.11.3",
|
|
77
77
|
"fflate": "0.8.3",
|
|
78
78
|
"zod": "4.4.3"
|