@poe-platform/safe-bash 0.1.773 → 0.1.774
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/image-ast/index.browser.js +742 -150
- package/dist/image-ast/index.js +742 -150
- package/dist/pdf-ast/index.js +742 -150
- package/dist/pdf-ast/vendor/pdfjs-fonts.d.mts +12 -0
- package/dist/pdf-ast/vendor/pdfjs-fonts.mjs +702 -0
- package/dist/safe-bash/command-chunks/{chunk-5VXZSNM2.js → chunk-4ZHDCMQX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-G3NVK25P.js → chunk-HH5QPKIN.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-B2MM5DIT.js → chunk-PM63UJE6.js} +742 -150
- package/dist/safe-bash/core.browser.js +63 -7
- package/dist/safe-bash/shell/runtime.js +17 -9
- package/dist/safe-bash/shell/sync-posix-regex.d.ts +3 -0
- package/dist/safe-bash/shell/sync-posix-regex.js +48 -0
- package/dist/safe-bash-command-ffmpeg/index.js +7250 -7046
- package/dist/safe-bash-command-gpg/index.js +28 -7
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-openssl/index.js +24 -6
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +742 -150
- package/dist/safe-bash-command-pdfinfo/index.js +742 -150
- package/dist/safe-bash-command-pdftk/index.js +742 -150
- package/dist/safe-bash-command-pdftoppm/index.js +742 -150
- package/dist/safe-bash-command-pdftotext/index.js +742 -150
- package/dist/safe-bash-command-qpdf/index.js +742 -150
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/index.js +742 -150
- package/dist/safe-bash-command-ssh/index.js +124 -23
- package/dist/safe-bash-command-wkhtmltopdf/index.js +748 -150
- package/package.json +2 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +22 -0
|
@@ -3588,6 +3588,11 @@ var FONT_IDENTITY_MATRIX = [1e-3, 0, 0, 1e-3, 0, 0];
|
|
|
3588
3588
|
var LINE_FACTOR = 1.35;
|
|
3589
3589
|
var LINE_DESCENT_FACTOR = 0.35;
|
|
3590
3590
|
var BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
|
|
3591
|
+
var MeshFigureType = {
|
|
3592
|
+
TRIANGLES: 1,
|
|
3593
|
+
LATTICE: 2,
|
|
3594
|
+
PATCH: 3
|
|
3595
|
+
};
|
|
3591
3596
|
var VerbosityLevel = {
|
|
3592
3597
|
ERRORS: 0,
|
|
3593
3598
|
WARNINGS: 1,
|
|
@@ -25120,6 +25125,700 @@ function buildPostScriptJsFunction(source, domain, range, forceInterpreter = fal
|
|
|
25120
25125
|
}
|
|
25121
25126
|
return PSStackBasedInterpreter.build(program, domain, range);
|
|
25122
25127
|
}
|
|
25128
|
+
var ShadingType = {
|
|
25129
|
+
FUNCTION_BASED: 1,
|
|
25130
|
+
AXIAL: 2,
|
|
25131
|
+
RADIAL: 3,
|
|
25132
|
+
FREE_FORM_MESH: 4,
|
|
25133
|
+
LATTICE_FORM_MESH: 5,
|
|
25134
|
+
COONS_PATCH_MESH: 6,
|
|
25135
|
+
TENSOR_PATCH_MESH: 7
|
|
25136
|
+
};
|
|
25137
|
+
var BaseShading = class _BaseShading {
|
|
25138
|
+
// A small number to offset the first/last color stops so we can insert ones
|
|
25139
|
+
// to support extend. Number.MIN_VALUE is too small and breaks the extend.
|
|
25140
|
+
static SMALL_NUMBER = 1e-6;
|
|
25141
|
+
constructor() {
|
|
25142
|
+
if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === _BaseShading) {
|
|
25143
|
+
unreachable2("Cannot initialize BaseShading.");
|
|
25144
|
+
}
|
|
25145
|
+
}
|
|
25146
|
+
getIR() {
|
|
25147
|
+
unreachable2("Abstract method `getIR` called.");
|
|
25148
|
+
}
|
|
25149
|
+
};
|
|
25150
|
+
function meshUpdateBounds(self) {
|
|
25151
|
+
let minX = self.coords[0][0], minY = self.coords[0][1], maxX = minX, maxY = minY;
|
|
25152
|
+
for (let i = 1, ii = self.coords.length; i < ii; i++) {
|
|
25153
|
+
const x = self.coords[i][0], y = self.coords[i][1];
|
|
25154
|
+
minX = minX > x ? x : minX;
|
|
25155
|
+
minY = minY > y ? y : minY;
|
|
25156
|
+
maxX = maxX < x ? x : maxX;
|
|
25157
|
+
maxY = maxY < y ? y : maxY;
|
|
25158
|
+
}
|
|
25159
|
+
self.bounds = [minX, minY, maxX, maxY];
|
|
25160
|
+
}
|
|
25161
|
+
function meshPackData(self) {
|
|
25162
|
+
let i, j, ii;
|
|
25163
|
+
const coords = self.coords;
|
|
25164
|
+
const coordsPacked = new Float32Array(coords.length * 2);
|
|
25165
|
+
for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
|
|
25166
|
+
const xy = coords[i];
|
|
25167
|
+
coordsPacked[j++] = xy[0];
|
|
25168
|
+
coordsPacked[j++] = xy[1];
|
|
25169
|
+
}
|
|
25170
|
+
self.coords = coordsPacked;
|
|
25171
|
+
const colors = self.colors;
|
|
25172
|
+
const colorsPacked = new Uint8Array(colors.length * 4);
|
|
25173
|
+
for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
|
|
25174
|
+
const c = colors[i];
|
|
25175
|
+
colorsPacked[j++] = c[0];
|
|
25176
|
+
colorsPacked[j++] = c[1];
|
|
25177
|
+
colorsPacked[j++] = c[2];
|
|
25178
|
+
j++;
|
|
25179
|
+
}
|
|
25180
|
+
self.colors = colorsPacked;
|
|
25181
|
+
for (const figure of self.figures) {
|
|
25182
|
+
figure.coords = new Uint32Array(figure.coords);
|
|
25183
|
+
figure.colors = new Uint32Array(figure.colors);
|
|
25184
|
+
}
|
|
25185
|
+
}
|
|
25186
|
+
function buildMeshVertexData(coords, colors, figures) {
|
|
25187
|
+
let vertexCount = 0;
|
|
25188
|
+
for (const figure of figures) {
|
|
25189
|
+
if (figure.type === MeshFigureType.TRIANGLES) {
|
|
25190
|
+
vertexCount += figure.coords.length;
|
|
25191
|
+
} else if (figure.type === MeshFigureType.LATTICE) {
|
|
25192
|
+
const vpr = figure.verticesPerRow;
|
|
25193
|
+
vertexCount += (Math.floor(figure.coords.length / vpr) - 1) * (vpr - 1) * 6;
|
|
25194
|
+
}
|
|
25195
|
+
}
|
|
25196
|
+
const posData = new Float32Array(vertexCount * 2);
|
|
25197
|
+
const colData = new Uint8Array(vertexCount * 4);
|
|
25198
|
+
let pOff = 0, cOff = 0;
|
|
25199
|
+
const addVertex = (pi, ci) => {
|
|
25200
|
+
posData[pOff++] = coords[pi * 2];
|
|
25201
|
+
posData[pOff++] = coords[pi * 2 + 1];
|
|
25202
|
+
colData[cOff++] = colors[ci * 4];
|
|
25203
|
+
colData[cOff++] = colors[ci * 4 + 1];
|
|
25204
|
+
colData[cOff++] = colors[ci * 4 + 2];
|
|
25205
|
+
cOff++;
|
|
25206
|
+
};
|
|
25207
|
+
for (const figure of figures) {
|
|
25208
|
+
const ps = figure.coords;
|
|
25209
|
+
const cs = figure.colors;
|
|
25210
|
+
if (figure.type === MeshFigureType.TRIANGLES) {
|
|
25211
|
+
for (let i = 0, ii = ps.length; i < ii; i++) {
|
|
25212
|
+
addVertex(ps[i], cs[i]);
|
|
25213
|
+
}
|
|
25214
|
+
} else if (figure.type === MeshFigureType.LATTICE) {
|
|
25215
|
+
const vpr = figure.verticesPerRow;
|
|
25216
|
+
const rows = Math.floor(ps.length / vpr) - 1;
|
|
25217
|
+
const cols = vpr - 1;
|
|
25218
|
+
for (let i = 0; i < rows; i++) {
|
|
25219
|
+
let q = i * vpr;
|
|
25220
|
+
for (let j = 0; j < cols; j++, q++) {
|
|
25221
|
+
addVertex(ps[q], cs[q]);
|
|
25222
|
+
addVertex(ps[q + 1], cs[q + 1]);
|
|
25223
|
+
addVertex(ps[q + vpr], cs[q + vpr]);
|
|
25224
|
+
addVertex(ps[q + vpr + 1], cs[q + vpr + 1]);
|
|
25225
|
+
addVertex(ps[q + 1], cs[q + 1]);
|
|
25226
|
+
addVertex(ps[q + vpr], cs[q + vpr]);
|
|
25227
|
+
}
|
|
25228
|
+
}
|
|
25229
|
+
}
|
|
25230
|
+
}
|
|
25231
|
+
return { posData, colData, vertexCount };
|
|
25232
|
+
}
|
|
25233
|
+
var MeshStreamReader = class {
|
|
25234
|
+
constructor(stream, context) {
|
|
25235
|
+
this.stream = stream;
|
|
25236
|
+
this.context = context;
|
|
25237
|
+
this.buffer = 0;
|
|
25238
|
+
this.bufferLength = 0;
|
|
25239
|
+
const numComps = context.numComps;
|
|
25240
|
+
this.tmpCompsBuf = new Float32Array(numComps);
|
|
25241
|
+
const csNumComps = context.colorSpace.numComps;
|
|
25242
|
+
this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
|
|
25243
|
+
}
|
|
25244
|
+
get hasData() {
|
|
25245
|
+
if (this.stream.end) {
|
|
25246
|
+
return this.stream.pos < this.stream.end;
|
|
25247
|
+
}
|
|
25248
|
+
if (this.bufferLength > 0) {
|
|
25249
|
+
return true;
|
|
25250
|
+
}
|
|
25251
|
+
const nextByte = this.stream.getByte();
|
|
25252
|
+
if (nextByte < 0) {
|
|
25253
|
+
return false;
|
|
25254
|
+
}
|
|
25255
|
+
this.buffer = nextByte;
|
|
25256
|
+
this.bufferLength = 8;
|
|
25257
|
+
return true;
|
|
25258
|
+
}
|
|
25259
|
+
readBits(n) {
|
|
25260
|
+
const { stream } = this;
|
|
25261
|
+
let { buffer, bufferLength } = this;
|
|
25262
|
+
if (n === 32) {
|
|
25263
|
+
if (bufferLength === 0) {
|
|
25264
|
+
return stream.getInt32() >>> 0;
|
|
25265
|
+
}
|
|
25266
|
+
buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte();
|
|
25267
|
+
const nextByte = stream.getByte();
|
|
25268
|
+
this.buffer = nextByte & (1 << bufferLength) - 1;
|
|
25269
|
+
return (buffer << 8 - bufferLength | (nextByte & 255) >> bufferLength) >>> 0;
|
|
25270
|
+
}
|
|
25271
|
+
if (n === 8 && bufferLength === 0) {
|
|
25272
|
+
return stream.getByte();
|
|
25273
|
+
}
|
|
25274
|
+
while (bufferLength < n) {
|
|
25275
|
+
buffer = buffer << 8 | stream.getByte();
|
|
25276
|
+
bufferLength += 8;
|
|
25277
|
+
}
|
|
25278
|
+
bufferLength -= n;
|
|
25279
|
+
this.bufferLength = bufferLength;
|
|
25280
|
+
this.buffer = buffer & (1 << bufferLength) - 1;
|
|
25281
|
+
return buffer >> bufferLength;
|
|
25282
|
+
}
|
|
25283
|
+
align() {
|
|
25284
|
+
this.buffer = 0;
|
|
25285
|
+
this.bufferLength = 0;
|
|
25286
|
+
}
|
|
25287
|
+
readFlag() {
|
|
25288
|
+
return this.readBits(this.context.bitsPerFlag);
|
|
25289
|
+
}
|
|
25290
|
+
readCoordinate() {
|
|
25291
|
+
const { bitsPerCoordinate, decode } = this.context;
|
|
25292
|
+
const xi = this.readBits(bitsPerCoordinate);
|
|
25293
|
+
const yi = this.readBits(bitsPerCoordinate);
|
|
25294
|
+
const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 23283064365386963e-26;
|
|
25295
|
+
return [
|
|
25296
|
+
xi * scale * (decode[1] - decode[0]) + decode[0],
|
|
25297
|
+
yi * scale * (decode[3] - decode[2]) + decode[2]
|
|
25298
|
+
];
|
|
25299
|
+
}
|
|
25300
|
+
readComponents() {
|
|
25301
|
+
const { bitsPerComponent, colorFn, colorSpace, decode, numComps } = this.context;
|
|
25302
|
+
const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 23283064365386963e-26;
|
|
25303
|
+
const components = this.tmpCompsBuf;
|
|
25304
|
+
for (let i = 0, j = 4; i < numComps; i++, j += 2) {
|
|
25305
|
+
const ci = this.readBits(bitsPerComponent);
|
|
25306
|
+
components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
|
|
25307
|
+
}
|
|
25308
|
+
const color = this.tmpCsCompsBuf;
|
|
25309
|
+
colorFn?.(components, 0, color, 0);
|
|
25310
|
+
return colorSpace.getRgb(color, 0);
|
|
25311
|
+
}
|
|
25312
|
+
};
|
|
25313
|
+
var bCache = null;
|
|
25314
|
+
function getB(count) {
|
|
25315
|
+
if (bCache?.has(count)) return bCache.get(count);
|
|
25316
|
+
const values = Array.from({ length: count + 1 }, (_, i) => {
|
|
25317
|
+
const t = i / count, t_ = 1 - t;
|
|
25318
|
+
return new Float32Array([
|
|
25319
|
+
t_ ** 3,
|
|
25320
|
+
3 * t * t_ ** 2,
|
|
25321
|
+
3 * t ** 2 * t_,
|
|
25322
|
+
t ** 3
|
|
25323
|
+
]);
|
|
25324
|
+
});
|
|
25325
|
+
(bCache ??= /* @__PURE__ */ new Map()).set(count, values);
|
|
25326
|
+
return values;
|
|
25327
|
+
}
|
|
25328
|
+
var MeshShading = class _MeshShading extends BaseShading {
|
|
25329
|
+
static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
|
|
25330
|
+
static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
|
|
25331
|
+
// Count of triangles per entire mesh bounds.
|
|
25332
|
+
static TRIANGLE_DENSITY = 20;
|
|
25333
|
+
constructor(shadingType, stream, context, rowVertices) {
|
|
25334
|
+
super();
|
|
25335
|
+
this.shadingType = shadingType;
|
|
25336
|
+
this.bbox = this.background = null;
|
|
25337
|
+
this.coords = [];
|
|
25338
|
+
this.colors = [];
|
|
25339
|
+
this.figures = [];
|
|
25340
|
+
const reader = new MeshStreamReader(stream, context);
|
|
25341
|
+
let patchMesh = false;
|
|
25342
|
+
switch (this.shadingType) {
|
|
25343
|
+
case ShadingType.FREE_FORM_MESH:
|
|
25344
|
+
this._decodeType4Shading(reader);
|
|
25345
|
+
break;
|
|
25346
|
+
case ShadingType.LATTICE_FORM_MESH:
|
|
25347
|
+
const verticesPerRow = rowVertices | 0;
|
|
25348
|
+
if (verticesPerRow < 2) {
|
|
25349
|
+
throw new FormatError("Invalid VerticesPerRow");
|
|
25350
|
+
}
|
|
25351
|
+
this._decodeType5Shading(reader, verticesPerRow);
|
|
25352
|
+
break;
|
|
25353
|
+
case ShadingType.COONS_PATCH_MESH:
|
|
25354
|
+
this._decodeType6Shading(reader);
|
|
25355
|
+
patchMesh = true;
|
|
25356
|
+
break;
|
|
25357
|
+
case ShadingType.TENSOR_PATCH_MESH:
|
|
25358
|
+
this._decodeType7Shading(reader);
|
|
25359
|
+
patchMesh = true;
|
|
25360
|
+
break;
|
|
25361
|
+
default:
|
|
25362
|
+
unreachable2("Unsupported mesh type.");
|
|
25363
|
+
break;
|
|
25364
|
+
}
|
|
25365
|
+
if (patchMesh) {
|
|
25366
|
+
this._updateBounds();
|
|
25367
|
+
for (let i = 0, ii = this.figures.length; i < ii; i++) {
|
|
25368
|
+
this._buildFigureFromPatch(i);
|
|
25369
|
+
}
|
|
25370
|
+
}
|
|
25371
|
+
this._updateBounds();
|
|
25372
|
+
this._packData();
|
|
25373
|
+
}
|
|
25374
|
+
_decodeType4Shading(reader) {
|
|
25375
|
+
const coords = this.coords;
|
|
25376
|
+
const colors = this.colors;
|
|
25377
|
+
const operators = [];
|
|
25378
|
+
const ps = [];
|
|
25379
|
+
let verticesLeft = 0;
|
|
25380
|
+
while (reader.hasData) {
|
|
25381
|
+
const f = reader.readFlag();
|
|
25382
|
+
const coord = reader.readCoordinate();
|
|
25383
|
+
const color = reader.readComponents();
|
|
25384
|
+
if (verticesLeft === 0) {
|
|
25385
|
+
if (!(0 <= f && f <= 2)) {
|
|
25386
|
+
throw new FormatError("Unknown type4 flag");
|
|
25387
|
+
}
|
|
25388
|
+
switch (f) {
|
|
25389
|
+
case 0:
|
|
25390
|
+
verticesLeft = 3;
|
|
25391
|
+
break;
|
|
25392
|
+
case 1:
|
|
25393
|
+
ps.push(ps.at(-2), ps.at(-1));
|
|
25394
|
+
verticesLeft = 1;
|
|
25395
|
+
break;
|
|
25396
|
+
case 2:
|
|
25397
|
+
ps.push(ps.at(-3), ps.at(-1));
|
|
25398
|
+
verticesLeft = 1;
|
|
25399
|
+
break;
|
|
25400
|
+
}
|
|
25401
|
+
operators.push(f);
|
|
25402
|
+
}
|
|
25403
|
+
ps.push(coords.length);
|
|
25404
|
+
coords.push(coord);
|
|
25405
|
+
colors.push(color);
|
|
25406
|
+
verticesLeft--;
|
|
25407
|
+
reader.align();
|
|
25408
|
+
}
|
|
25409
|
+
this.figures.push({
|
|
25410
|
+
type: MeshFigureType.TRIANGLES,
|
|
25411
|
+
coords: new Int32Array(ps),
|
|
25412
|
+
colors: new Int32Array(ps)
|
|
25413
|
+
});
|
|
25414
|
+
}
|
|
25415
|
+
_decodeType5Shading(reader, verticesPerRow) {
|
|
25416
|
+
const coords = this.coords;
|
|
25417
|
+
const colors = this.colors;
|
|
25418
|
+
const ps = [];
|
|
25419
|
+
while (reader.hasData) {
|
|
25420
|
+
const coord = reader.readCoordinate();
|
|
25421
|
+
const color = reader.readComponents();
|
|
25422
|
+
ps.push(coords.length);
|
|
25423
|
+
coords.push(coord);
|
|
25424
|
+
colors.push(color);
|
|
25425
|
+
}
|
|
25426
|
+
this.figures.push({
|
|
25427
|
+
type: MeshFigureType.LATTICE,
|
|
25428
|
+
coords: new Int32Array(ps),
|
|
25429
|
+
colors: new Int32Array(ps),
|
|
25430
|
+
verticesPerRow
|
|
25431
|
+
});
|
|
25432
|
+
}
|
|
25433
|
+
_decodeType6Shading(reader) {
|
|
25434
|
+
const coords = this.coords;
|
|
25435
|
+
const colors = this.colors;
|
|
25436
|
+
const ps = new Int32Array(16);
|
|
25437
|
+
const cs = new Int32Array(4);
|
|
25438
|
+
while (reader.hasData) {
|
|
25439
|
+
const f = reader.readFlag();
|
|
25440
|
+
if (!(0 <= f && f <= 3)) {
|
|
25441
|
+
throw new FormatError("Unknown type6 flag");
|
|
25442
|
+
}
|
|
25443
|
+
const pi = coords.length;
|
|
25444
|
+
for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
|
|
25445
|
+
coords.push(reader.readCoordinate());
|
|
25446
|
+
}
|
|
25447
|
+
const ci = colors.length;
|
|
25448
|
+
for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
|
25449
|
+
colors.push(reader.readComponents());
|
|
25450
|
+
}
|
|
25451
|
+
let tmp1, tmp2, tmp3, tmp4;
|
|
25452
|
+
switch (f) {
|
|
25453
|
+
// prettier-ignore
|
|
25454
|
+
case 0:
|
|
25455
|
+
ps[12] = pi + 3;
|
|
25456
|
+
ps[13] = pi + 4;
|
|
25457
|
+
ps[14] = pi + 5;
|
|
25458
|
+
ps[15] = pi + 6;
|
|
25459
|
+
ps[8] = pi + 2;
|
|
25460
|
+
ps[11] = pi + 7;
|
|
25461
|
+
ps[4] = pi + 1;
|
|
25462
|
+
ps[7] = pi + 8;
|
|
25463
|
+
ps[0] = pi;
|
|
25464
|
+
ps[1] = pi + 11;
|
|
25465
|
+
ps[2] = pi + 10;
|
|
25466
|
+
ps[3] = pi + 9;
|
|
25467
|
+
cs[2] = ci + 1;
|
|
25468
|
+
cs[3] = ci + 2;
|
|
25469
|
+
cs[0] = ci;
|
|
25470
|
+
cs[1] = ci + 3;
|
|
25471
|
+
break;
|
|
25472
|
+
// prettier-ignore
|
|
25473
|
+
case 1:
|
|
25474
|
+
tmp1 = ps[12];
|
|
25475
|
+
tmp2 = ps[13];
|
|
25476
|
+
tmp3 = ps[14];
|
|
25477
|
+
tmp4 = ps[15];
|
|
25478
|
+
ps[12] = tmp4;
|
|
25479
|
+
ps[13] = pi + 0;
|
|
25480
|
+
ps[14] = pi + 1;
|
|
25481
|
+
ps[15] = pi + 2;
|
|
25482
|
+
ps[8] = tmp3;
|
|
25483
|
+
ps[11] = pi + 3;
|
|
25484
|
+
ps[4] = tmp2;
|
|
25485
|
+
ps[7] = pi + 4;
|
|
25486
|
+
ps[0] = tmp1;
|
|
25487
|
+
ps[1] = pi + 7;
|
|
25488
|
+
ps[2] = pi + 6;
|
|
25489
|
+
ps[3] = pi + 5;
|
|
25490
|
+
tmp1 = cs[2];
|
|
25491
|
+
tmp2 = cs[3];
|
|
25492
|
+
cs[2] = tmp2;
|
|
25493
|
+
cs[3] = ci;
|
|
25494
|
+
cs[0] = tmp1;
|
|
25495
|
+
cs[1] = ci + 1;
|
|
25496
|
+
break;
|
|
25497
|
+
// prettier-ignore
|
|
25498
|
+
case 2:
|
|
25499
|
+
tmp1 = ps[15];
|
|
25500
|
+
tmp2 = ps[11];
|
|
25501
|
+
ps[12] = ps[3];
|
|
25502
|
+
ps[13] = pi + 0;
|
|
25503
|
+
ps[14] = pi + 1;
|
|
25504
|
+
ps[15] = pi + 2;
|
|
25505
|
+
ps[8] = ps[7];
|
|
25506
|
+
ps[11] = pi + 3;
|
|
25507
|
+
ps[4] = tmp2;
|
|
25508
|
+
ps[7] = pi + 4;
|
|
25509
|
+
ps[0] = tmp1;
|
|
25510
|
+
ps[1] = pi + 7;
|
|
25511
|
+
ps[2] = pi + 6;
|
|
25512
|
+
ps[3] = pi + 5;
|
|
25513
|
+
tmp1 = cs[3];
|
|
25514
|
+
cs[2] = cs[1];
|
|
25515
|
+
cs[3] = ci;
|
|
25516
|
+
cs[0] = tmp1;
|
|
25517
|
+
cs[1] = ci + 1;
|
|
25518
|
+
break;
|
|
25519
|
+
// prettier-ignore
|
|
25520
|
+
case 3:
|
|
25521
|
+
ps[12] = ps[0];
|
|
25522
|
+
ps[13] = pi + 0;
|
|
25523
|
+
ps[14] = pi + 1;
|
|
25524
|
+
ps[15] = pi + 2;
|
|
25525
|
+
ps[8] = ps[1];
|
|
25526
|
+
ps[11] = pi + 3;
|
|
25527
|
+
ps[4] = ps[2];
|
|
25528
|
+
ps[7] = pi + 4;
|
|
25529
|
+
ps[0] = ps[3];
|
|
25530
|
+
ps[1] = pi + 7;
|
|
25531
|
+
ps[2] = pi + 6;
|
|
25532
|
+
ps[3] = pi + 5;
|
|
25533
|
+
cs[2] = cs[0];
|
|
25534
|
+
cs[3] = ci;
|
|
25535
|
+
cs[0] = cs[1];
|
|
25536
|
+
cs[1] = ci + 1;
|
|
25537
|
+
break;
|
|
25538
|
+
}
|
|
25539
|
+
ps[5] = coords.length;
|
|
25540
|
+
coords.push([
|
|
25541
|
+
(-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
|
|
25542
|
+
(-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
|
|
25543
|
+
]);
|
|
25544
|
+
ps[6] = coords.length;
|
|
25545
|
+
coords.push([
|
|
25546
|
+
(-4 * coords[ps[3]][0] - coords[ps[12]][0] + 6 * (coords[ps[2]][0] + coords[ps[7]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
|
|
25547
|
+
(-4 * coords[ps[3]][1] - coords[ps[12]][1] + 6 * (coords[ps[2]][1] + coords[ps[7]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
|
|
25548
|
+
]);
|
|
25549
|
+
ps[9] = coords.length;
|
|
25550
|
+
coords.push([
|
|
25551
|
+
(-4 * coords[ps[12]][0] - coords[ps[3]][0] + 6 * (coords[ps[8]][0] + coords[ps[13]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
|
|
25552
|
+
(-4 * coords[ps[12]][1] - coords[ps[3]][1] + 6 * (coords[ps[8]][1] + coords[ps[13]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
|
|
25553
|
+
]);
|
|
25554
|
+
ps[10] = coords.length;
|
|
25555
|
+
coords.push([
|
|
25556
|
+
(-4 * coords[ps[15]][0] - coords[ps[0]][0] + 6 * (coords[ps[11]][0] + coords[ps[14]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
|
|
25557
|
+
(-4 * coords[ps[15]][1] - coords[ps[0]][1] + 6 * (coords[ps[11]][1] + coords[ps[14]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
|
|
25558
|
+
]);
|
|
25559
|
+
this.figures.push({
|
|
25560
|
+
type: MeshFigureType.PATCH,
|
|
25561
|
+
coords: new Int32Array(ps),
|
|
25562
|
+
// making copies of ps and cs
|
|
25563
|
+
colors: new Int32Array(cs)
|
|
25564
|
+
});
|
|
25565
|
+
}
|
|
25566
|
+
}
|
|
25567
|
+
_decodeType7Shading(reader) {
|
|
25568
|
+
const coords = this.coords;
|
|
25569
|
+
const colors = this.colors;
|
|
25570
|
+
const ps = new Int32Array(16);
|
|
25571
|
+
const cs = new Int32Array(4);
|
|
25572
|
+
while (reader.hasData) {
|
|
25573
|
+
const f = reader.readFlag();
|
|
25574
|
+
if (!(0 <= f && f <= 3)) {
|
|
25575
|
+
throw new FormatError("Unknown type7 flag");
|
|
25576
|
+
}
|
|
25577
|
+
const pi = coords.length;
|
|
25578
|
+
for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
|
|
25579
|
+
coords.push(reader.readCoordinate());
|
|
25580
|
+
}
|
|
25581
|
+
const ci = colors.length;
|
|
25582
|
+
for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
|
25583
|
+
colors.push(reader.readComponents());
|
|
25584
|
+
}
|
|
25585
|
+
let tmp1, tmp2, tmp3, tmp4;
|
|
25586
|
+
switch (f) {
|
|
25587
|
+
// prettier-ignore
|
|
25588
|
+
case 0:
|
|
25589
|
+
ps[12] = pi + 3;
|
|
25590
|
+
ps[13] = pi + 4;
|
|
25591
|
+
ps[14] = pi + 5;
|
|
25592
|
+
ps[15] = pi + 6;
|
|
25593
|
+
ps[8] = pi + 2;
|
|
25594
|
+
ps[9] = pi + 13;
|
|
25595
|
+
ps[10] = pi + 14;
|
|
25596
|
+
ps[11] = pi + 7;
|
|
25597
|
+
ps[4] = pi + 1;
|
|
25598
|
+
ps[5] = pi + 12;
|
|
25599
|
+
ps[6] = pi + 15;
|
|
25600
|
+
ps[7] = pi + 8;
|
|
25601
|
+
ps[0] = pi;
|
|
25602
|
+
ps[1] = pi + 11;
|
|
25603
|
+
ps[2] = pi + 10;
|
|
25604
|
+
ps[3] = pi + 9;
|
|
25605
|
+
cs[2] = ci + 1;
|
|
25606
|
+
cs[3] = ci + 2;
|
|
25607
|
+
cs[0] = ci;
|
|
25608
|
+
cs[1] = ci + 3;
|
|
25609
|
+
break;
|
|
25610
|
+
// prettier-ignore
|
|
25611
|
+
case 1:
|
|
25612
|
+
tmp1 = ps[12];
|
|
25613
|
+
tmp2 = ps[13];
|
|
25614
|
+
tmp3 = ps[14];
|
|
25615
|
+
tmp4 = ps[15];
|
|
25616
|
+
ps[12] = tmp4;
|
|
25617
|
+
ps[13] = pi + 0;
|
|
25618
|
+
ps[14] = pi + 1;
|
|
25619
|
+
ps[15] = pi + 2;
|
|
25620
|
+
ps[8] = tmp3;
|
|
25621
|
+
ps[9] = pi + 9;
|
|
25622
|
+
ps[10] = pi + 10;
|
|
25623
|
+
ps[11] = pi + 3;
|
|
25624
|
+
ps[4] = tmp2;
|
|
25625
|
+
ps[5] = pi + 8;
|
|
25626
|
+
ps[6] = pi + 11;
|
|
25627
|
+
ps[7] = pi + 4;
|
|
25628
|
+
ps[0] = tmp1;
|
|
25629
|
+
ps[1] = pi + 7;
|
|
25630
|
+
ps[2] = pi + 6;
|
|
25631
|
+
ps[3] = pi + 5;
|
|
25632
|
+
tmp1 = cs[2];
|
|
25633
|
+
tmp2 = cs[3];
|
|
25634
|
+
cs[2] = tmp2;
|
|
25635
|
+
cs[3] = ci;
|
|
25636
|
+
cs[0] = tmp1;
|
|
25637
|
+
cs[1] = ci + 1;
|
|
25638
|
+
break;
|
|
25639
|
+
// prettier-ignore
|
|
25640
|
+
case 2:
|
|
25641
|
+
tmp1 = ps[15];
|
|
25642
|
+
tmp2 = ps[11];
|
|
25643
|
+
ps[12] = ps[3];
|
|
25644
|
+
ps[13] = pi + 0;
|
|
25645
|
+
ps[14] = pi + 1;
|
|
25646
|
+
ps[15] = pi + 2;
|
|
25647
|
+
ps[8] = ps[7];
|
|
25648
|
+
ps[9] = pi + 9;
|
|
25649
|
+
ps[10] = pi + 10;
|
|
25650
|
+
ps[11] = pi + 3;
|
|
25651
|
+
ps[4] = tmp2;
|
|
25652
|
+
ps[5] = pi + 8;
|
|
25653
|
+
ps[6] = pi + 11;
|
|
25654
|
+
ps[7] = pi + 4;
|
|
25655
|
+
ps[0] = tmp1;
|
|
25656
|
+
ps[1] = pi + 7;
|
|
25657
|
+
ps[2] = pi + 6;
|
|
25658
|
+
ps[3] = pi + 5;
|
|
25659
|
+
tmp1 = cs[3];
|
|
25660
|
+
cs[2] = cs[1];
|
|
25661
|
+
cs[3] = ci;
|
|
25662
|
+
cs[0] = tmp1;
|
|
25663
|
+
cs[1] = ci + 1;
|
|
25664
|
+
break;
|
|
25665
|
+
// prettier-ignore
|
|
25666
|
+
case 3:
|
|
25667
|
+
ps[12] = ps[0];
|
|
25668
|
+
ps[13] = pi + 0;
|
|
25669
|
+
ps[14] = pi + 1;
|
|
25670
|
+
ps[15] = pi + 2;
|
|
25671
|
+
ps[8] = ps[1];
|
|
25672
|
+
ps[9] = pi + 9;
|
|
25673
|
+
ps[10] = pi + 10;
|
|
25674
|
+
ps[11] = pi + 3;
|
|
25675
|
+
ps[4] = ps[2];
|
|
25676
|
+
ps[5] = pi + 8;
|
|
25677
|
+
ps[6] = pi + 11;
|
|
25678
|
+
ps[7] = pi + 4;
|
|
25679
|
+
ps[0] = ps[3];
|
|
25680
|
+
ps[1] = pi + 7;
|
|
25681
|
+
ps[2] = pi + 6;
|
|
25682
|
+
ps[3] = pi + 5;
|
|
25683
|
+
cs[2] = cs[0];
|
|
25684
|
+
cs[3] = ci;
|
|
25685
|
+
cs[0] = cs[1];
|
|
25686
|
+
cs[1] = ci + 1;
|
|
25687
|
+
break;
|
|
25688
|
+
}
|
|
25689
|
+
this.figures.push({
|
|
25690
|
+
type: MeshFigureType.PATCH,
|
|
25691
|
+
coords: new Int32Array(ps),
|
|
25692
|
+
// making copies of ps and cs
|
|
25693
|
+
colors: new Int32Array(cs)
|
|
25694
|
+
});
|
|
25695
|
+
}
|
|
25696
|
+
}
|
|
25697
|
+
_buildFigureFromPatch(index) {
|
|
25698
|
+
const figure = this.figures[index];
|
|
25699
|
+
assert2(
|
|
25700
|
+
figure.type === MeshFigureType.PATCH,
|
|
25701
|
+
"Unexpected patch mesh figure"
|
|
25702
|
+
);
|
|
25703
|
+
const coords = this.coords, colors = this.colors;
|
|
25704
|
+
const pi = figure.coords;
|
|
25705
|
+
const ci = figure.colors;
|
|
25706
|
+
const figureMinX = Math.min(
|
|
25707
|
+
coords[pi[0]][0],
|
|
25708
|
+
coords[pi[3]][0],
|
|
25709
|
+
coords[pi[12]][0],
|
|
25710
|
+
coords[pi[15]][0]
|
|
25711
|
+
);
|
|
25712
|
+
const figureMinY = Math.min(
|
|
25713
|
+
coords[pi[0]][1],
|
|
25714
|
+
coords[pi[3]][1],
|
|
25715
|
+
coords[pi[12]][1],
|
|
25716
|
+
coords[pi[15]][1]
|
|
25717
|
+
);
|
|
25718
|
+
const figureMaxX = Math.max(
|
|
25719
|
+
coords[pi[0]][0],
|
|
25720
|
+
coords[pi[3]][0],
|
|
25721
|
+
coords[pi[12]][0],
|
|
25722
|
+
coords[pi[15]][0]
|
|
25723
|
+
);
|
|
25724
|
+
const figureMaxY = Math.max(
|
|
25725
|
+
coords[pi[0]][1],
|
|
25726
|
+
coords[pi[3]][1],
|
|
25727
|
+
coords[pi[12]][1],
|
|
25728
|
+
coords[pi[15]][1]
|
|
25729
|
+
);
|
|
25730
|
+
let splitXBy = Math.ceil(
|
|
25731
|
+
(figureMaxX - figureMinX) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])
|
|
25732
|
+
);
|
|
25733
|
+
splitXBy = MathClamp(
|
|
25734
|
+
splitXBy,
|
|
25735
|
+
_MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
|
25736
|
+
_MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
|
|
25737
|
+
);
|
|
25738
|
+
let splitYBy = Math.ceil(
|
|
25739
|
+
(figureMaxY - figureMinY) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])
|
|
25740
|
+
);
|
|
25741
|
+
splitYBy = MathClamp(
|
|
25742
|
+
splitYBy,
|
|
25743
|
+
_MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
|
25744
|
+
_MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
|
|
25745
|
+
);
|
|
25746
|
+
const verticesPerRow = splitXBy + 1;
|
|
25747
|
+
const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
|
|
25748
|
+
const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
|
|
25749
|
+
let k = 0;
|
|
25750
|
+
const cl = new Uint8Array(3), cr = new Uint8Array(3);
|
|
25751
|
+
const c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
|
|
25752
|
+
const bRow = getB(splitYBy), bCol = getB(splitXBy);
|
|
25753
|
+
for (let row = 0; row <= splitYBy; row++) {
|
|
25754
|
+
cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
|
|
25755
|
+
cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
|
|
25756
|
+
cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
|
|
25757
|
+
cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
|
|
25758
|
+
cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
|
|
25759
|
+
cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
|
|
25760
|
+
for (let col = 0; col <= splitXBy; col++, k++) {
|
|
25761
|
+
if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
|
|
25762
|
+
continue;
|
|
25763
|
+
}
|
|
25764
|
+
let x = 0, y = 0;
|
|
25765
|
+
let q = 0;
|
|
25766
|
+
for (let i = 0; i <= 3; i++) {
|
|
25767
|
+
for (let j = 0; j <= 3; j++, q++) {
|
|
25768
|
+
const m = bRow[row][i] * bCol[col][j];
|
|
25769
|
+
x += coords[pi[q]][0] * m;
|
|
25770
|
+
y += coords[pi[q]][1] * m;
|
|
25771
|
+
}
|
|
25772
|
+
}
|
|
25773
|
+
figureCoords[k] = coords.length;
|
|
25774
|
+
coords.push([x, y]);
|
|
25775
|
+
figureColors[k] = colors.length;
|
|
25776
|
+
const newColor = new Uint8Array(3);
|
|
25777
|
+
newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
|
|
25778
|
+
newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
|
|
25779
|
+
newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
|
|
25780
|
+
colors.push(newColor);
|
|
25781
|
+
}
|
|
25782
|
+
}
|
|
25783
|
+
figureCoords[0] = pi[0];
|
|
25784
|
+
figureColors[0] = ci[0];
|
|
25785
|
+
figureCoords[splitXBy] = pi[3];
|
|
25786
|
+
figureColors[splitXBy] = ci[1];
|
|
25787
|
+
figureCoords[verticesPerRow * splitYBy] = pi[12];
|
|
25788
|
+
figureColors[verticesPerRow * splitYBy] = ci[2];
|
|
25789
|
+
figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
|
|
25790
|
+
figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
|
|
25791
|
+
this.figures[index] = {
|
|
25792
|
+
type: MeshFigureType.LATTICE,
|
|
25793
|
+
coords: figureCoords,
|
|
25794
|
+
colors: figureColors,
|
|
25795
|
+
verticesPerRow
|
|
25796
|
+
};
|
|
25797
|
+
}
|
|
25798
|
+
_updateBounds() {
|
|
25799
|
+
meshUpdateBounds(this);
|
|
25800
|
+
}
|
|
25801
|
+
_packData() {
|
|
25802
|
+
meshPackData(this);
|
|
25803
|
+
}
|
|
25804
|
+
getIR() {
|
|
25805
|
+
const { posData, colData, vertexCount } = buildMeshVertexData(
|
|
25806
|
+
this.coords,
|
|
25807
|
+
this.colors,
|
|
25808
|
+
this.figures
|
|
25809
|
+
);
|
|
25810
|
+
return [
|
|
25811
|
+
"Mesh",
|
|
25812
|
+
this.shadingType,
|
|
25813
|
+
posData,
|
|
25814
|
+
colData,
|
|
25815
|
+
vertexCount,
|
|
25816
|
+
this.bounds,
|
|
25817
|
+
this.bbox,
|
|
25818
|
+
this.background
|
|
25819
|
+
];
|
|
25820
|
+
}
|
|
25821
|
+
};
|
|
25123
25822
|
var PdfError = class extends Error {
|
|
25124
25823
|
constructor(code, message) {
|
|
25125
25824
|
super(message);
|
|
@@ -28025,11 +28724,16 @@ function parseDictionaryStream(dictNode, lexer, bytes) {
|
|
|
28025
28724
|
let streamEnd = streamStart;
|
|
28026
28725
|
if (resolvedLength !== void 0 && resolvedLength >= 0 && streamStart + resolvedLength <= bytes.length) {
|
|
28027
28726
|
const candidateEnd = streamStart + resolvedLength;
|
|
28028
|
-
const
|
|
28029
|
-
|
|
28030
|
-
|
|
28727
|
+
const tailLexer = new CosByteLexer(bytes, candidateEnd);
|
|
28728
|
+
let endToken;
|
|
28729
|
+
try {
|
|
28730
|
+
endToken = tailLexer.nextToken();
|
|
28731
|
+
} catch (error) {
|
|
28732
|
+
if (!(error instanceof PdfError) || error.code !== "E_PARSE") throw error;
|
|
28733
|
+
}
|
|
28734
|
+
if (endToken?.kind === "keyword" && endToken.value === "endstream") {
|
|
28031
28735
|
rawStreamBytes = bytes.subarray(streamStart, candidateEnd);
|
|
28032
|
-
streamEnd =
|
|
28736
|
+
streamEnd = tailLexer.offset;
|
|
28033
28737
|
}
|
|
28034
28738
|
}
|
|
28035
28739
|
if (!rawStreamBytes) {
|
|
@@ -37397,143 +38101,28 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
37397
38101
|
const r = doc.resolve(it);
|
|
37398
38102
|
return r?.kind === "number" ? r.value : 0;
|
|
37399
38103
|
});
|
|
37400
|
-
const xmin = decodeNums[0], xmax = decodeNums[1], ymin = decodeNums[2], ymax = decodeNums[3];
|
|
37401
|
-
const numColorParams = Math.max(1, Math.floor((decodeNums.length - 4) / 2));
|
|
37402
38104
|
const fnNode = dictGet(shDict, "Function");
|
|
37403
38105
|
const csNode = doc.resolve(dictGet(shDict, "ColorSpace"));
|
|
37404
38106
|
const csName = csNode?.kind === "name" ? csNode.decoded : "DeviceRGB";
|
|
37405
|
-
|
|
37406
|
-
const
|
|
37407
|
-
|
|
37408
|
-
|
|
37409
|
-
|
|
37410
|
-
|
|
37411
|
-
|
|
37412
|
-
|
|
37413
|
-
|
|
37414
|
-
|
|
37415
|
-
|
|
37416
|
-
|
|
37417
|
-
|
|
37418
|
-
|
|
37419
|
-
|
|
37420
|
-
|
|
37421
|
-
|
|
37422
|
-
|
|
37423
|
-
|
|
37424
|
-
};
|
|
37425
|
-
const readColorRgb = () => {
|
|
37426
|
-
const params = [];
|
|
37427
|
-
for (let c = 0; c < numColorParams; c++) {
|
|
37428
|
-
const rc = readBits(bpcComp) / compMax;
|
|
37429
|
-
const cMin = decodeNums[4 + c * 2] ?? 0;
|
|
37430
|
-
const cMax = decodeNums[4 + c * 2 + 1] ?? 1;
|
|
37431
|
-
params.push(cMin + rc * (cMax - cMin));
|
|
37432
|
-
}
|
|
37433
|
-
const comps = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
|
|
37434
|
-
return convertColorSpaceComponentsToRgb(doc, csNode, csName, comps);
|
|
37435
|
-
};
|
|
37436
|
-
const triangles = [];
|
|
37437
|
-
if (shType === 4) {
|
|
37438
|
-
const minBitsPerVert = bpcFlag + 2 * bpcCoord + numColorParams * bpcComp;
|
|
37439
|
-
let triVerts;
|
|
37440
|
-
while (bitPos + minBitsPerVert <= totalBits) {
|
|
37441
|
-
const flag = readBits(bpcFlag) & 3;
|
|
37442
|
-
const [x, y] = readCoord();
|
|
37443
|
-
const rgb2 = readColorRgb();
|
|
37444
|
-
const vNew = { x, y, rgb: rgb2 };
|
|
37445
|
-
if (flag === 0 || !triVerts) {
|
|
37446
|
-
if (bitPos + 2 * minBitsPerVert > totalBits) break;
|
|
37447
|
-
readBits(bpcFlag);
|
|
37448
|
-
const [x1, y1] = readCoord();
|
|
37449
|
-
const rgb1 = readColorRgb();
|
|
37450
|
-
readBits(bpcFlag);
|
|
37451
|
-
const [x2, y2] = readCoord();
|
|
37452
|
-
const rgb22 = readColorRgb();
|
|
37453
|
-
triVerts = [vNew, { x: x1, y: y1, rgb: rgb1 }, { x: x2, y: y2, rgb: rgb22 }];
|
|
37454
|
-
triangles.push(triVerts);
|
|
37455
|
-
} else if (flag === 1) {
|
|
37456
|
-
triVerts = [triVerts[1], triVerts[2], vNew];
|
|
37457
|
-
triangles.push(triVerts);
|
|
37458
|
-
} else if (flag === 2) {
|
|
37459
|
-
triVerts = [triVerts[0], triVerts[2], vNew];
|
|
37460
|
-
triangles.push(triVerts);
|
|
37461
|
-
}
|
|
37462
|
-
}
|
|
37463
|
-
} else if (shType === 5) {
|
|
37464
|
-
const minBitsPerVert = 2 * bpcCoord + numColorParams * bpcComp;
|
|
37465
|
-
const verts = [];
|
|
37466
|
-
while (bitPos + minBitsPerVert <= totalBits) {
|
|
37467
|
-
const [x, y] = readCoord();
|
|
37468
|
-
const rgb2 = readColorRgb();
|
|
37469
|
-
verts.push({ x, y, rgb: rgb2 });
|
|
37470
|
-
}
|
|
37471
|
-
const numRows = Math.floor(verts.length / vPerRow);
|
|
37472
|
-
for (let r = 0; r + 1 < numRows; r++) {
|
|
37473
|
-
for (let c = 0; c + 1 < vPerRow; c++) {
|
|
37474
|
-
const v00 = verts[r * vPerRow + c];
|
|
37475
|
-
const v01 = verts[r * vPerRow + c + 1];
|
|
37476
|
-
const v11 = verts[(r + 1) * vPerRow + c + 1];
|
|
37477
|
-
const v10 = verts[(r + 1) * vPerRow + c];
|
|
37478
|
-
triangles.push([v00, v01, v11], [v00, v11, v10]);
|
|
37479
|
-
}
|
|
37480
|
-
}
|
|
37481
|
-
} else if (shType === 6 || shType === 7) {
|
|
37482
|
-
const numCtrl = shType === 6 ? 12 : 16;
|
|
37483
|
-
const minBitsPatch = bpcFlag + (numCtrl - 4) * 2 * bpcCoord + 2 * numColorParams * bpcComp;
|
|
37484
|
-
let prevPts;
|
|
37485
|
-
let prevColors;
|
|
37486
|
-
while (bitPos + minBitsPatch <= totalBits) {
|
|
37487
|
-
const flag = readBits(bpcFlag) & 3;
|
|
37488
|
-
let pts = [];
|
|
37489
|
-
let cols = [];
|
|
37490
|
-
if (flag === 0 || !prevPts || !prevColors) {
|
|
37491
|
-
for (let i = 0; i < numCtrl; i++) pts.push(readCoord());
|
|
37492
|
-
for (let i = 0; i < 4; i++) cols.push(readColorRgb());
|
|
37493
|
-
} else {
|
|
37494
|
-
const extraCtrl = numCtrl - 4;
|
|
37495
|
-
const readExtra = [];
|
|
37496
|
-
for (let i = 0; i < extraCtrl; i++) readExtra.push(readCoord());
|
|
37497
|
-
const c2 = readColorRgb();
|
|
37498
|
-
const c3 = readColorRgb();
|
|
37499
|
-
pts = [prevPts[3], prevPts[4], prevPts[5], prevPts[6], ...readExtra];
|
|
37500
|
-
cols = [prevColors[1], prevColors[2], c2, c3];
|
|
37501
|
-
}
|
|
37502
|
-
prevPts = pts;
|
|
37503
|
-
prevColors = cols;
|
|
37504
|
-
const p00 = pts[0];
|
|
37505
|
-
const p03 = pts[3];
|
|
37506
|
-
const p33 = pts[6];
|
|
37507
|
-
const p30 = pts[9];
|
|
37508
|
-
const c00 = cols[0], c03 = cols[1], c33 = cols[2], c30 = cols[3];
|
|
37509
|
-
const steps = 4;
|
|
37510
|
-
const grid = [];
|
|
37511
|
-
for (let iu = 0; iu <= steps; iu++) {
|
|
37512
|
-
const u = iu / steps;
|
|
37513
|
-
const row = [];
|
|
37514
|
-
for (let iv = 0; iv <= steps; iv++) {
|
|
37515
|
-
const v = iv / steps;
|
|
37516
|
-
const x = (1 - u) * (1 - v) * p00[0] + (1 - u) * v * p03[0] + u * v * p33[0] + u * (1 - v) * p30[0];
|
|
37517
|
-
const y = (1 - u) * (1 - v) * p00[1] + (1 - u) * v * p03[1] + u * v * p33[1] + u * (1 - v) * p30[1];
|
|
37518
|
-
const r = (1 - u) * (1 - v) * c00[0] + (1 - u) * v * c03[0] + u * v * c33[0] + u * (1 - v) * c30[0];
|
|
37519
|
-
const g = (1 - u) * (1 - v) * c00[1] + (1 - u) * v * c03[1] + u * v * c33[1] + u * (1 - v) * c30[1];
|
|
37520
|
-
const b = (1 - u) * (1 - v) * c00[2] + (1 - u) * v * c03[2] + u * v * c33[2] + u * (1 - v) * c30[2];
|
|
37521
|
-
row.push({ x, y, rgb: [r, g, b] });
|
|
37522
|
-
}
|
|
37523
|
-
grid.push(row);
|
|
37524
|
-
}
|
|
37525
|
-
for (let iu = 0; iu < steps; iu++) {
|
|
37526
|
-
for (let iv = 0; iv < steps; iv++) {
|
|
37527
|
-
const g00 = grid[iu][iv];
|
|
37528
|
-
const g01 = grid[iu][iv + 1];
|
|
37529
|
-
const g11 = grid[iu + 1][iv + 1];
|
|
37530
|
-
const g10 = grid[iu + 1][iv];
|
|
37531
|
-
triangles.push([g00, g01, g11], [g00, g11, g10]);
|
|
37532
|
-
}
|
|
37533
|
-
}
|
|
37534
|
-
}
|
|
37535
|
-
}
|
|
37536
|
-
if (triangles.length === 0) return void 0;
|
|
38107
|
+
const numComps = fnNode ? 1 : getColorSpaceComponentCount(doc, csNode);
|
|
38108
|
+
const mesh = new MeshShading(shType, new Stream(bytes), {
|
|
38109
|
+
bitsPerCoordinate: bpcCoord,
|
|
38110
|
+
bitsPerComponent: bpcComp,
|
|
38111
|
+
bitsPerFlag: bpcFlag,
|
|
38112
|
+
decode: decodeNums,
|
|
38113
|
+
numComps,
|
|
38114
|
+
colorFn: null,
|
|
38115
|
+
colorSpace: {
|
|
38116
|
+
numComps,
|
|
38117
|
+
getRgb(components) {
|
|
38118
|
+
const params = Array.from(components);
|
|
38119
|
+
const values = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
|
|
38120
|
+
return new Uint8Array(convertColorSpaceComponentsToRgb(doc, csNode, csName, values).map((value) => Math.round(Math.max(0, Math.min(1, value)) * 255)));
|
|
38121
|
+
}
|
|
38122
|
+
}
|
|
38123
|
+
}, vPerRow);
|
|
38124
|
+
const [, , positions, colors, vertexCount] = mesh.getIR();
|
|
38125
|
+
if (vertexCount === 0) return void 0;
|
|
37537
38126
|
const [bx0, by0, bx1, by1] = targetBox;
|
|
37538
38127
|
const boxW = Math.max(1, bx1 - bx0);
|
|
37539
38128
|
const boxH = Math.max(1, by1 - by0);
|
|
@@ -37545,10 +38134,10 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
37545
38134
|
const [px, py] = transformPoint(effectiveCtm, vx, vy);
|
|
37546
38135
|
return [(px - bx0) / boxW * imgW, (by1 - py) / boxH * imgH];
|
|
37547
38136
|
};
|
|
37548
|
-
for (
|
|
37549
|
-
const [x0, y0] = toImgCoords(
|
|
37550
|
-
const [x1, y1] = toImgCoords(
|
|
37551
|
-
const [x2, y2] = toImgCoords(
|
|
38137
|
+
for (let vertex = 0; vertex < vertexCount; vertex += 3) {
|
|
38138
|
+
const [x0, y0] = toImgCoords(positions[vertex * 2], positions[vertex * 2 + 1]);
|
|
38139
|
+
const [x1, y1] = toImgCoords(positions[vertex * 2 + 2], positions[vertex * 2 + 3]);
|
|
38140
|
+
const [x2, y2] = toImgCoords(positions[vertex * 2 + 4], positions[vertex * 2 + 5]);
|
|
37552
38141
|
const denom = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2);
|
|
37553
38142
|
if (Math.abs(denom) < 1e-6) continue;
|
|
37554
38143
|
const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
|
|
@@ -37563,13 +38152,12 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
37563
38152
|
const w1 = ((y2 - y0) * (px - x2) + (x0 - x2) * (py - y2)) / denom;
|
|
37564
38153
|
const w2 = 1 - w0 - w1;
|
|
37565
38154
|
if (w0 >= -1e-4 && w1 >= -1e-4 && w2 >= -1e-4) {
|
|
37566
|
-
const r = w0 * v0.rgb[0] + w1 * v1.rgb[0] + w2 * v2.rgb[0];
|
|
37567
|
-
const g = w0 * v0.rgb[1] + w1 * v1.rgb[1] + w2 * v2.rgb[1];
|
|
37568
|
-
const b = w0 * v0.rgb[2] + w1 * v1.rgb[2] + w2 * v2.rgb[2];
|
|
37569
38155
|
const pIdx = (iy * imgW + ix) * 4;
|
|
37570
|
-
|
|
37571
|
-
|
|
37572
|
-
|
|
38156
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
38157
|
+
rgba[pIdx + channel] = Math.round(
|
|
38158
|
+
w0 * colors[vertex * 4 + channel] + w1 * colors[vertex * 4 + 4 + channel] + w2 * colors[vertex * 4 + 8 + channel]
|
|
38159
|
+
);
|
|
38160
|
+
}
|
|
37573
38161
|
rgba[pIdx + 3] = a8;
|
|
37574
38162
|
}
|
|
37575
38163
|
}
|
|
@@ -37656,6 +38244,8 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
|
|
|
37656
38244
|
const [a, b, c, d, e, f] = effectiveCtm;
|
|
37657
38245
|
const det = a * d - b * c;
|
|
37658
38246
|
if (Math.abs(det) <= 1e-8) return void 0;
|
|
38247
|
+
const [sa, sb, sc, sd, se, sf] = shadingCtm;
|
|
38248
|
+
const shadingDet = sa * sd - sb * sc;
|
|
37659
38249
|
const t0Dom = shDomain[0] ?? 0;
|
|
37660
38250
|
const t1Dom = shDomain[1] ?? 1;
|
|
37661
38251
|
for (let iy = 0; iy < imgH; iy++) {
|
|
@@ -37666,8 +38256,10 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
|
|
|
37666
38256
|
const dxPdf = xPdf - e;
|
|
37667
38257
|
const xs = (d * dxPdf - c * dyPdf) / det;
|
|
37668
38258
|
const ys = (-b * dxPdf + a * dyPdf) / det;
|
|
37669
|
-
if (shBBox
|
|
37670
|
-
|
|
38259
|
+
if (shBBox) {
|
|
38260
|
+
const bboxX = (sd * (xPdf - se) - sc * (yPdf - sf)) / shadingDet;
|
|
38261
|
+
const bboxY = (-sb * (xPdf - se) + sa * (yPdf - sf)) / shadingDet;
|
|
38262
|
+
if (bboxX < shBBox[0] || bboxX > shBBox[2] || bboxY < shBBox[1] || bboxY > shBBox[3]) continue;
|
|
37671
38263
|
}
|
|
37672
38264
|
let comps;
|
|
37673
38265
|
if (shType === 1) {
|