@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,
|
|
@@ -25314,6 +25319,700 @@ function buildPostScriptJsFunction(source, domain, range, forceInterpreter = fal
|
|
|
25314
25319
|
}
|
|
25315
25320
|
return PSStackBasedInterpreter.build(program, domain, range);
|
|
25316
25321
|
}
|
|
25322
|
+
var ShadingType = {
|
|
25323
|
+
FUNCTION_BASED: 1,
|
|
25324
|
+
AXIAL: 2,
|
|
25325
|
+
RADIAL: 3,
|
|
25326
|
+
FREE_FORM_MESH: 4,
|
|
25327
|
+
LATTICE_FORM_MESH: 5,
|
|
25328
|
+
COONS_PATCH_MESH: 6,
|
|
25329
|
+
TENSOR_PATCH_MESH: 7
|
|
25330
|
+
};
|
|
25331
|
+
var BaseShading = class _BaseShading {
|
|
25332
|
+
// A small number to offset the first/last color stops so we can insert ones
|
|
25333
|
+
// to support extend. Number.MIN_VALUE is too small and breaks the extend.
|
|
25334
|
+
static SMALL_NUMBER = 1e-6;
|
|
25335
|
+
constructor() {
|
|
25336
|
+
if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === _BaseShading) {
|
|
25337
|
+
unreachable2("Cannot initialize BaseShading.");
|
|
25338
|
+
}
|
|
25339
|
+
}
|
|
25340
|
+
getIR() {
|
|
25341
|
+
unreachable2("Abstract method `getIR` called.");
|
|
25342
|
+
}
|
|
25343
|
+
};
|
|
25344
|
+
function meshUpdateBounds(self) {
|
|
25345
|
+
let minX = self.coords[0][0], minY = self.coords[0][1], maxX = minX, maxY = minY;
|
|
25346
|
+
for (let i = 1, ii = self.coords.length; i < ii; i++) {
|
|
25347
|
+
const x = self.coords[i][0], y = self.coords[i][1];
|
|
25348
|
+
minX = minX > x ? x : minX;
|
|
25349
|
+
minY = minY > y ? y : minY;
|
|
25350
|
+
maxX = maxX < x ? x : maxX;
|
|
25351
|
+
maxY = maxY < y ? y : maxY;
|
|
25352
|
+
}
|
|
25353
|
+
self.bounds = [minX, minY, maxX, maxY];
|
|
25354
|
+
}
|
|
25355
|
+
function meshPackData(self) {
|
|
25356
|
+
let i, j, ii;
|
|
25357
|
+
const coords = self.coords;
|
|
25358
|
+
const coordsPacked = new Float32Array(coords.length * 2);
|
|
25359
|
+
for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
|
|
25360
|
+
const xy = coords[i];
|
|
25361
|
+
coordsPacked[j++] = xy[0];
|
|
25362
|
+
coordsPacked[j++] = xy[1];
|
|
25363
|
+
}
|
|
25364
|
+
self.coords = coordsPacked;
|
|
25365
|
+
const colors = self.colors;
|
|
25366
|
+
const colorsPacked = new Uint8Array(colors.length * 4);
|
|
25367
|
+
for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
|
|
25368
|
+
const c = colors[i];
|
|
25369
|
+
colorsPacked[j++] = c[0];
|
|
25370
|
+
colorsPacked[j++] = c[1];
|
|
25371
|
+
colorsPacked[j++] = c[2];
|
|
25372
|
+
j++;
|
|
25373
|
+
}
|
|
25374
|
+
self.colors = colorsPacked;
|
|
25375
|
+
for (const figure of self.figures) {
|
|
25376
|
+
figure.coords = new Uint32Array(figure.coords);
|
|
25377
|
+
figure.colors = new Uint32Array(figure.colors);
|
|
25378
|
+
}
|
|
25379
|
+
}
|
|
25380
|
+
function buildMeshVertexData(coords, colors, figures) {
|
|
25381
|
+
let vertexCount = 0;
|
|
25382
|
+
for (const figure of figures) {
|
|
25383
|
+
if (figure.type === MeshFigureType.TRIANGLES) {
|
|
25384
|
+
vertexCount += figure.coords.length;
|
|
25385
|
+
} else if (figure.type === MeshFigureType.LATTICE) {
|
|
25386
|
+
const vpr = figure.verticesPerRow;
|
|
25387
|
+
vertexCount += (Math.floor(figure.coords.length / vpr) - 1) * (vpr - 1) * 6;
|
|
25388
|
+
}
|
|
25389
|
+
}
|
|
25390
|
+
const posData = new Float32Array(vertexCount * 2);
|
|
25391
|
+
const colData = new Uint8Array(vertexCount * 4);
|
|
25392
|
+
let pOff = 0, cOff = 0;
|
|
25393
|
+
const addVertex = (pi, ci) => {
|
|
25394
|
+
posData[pOff++] = coords[pi * 2];
|
|
25395
|
+
posData[pOff++] = coords[pi * 2 + 1];
|
|
25396
|
+
colData[cOff++] = colors[ci * 4];
|
|
25397
|
+
colData[cOff++] = colors[ci * 4 + 1];
|
|
25398
|
+
colData[cOff++] = colors[ci * 4 + 2];
|
|
25399
|
+
cOff++;
|
|
25400
|
+
};
|
|
25401
|
+
for (const figure of figures) {
|
|
25402
|
+
const ps = figure.coords;
|
|
25403
|
+
const cs = figure.colors;
|
|
25404
|
+
if (figure.type === MeshFigureType.TRIANGLES) {
|
|
25405
|
+
for (let i = 0, ii = ps.length; i < ii; i++) {
|
|
25406
|
+
addVertex(ps[i], cs[i]);
|
|
25407
|
+
}
|
|
25408
|
+
} else if (figure.type === MeshFigureType.LATTICE) {
|
|
25409
|
+
const vpr = figure.verticesPerRow;
|
|
25410
|
+
const rows = Math.floor(ps.length / vpr) - 1;
|
|
25411
|
+
const cols = vpr - 1;
|
|
25412
|
+
for (let i = 0; i < rows; i++) {
|
|
25413
|
+
let q = i * vpr;
|
|
25414
|
+
for (let j = 0; j < cols; j++, q++) {
|
|
25415
|
+
addVertex(ps[q], cs[q]);
|
|
25416
|
+
addVertex(ps[q + 1], cs[q + 1]);
|
|
25417
|
+
addVertex(ps[q + vpr], cs[q + vpr]);
|
|
25418
|
+
addVertex(ps[q + vpr + 1], cs[q + vpr + 1]);
|
|
25419
|
+
addVertex(ps[q + 1], cs[q + 1]);
|
|
25420
|
+
addVertex(ps[q + vpr], cs[q + vpr]);
|
|
25421
|
+
}
|
|
25422
|
+
}
|
|
25423
|
+
}
|
|
25424
|
+
}
|
|
25425
|
+
return { posData, colData, vertexCount };
|
|
25426
|
+
}
|
|
25427
|
+
var MeshStreamReader = class {
|
|
25428
|
+
constructor(stream, context) {
|
|
25429
|
+
this.stream = stream;
|
|
25430
|
+
this.context = context;
|
|
25431
|
+
this.buffer = 0;
|
|
25432
|
+
this.bufferLength = 0;
|
|
25433
|
+
const numComps = context.numComps;
|
|
25434
|
+
this.tmpCompsBuf = new Float32Array(numComps);
|
|
25435
|
+
const csNumComps = context.colorSpace.numComps;
|
|
25436
|
+
this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
|
|
25437
|
+
}
|
|
25438
|
+
get hasData() {
|
|
25439
|
+
if (this.stream.end) {
|
|
25440
|
+
return this.stream.pos < this.stream.end;
|
|
25441
|
+
}
|
|
25442
|
+
if (this.bufferLength > 0) {
|
|
25443
|
+
return true;
|
|
25444
|
+
}
|
|
25445
|
+
const nextByte = this.stream.getByte();
|
|
25446
|
+
if (nextByte < 0) {
|
|
25447
|
+
return false;
|
|
25448
|
+
}
|
|
25449
|
+
this.buffer = nextByte;
|
|
25450
|
+
this.bufferLength = 8;
|
|
25451
|
+
return true;
|
|
25452
|
+
}
|
|
25453
|
+
readBits(n) {
|
|
25454
|
+
const { stream } = this;
|
|
25455
|
+
let { buffer, bufferLength } = this;
|
|
25456
|
+
if (n === 32) {
|
|
25457
|
+
if (bufferLength === 0) {
|
|
25458
|
+
return stream.getInt32() >>> 0;
|
|
25459
|
+
}
|
|
25460
|
+
buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte();
|
|
25461
|
+
const nextByte = stream.getByte();
|
|
25462
|
+
this.buffer = nextByte & (1 << bufferLength) - 1;
|
|
25463
|
+
return (buffer << 8 - bufferLength | (nextByte & 255) >> bufferLength) >>> 0;
|
|
25464
|
+
}
|
|
25465
|
+
if (n === 8 && bufferLength === 0) {
|
|
25466
|
+
return stream.getByte();
|
|
25467
|
+
}
|
|
25468
|
+
while (bufferLength < n) {
|
|
25469
|
+
buffer = buffer << 8 | stream.getByte();
|
|
25470
|
+
bufferLength += 8;
|
|
25471
|
+
}
|
|
25472
|
+
bufferLength -= n;
|
|
25473
|
+
this.bufferLength = bufferLength;
|
|
25474
|
+
this.buffer = buffer & (1 << bufferLength) - 1;
|
|
25475
|
+
return buffer >> bufferLength;
|
|
25476
|
+
}
|
|
25477
|
+
align() {
|
|
25478
|
+
this.buffer = 0;
|
|
25479
|
+
this.bufferLength = 0;
|
|
25480
|
+
}
|
|
25481
|
+
readFlag() {
|
|
25482
|
+
return this.readBits(this.context.bitsPerFlag);
|
|
25483
|
+
}
|
|
25484
|
+
readCoordinate() {
|
|
25485
|
+
const { bitsPerCoordinate, decode } = this.context;
|
|
25486
|
+
const xi = this.readBits(bitsPerCoordinate);
|
|
25487
|
+
const yi = this.readBits(bitsPerCoordinate);
|
|
25488
|
+
const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 23283064365386963e-26;
|
|
25489
|
+
return [
|
|
25490
|
+
xi * scale * (decode[1] - decode[0]) + decode[0],
|
|
25491
|
+
yi * scale * (decode[3] - decode[2]) + decode[2]
|
|
25492
|
+
];
|
|
25493
|
+
}
|
|
25494
|
+
readComponents() {
|
|
25495
|
+
const { bitsPerComponent, colorFn, colorSpace, decode, numComps } = this.context;
|
|
25496
|
+
const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 23283064365386963e-26;
|
|
25497
|
+
const components = this.tmpCompsBuf;
|
|
25498
|
+
for (let i = 0, j = 4; i < numComps; i++, j += 2) {
|
|
25499
|
+
const ci = this.readBits(bitsPerComponent);
|
|
25500
|
+
components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
|
|
25501
|
+
}
|
|
25502
|
+
const color = this.tmpCsCompsBuf;
|
|
25503
|
+
colorFn?.(components, 0, color, 0);
|
|
25504
|
+
return colorSpace.getRgb(color, 0);
|
|
25505
|
+
}
|
|
25506
|
+
};
|
|
25507
|
+
var bCache = null;
|
|
25508
|
+
function getB(count) {
|
|
25509
|
+
if (bCache?.has(count)) return bCache.get(count);
|
|
25510
|
+
const values = Array.from({ length: count + 1 }, (_, i) => {
|
|
25511
|
+
const t = i / count, t_ = 1 - t;
|
|
25512
|
+
return new Float32Array([
|
|
25513
|
+
t_ ** 3,
|
|
25514
|
+
3 * t * t_ ** 2,
|
|
25515
|
+
3 * t ** 2 * t_,
|
|
25516
|
+
t ** 3
|
|
25517
|
+
]);
|
|
25518
|
+
});
|
|
25519
|
+
(bCache ??= /* @__PURE__ */ new Map()).set(count, values);
|
|
25520
|
+
return values;
|
|
25521
|
+
}
|
|
25522
|
+
var MeshShading = class _MeshShading extends BaseShading {
|
|
25523
|
+
static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
|
|
25524
|
+
static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
|
|
25525
|
+
// Count of triangles per entire mesh bounds.
|
|
25526
|
+
static TRIANGLE_DENSITY = 20;
|
|
25527
|
+
constructor(shadingType, stream, context, rowVertices) {
|
|
25528
|
+
super();
|
|
25529
|
+
this.shadingType = shadingType;
|
|
25530
|
+
this.bbox = this.background = null;
|
|
25531
|
+
this.coords = [];
|
|
25532
|
+
this.colors = [];
|
|
25533
|
+
this.figures = [];
|
|
25534
|
+
const reader = new MeshStreamReader(stream, context);
|
|
25535
|
+
let patchMesh = false;
|
|
25536
|
+
switch (this.shadingType) {
|
|
25537
|
+
case ShadingType.FREE_FORM_MESH:
|
|
25538
|
+
this._decodeType4Shading(reader);
|
|
25539
|
+
break;
|
|
25540
|
+
case ShadingType.LATTICE_FORM_MESH:
|
|
25541
|
+
const verticesPerRow = rowVertices | 0;
|
|
25542
|
+
if (verticesPerRow < 2) {
|
|
25543
|
+
throw new FormatError("Invalid VerticesPerRow");
|
|
25544
|
+
}
|
|
25545
|
+
this._decodeType5Shading(reader, verticesPerRow);
|
|
25546
|
+
break;
|
|
25547
|
+
case ShadingType.COONS_PATCH_MESH:
|
|
25548
|
+
this._decodeType6Shading(reader);
|
|
25549
|
+
patchMesh = true;
|
|
25550
|
+
break;
|
|
25551
|
+
case ShadingType.TENSOR_PATCH_MESH:
|
|
25552
|
+
this._decodeType7Shading(reader);
|
|
25553
|
+
patchMesh = true;
|
|
25554
|
+
break;
|
|
25555
|
+
default:
|
|
25556
|
+
unreachable2("Unsupported mesh type.");
|
|
25557
|
+
break;
|
|
25558
|
+
}
|
|
25559
|
+
if (patchMesh) {
|
|
25560
|
+
this._updateBounds();
|
|
25561
|
+
for (let i = 0, ii = this.figures.length; i < ii; i++) {
|
|
25562
|
+
this._buildFigureFromPatch(i);
|
|
25563
|
+
}
|
|
25564
|
+
}
|
|
25565
|
+
this._updateBounds();
|
|
25566
|
+
this._packData();
|
|
25567
|
+
}
|
|
25568
|
+
_decodeType4Shading(reader) {
|
|
25569
|
+
const coords = this.coords;
|
|
25570
|
+
const colors = this.colors;
|
|
25571
|
+
const operators = [];
|
|
25572
|
+
const ps = [];
|
|
25573
|
+
let verticesLeft = 0;
|
|
25574
|
+
while (reader.hasData) {
|
|
25575
|
+
const f = reader.readFlag();
|
|
25576
|
+
const coord = reader.readCoordinate();
|
|
25577
|
+
const color = reader.readComponents();
|
|
25578
|
+
if (verticesLeft === 0) {
|
|
25579
|
+
if (!(0 <= f && f <= 2)) {
|
|
25580
|
+
throw new FormatError("Unknown type4 flag");
|
|
25581
|
+
}
|
|
25582
|
+
switch (f) {
|
|
25583
|
+
case 0:
|
|
25584
|
+
verticesLeft = 3;
|
|
25585
|
+
break;
|
|
25586
|
+
case 1:
|
|
25587
|
+
ps.push(ps.at(-2), ps.at(-1));
|
|
25588
|
+
verticesLeft = 1;
|
|
25589
|
+
break;
|
|
25590
|
+
case 2:
|
|
25591
|
+
ps.push(ps.at(-3), ps.at(-1));
|
|
25592
|
+
verticesLeft = 1;
|
|
25593
|
+
break;
|
|
25594
|
+
}
|
|
25595
|
+
operators.push(f);
|
|
25596
|
+
}
|
|
25597
|
+
ps.push(coords.length);
|
|
25598
|
+
coords.push(coord);
|
|
25599
|
+
colors.push(color);
|
|
25600
|
+
verticesLeft--;
|
|
25601
|
+
reader.align();
|
|
25602
|
+
}
|
|
25603
|
+
this.figures.push({
|
|
25604
|
+
type: MeshFigureType.TRIANGLES,
|
|
25605
|
+
coords: new Int32Array(ps),
|
|
25606
|
+
colors: new Int32Array(ps)
|
|
25607
|
+
});
|
|
25608
|
+
}
|
|
25609
|
+
_decodeType5Shading(reader, verticesPerRow) {
|
|
25610
|
+
const coords = this.coords;
|
|
25611
|
+
const colors = this.colors;
|
|
25612
|
+
const ps = [];
|
|
25613
|
+
while (reader.hasData) {
|
|
25614
|
+
const coord = reader.readCoordinate();
|
|
25615
|
+
const color = reader.readComponents();
|
|
25616
|
+
ps.push(coords.length);
|
|
25617
|
+
coords.push(coord);
|
|
25618
|
+
colors.push(color);
|
|
25619
|
+
}
|
|
25620
|
+
this.figures.push({
|
|
25621
|
+
type: MeshFigureType.LATTICE,
|
|
25622
|
+
coords: new Int32Array(ps),
|
|
25623
|
+
colors: new Int32Array(ps),
|
|
25624
|
+
verticesPerRow
|
|
25625
|
+
});
|
|
25626
|
+
}
|
|
25627
|
+
_decodeType6Shading(reader) {
|
|
25628
|
+
const coords = this.coords;
|
|
25629
|
+
const colors = this.colors;
|
|
25630
|
+
const ps = new Int32Array(16);
|
|
25631
|
+
const cs = new Int32Array(4);
|
|
25632
|
+
while (reader.hasData) {
|
|
25633
|
+
const f = reader.readFlag();
|
|
25634
|
+
if (!(0 <= f && f <= 3)) {
|
|
25635
|
+
throw new FormatError("Unknown type6 flag");
|
|
25636
|
+
}
|
|
25637
|
+
const pi = coords.length;
|
|
25638
|
+
for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
|
|
25639
|
+
coords.push(reader.readCoordinate());
|
|
25640
|
+
}
|
|
25641
|
+
const ci = colors.length;
|
|
25642
|
+
for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
|
25643
|
+
colors.push(reader.readComponents());
|
|
25644
|
+
}
|
|
25645
|
+
let tmp1, tmp2, tmp3, tmp4;
|
|
25646
|
+
switch (f) {
|
|
25647
|
+
// prettier-ignore
|
|
25648
|
+
case 0:
|
|
25649
|
+
ps[12] = pi + 3;
|
|
25650
|
+
ps[13] = pi + 4;
|
|
25651
|
+
ps[14] = pi + 5;
|
|
25652
|
+
ps[15] = pi + 6;
|
|
25653
|
+
ps[8] = pi + 2;
|
|
25654
|
+
ps[11] = pi + 7;
|
|
25655
|
+
ps[4] = pi + 1;
|
|
25656
|
+
ps[7] = pi + 8;
|
|
25657
|
+
ps[0] = pi;
|
|
25658
|
+
ps[1] = pi + 11;
|
|
25659
|
+
ps[2] = pi + 10;
|
|
25660
|
+
ps[3] = pi + 9;
|
|
25661
|
+
cs[2] = ci + 1;
|
|
25662
|
+
cs[3] = ci + 2;
|
|
25663
|
+
cs[0] = ci;
|
|
25664
|
+
cs[1] = ci + 3;
|
|
25665
|
+
break;
|
|
25666
|
+
// prettier-ignore
|
|
25667
|
+
case 1:
|
|
25668
|
+
tmp1 = ps[12];
|
|
25669
|
+
tmp2 = ps[13];
|
|
25670
|
+
tmp3 = ps[14];
|
|
25671
|
+
tmp4 = ps[15];
|
|
25672
|
+
ps[12] = tmp4;
|
|
25673
|
+
ps[13] = pi + 0;
|
|
25674
|
+
ps[14] = pi + 1;
|
|
25675
|
+
ps[15] = pi + 2;
|
|
25676
|
+
ps[8] = tmp3;
|
|
25677
|
+
ps[11] = pi + 3;
|
|
25678
|
+
ps[4] = tmp2;
|
|
25679
|
+
ps[7] = pi + 4;
|
|
25680
|
+
ps[0] = tmp1;
|
|
25681
|
+
ps[1] = pi + 7;
|
|
25682
|
+
ps[2] = pi + 6;
|
|
25683
|
+
ps[3] = pi + 5;
|
|
25684
|
+
tmp1 = cs[2];
|
|
25685
|
+
tmp2 = cs[3];
|
|
25686
|
+
cs[2] = tmp2;
|
|
25687
|
+
cs[3] = ci;
|
|
25688
|
+
cs[0] = tmp1;
|
|
25689
|
+
cs[1] = ci + 1;
|
|
25690
|
+
break;
|
|
25691
|
+
// prettier-ignore
|
|
25692
|
+
case 2:
|
|
25693
|
+
tmp1 = ps[15];
|
|
25694
|
+
tmp2 = ps[11];
|
|
25695
|
+
ps[12] = ps[3];
|
|
25696
|
+
ps[13] = pi + 0;
|
|
25697
|
+
ps[14] = pi + 1;
|
|
25698
|
+
ps[15] = pi + 2;
|
|
25699
|
+
ps[8] = ps[7];
|
|
25700
|
+
ps[11] = pi + 3;
|
|
25701
|
+
ps[4] = tmp2;
|
|
25702
|
+
ps[7] = pi + 4;
|
|
25703
|
+
ps[0] = tmp1;
|
|
25704
|
+
ps[1] = pi + 7;
|
|
25705
|
+
ps[2] = pi + 6;
|
|
25706
|
+
ps[3] = pi + 5;
|
|
25707
|
+
tmp1 = cs[3];
|
|
25708
|
+
cs[2] = cs[1];
|
|
25709
|
+
cs[3] = ci;
|
|
25710
|
+
cs[0] = tmp1;
|
|
25711
|
+
cs[1] = ci + 1;
|
|
25712
|
+
break;
|
|
25713
|
+
// prettier-ignore
|
|
25714
|
+
case 3:
|
|
25715
|
+
ps[12] = ps[0];
|
|
25716
|
+
ps[13] = pi + 0;
|
|
25717
|
+
ps[14] = pi + 1;
|
|
25718
|
+
ps[15] = pi + 2;
|
|
25719
|
+
ps[8] = ps[1];
|
|
25720
|
+
ps[11] = pi + 3;
|
|
25721
|
+
ps[4] = ps[2];
|
|
25722
|
+
ps[7] = pi + 4;
|
|
25723
|
+
ps[0] = ps[3];
|
|
25724
|
+
ps[1] = pi + 7;
|
|
25725
|
+
ps[2] = pi + 6;
|
|
25726
|
+
ps[3] = pi + 5;
|
|
25727
|
+
cs[2] = cs[0];
|
|
25728
|
+
cs[3] = ci;
|
|
25729
|
+
cs[0] = cs[1];
|
|
25730
|
+
cs[1] = ci + 1;
|
|
25731
|
+
break;
|
|
25732
|
+
}
|
|
25733
|
+
ps[5] = coords.length;
|
|
25734
|
+
coords.push([
|
|
25735
|
+
(-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,
|
|
25736
|
+
(-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
|
|
25737
|
+
]);
|
|
25738
|
+
ps[6] = coords.length;
|
|
25739
|
+
coords.push([
|
|
25740
|
+
(-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,
|
|
25741
|
+
(-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
|
|
25742
|
+
]);
|
|
25743
|
+
ps[9] = coords.length;
|
|
25744
|
+
coords.push([
|
|
25745
|
+
(-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,
|
|
25746
|
+
(-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
|
|
25747
|
+
]);
|
|
25748
|
+
ps[10] = coords.length;
|
|
25749
|
+
coords.push([
|
|
25750
|
+
(-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,
|
|
25751
|
+
(-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
|
|
25752
|
+
]);
|
|
25753
|
+
this.figures.push({
|
|
25754
|
+
type: MeshFigureType.PATCH,
|
|
25755
|
+
coords: new Int32Array(ps),
|
|
25756
|
+
// making copies of ps and cs
|
|
25757
|
+
colors: new Int32Array(cs)
|
|
25758
|
+
});
|
|
25759
|
+
}
|
|
25760
|
+
}
|
|
25761
|
+
_decodeType7Shading(reader) {
|
|
25762
|
+
const coords = this.coords;
|
|
25763
|
+
const colors = this.colors;
|
|
25764
|
+
const ps = new Int32Array(16);
|
|
25765
|
+
const cs = new Int32Array(4);
|
|
25766
|
+
while (reader.hasData) {
|
|
25767
|
+
const f = reader.readFlag();
|
|
25768
|
+
if (!(0 <= f && f <= 3)) {
|
|
25769
|
+
throw new FormatError("Unknown type7 flag");
|
|
25770
|
+
}
|
|
25771
|
+
const pi = coords.length;
|
|
25772
|
+
for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
|
|
25773
|
+
coords.push(reader.readCoordinate());
|
|
25774
|
+
}
|
|
25775
|
+
const ci = colors.length;
|
|
25776
|
+
for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
|
25777
|
+
colors.push(reader.readComponents());
|
|
25778
|
+
}
|
|
25779
|
+
let tmp1, tmp2, tmp3, tmp4;
|
|
25780
|
+
switch (f) {
|
|
25781
|
+
// prettier-ignore
|
|
25782
|
+
case 0:
|
|
25783
|
+
ps[12] = pi + 3;
|
|
25784
|
+
ps[13] = pi + 4;
|
|
25785
|
+
ps[14] = pi + 5;
|
|
25786
|
+
ps[15] = pi + 6;
|
|
25787
|
+
ps[8] = pi + 2;
|
|
25788
|
+
ps[9] = pi + 13;
|
|
25789
|
+
ps[10] = pi + 14;
|
|
25790
|
+
ps[11] = pi + 7;
|
|
25791
|
+
ps[4] = pi + 1;
|
|
25792
|
+
ps[5] = pi + 12;
|
|
25793
|
+
ps[6] = pi + 15;
|
|
25794
|
+
ps[7] = pi + 8;
|
|
25795
|
+
ps[0] = pi;
|
|
25796
|
+
ps[1] = pi + 11;
|
|
25797
|
+
ps[2] = pi + 10;
|
|
25798
|
+
ps[3] = pi + 9;
|
|
25799
|
+
cs[2] = ci + 1;
|
|
25800
|
+
cs[3] = ci + 2;
|
|
25801
|
+
cs[0] = ci;
|
|
25802
|
+
cs[1] = ci + 3;
|
|
25803
|
+
break;
|
|
25804
|
+
// prettier-ignore
|
|
25805
|
+
case 1:
|
|
25806
|
+
tmp1 = ps[12];
|
|
25807
|
+
tmp2 = ps[13];
|
|
25808
|
+
tmp3 = ps[14];
|
|
25809
|
+
tmp4 = ps[15];
|
|
25810
|
+
ps[12] = tmp4;
|
|
25811
|
+
ps[13] = pi + 0;
|
|
25812
|
+
ps[14] = pi + 1;
|
|
25813
|
+
ps[15] = pi + 2;
|
|
25814
|
+
ps[8] = tmp3;
|
|
25815
|
+
ps[9] = pi + 9;
|
|
25816
|
+
ps[10] = pi + 10;
|
|
25817
|
+
ps[11] = pi + 3;
|
|
25818
|
+
ps[4] = tmp2;
|
|
25819
|
+
ps[5] = pi + 8;
|
|
25820
|
+
ps[6] = pi + 11;
|
|
25821
|
+
ps[7] = pi + 4;
|
|
25822
|
+
ps[0] = tmp1;
|
|
25823
|
+
ps[1] = pi + 7;
|
|
25824
|
+
ps[2] = pi + 6;
|
|
25825
|
+
ps[3] = pi + 5;
|
|
25826
|
+
tmp1 = cs[2];
|
|
25827
|
+
tmp2 = cs[3];
|
|
25828
|
+
cs[2] = tmp2;
|
|
25829
|
+
cs[3] = ci;
|
|
25830
|
+
cs[0] = tmp1;
|
|
25831
|
+
cs[1] = ci + 1;
|
|
25832
|
+
break;
|
|
25833
|
+
// prettier-ignore
|
|
25834
|
+
case 2:
|
|
25835
|
+
tmp1 = ps[15];
|
|
25836
|
+
tmp2 = ps[11];
|
|
25837
|
+
ps[12] = ps[3];
|
|
25838
|
+
ps[13] = pi + 0;
|
|
25839
|
+
ps[14] = pi + 1;
|
|
25840
|
+
ps[15] = pi + 2;
|
|
25841
|
+
ps[8] = ps[7];
|
|
25842
|
+
ps[9] = pi + 9;
|
|
25843
|
+
ps[10] = pi + 10;
|
|
25844
|
+
ps[11] = pi + 3;
|
|
25845
|
+
ps[4] = tmp2;
|
|
25846
|
+
ps[5] = pi + 8;
|
|
25847
|
+
ps[6] = pi + 11;
|
|
25848
|
+
ps[7] = pi + 4;
|
|
25849
|
+
ps[0] = tmp1;
|
|
25850
|
+
ps[1] = pi + 7;
|
|
25851
|
+
ps[2] = pi + 6;
|
|
25852
|
+
ps[3] = pi + 5;
|
|
25853
|
+
tmp1 = cs[3];
|
|
25854
|
+
cs[2] = cs[1];
|
|
25855
|
+
cs[3] = ci;
|
|
25856
|
+
cs[0] = tmp1;
|
|
25857
|
+
cs[1] = ci + 1;
|
|
25858
|
+
break;
|
|
25859
|
+
// prettier-ignore
|
|
25860
|
+
case 3:
|
|
25861
|
+
ps[12] = ps[0];
|
|
25862
|
+
ps[13] = pi + 0;
|
|
25863
|
+
ps[14] = pi + 1;
|
|
25864
|
+
ps[15] = pi + 2;
|
|
25865
|
+
ps[8] = ps[1];
|
|
25866
|
+
ps[9] = pi + 9;
|
|
25867
|
+
ps[10] = pi + 10;
|
|
25868
|
+
ps[11] = pi + 3;
|
|
25869
|
+
ps[4] = ps[2];
|
|
25870
|
+
ps[5] = pi + 8;
|
|
25871
|
+
ps[6] = pi + 11;
|
|
25872
|
+
ps[7] = pi + 4;
|
|
25873
|
+
ps[0] = ps[3];
|
|
25874
|
+
ps[1] = pi + 7;
|
|
25875
|
+
ps[2] = pi + 6;
|
|
25876
|
+
ps[3] = pi + 5;
|
|
25877
|
+
cs[2] = cs[0];
|
|
25878
|
+
cs[3] = ci;
|
|
25879
|
+
cs[0] = cs[1];
|
|
25880
|
+
cs[1] = ci + 1;
|
|
25881
|
+
break;
|
|
25882
|
+
}
|
|
25883
|
+
this.figures.push({
|
|
25884
|
+
type: MeshFigureType.PATCH,
|
|
25885
|
+
coords: new Int32Array(ps),
|
|
25886
|
+
// making copies of ps and cs
|
|
25887
|
+
colors: new Int32Array(cs)
|
|
25888
|
+
});
|
|
25889
|
+
}
|
|
25890
|
+
}
|
|
25891
|
+
_buildFigureFromPatch(index) {
|
|
25892
|
+
const figure = this.figures[index];
|
|
25893
|
+
assert2(
|
|
25894
|
+
figure.type === MeshFigureType.PATCH,
|
|
25895
|
+
"Unexpected patch mesh figure"
|
|
25896
|
+
);
|
|
25897
|
+
const coords = this.coords, colors = this.colors;
|
|
25898
|
+
const pi = figure.coords;
|
|
25899
|
+
const ci = figure.colors;
|
|
25900
|
+
const figureMinX = Math.min(
|
|
25901
|
+
coords[pi[0]][0],
|
|
25902
|
+
coords[pi[3]][0],
|
|
25903
|
+
coords[pi[12]][0],
|
|
25904
|
+
coords[pi[15]][0]
|
|
25905
|
+
);
|
|
25906
|
+
const figureMinY = Math.min(
|
|
25907
|
+
coords[pi[0]][1],
|
|
25908
|
+
coords[pi[3]][1],
|
|
25909
|
+
coords[pi[12]][1],
|
|
25910
|
+
coords[pi[15]][1]
|
|
25911
|
+
);
|
|
25912
|
+
const figureMaxX = Math.max(
|
|
25913
|
+
coords[pi[0]][0],
|
|
25914
|
+
coords[pi[3]][0],
|
|
25915
|
+
coords[pi[12]][0],
|
|
25916
|
+
coords[pi[15]][0]
|
|
25917
|
+
);
|
|
25918
|
+
const figureMaxY = Math.max(
|
|
25919
|
+
coords[pi[0]][1],
|
|
25920
|
+
coords[pi[3]][1],
|
|
25921
|
+
coords[pi[12]][1],
|
|
25922
|
+
coords[pi[15]][1]
|
|
25923
|
+
);
|
|
25924
|
+
let splitXBy = Math.ceil(
|
|
25925
|
+
(figureMaxX - figureMinX) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])
|
|
25926
|
+
);
|
|
25927
|
+
splitXBy = MathClamp(
|
|
25928
|
+
splitXBy,
|
|
25929
|
+
_MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
|
25930
|
+
_MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
|
|
25931
|
+
);
|
|
25932
|
+
let splitYBy = Math.ceil(
|
|
25933
|
+
(figureMaxY - figureMinY) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])
|
|
25934
|
+
);
|
|
25935
|
+
splitYBy = MathClamp(
|
|
25936
|
+
splitYBy,
|
|
25937
|
+
_MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
|
25938
|
+
_MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
|
|
25939
|
+
);
|
|
25940
|
+
const verticesPerRow = splitXBy + 1;
|
|
25941
|
+
const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
|
|
25942
|
+
const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
|
|
25943
|
+
let k = 0;
|
|
25944
|
+
const cl = new Uint8Array(3), cr = new Uint8Array(3);
|
|
25945
|
+
const c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
|
|
25946
|
+
const bRow = getB(splitYBy), bCol = getB(splitXBy);
|
|
25947
|
+
for (let row = 0; row <= splitYBy; row++) {
|
|
25948
|
+
cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
|
|
25949
|
+
cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
|
|
25950
|
+
cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
|
|
25951
|
+
cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
|
|
25952
|
+
cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
|
|
25953
|
+
cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
|
|
25954
|
+
for (let col = 0; col <= splitXBy; col++, k++) {
|
|
25955
|
+
if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
|
|
25956
|
+
continue;
|
|
25957
|
+
}
|
|
25958
|
+
let x = 0, y = 0;
|
|
25959
|
+
let q = 0;
|
|
25960
|
+
for (let i = 0; i <= 3; i++) {
|
|
25961
|
+
for (let j = 0; j <= 3; j++, q++) {
|
|
25962
|
+
const m = bRow[row][i] * bCol[col][j];
|
|
25963
|
+
x += coords[pi[q]][0] * m;
|
|
25964
|
+
y += coords[pi[q]][1] * m;
|
|
25965
|
+
}
|
|
25966
|
+
}
|
|
25967
|
+
figureCoords[k] = coords.length;
|
|
25968
|
+
coords.push([x, y]);
|
|
25969
|
+
figureColors[k] = colors.length;
|
|
25970
|
+
const newColor = new Uint8Array(3);
|
|
25971
|
+
newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
|
|
25972
|
+
newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
|
|
25973
|
+
newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
|
|
25974
|
+
colors.push(newColor);
|
|
25975
|
+
}
|
|
25976
|
+
}
|
|
25977
|
+
figureCoords[0] = pi[0];
|
|
25978
|
+
figureColors[0] = ci[0];
|
|
25979
|
+
figureCoords[splitXBy] = pi[3];
|
|
25980
|
+
figureColors[splitXBy] = ci[1];
|
|
25981
|
+
figureCoords[verticesPerRow * splitYBy] = pi[12];
|
|
25982
|
+
figureColors[verticesPerRow * splitYBy] = ci[2];
|
|
25983
|
+
figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
|
|
25984
|
+
figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
|
|
25985
|
+
this.figures[index] = {
|
|
25986
|
+
type: MeshFigureType.LATTICE,
|
|
25987
|
+
coords: figureCoords,
|
|
25988
|
+
colors: figureColors,
|
|
25989
|
+
verticesPerRow
|
|
25990
|
+
};
|
|
25991
|
+
}
|
|
25992
|
+
_updateBounds() {
|
|
25993
|
+
meshUpdateBounds(this);
|
|
25994
|
+
}
|
|
25995
|
+
_packData() {
|
|
25996
|
+
meshPackData(this);
|
|
25997
|
+
}
|
|
25998
|
+
getIR() {
|
|
25999
|
+
const { posData, colData, vertexCount } = buildMeshVertexData(
|
|
26000
|
+
this.coords,
|
|
26001
|
+
this.colors,
|
|
26002
|
+
this.figures
|
|
26003
|
+
);
|
|
26004
|
+
return [
|
|
26005
|
+
"Mesh",
|
|
26006
|
+
this.shadingType,
|
|
26007
|
+
posData,
|
|
26008
|
+
colData,
|
|
26009
|
+
vertexCount,
|
|
26010
|
+
this.bounds,
|
|
26011
|
+
this.bbox,
|
|
26012
|
+
this.background
|
|
26013
|
+
];
|
|
26014
|
+
}
|
|
26015
|
+
};
|
|
25317
26016
|
var PdfError = class extends Error {
|
|
25318
26017
|
constructor(code, message) {
|
|
25319
26018
|
super(message);
|
|
@@ -28219,11 +28918,16 @@ function parseDictionaryStream(dictNode, lexer, bytes) {
|
|
|
28219
28918
|
let streamEnd = streamStart;
|
|
28220
28919
|
if (resolvedLength !== void 0 && resolvedLength >= 0 && streamStart + resolvedLength <= bytes.length) {
|
|
28221
28920
|
const candidateEnd = streamStart + resolvedLength;
|
|
28222
|
-
const
|
|
28223
|
-
|
|
28224
|
-
|
|
28921
|
+
const tailLexer = new CosByteLexer(bytes, candidateEnd);
|
|
28922
|
+
let endToken;
|
|
28923
|
+
try {
|
|
28924
|
+
endToken = tailLexer.nextToken();
|
|
28925
|
+
} catch (error) {
|
|
28926
|
+
if (!(error instanceof PdfError) || error.code !== "E_PARSE") throw error;
|
|
28927
|
+
}
|
|
28928
|
+
if (endToken?.kind === "keyword" && endToken.value === "endstream") {
|
|
28225
28929
|
rawStreamBytes = bytes.subarray(streamStart, candidateEnd);
|
|
28226
|
-
streamEnd =
|
|
28930
|
+
streamEnd = tailLexer.offset;
|
|
28227
28931
|
}
|
|
28228
28932
|
}
|
|
28229
28933
|
if (!rawStreamBytes) {
|
|
@@ -37936,143 +38640,28 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
37936
38640
|
const r = doc.resolve(it);
|
|
37937
38641
|
return r?.kind === "number" ? r.value : 0;
|
|
37938
38642
|
});
|
|
37939
|
-
const xmin = decodeNums[0], xmax = decodeNums[1], ymin = decodeNums[2], ymax = decodeNums[3];
|
|
37940
|
-
const numColorParams = Math.max(1, Math.floor((decodeNums.length - 4) / 2));
|
|
37941
38643
|
const fnNode = dictGet(shDict, "Function");
|
|
37942
38644
|
const csNode = doc.resolve(dictGet(shDict, "ColorSpace"));
|
|
37943
38645
|
const csName = csNode?.kind === "name" ? csNode.decoded : "DeviceRGB";
|
|
37944
|
-
|
|
37945
|
-
const
|
|
37946
|
-
|
|
37947
|
-
|
|
37948
|
-
|
|
37949
|
-
|
|
37950
|
-
|
|
37951
|
-
|
|
37952
|
-
|
|
37953
|
-
|
|
37954
|
-
|
|
37955
|
-
|
|
37956
|
-
|
|
37957
|
-
|
|
37958
|
-
|
|
37959
|
-
|
|
37960
|
-
|
|
37961
|
-
|
|
37962
|
-
|
|
37963
|
-
};
|
|
37964
|
-
const readColorRgb = () => {
|
|
37965
|
-
const params = [];
|
|
37966
|
-
for (let c = 0; c < numColorParams; c++) {
|
|
37967
|
-
const rc = readBits(bpcComp) / compMax;
|
|
37968
|
-
const cMin = decodeNums[4 + c * 2] ?? 0;
|
|
37969
|
-
const cMax = decodeNums[4 + c * 2 + 1] ?? 1;
|
|
37970
|
-
params.push(cMin + rc * (cMax - cMin));
|
|
37971
|
-
}
|
|
37972
|
-
const comps = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
|
|
37973
|
-
return convertColorSpaceComponentsToRgb(doc, csNode, csName, comps);
|
|
37974
|
-
};
|
|
37975
|
-
const triangles = [];
|
|
37976
|
-
if (shType === 4) {
|
|
37977
|
-
const minBitsPerVert = bpcFlag + 2 * bpcCoord + numColorParams * bpcComp;
|
|
37978
|
-
let triVerts;
|
|
37979
|
-
while (bitPos + minBitsPerVert <= totalBits) {
|
|
37980
|
-
const flag = readBits(bpcFlag) & 3;
|
|
37981
|
-
const [x, y] = readCoord();
|
|
37982
|
-
const rgb2 = readColorRgb();
|
|
37983
|
-
const vNew = { x, y, rgb: rgb2 };
|
|
37984
|
-
if (flag === 0 || !triVerts) {
|
|
37985
|
-
if (bitPos + 2 * minBitsPerVert > totalBits) break;
|
|
37986
|
-
readBits(bpcFlag);
|
|
37987
|
-
const [x1, y1] = readCoord();
|
|
37988
|
-
const rgb1 = readColorRgb();
|
|
37989
|
-
readBits(bpcFlag);
|
|
37990
|
-
const [x2, y2] = readCoord();
|
|
37991
|
-
const rgb22 = readColorRgb();
|
|
37992
|
-
triVerts = [vNew, { x: x1, y: y1, rgb: rgb1 }, { x: x2, y: y2, rgb: rgb22 }];
|
|
37993
|
-
triangles.push(triVerts);
|
|
37994
|
-
} else if (flag === 1) {
|
|
37995
|
-
triVerts = [triVerts[1], triVerts[2], vNew];
|
|
37996
|
-
triangles.push(triVerts);
|
|
37997
|
-
} else if (flag === 2) {
|
|
37998
|
-
triVerts = [triVerts[0], triVerts[2], vNew];
|
|
37999
|
-
triangles.push(triVerts);
|
|
38000
|
-
}
|
|
38001
|
-
}
|
|
38002
|
-
} else if (shType === 5) {
|
|
38003
|
-
const minBitsPerVert = 2 * bpcCoord + numColorParams * bpcComp;
|
|
38004
|
-
const verts = [];
|
|
38005
|
-
while (bitPos + minBitsPerVert <= totalBits) {
|
|
38006
|
-
const [x, y] = readCoord();
|
|
38007
|
-
const rgb2 = readColorRgb();
|
|
38008
|
-
verts.push({ x, y, rgb: rgb2 });
|
|
38009
|
-
}
|
|
38010
|
-
const numRows = Math.floor(verts.length / vPerRow);
|
|
38011
|
-
for (let r = 0; r + 1 < numRows; r++) {
|
|
38012
|
-
for (let c = 0; c + 1 < vPerRow; c++) {
|
|
38013
|
-
const v00 = verts[r * vPerRow + c];
|
|
38014
|
-
const v01 = verts[r * vPerRow + c + 1];
|
|
38015
|
-
const v11 = verts[(r + 1) * vPerRow + c + 1];
|
|
38016
|
-
const v10 = verts[(r + 1) * vPerRow + c];
|
|
38017
|
-
triangles.push([v00, v01, v11], [v00, v11, v10]);
|
|
38018
|
-
}
|
|
38019
|
-
}
|
|
38020
|
-
} else if (shType === 6 || shType === 7) {
|
|
38021
|
-
const numCtrl = shType === 6 ? 12 : 16;
|
|
38022
|
-
const minBitsPatch = bpcFlag + (numCtrl - 4) * 2 * bpcCoord + 2 * numColorParams * bpcComp;
|
|
38023
|
-
let prevPts;
|
|
38024
|
-
let prevColors;
|
|
38025
|
-
while (bitPos + minBitsPatch <= totalBits) {
|
|
38026
|
-
const flag = readBits(bpcFlag) & 3;
|
|
38027
|
-
let pts = [];
|
|
38028
|
-
let cols = [];
|
|
38029
|
-
if (flag === 0 || !prevPts || !prevColors) {
|
|
38030
|
-
for (let i = 0; i < numCtrl; i++) pts.push(readCoord());
|
|
38031
|
-
for (let i = 0; i < 4; i++) cols.push(readColorRgb());
|
|
38032
|
-
} else {
|
|
38033
|
-
const extraCtrl = numCtrl - 4;
|
|
38034
|
-
const readExtra = [];
|
|
38035
|
-
for (let i = 0; i < extraCtrl; i++) readExtra.push(readCoord());
|
|
38036
|
-
const c2 = readColorRgb();
|
|
38037
|
-
const c3 = readColorRgb();
|
|
38038
|
-
pts = [prevPts[3], prevPts[4], prevPts[5], prevPts[6], ...readExtra];
|
|
38039
|
-
cols = [prevColors[1], prevColors[2], c2, c3];
|
|
38040
|
-
}
|
|
38041
|
-
prevPts = pts;
|
|
38042
|
-
prevColors = cols;
|
|
38043
|
-
const p00 = pts[0];
|
|
38044
|
-
const p03 = pts[3];
|
|
38045
|
-
const p33 = pts[6];
|
|
38046
|
-
const p30 = pts[9];
|
|
38047
|
-
const c00 = cols[0], c03 = cols[1], c33 = cols[2], c30 = cols[3];
|
|
38048
|
-
const steps = 4;
|
|
38049
|
-
const grid = [];
|
|
38050
|
-
for (let iu = 0; iu <= steps; iu++) {
|
|
38051
|
-
const u = iu / steps;
|
|
38052
|
-
const row = [];
|
|
38053
|
-
for (let iv = 0; iv <= steps; iv++) {
|
|
38054
|
-
const v = iv / steps;
|
|
38055
|
-
const x = (1 - u) * (1 - v) * p00[0] + (1 - u) * v * p03[0] + u * v * p33[0] + u * (1 - v) * p30[0];
|
|
38056
|
-
const y = (1 - u) * (1 - v) * p00[1] + (1 - u) * v * p03[1] + u * v * p33[1] + u * (1 - v) * p30[1];
|
|
38057
|
-
const r = (1 - u) * (1 - v) * c00[0] + (1 - u) * v * c03[0] + u * v * c33[0] + u * (1 - v) * c30[0];
|
|
38058
|
-
const g = (1 - u) * (1 - v) * c00[1] + (1 - u) * v * c03[1] + u * v * c33[1] + u * (1 - v) * c30[1];
|
|
38059
|
-
const b = (1 - u) * (1 - v) * c00[2] + (1 - u) * v * c03[2] + u * v * c33[2] + u * (1 - v) * c30[2];
|
|
38060
|
-
row.push({ x, y, rgb: [r, g, b] });
|
|
38061
|
-
}
|
|
38062
|
-
grid.push(row);
|
|
38063
|
-
}
|
|
38064
|
-
for (let iu = 0; iu < steps; iu++) {
|
|
38065
|
-
for (let iv = 0; iv < steps; iv++) {
|
|
38066
|
-
const g00 = grid[iu][iv];
|
|
38067
|
-
const g01 = grid[iu][iv + 1];
|
|
38068
|
-
const g11 = grid[iu + 1][iv + 1];
|
|
38069
|
-
const g10 = grid[iu + 1][iv];
|
|
38070
|
-
triangles.push([g00, g01, g11], [g00, g11, g10]);
|
|
38071
|
-
}
|
|
38072
|
-
}
|
|
38073
|
-
}
|
|
38074
|
-
}
|
|
38075
|
-
if (triangles.length === 0) return void 0;
|
|
38646
|
+
const numComps = fnNode ? 1 : getColorSpaceComponentCount(doc, csNode);
|
|
38647
|
+
const mesh = new MeshShading(shType, new Stream(bytes), {
|
|
38648
|
+
bitsPerCoordinate: bpcCoord,
|
|
38649
|
+
bitsPerComponent: bpcComp,
|
|
38650
|
+
bitsPerFlag: bpcFlag,
|
|
38651
|
+
decode: decodeNums,
|
|
38652
|
+
numComps,
|
|
38653
|
+
colorFn: null,
|
|
38654
|
+
colorSpace: {
|
|
38655
|
+
numComps,
|
|
38656
|
+
getRgb(components) {
|
|
38657
|
+
const params = Array.from(components);
|
|
38658
|
+
const values = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
|
|
38659
|
+
return new Uint8Array(convertColorSpaceComponentsToRgb(doc, csNode, csName, values).map((value) => Math.round(Math.max(0, Math.min(1, value)) * 255)));
|
|
38660
|
+
}
|
|
38661
|
+
}
|
|
38662
|
+
}, vPerRow);
|
|
38663
|
+
const [, , positions, colors, vertexCount] = mesh.getIR();
|
|
38664
|
+
if (vertexCount === 0) return void 0;
|
|
38076
38665
|
const [bx0, by0, bx1, by1] = targetBox;
|
|
38077
38666
|
const boxW = Math.max(1, bx1 - bx0);
|
|
38078
38667
|
const boxH = Math.max(1, by1 - by0);
|
|
@@ -38084,10 +38673,10 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
38084
38673
|
const [px, py] = transformPoint(effectiveCtm, vx, vy);
|
|
38085
38674
|
return [(px - bx0) / boxW * imgW, (by1 - py) / boxH * imgH];
|
|
38086
38675
|
};
|
|
38087
|
-
for (
|
|
38088
|
-
const [x0, y0] = toImgCoords(
|
|
38089
|
-
const [x1, y1] = toImgCoords(
|
|
38090
|
-
const [x2, y2] = toImgCoords(
|
|
38676
|
+
for (let vertex = 0; vertex < vertexCount; vertex += 3) {
|
|
38677
|
+
const [x0, y0] = toImgCoords(positions[vertex * 2], positions[vertex * 2 + 1]);
|
|
38678
|
+
const [x1, y1] = toImgCoords(positions[vertex * 2 + 2], positions[vertex * 2 + 3]);
|
|
38679
|
+
const [x2, y2] = toImgCoords(positions[vertex * 2 + 4], positions[vertex * 2 + 5]);
|
|
38091
38680
|
const denom = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2);
|
|
38092
38681
|
if (Math.abs(denom) < 1e-6) continue;
|
|
38093
38682
|
const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
|
|
@@ -38102,13 +38691,12 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
38102
38691
|
const w1 = ((y2 - y0) * (px - x2) + (x0 - x2) * (py - y2)) / denom;
|
|
38103
38692
|
const w2 = 1 - w0 - w1;
|
|
38104
38693
|
if (w0 >= -1e-4 && w1 >= -1e-4 && w2 >= -1e-4) {
|
|
38105
|
-
const r = w0 * v0.rgb[0] + w1 * v1.rgb[0] + w2 * v2.rgb[0];
|
|
38106
|
-
const g = w0 * v0.rgb[1] + w1 * v1.rgb[1] + w2 * v2.rgb[1];
|
|
38107
|
-
const b = w0 * v0.rgb[2] + w1 * v1.rgb[2] + w2 * v2.rgb[2];
|
|
38108
38694
|
const pIdx = (iy * imgW + ix) * 4;
|
|
38109
|
-
|
|
38110
|
-
|
|
38111
|
-
|
|
38695
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
38696
|
+
rgba[pIdx + channel] = Math.round(
|
|
38697
|
+
w0 * colors[vertex * 4 + channel] + w1 * colors[vertex * 4 + 4 + channel] + w2 * colors[vertex * 4 + 8 + channel]
|
|
38698
|
+
);
|
|
38699
|
+
}
|
|
38112
38700
|
rgba[pIdx + 3] = a8;
|
|
38113
38701
|
}
|
|
38114
38702
|
}
|
|
@@ -38195,6 +38783,8 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
|
|
|
38195
38783
|
const [a, b, c, d, e, f] = effectiveCtm;
|
|
38196
38784
|
const det = a * d - b * c;
|
|
38197
38785
|
if (Math.abs(det) <= 1e-8) return void 0;
|
|
38786
|
+
const [sa, sb, sc, sd, se, sf] = shadingCtm;
|
|
38787
|
+
const shadingDet = sa * sd - sb * sc;
|
|
38198
38788
|
const t0Dom = shDomain[0] ?? 0;
|
|
38199
38789
|
const t1Dom = shDomain[1] ?? 1;
|
|
38200
38790
|
for (let iy = 0; iy < imgH; iy++) {
|
|
@@ -38205,8 +38795,10 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
|
|
|
38205
38795
|
const dxPdf = xPdf - e;
|
|
38206
38796
|
const xs = (d * dxPdf - c * dyPdf) / det;
|
|
38207
38797
|
const ys = (-b * dxPdf + a * dyPdf) / det;
|
|
38208
|
-
if (shBBox
|
|
38209
|
-
|
|
38798
|
+
if (shBBox) {
|
|
38799
|
+
const bboxX = (sd * (xPdf - se) - sc * (yPdf - sf)) / shadingDet;
|
|
38800
|
+
const bboxY = (-sb * (xPdf - se) + sa * (yPdf - sf)) / shadingDet;
|
|
38801
|
+
if (bboxX < shBBox[0] || bboxX > shBBox[2] || bboxY < shBBox[1] || bboxY > shBBox[3]) continue;
|
|
38210
38802
|
}
|
|
38211
38803
|
let comps;
|
|
38212
38804
|
if (shType === 1) {
|