pdf-codec 1.6.0 → 1.7.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 +67 -9
- package/dist/cff-bounds.cjs +432 -0
- package/dist/cff-bounds.d.cts +9 -0
- package/dist/cff-bounds.d.ts +9 -0
- package/dist/cff-bounds.js +431 -0
- package/dist/cff-probe.cjs +8 -106
- package/dist/cff-probe.js +9 -107
- package/dist/cff.cjs +158 -0
- package/dist/cff.d.cts +17 -0
- package/dist/cff.d.ts +17 -0
- package/dist/cff.js +150 -0
- package/dist/filters.cjs +45 -2
- package/dist/filters.d.cts +4 -3
- package/dist/filters.d.ts +4 -3
- package/dist/filters.js +45 -2
- package/dist/formula.d.cts +1 -1
- package/dist/formula.d.ts +1 -1
- package/dist/glyf.cjs +62 -6
- package/dist/glyf.d.cts +2 -0
- package/dist/glyf.d.ts +2 -0
- package/dist/glyf.js +62 -6
- package/dist/glyph-bounds-BV_Z40KS.d.cts +10 -0
- package/dist/glyph-bounds-BV_Z40KS.d.ts +10 -0
- package/dist/glyph-bounds.cjs +12 -0
- package/dist/glyph-bounds.d.cts +2 -0
- package/dist/glyph-bounds.d.ts +2 -0
- package/dist/glyph-bounds.js +11 -0
- package/dist/image/jbig2-arith.cjs +432 -0
- package/dist/image/jbig2-arith.d.cts +23 -0
- package/dist/image/jbig2-arith.d.ts +23 -0
- package/dist/image/jbig2-arith.js +426 -0
- package/dist/image/jbig2-bitmap.cjs +80 -0
- package/dist/image/jbig2-bitmap.d.cts +20 -0
- package/dist/image/jbig2-bitmap.d.ts +20 -0
- package/dist/image/jbig2-bitmap.js +72 -0
- package/dist/image/jbig2-errors.cjs +17 -0
- package/dist/image/jbig2-errors.d.cts +2 -0
- package/dist/image/jbig2-errors.d.ts +2 -0
- package/dist/image/jbig2-errors.js +15 -0
- package/dist/image/jbig2-generic.cjs +242 -0
- package/dist/image/jbig2-generic.d.cts +27 -0
- package/dist/image/jbig2-generic.d.ts +27 -0
- package/dist/image/jbig2-generic.js +237 -0
- package/dist/image/jbig2-text.cjs +175 -0
- package/dist/image/jbig2-text.d.cts +58 -0
- package/dist/image/jbig2-text.d.ts +58 -0
- package/dist/image/jbig2-text.js +170 -0
- package/dist/image/jbig2.cjs +333 -0
- package/dist/image/jbig2.d.cts +15 -0
- package/dist/image/jbig2.d.ts +15 -0
- package/dist/image/jbig2.js +332 -0
- package/dist/image/jp2-boxes.cjs +148 -0
- package/dist/image/jp2-boxes.d.cts +26 -0
- package/dist/image/jp2-boxes.d.ts +26 -0
- package/dist/image/jp2-boxes.js +146 -0
- package/dist/image/jpeg2000-codestream.cjs +309 -0
- package/dist/image/jpeg2000-codestream.d.cts +78 -0
- package/dist/image/jpeg2000-codestream.d.ts +78 -0
- package/dist/image/jpeg2000-codestream.js +308 -0
- package/dist/image/jpeg2000-dwt.cjs +148 -0
- package/dist/image/jpeg2000-dwt.d.cts +34 -0
- package/dist/image/jpeg2000-dwt.d.ts +34 -0
- package/dist/image/jpeg2000-dwt.js +145 -0
- package/dist/image/jpeg2000-errors.cjs +17 -0
- package/dist/image/jpeg2000-errors.d.cts +9 -0
- package/dist/image/jpeg2000-errors.d.ts +9 -0
- package/dist/image/jpeg2000-errors.js +15 -0
- package/dist/image/jpeg2000-t1.cjs +254 -0
- package/dist/image/jpeg2000-t1.d.cts +18 -0
- package/dist/image/jpeg2000-t1.d.ts +18 -0
- package/dist/image/jpeg2000-t1.js +253 -0
- package/dist/image/jpeg2000-t2.cjs +316 -0
- package/dist/image/jpeg2000-t2.d.cts +79 -0
- package/dist/image/jpeg2000-t2.d.ts +79 -0
- package/dist/image/jpeg2000-t2.js +311 -0
- package/dist/image/jpeg2000-tagtree.cjs +105 -0
- package/dist/image/jpeg2000-tagtree.d.cts +29 -0
- package/dist/image/jpeg2000-tagtree.d.ts +29 -0
- package/dist/image/jpeg2000-tagtree.js +103 -0
- package/dist/image/jpeg2000.cjs +322 -0
- package/dist/image/jpeg2000.d.cts +54 -0
- package/dist/image/jpeg2000.d.ts +54 -0
- package/dist/image/jpeg2000.js +320 -0
- package/dist/images-read.cjs +78 -1
- package/dist/images-read.js +78 -1
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +7 -1
- package/dist/jbig2-errors-Bj6MPxrx.d.cts +9 -0
- package/dist/jbig2-errors-Bj6MPxrx.d.ts +9 -0
- package/dist/math-font.cjs +43 -18
- package/dist/math-font.d.cts +8 -1
- package/dist/math-font.d.ts +8 -1
- package/dist/math-font.js +43 -18
- package/dist/math-stretch-Bwk_bxh1.d.ts +24 -0
- package/dist/math-stretch-DXWjs8gL.d.cts +24 -0
- package/dist/math-stretch.cjs +96 -0
- package/dist/math-stretch.d.cts +2 -0
- package/dist/math-stretch.d.ts +2 -0
- package/dist/math-stretch.js +94 -0
- package/dist/math-table-DhPrNoPa.d.ts +70 -0
- package/dist/math-table-gFNB8DmQ.d.cts +70 -0
- package/dist/math-table.cjs +69 -1
- package/dist/math-table.d.cts +2 -45
- package/dist/math-table.d.ts +2 -45
- package/dist/math-table.js +69 -1
- package/dist/{math-types-Ba8qAf1p.d.cts → math-types-YSQUTviw.d.cts} +2 -0
- package/dist/{math-types-Ba8qAf1p.d.ts → math-types-YSQUTviw.d.ts} +2 -0
- package/dist/math-types.d.cts +1 -1
- package/dist/math-types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sfnt = require("./sfnt.cjs");
|
|
3
|
+
const require_cff = require("./cff.cjs");
|
|
4
|
+
//#region src/cff-bounds.ts
|
|
5
|
+
const CFF_HEADER_MIN_SIZE = 4;
|
|
6
|
+
const CFF_MAJOR_VERSION = 1;
|
|
7
|
+
const CFF_HEADER_SIZE_OFFSET = 2;
|
|
8
|
+
const CS_OPERAND_INT16 = 28;
|
|
9
|
+
const CS_OPERAND_FIXED = 255;
|
|
10
|
+
const CS_OPERAND_SMALL_FIRST = 32;
|
|
11
|
+
const CS_OPERAND_SMALL_LAST = 246;
|
|
12
|
+
const CS_OPERAND_MEDIUM_FIRST = 247;
|
|
13
|
+
const CS_OPERAND_MEDIUM_LAST = 250;
|
|
14
|
+
const CS_OPERAND_NEGATIVE_MEDIUM_FIRST = 251;
|
|
15
|
+
const CS_OPERAND_NEGATIVE_MEDIUM_LAST = 254;
|
|
16
|
+
const CS_OPERAND_SMALL_BIAS = 139;
|
|
17
|
+
const CS_OPERAND_MEDIUM_BIAS = 108;
|
|
18
|
+
const CS_OPERAND_MEDIUM_FIRST_BYTE_BIAS = 247;
|
|
19
|
+
const CS_OPERAND_NEGATIVE_MEDIUM_FIRST_BYTE_BIAS = 251;
|
|
20
|
+
const BYTE_RADIX = 256;
|
|
21
|
+
const FIXED_POINT_SCALE = 65536;
|
|
22
|
+
const OP_HSTEM = 1;
|
|
23
|
+
const OP_VSTEM = 3;
|
|
24
|
+
const OP_VMOVETO = 4;
|
|
25
|
+
const OP_RLINETO = 5;
|
|
26
|
+
const OP_HLINETO = 6;
|
|
27
|
+
const OP_VLINETO = 7;
|
|
28
|
+
const OP_RRCURVETO = 8;
|
|
29
|
+
const OP_CALLSUBR = 10;
|
|
30
|
+
const OP_RETURN = 11;
|
|
31
|
+
const OP_ESCAPE = 12;
|
|
32
|
+
const OP_ENDCHAR = 14;
|
|
33
|
+
const OP_HSTEMHM = 18;
|
|
34
|
+
const OP_HINTMASK = 19;
|
|
35
|
+
const OP_CNTRMASK = 20;
|
|
36
|
+
const OP_RMOVETO = 21;
|
|
37
|
+
const OP_HMOVETO = 22;
|
|
38
|
+
const OP_VSTEMHM = 23;
|
|
39
|
+
const OP_RCURVELINE = 24;
|
|
40
|
+
const OP_RLINECURVE = 25;
|
|
41
|
+
const OP_VVCURVETO = 26;
|
|
42
|
+
const OP_HHCURVETO = 27;
|
|
43
|
+
const OP_CALLGSUBR = 29;
|
|
44
|
+
const OP_VHCURVETO = 30;
|
|
45
|
+
const OP_HVCURVETO = 31;
|
|
46
|
+
const CHARSTRING_OPERATOR_LIMIT = 31;
|
|
47
|
+
const ESC_HFLEX = 34;
|
|
48
|
+
const ESC_FLEX = 35;
|
|
49
|
+
const ESC_HFLEX1 = 36;
|
|
50
|
+
const ESC_FLEX1 = 37;
|
|
51
|
+
const SUBR_BIAS_SMALL_LIMIT = 1240;
|
|
52
|
+
const SUBR_BIAS_MEDIUM_LIMIT = 33900;
|
|
53
|
+
const SUBR_BIAS_SMALL = 107;
|
|
54
|
+
const SUBR_BIAS_MEDIUM = 1131;
|
|
55
|
+
const SUBR_BIAS_LARGE = 32768;
|
|
56
|
+
const HINT_MASK_BITS_PER_BYTE = 8;
|
|
57
|
+
const STEM_ARGS_PER_STEM = 2;
|
|
58
|
+
const MAX_OPERAND_STACK = 48;
|
|
59
|
+
const MAX_SUBR_DEPTH = 10;
|
|
60
|
+
const MAX_OPERATIONS_PER_GLYPH = 1e5;
|
|
61
|
+
const ENDCHAR_SEAC_ARG_COUNT = 4;
|
|
62
|
+
function subrBias(count) {
|
|
63
|
+
if (count < SUBR_BIAS_SMALL_LIMIT) return SUBR_BIAS_SMALL;
|
|
64
|
+
if (count < SUBR_BIAS_MEDIUM_LIMIT) return SUBR_BIAS_MEDIUM;
|
|
65
|
+
return SUBR_BIAS_LARGE;
|
|
66
|
+
}
|
|
67
|
+
function includePoint(box, x, y) {
|
|
68
|
+
box.minX = Math.min(box.minX, x);
|
|
69
|
+
box.minY = Math.min(box.minY, y);
|
|
70
|
+
box.maxX = Math.max(box.maxX, x);
|
|
71
|
+
box.maxY = Math.max(box.maxY, y);
|
|
72
|
+
box.drawn = true;
|
|
73
|
+
}
|
|
74
|
+
function cubicAt(p0, p1, p2, p3, t) {
|
|
75
|
+
const s = 1 - t;
|
|
76
|
+
return s * s * s * p0 + 3 * s * s * t * p1 + 3 * s * t * t * p2 + t * t * t * p3;
|
|
77
|
+
}
|
|
78
|
+
function includeCubicAxis(p0, p1, p2, p3, apply) {
|
|
79
|
+
apply(p0);
|
|
80
|
+
apply(p3);
|
|
81
|
+
const a = -p0 + 3 * p1 - 3 * p2 + p3;
|
|
82
|
+
const b = 2 * (p0 - 2 * p1 + p2);
|
|
83
|
+
const c = p1 - p0;
|
|
84
|
+
const roots = [];
|
|
85
|
+
if (a === 0) {
|
|
86
|
+
if (b !== 0) roots.push(-c / b);
|
|
87
|
+
} else {
|
|
88
|
+
const discriminant = b * b - 4 * a * c;
|
|
89
|
+
if (discriminant >= 0) {
|
|
90
|
+
const root = Math.sqrt(discriminant);
|
|
91
|
+
roots.push((-b + root) / (2 * a), (-b - root) / (2 * a));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (const t of roots) if (t > 0 && t < 1) apply(cubicAt(p0, p1, p2, p3, t));
|
|
95
|
+
}
|
|
96
|
+
function includeCubic(box, x0, y0, x1, y1, x2, y2, x3, y3) {
|
|
97
|
+
includeCubicAxis(x0, x1, x2, x3, (value) => {
|
|
98
|
+
box.minX = Math.min(box.minX, value);
|
|
99
|
+
box.maxX = Math.max(box.maxX, value);
|
|
100
|
+
});
|
|
101
|
+
includeCubicAxis(y0, y1, y2, y3, (value) => {
|
|
102
|
+
box.minY = Math.min(box.minY, value);
|
|
103
|
+
box.maxY = Math.max(box.maxY, value);
|
|
104
|
+
});
|
|
105
|
+
box.drawn = true;
|
|
106
|
+
}
|
|
107
|
+
function curveTo(state, dx1, dy1, dx2, dy2, dx3, dy3) {
|
|
108
|
+
const x0 = state.x;
|
|
109
|
+
const y0 = state.y;
|
|
110
|
+
const x1 = x0 + dx1;
|
|
111
|
+
const y1 = y0 + dy1;
|
|
112
|
+
const x2 = x1 + dx2;
|
|
113
|
+
const y2 = y1 + dy2;
|
|
114
|
+
const x3 = x2 + dx3;
|
|
115
|
+
const y3 = y2 + dy3;
|
|
116
|
+
includeCubic(state.box, x0, y0, x1, y1, x2, y2, x3, y3);
|
|
117
|
+
state.x = x3;
|
|
118
|
+
state.y = y3;
|
|
119
|
+
}
|
|
120
|
+
function lineTo(state, dx, dy) {
|
|
121
|
+
includePoint(state.box, state.x, state.y);
|
|
122
|
+
state.x += dx;
|
|
123
|
+
state.y += dy;
|
|
124
|
+
includePoint(state.box, state.x, state.y);
|
|
125
|
+
}
|
|
126
|
+
function moveTo(state, dx, dy) {
|
|
127
|
+
state.x += dx;
|
|
128
|
+
state.y += dy;
|
|
129
|
+
}
|
|
130
|
+
function takeWidth(state, evenArgs, expected) {
|
|
131
|
+
if (state.widthParsed) return;
|
|
132
|
+
state.widthParsed = true;
|
|
133
|
+
if (evenArgs ? state.stack.length % STEM_ARGS_PER_STEM !== 0 : state.stack.length > expected) state.stack.shift();
|
|
134
|
+
}
|
|
135
|
+
function readOperand(code, offset) {
|
|
136
|
+
const b0 = code[offset];
|
|
137
|
+
if (b0 === CS_OPERAND_INT16) {
|
|
138
|
+
if (!require_sfnt.hasBytes(code, offset + 1, 2)) return;
|
|
139
|
+
const raw = require_sfnt.u16(code, offset + 1);
|
|
140
|
+
return {
|
|
141
|
+
value: raw >= 32768 ? raw - 65536 : raw,
|
|
142
|
+
endOffset: offset + 3
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (b0 === CS_OPERAND_FIXED) {
|
|
146
|
+
if (!require_sfnt.hasBytes(code, offset + 1, 4)) return;
|
|
147
|
+
return {
|
|
148
|
+
value: (require_sfnt.u32(code, offset + 1) | 0) / FIXED_POINT_SCALE,
|
|
149
|
+
endOffset: offset + 5
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (b0 >= CS_OPERAND_SMALL_FIRST && b0 <= CS_OPERAND_SMALL_LAST) return {
|
|
153
|
+
value: b0 - CS_OPERAND_SMALL_BIAS,
|
|
154
|
+
endOffset: offset + 1
|
|
155
|
+
};
|
|
156
|
+
if (b0 >= CS_OPERAND_MEDIUM_FIRST && b0 <= CS_OPERAND_MEDIUM_LAST) {
|
|
157
|
+
if (!require_sfnt.hasBytes(code, offset + 1, 1)) return;
|
|
158
|
+
return {
|
|
159
|
+
value: (b0 - CS_OPERAND_MEDIUM_FIRST_BYTE_BIAS) * BYTE_RADIX + require_sfnt.u8(code, offset + 1) + CS_OPERAND_MEDIUM_BIAS,
|
|
160
|
+
endOffset: offset + 2
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (b0 >= CS_OPERAND_NEGATIVE_MEDIUM_FIRST && b0 <= CS_OPERAND_NEGATIVE_MEDIUM_LAST) {
|
|
164
|
+
if (!require_sfnt.hasBytes(code, offset + 1, 1)) return;
|
|
165
|
+
return {
|
|
166
|
+
value: -(b0 - CS_OPERAND_NEGATIVE_MEDIUM_FIRST_BYTE_BIAS) * BYTE_RADIX - require_sfnt.u8(code, offset + 1) - CS_OPERAND_MEDIUM_BIAS,
|
|
167
|
+
endOffset: offset + 2
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function execute(code, state, context, depth) {
|
|
172
|
+
if (depth > MAX_SUBR_DEPTH) return false;
|
|
173
|
+
const stack = state.stack;
|
|
174
|
+
let i = 0;
|
|
175
|
+
while (i < code.length) {
|
|
176
|
+
state.operations += 1;
|
|
177
|
+
if (state.operations > MAX_OPERATIONS_PER_GLYPH) return false;
|
|
178
|
+
const b0 = code[i];
|
|
179
|
+
const operand = readOperand(code, i);
|
|
180
|
+
if (operand !== void 0) {
|
|
181
|
+
if (stack.length >= MAX_OPERAND_STACK) return false;
|
|
182
|
+
stack.push(operand.value);
|
|
183
|
+
i = operand.endOffset;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (b0 > CHARSTRING_OPERATOR_LIMIT) return false;
|
|
187
|
+
i += 1;
|
|
188
|
+
switch (b0) {
|
|
189
|
+
case OP_HSTEM:
|
|
190
|
+
case OP_VSTEM:
|
|
191
|
+
case OP_HSTEMHM:
|
|
192
|
+
case OP_VSTEMHM:
|
|
193
|
+
takeWidth(state, true, 0);
|
|
194
|
+
state.stems += Math.floor(stack.length / STEM_ARGS_PER_STEM);
|
|
195
|
+
stack.length = 0;
|
|
196
|
+
break;
|
|
197
|
+
case OP_HINTMASK:
|
|
198
|
+
case OP_CNTRMASK: {
|
|
199
|
+
takeWidth(state, true, 0);
|
|
200
|
+
state.stems += Math.floor(stack.length / STEM_ARGS_PER_STEM);
|
|
201
|
+
stack.length = 0;
|
|
202
|
+
const maskBytes = Math.ceil(state.stems / HINT_MASK_BITS_PER_BYTE);
|
|
203
|
+
if (!require_sfnt.hasBytes(code, i, maskBytes)) return false;
|
|
204
|
+
i += maskBytes;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
case OP_RMOVETO:
|
|
208
|
+
takeWidth(state, false, 2);
|
|
209
|
+
if (stack.length < 2) return false;
|
|
210
|
+
moveTo(state, stack[stack.length - 2], stack[stack.length - 1]);
|
|
211
|
+
stack.length = 0;
|
|
212
|
+
break;
|
|
213
|
+
case OP_HMOVETO:
|
|
214
|
+
case OP_VMOVETO: {
|
|
215
|
+
takeWidth(state, false, 1);
|
|
216
|
+
if (stack.length < 1) return false;
|
|
217
|
+
const delta = stack[stack.length - 1];
|
|
218
|
+
moveTo(state, b0 === OP_HMOVETO ? delta : 0, b0 === OP_HMOVETO ? 0 : delta);
|
|
219
|
+
stack.length = 0;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
case OP_RLINETO:
|
|
223
|
+
for (let k = 0; k + 1 < stack.length; k += 2) lineTo(state, stack[k], stack[k + 1]);
|
|
224
|
+
stack.length = 0;
|
|
225
|
+
break;
|
|
226
|
+
case OP_HLINETO:
|
|
227
|
+
case OP_VLINETO: {
|
|
228
|
+
let horizontal = b0 === OP_HLINETO;
|
|
229
|
+
for (const delta of stack) {
|
|
230
|
+
lineTo(state, horizontal ? delta : 0, horizontal ? 0 : delta);
|
|
231
|
+
horizontal = !horizontal;
|
|
232
|
+
}
|
|
233
|
+
stack.length = 0;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
case OP_RRCURVETO:
|
|
237
|
+
for (let k = 0; k + 5 < stack.length; k += 6) curveTo(state, stack[k], stack[k + 1], stack[k + 2], stack[k + 3], stack[k + 4], stack[k + 5]);
|
|
238
|
+
stack.length = 0;
|
|
239
|
+
break;
|
|
240
|
+
case OP_RCURVELINE: {
|
|
241
|
+
let k = 0;
|
|
242
|
+
for (; k + 5 < stack.length - 2; k += 6) curveTo(state, stack[k], stack[k + 1], stack[k + 2], stack[k + 3], stack[k + 4], stack[k + 5]);
|
|
243
|
+
if (k + 1 < stack.length) lineTo(state, stack[k], stack[k + 1]);
|
|
244
|
+
stack.length = 0;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
case OP_RLINECURVE: {
|
|
248
|
+
let k = 0;
|
|
249
|
+
for (; k + 1 < stack.length - 6; k += 2) lineTo(state, stack[k], stack[k + 1]);
|
|
250
|
+
if (k + 5 < stack.length) curveTo(state, stack[k], stack[k + 1], stack[k + 2], stack[k + 3], stack[k + 4], stack[k + 5]);
|
|
251
|
+
stack.length = 0;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case OP_VVCURVETO:
|
|
255
|
+
case OP_HHCURVETO: {
|
|
256
|
+
let k = 0;
|
|
257
|
+
let firstCross = 0;
|
|
258
|
+
if (stack.length % 4 === 1) {
|
|
259
|
+
firstCross = stack[0];
|
|
260
|
+
k = 1;
|
|
261
|
+
}
|
|
262
|
+
for (; k + 3 < stack.length; k += 4) {
|
|
263
|
+
const cross = k <= 1 ? firstCross : 0;
|
|
264
|
+
if (b0 === OP_VVCURVETO) curveTo(state, cross, stack[k], stack[k + 1], stack[k + 2], 0, stack[k + 3]);
|
|
265
|
+
else curveTo(state, stack[k], cross, stack[k + 1], stack[k + 2], stack[k + 3], 0);
|
|
266
|
+
}
|
|
267
|
+
stack.length = 0;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case OP_VHCURVETO:
|
|
271
|
+
case OP_HVCURVETO: {
|
|
272
|
+
let horizontal = b0 === OP_HVCURVETO;
|
|
273
|
+
let k = 0;
|
|
274
|
+
while (stack.length - k >= 4) {
|
|
275
|
+
const extra = stack.length - k === 5 ? stack[k + 4] : 0;
|
|
276
|
+
if (horizontal) curveTo(state, stack[k], 0, stack[k + 1], stack[k + 2], extra, stack[k + 3]);
|
|
277
|
+
else curveTo(state, 0, stack[k], stack[k + 1], stack[k + 2], stack[k + 3], extra);
|
|
278
|
+
k += 4;
|
|
279
|
+
horizontal = !horizontal;
|
|
280
|
+
}
|
|
281
|
+
stack.length = 0;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case OP_CALLSUBR:
|
|
285
|
+
case OP_CALLGSUBR: {
|
|
286
|
+
const index = stack.pop();
|
|
287
|
+
if (index === void 0) return false;
|
|
288
|
+
const subrs = b0 === OP_CALLSUBR ? context.localSubrs : context.globalSubrs;
|
|
289
|
+
const bias = b0 === OP_CALLSUBR ? context.localBias : context.globalBias;
|
|
290
|
+
const code2 = subrs?.entry(index + bias);
|
|
291
|
+
if (code2 === void 0) return false;
|
|
292
|
+
if (!execute(code2, state, context, depth + 1)) return false;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
case OP_RETURN: return true;
|
|
296
|
+
case OP_ENDCHAR:
|
|
297
|
+
if (!state.widthParsed) {
|
|
298
|
+
state.widthParsed = true;
|
|
299
|
+
if (stack.length === 1 || stack.length === 5) stack.shift();
|
|
300
|
+
}
|
|
301
|
+
return stack.length < ENDCHAR_SEAC_ARG_COUNT;
|
|
302
|
+
case OP_ESCAPE: {
|
|
303
|
+
if (i >= code.length) return false;
|
|
304
|
+
const b1 = code[i];
|
|
305
|
+
i += 1;
|
|
306
|
+
if (!executeEscaped(b1, state)) return false;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
default: return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
function executeEscaped(operator, state) {
|
|
315
|
+
const stack = state.stack;
|
|
316
|
+
const startY = state.y;
|
|
317
|
+
if (operator === ESC_FLEX) {
|
|
318
|
+
if (stack.length < 13) return false;
|
|
319
|
+
curveTo(state, stack[0], stack[1], stack[2], stack[3], stack[4], stack[5]);
|
|
320
|
+
curveTo(state, stack[6], stack[7], stack[8], stack[9], stack[10], stack[11]);
|
|
321
|
+
stack.length = 0;
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
if (operator === ESC_HFLEX) {
|
|
325
|
+
if (stack.length < 7) return false;
|
|
326
|
+
curveTo(state, stack[0], 0, stack[1], stack[2], stack[3], 0);
|
|
327
|
+
curveTo(state, stack[4], 0, stack[5], -stack[2], stack[6], 0);
|
|
328
|
+
stack.length = 0;
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
if (operator === ESC_HFLEX1) {
|
|
332
|
+
if (stack.length < 9) return false;
|
|
333
|
+
curveTo(state, stack[0], stack[1], stack[2], stack[3], stack[4], 0);
|
|
334
|
+
const dy5 = stack[7];
|
|
335
|
+
curveTo(state, stack[5], 0, stack[6], dy5, stack[8], startY - (state.y + dy5));
|
|
336
|
+
stack.length = 0;
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
if (operator === ESC_FLEX1) {
|
|
340
|
+
if (stack.length < 11) return false;
|
|
341
|
+
const startX = state.x;
|
|
342
|
+
let dx = 0;
|
|
343
|
+
let dy = 0;
|
|
344
|
+
for (let k = 0; k < 10; k += 2) {
|
|
345
|
+
dx += stack[k];
|
|
346
|
+
dy += stack[k + 1];
|
|
347
|
+
}
|
|
348
|
+
curveTo(state, stack[0], stack[1], stack[2], stack[3], stack[4], stack[5]);
|
|
349
|
+
const controlX = state.x + stack[6] + stack[8];
|
|
350
|
+
const controlY = state.y + stack[7] + stack[9];
|
|
351
|
+
if (Math.abs(dx) > Math.abs(dy)) curveTo(state, stack[6], stack[7], stack[8], stack[9], stack[10], startY - controlY);
|
|
352
|
+
else curveTo(state, stack[6], stack[7], stack[8], stack[9], startX - controlX, stack[10]);
|
|
353
|
+
stack.length = 0;
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
function readPrivateSubrs(bytes, privateOperands) {
|
|
359
|
+
if (privateOperands === void 0 || privateOperands.length < 2) return;
|
|
360
|
+
const size = privateOperands[0];
|
|
361
|
+
const offset = privateOperands[1];
|
|
362
|
+
if (!Number.isInteger(size) || !Number.isInteger(offset) || !require_sfnt.hasBytes(bytes, offset, size)) return;
|
|
363
|
+
const subrsOffset = require_cff.parseCffDict(bytes.subarray(offset, offset + size))?.get(19)?.[0];
|
|
364
|
+
if (subrsOffset === void 0 || !Number.isInteger(subrsOffset)) return;
|
|
365
|
+
return require_cff.readCffIndex(bytes, offset + subrsOffset);
|
|
366
|
+
}
|
|
367
|
+
function parseCffGlyphBounds(bytes) {
|
|
368
|
+
if (!require_sfnt.hasBytes(bytes, 0, CFF_HEADER_MIN_SIZE) || require_sfnt.u8(bytes, 0) !== CFF_MAJOR_VERSION) return;
|
|
369
|
+
const headerSize = require_sfnt.u8(bytes, CFF_HEADER_SIZE_OFFSET);
|
|
370
|
+
if (headerSize < CFF_HEADER_MIN_SIZE) return;
|
|
371
|
+
const nameIndex = require_cff.readCffIndex(bytes, headerSize);
|
|
372
|
+
if (nameIndex === void 0) return;
|
|
373
|
+
const topDictIndex = require_cff.readCffIndex(bytes, nameIndex.endOffset);
|
|
374
|
+
const topDictBytes = topDictIndex?.entry(0);
|
|
375
|
+
if (topDictIndex === void 0 || topDictBytes === void 0) return;
|
|
376
|
+
const topDict = require_cff.parseCffDict(topDictBytes);
|
|
377
|
+
if (topDict === void 0 || topDict.has(1230)) return;
|
|
378
|
+
const stringIndex = require_cff.readCffIndex(bytes, topDictIndex.endOffset);
|
|
379
|
+
if (stringIndex === void 0) return;
|
|
380
|
+
const globalSubrs = require_cff.readCffIndex(bytes, stringIndex.endOffset);
|
|
381
|
+
if (globalSubrs === void 0) return;
|
|
382
|
+
const charStringsOffset = topDict.get(17)?.[0];
|
|
383
|
+
if (charStringsOffset === void 0 || !Number.isInteger(charStringsOffset)) return;
|
|
384
|
+
const charStrings = require_cff.readCffIndex(bytes, charStringsOffset);
|
|
385
|
+
if (charStrings === void 0) return;
|
|
386
|
+
const localSubrs = readPrivateSubrs(bytes, topDict.get(18));
|
|
387
|
+
const context = {
|
|
388
|
+
charStrings,
|
|
389
|
+
globalSubrs,
|
|
390
|
+
localSubrs,
|
|
391
|
+
globalBias: subrBias(globalSubrs.count),
|
|
392
|
+
localBias: localSubrs === void 0 ? 0 : subrBias(localSubrs.count)
|
|
393
|
+
};
|
|
394
|
+
const memo = /* @__PURE__ */ new Map();
|
|
395
|
+
return {
|
|
396
|
+
numGlyphs: charStrings.count,
|
|
397
|
+
bounds(glyphId) {
|
|
398
|
+
if (memo.has(glyphId)) return memo.get(glyphId);
|
|
399
|
+
const computed = computeBounds(glyphId, context);
|
|
400
|
+
memo.set(glyphId, computed);
|
|
401
|
+
return computed;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function computeBounds(glyphId, context) {
|
|
406
|
+
const code = context.charStrings.entry(glyphId);
|
|
407
|
+
if (code === void 0) return;
|
|
408
|
+
const state = {
|
|
409
|
+
x: 0,
|
|
410
|
+
y: 0,
|
|
411
|
+
stack: [],
|
|
412
|
+
stems: 0,
|
|
413
|
+
widthParsed: false,
|
|
414
|
+
operations: 0,
|
|
415
|
+
box: {
|
|
416
|
+
minX: Infinity,
|
|
417
|
+
minY: Infinity,
|
|
418
|
+
maxX: -Infinity,
|
|
419
|
+
maxY: -Infinity,
|
|
420
|
+
drawn: false
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
if (!execute(code, state, context, 0) || !state.box.drawn) return;
|
|
424
|
+
return {
|
|
425
|
+
xMin: state.box.minX,
|
|
426
|
+
yMin: state.box.minY,
|
|
427
|
+
xMax: state.box.maxX,
|
|
428
|
+
yMax: state.box.maxY
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
//#endregion
|
|
432
|
+
exports.parseCffGlyphBounds = parseCffGlyphBounds;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
|
|
2
|
+
//#region src/cff-bounds.d.ts
|
|
3
|
+
interface CffGlyphBounds {
|
|
4
|
+
readonly numGlyphs: number;
|
|
5
|
+
bounds(glyphId: number): GlyphInkBounds | undefined;
|
|
6
|
+
}
|
|
7
|
+
declare function parseCffGlyphBounds(bytes: Uint8Array<ArrayBuffer>): CffGlyphBounds | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { CffGlyphBounds, parseCffGlyphBounds };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
|
|
2
|
+
//#region src/cff-bounds.d.ts
|
|
3
|
+
interface CffGlyphBounds {
|
|
4
|
+
readonly numGlyphs: number;
|
|
5
|
+
bounds(glyphId: number): GlyphInkBounds | undefined;
|
|
6
|
+
}
|
|
7
|
+
declare function parseCffGlyphBounds(bytes: Uint8Array<ArrayBuffer>): CffGlyphBounds | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { CffGlyphBounds, parseCffGlyphBounds };
|