@poe-platform/safe-bash 0.1.773 → 0.1.775

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.
Files changed (31) hide show
  1. package/dist/image-ast/index.browser.js +754 -162
  2. package/dist/image-ast/index.js +754 -162
  3. package/dist/pdf-ast/index.js +754 -162
  4. package/dist/pdf-ast/vendor/pdfjs-fonts.d.mts +12 -0
  5. package/dist/pdf-ast/vendor/pdfjs-fonts.mjs +702 -0
  6. package/dist/safe-bash/command-chunks/{chunk-B2MM5DIT.js → chunk-3444RZLY.js} +754 -162
  7. package/dist/safe-bash/command-chunks/{chunk-G3NVK25P.js → chunk-QLYJUVVM.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-5VXZSNM2.js → chunk-ZY6PMCW5.js} +2 -2
  9. package/dist/safe-bash/core.browser.js +63 -7
  10. package/dist/safe-bash/shell/runtime.js +17 -9
  11. package/dist/safe-bash/shell/sync-posix-regex.d.ts +3 -0
  12. package/dist/safe-bash/shell/sync-posix-regex.js +48 -0
  13. package/dist/safe-bash-command-ffmpeg/index.js +7249 -7039
  14. package/dist/safe-bash-command-gpg/index.js +28 -7
  15. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  16. package/dist/safe-bash-command-openssl/index.js +24 -6
  17. package/dist/safe-bash-command-pandoc/command.js +3 -3
  18. package/dist/safe-bash-command-pandoc/index.js +3 -3
  19. package/dist/safe-bash-command-pdfimages/index.js +754 -162
  20. package/dist/safe-bash-command-pdfinfo/index.js +754 -162
  21. package/dist/safe-bash-command-pdftk/index.js +754 -162
  22. package/dist/safe-bash-command-pdftoppm/index.js +754 -162
  23. package/dist/safe-bash-command-pdftotext/index.js +754 -162
  24. package/dist/safe-bash-command-qpdf/index.js +754 -162
  25. package/dist/safe-bash-command-sips/index.js +2 -2
  26. package/dist/safe-bash-command-soffice/index.js +1 -1
  27. package/dist/safe-bash-command-ssconvert/index.js +754 -162
  28. package/dist/safe-bash-command-ssh/index.js +124 -23
  29. package/dist/safe-bash-command-wkhtmltopdf/index.js +760 -162
  30. package/package.json +2 -2
  31. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +29 -0
@@ -3578,6 +3578,11 @@ var FONT_IDENTITY_MATRIX = [1e-3, 0, 0, 1e-3, 0, 0];
3578
3578
  var LINE_FACTOR = 1.35;
3579
3579
  var LINE_DESCENT_FACTOR = 0.35;
3580
3580
  var BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
3581
+ var MeshFigureType = {
3582
+ TRIANGLES: 1,
3583
+ LATTICE: 2,
3584
+ PATCH: 3
3585
+ };
3581
3586
  var VerbosityLevel = {
3582
3587
  ERRORS: 0,
3583
3588
  WARNINGS: 1,
@@ -25304,6 +25309,700 @@ function buildPostScriptJsFunction(source, domain, range, forceInterpreter = fal
25304
25309
  }
25305
25310
  return PSStackBasedInterpreter.build(program, domain, range);
25306
25311
  }
25312
+ var ShadingType = {
25313
+ FUNCTION_BASED: 1,
25314
+ AXIAL: 2,
25315
+ RADIAL: 3,
25316
+ FREE_FORM_MESH: 4,
25317
+ LATTICE_FORM_MESH: 5,
25318
+ COONS_PATCH_MESH: 6,
25319
+ TENSOR_PATCH_MESH: 7
25320
+ };
25321
+ var BaseShading = class _BaseShading {
25322
+ // A small number to offset the first/last color stops so we can insert ones
25323
+ // to support extend. Number.MIN_VALUE is too small and breaks the extend.
25324
+ static SMALL_NUMBER = 1e-6;
25325
+ constructor() {
25326
+ if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === _BaseShading) {
25327
+ unreachable2("Cannot initialize BaseShading.");
25328
+ }
25329
+ }
25330
+ getIR() {
25331
+ unreachable2("Abstract method `getIR` called.");
25332
+ }
25333
+ };
25334
+ function meshUpdateBounds(self) {
25335
+ let minX = self.coords[0][0], minY = self.coords[0][1], maxX = minX, maxY = minY;
25336
+ for (let i = 1, ii = self.coords.length; i < ii; i++) {
25337
+ const x = self.coords[i][0], y = self.coords[i][1];
25338
+ minX = minX > x ? x : minX;
25339
+ minY = minY > y ? y : minY;
25340
+ maxX = maxX < x ? x : maxX;
25341
+ maxY = maxY < y ? y : maxY;
25342
+ }
25343
+ self.bounds = [minX, minY, maxX, maxY];
25344
+ }
25345
+ function meshPackData(self) {
25346
+ let i, j, ii;
25347
+ const coords = self.coords;
25348
+ const coordsPacked = new Float32Array(coords.length * 2);
25349
+ for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
25350
+ const xy = coords[i];
25351
+ coordsPacked[j++] = xy[0];
25352
+ coordsPacked[j++] = xy[1];
25353
+ }
25354
+ self.coords = coordsPacked;
25355
+ const colors = self.colors;
25356
+ const colorsPacked = new Uint8Array(colors.length * 4);
25357
+ for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
25358
+ const c = colors[i];
25359
+ colorsPacked[j++] = c[0];
25360
+ colorsPacked[j++] = c[1];
25361
+ colorsPacked[j++] = c[2];
25362
+ j++;
25363
+ }
25364
+ self.colors = colorsPacked;
25365
+ for (const figure of self.figures) {
25366
+ figure.coords = new Uint32Array(figure.coords);
25367
+ figure.colors = new Uint32Array(figure.colors);
25368
+ }
25369
+ }
25370
+ function buildMeshVertexData(coords, colors, figures) {
25371
+ let vertexCount = 0;
25372
+ for (const figure of figures) {
25373
+ if (figure.type === MeshFigureType.TRIANGLES) {
25374
+ vertexCount += figure.coords.length;
25375
+ } else if (figure.type === MeshFigureType.LATTICE) {
25376
+ const vpr = figure.verticesPerRow;
25377
+ vertexCount += (Math.floor(figure.coords.length / vpr) - 1) * (vpr - 1) * 6;
25378
+ }
25379
+ }
25380
+ const posData = new Float32Array(vertexCount * 2);
25381
+ const colData = new Uint8Array(vertexCount * 4);
25382
+ let pOff = 0, cOff = 0;
25383
+ const addVertex = (pi, ci) => {
25384
+ posData[pOff++] = coords[pi * 2];
25385
+ posData[pOff++] = coords[pi * 2 + 1];
25386
+ colData[cOff++] = colors[ci * 4];
25387
+ colData[cOff++] = colors[ci * 4 + 1];
25388
+ colData[cOff++] = colors[ci * 4 + 2];
25389
+ cOff++;
25390
+ };
25391
+ for (const figure of figures) {
25392
+ const ps = figure.coords;
25393
+ const cs = figure.colors;
25394
+ if (figure.type === MeshFigureType.TRIANGLES) {
25395
+ for (let i = 0, ii = ps.length; i < ii; i++) {
25396
+ addVertex(ps[i], cs[i]);
25397
+ }
25398
+ } else if (figure.type === MeshFigureType.LATTICE) {
25399
+ const vpr = figure.verticesPerRow;
25400
+ const rows = Math.floor(ps.length / vpr) - 1;
25401
+ const cols = vpr - 1;
25402
+ for (let i = 0; i < rows; i++) {
25403
+ let q = i * vpr;
25404
+ for (let j = 0; j < cols; j++, q++) {
25405
+ addVertex(ps[q], cs[q]);
25406
+ addVertex(ps[q + 1], cs[q + 1]);
25407
+ addVertex(ps[q + vpr], cs[q + vpr]);
25408
+ addVertex(ps[q + vpr + 1], cs[q + vpr + 1]);
25409
+ addVertex(ps[q + 1], cs[q + 1]);
25410
+ addVertex(ps[q + vpr], cs[q + vpr]);
25411
+ }
25412
+ }
25413
+ }
25414
+ }
25415
+ return { posData, colData, vertexCount };
25416
+ }
25417
+ var MeshStreamReader = class {
25418
+ constructor(stream, context) {
25419
+ this.stream = stream;
25420
+ this.context = context;
25421
+ this.buffer = 0;
25422
+ this.bufferLength = 0;
25423
+ const numComps = context.numComps;
25424
+ this.tmpCompsBuf = new Float32Array(numComps);
25425
+ const csNumComps = context.colorSpace.numComps;
25426
+ this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
25427
+ }
25428
+ get hasData() {
25429
+ if (this.stream.end) {
25430
+ return this.stream.pos < this.stream.end;
25431
+ }
25432
+ if (this.bufferLength > 0) {
25433
+ return true;
25434
+ }
25435
+ const nextByte = this.stream.getByte();
25436
+ if (nextByte < 0) {
25437
+ return false;
25438
+ }
25439
+ this.buffer = nextByte;
25440
+ this.bufferLength = 8;
25441
+ return true;
25442
+ }
25443
+ readBits(n) {
25444
+ const { stream } = this;
25445
+ let { buffer, bufferLength } = this;
25446
+ if (n === 32) {
25447
+ if (bufferLength === 0) {
25448
+ return stream.getInt32() >>> 0;
25449
+ }
25450
+ buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte();
25451
+ const nextByte = stream.getByte();
25452
+ this.buffer = nextByte & (1 << bufferLength) - 1;
25453
+ return (buffer << 8 - bufferLength | (nextByte & 255) >> bufferLength) >>> 0;
25454
+ }
25455
+ if (n === 8 && bufferLength === 0) {
25456
+ return stream.getByte();
25457
+ }
25458
+ while (bufferLength < n) {
25459
+ buffer = buffer << 8 | stream.getByte();
25460
+ bufferLength += 8;
25461
+ }
25462
+ bufferLength -= n;
25463
+ this.bufferLength = bufferLength;
25464
+ this.buffer = buffer & (1 << bufferLength) - 1;
25465
+ return buffer >> bufferLength;
25466
+ }
25467
+ align() {
25468
+ this.buffer = 0;
25469
+ this.bufferLength = 0;
25470
+ }
25471
+ readFlag() {
25472
+ return this.readBits(this.context.bitsPerFlag);
25473
+ }
25474
+ readCoordinate() {
25475
+ const { bitsPerCoordinate, decode } = this.context;
25476
+ const xi = this.readBits(bitsPerCoordinate);
25477
+ const yi = this.readBits(bitsPerCoordinate);
25478
+ const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 23283064365386963e-26;
25479
+ return [
25480
+ xi * scale * (decode[1] - decode[0]) + decode[0],
25481
+ yi * scale * (decode[3] - decode[2]) + decode[2]
25482
+ ];
25483
+ }
25484
+ readComponents() {
25485
+ const { bitsPerComponent, colorFn, colorSpace, decode, numComps } = this.context;
25486
+ const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 23283064365386963e-26;
25487
+ const components = this.tmpCompsBuf;
25488
+ for (let i = 0, j = 4; i < numComps; i++, j += 2) {
25489
+ const ci = this.readBits(bitsPerComponent);
25490
+ components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
25491
+ }
25492
+ const color = this.tmpCsCompsBuf;
25493
+ colorFn?.(components, 0, color, 0);
25494
+ return colorSpace.getRgb(color, 0);
25495
+ }
25496
+ };
25497
+ var bCache = null;
25498
+ function getB(count) {
25499
+ if (bCache?.has(count)) return bCache.get(count);
25500
+ const values = Array.from({ length: count + 1 }, (_, i) => {
25501
+ const t = i / count, t_ = 1 - t;
25502
+ return new Float32Array([
25503
+ t_ ** 3,
25504
+ 3 * t * t_ ** 2,
25505
+ 3 * t ** 2 * t_,
25506
+ t ** 3
25507
+ ]);
25508
+ });
25509
+ (bCache ??= /* @__PURE__ */ new Map()).set(count, values);
25510
+ return values;
25511
+ }
25512
+ var MeshShading = class _MeshShading extends BaseShading {
25513
+ static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
25514
+ static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
25515
+ // Count of triangles per entire mesh bounds.
25516
+ static TRIANGLE_DENSITY = 20;
25517
+ constructor(shadingType, stream, context, rowVertices) {
25518
+ super();
25519
+ this.shadingType = shadingType;
25520
+ this.bbox = this.background = null;
25521
+ this.coords = [];
25522
+ this.colors = [];
25523
+ this.figures = [];
25524
+ const reader = new MeshStreamReader(stream, context);
25525
+ let patchMesh = false;
25526
+ switch (this.shadingType) {
25527
+ case ShadingType.FREE_FORM_MESH:
25528
+ this._decodeType4Shading(reader);
25529
+ break;
25530
+ case ShadingType.LATTICE_FORM_MESH:
25531
+ const verticesPerRow = rowVertices | 0;
25532
+ if (verticesPerRow < 2) {
25533
+ throw new FormatError("Invalid VerticesPerRow");
25534
+ }
25535
+ this._decodeType5Shading(reader, verticesPerRow);
25536
+ break;
25537
+ case ShadingType.COONS_PATCH_MESH:
25538
+ this._decodeType6Shading(reader);
25539
+ patchMesh = true;
25540
+ break;
25541
+ case ShadingType.TENSOR_PATCH_MESH:
25542
+ this._decodeType7Shading(reader);
25543
+ patchMesh = true;
25544
+ break;
25545
+ default:
25546
+ unreachable2("Unsupported mesh type.");
25547
+ break;
25548
+ }
25549
+ if (patchMesh) {
25550
+ this._updateBounds();
25551
+ for (let i = 0, ii = this.figures.length; i < ii; i++) {
25552
+ this._buildFigureFromPatch(i);
25553
+ }
25554
+ }
25555
+ this._updateBounds();
25556
+ this._packData();
25557
+ }
25558
+ _decodeType4Shading(reader) {
25559
+ const coords = this.coords;
25560
+ const colors = this.colors;
25561
+ const operators = [];
25562
+ const ps = [];
25563
+ let verticesLeft = 0;
25564
+ while (reader.hasData) {
25565
+ const f = reader.readFlag();
25566
+ const coord = reader.readCoordinate();
25567
+ const color = reader.readComponents();
25568
+ if (verticesLeft === 0) {
25569
+ if (!(0 <= f && f <= 2)) {
25570
+ throw new FormatError("Unknown type4 flag");
25571
+ }
25572
+ switch (f) {
25573
+ case 0:
25574
+ verticesLeft = 3;
25575
+ break;
25576
+ case 1:
25577
+ ps.push(ps.at(-2), ps.at(-1));
25578
+ verticesLeft = 1;
25579
+ break;
25580
+ case 2:
25581
+ ps.push(ps.at(-3), ps.at(-1));
25582
+ verticesLeft = 1;
25583
+ break;
25584
+ }
25585
+ operators.push(f);
25586
+ }
25587
+ ps.push(coords.length);
25588
+ coords.push(coord);
25589
+ colors.push(color);
25590
+ verticesLeft--;
25591
+ reader.align();
25592
+ }
25593
+ this.figures.push({
25594
+ type: MeshFigureType.TRIANGLES,
25595
+ coords: new Int32Array(ps),
25596
+ colors: new Int32Array(ps)
25597
+ });
25598
+ }
25599
+ _decodeType5Shading(reader, verticesPerRow) {
25600
+ const coords = this.coords;
25601
+ const colors = this.colors;
25602
+ const ps = [];
25603
+ while (reader.hasData) {
25604
+ const coord = reader.readCoordinate();
25605
+ const color = reader.readComponents();
25606
+ ps.push(coords.length);
25607
+ coords.push(coord);
25608
+ colors.push(color);
25609
+ }
25610
+ this.figures.push({
25611
+ type: MeshFigureType.LATTICE,
25612
+ coords: new Int32Array(ps),
25613
+ colors: new Int32Array(ps),
25614
+ verticesPerRow
25615
+ });
25616
+ }
25617
+ _decodeType6Shading(reader) {
25618
+ const coords = this.coords;
25619
+ const colors = this.colors;
25620
+ const ps = new Int32Array(16);
25621
+ const cs = new Int32Array(4);
25622
+ while (reader.hasData) {
25623
+ const f = reader.readFlag();
25624
+ if (!(0 <= f && f <= 3)) {
25625
+ throw new FormatError("Unknown type6 flag");
25626
+ }
25627
+ const pi = coords.length;
25628
+ for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
25629
+ coords.push(reader.readCoordinate());
25630
+ }
25631
+ const ci = colors.length;
25632
+ for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
25633
+ colors.push(reader.readComponents());
25634
+ }
25635
+ let tmp1, tmp2, tmp3, tmp4;
25636
+ switch (f) {
25637
+ // prettier-ignore
25638
+ case 0:
25639
+ ps[12] = pi + 3;
25640
+ ps[13] = pi + 4;
25641
+ ps[14] = pi + 5;
25642
+ ps[15] = pi + 6;
25643
+ ps[8] = pi + 2;
25644
+ ps[11] = pi + 7;
25645
+ ps[4] = pi + 1;
25646
+ ps[7] = pi + 8;
25647
+ ps[0] = pi;
25648
+ ps[1] = pi + 11;
25649
+ ps[2] = pi + 10;
25650
+ ps[3] = pi + 9;
25651
+ cs[2] = ci + 1;
25652
+ cs[3] = ci + 2;
25653
+ cs[0] = ci;
25654
+ cs[1] = ci + 3;
25655
+ break;
25656
+ // prettier-ignore
25657
+ case 1:
25658
+ tmp1 = ps[12];
25659
+ tmp2 = ps[13];
25660
+ tmp3 = ps[14];
25661
+ tmp4 = ps[15];
25662
+ ps[12] = tmp4;
25663
+ ps[13] = pi + 0;
25664
+ ps[14] = pi + 1;
25665
+ ps[15] = pi + 2;
25666
+ ps[8] = tmp3;
25667
+ ps[11] = pi + 3;
25668
+ ps[4] = tmp2;
25669
+ ps[7] = pi + 4;
25670
+ ps[0] = tmp1;
25671
+ ps[1] = pi + 7;
25672
+ ps[2] = pi + 6;
25673
+ ps[3] = pi + 5;
25674
+ tmp1 = cs[2];
25675
+ tmp2 = cs[3];
25676
+ cs[2] = tmp2;
25677
+ cs[3] = ci;
25678
+ cs[0] = tmp1;
25679
+ cs[1] = ci + 1;
25680
+ break;
25681
+ // prettier-ignore
25682
+ case 2:
25683
+ tmp1 = ps[15];
25684
+ tmp2 = ps[11];
25685
+ ps[12] = ps[3];
25686
+ ps[13] = pi + 0;
25687
+ ps[14] = pi + 1;
25688
+ ps[15] = pi + 2;
25689
+ ps[8] = ps[7];
25690
+ ps[11] = pi + 3;
25691
+ ps[4] = tmp2;
25692
+ ps[7] = pi + 4;
25693
+ ps[0] = tmp1;
25694
+ ps[1] = pi + 7;
25695
+ ps[2] = pi + 6;
25696
+ ps[3] = pi + 5;
25697
+ tmp1 = cs[3];
25698
+ cs[2] = cs[1];
25699
+ cs[3] = ci;
25700
+ cs[0] = tmp1;
25701
+ cs[1] = ci + 1;
25702
+ break;
25703
+ // prettier-ignore
25704
+ case 3:
25705
+ ps[12] = ps[0];
25706
+ ps[13] = pi + 0;
25707
+ ps[14] = pi + 1;
25708
+ ps[15] = pi + 2;
25709
+ ps[8] = ps[1];
25710
+ ps[11] = pi + 3;
25711
+ ps[4] = ps[2];
25712
+ ps[7] = pi + 4;
25713
+ ps[0] = ps[3];
25714
+ ps[1] = pi + 7;
25715
+ ps[2] = pi + 6;
25716
+ ps[3] = pi + 5;
25717
+ cs[2] = cs[0];
25718
+ cs[3] = ci;
25719
+ cs[0] = cs[1];
25720
+ cs[1] = ci + 1;
25721
+ break;
25722
+ }
25723
+ ps[5] = coords.length;
25724
+ coords.push([
25725
+ (-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,
25726
+ (-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
25727
+ ]);
25728
+ ps[6] = coords.length;
25729
+ coords.push([
25730
+ (-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,
25731
+ (-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
25732
+ ]);
25733
+ ps[9] = coords.length;
25734
+ coords.push([
25735
+ (-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,
25736
+ (-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
25737
+ ]);
25738
+ ps[10] = coords.length;
25739
+ coords.push([
25740
+ (-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,
25741
+ (-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
25742
+ ]);
25743
+ this.figures.push({
25744
+ type: MeshFigureType.PATCH,
25745
+ coords: new Int32Array(ps),
25746
+ // making copies of ps and cs
25747
+ colors: new Int32Array(cs)
25748
+ });
25749
+ }
25750
+ }
25751
+ _decodeType7Shading(reader) {
25752
+ const coords = this.coords;
25753
+ const colors = this.colors;
25754
+ const ps = new Int32Array(16);
25755
+ const cs = new Int32Array(4);
25756
+ while (reader.hasData) {
25757
+ const f = reader.readFlag();
25758
+ if (!(0 <= f && f <= 3)) {
25759
+ throw new FormatError("Unknown type7 flag");
25760
+ }
25761
+ const pi = coords.length;
25762
+ for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
25763
+ coords.push(reader.readCoordinate());
25764
+ }
25765
+ const ci = colors.length;
25766
+ for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
25767
+ colors.push(reader.readComponents());
25768
+ }
25769
+ let tmp1, tmp2, tmp3, tmp4;
25770
+ switch (f) {
25771
+ // prettier-ignore
25772
+ case 0:
25773
+ ps[12] = pi + 3;
25774
+ ps[13] = pi + 4;
25775
+ ps[14] = pi + 5;
25776
+ ps[15] = pi + 6;
25777
+ ps[8] = pi + 2;
25778
+ ps[9] = pi + 13;
25779
+ ps[10] = pi + 14;
25780
+ ps[11] = pi + 7;
25781
+ ps[4] = pi + 1;
25782
+ ps[5] = pi + 12;
25783
+ ps[6] = pi + 15;
25784
+ ps[7] = pi + 8;
25785
+ ps[0] = pi;
25786
+ ps[1] = pi + 11;
25787
+ ps[2] = pi + 10;
25788
+ ps[3] = pi + 9;
25789
+ cs[2] = ci + 1;
25790
+ cs[3] = ci + 2;
25791
+ cs[0] = ci;
25792
+ cs[1] = ci + 3;
25793
+ break;
25794
+ // prettier-ignore
25795
+ case 1:
25796
+ tmp1 = ps[12];
25797
+ tmp2 = ps[13];
25798
+ tmp3 = ps[14];
25799
+ tmp4 = ps[15];
25800
+ ps[12] = tmp4;
25801
+ ps[13] = pi + 0;
25802
+ ps[14] = pi + 1;
25803
+ ps[15] = pi + 2;
25804
+ ps[8] = tmp3;
25805
+ ps[9] = pi + 9;
25806
+ ps[10] = pi + 10;
25807
+ ps[11] = pi + 3;
25808
+ ps[4] = tmp2;
25809
+ ps[5] = pi + 8;
25810
+ ps[6] = pi + 11;
25811
+ ps[7] = pi + 4;
25812
+ ps[0] = tmp1;
25813
+ ps[1] = pi + 7;
25814
+ ps[2] = pi + 6;
25815
+ ps[3] = pi + 5;
25816
+ tmp1 = cs[2];
25817
+ tmp2 = cs[3];
25818
+ cs[2] = tmp2;
25819
+ cs[3] = ci;
25820
+ cs[0] = tmp1;
25821
+ cs[1] = ci + 1;
25822
+ break;
25823
+ // prettier-ignore
25824
+ case 2:
25825
+ tmp1 = ps[15];
25826
+ tmp2 = ps[11];
25827
+ ps[12] = ps[3];
25828
+ ps[13] = pi + 0;
25829
+ ps[14] = pi + 1;
25830
+ ps[15] = pi + 2;
25831
+ ps[8] = ps[7];
25832
+ ps[9] = pi + 9;
25833
+ ps[10] = pi + 10;
25834
+ ps[11] = pi + 3;
25835
+ ps[4] = tmp2;
25836
+ ps[5] = pi + 8;
25837
+ ps[6] = pi + 11;
25838
+ ps[7] = pi + 4;
25839
+ ps[0] = tmp1;
25840
+ ps[1] = pi + 7;
25841
+ ps[2] = pi + 6;
25842
+ ps[3] = pi + 5;
25843
+ tmp1 = cs[3];
25844
+ cs[2] = cs[1];
25845
+ cs[3] = ci;
25846
+ cs[0] = tmp1;
25847
+ cs[1] = ci + 1;
25848
+ break;
25849
+ // prettier-ignore
25850
+ case 3:
25851
+ ps[12] = ps[0];
25852
+ ps[13] = pi + 0;
25853
+ ps[14] = pi + 1;
25854
+ ps[15] = pi + 2;
25855
+ ps[8] = ps[1];
25856
+ ps[9] = pi + 9;
25857
+ ps[10] = pi + 10;
25858
+ ps[11] = pi + 3;
25859
+ ps[4] = ps[2];
25860
+ ps[5] = pi + 8;
25861
+ ps[6] = pi + 11;
25862
+ ps[7] = pi + 4;
25863
+ ps[0] = ps[3];
25864
+ ps[1] = pi + 7;
25865
+ ps[2] = pi + 6;
25866
+ ps[3] = pi + 5;
25867
+ cs[2] = cs[0];
25868
+ cs[3] = ci;
25869
+ cs[0] = cs[1];
25870
+ cs[1] = ci + 1;
25871
+ break;
25872
+ }
25873
+ this.figures.push({
25874
+ type: MeshFigureType.PATCH,
25875
+ coords: new Int32Array(ps),
25876
+ // making copies of ps and cs
25877
+ colors: new Int32Array(cs)
25878
+ });
25879
+ }
25880
+ }
25881
+ _buildFigureFromPatch(index) {
25882
+ const figure = this.figures[index];
25883
+ assert2(
25884
+ figure.type === MeshFigureType.PATCH,
25885
+ "Unexpected patch mesh figure"
25886
+ );
25887
+ const coords = this.coords, colors = this.colors;
25888
+ const pi = figure.coords;
25889
+ const ci = figure.colors;
25890
+ const figureMinX = Math.min(
25891
+ coords[pi[0]][0],
25892
+ coords[pi[3]][0],
25893
+ coords[pi[12]][0],
25894
+ coords[pi[15]][0]
25895
+ );
25896
+ const figureMinY = Math.min(
25897
+ coords[pi[0]][1],
25898
+ coords[pi[3]][1],
25899
+ coords[pi[12]][1],
25900
+ coords[pi[15]][1]
25901
+ );
25902
+ const figureMaxX = Math.max(
25903
+ coords[pi[0]][0],
25904
+ coords[pi[3]][0],
25905
+ coords[pi[12]][0],
25906
+ coords[pi[15]][0]
25907
+ );
25908
+ const figureMaxY = Math.max(
25909
+ coords[pi[0]][1],
25910
+ coords[pi[3]][1],
25911
+ coords[pi[12]][1],
25912
+ coords[pi[15]][1]
25913
+ );
25914
+ let splitXBy = Math.ceil(
25915
+ (figureMaxX - figureMinX) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])
25916
+ );
25917
+ splitXBy = MathClamp(
25918
+ splitXBy,
25919
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
25920
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
25921
+ );
25922
+ let splitYBy = Math.ceil(
25923
+ (figureMaxY - figureMinY) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])
25924
+ );
25925
+ splitYBy = MathClamp(
25926
+ splitYBy,
25927
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
25928
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
25929
+ );
25930
+ const verticesPerRow = splitXBy + 1;
25931
+ const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
25932
+ const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
25933
+ let k = 0;
25934
+ const cl = new Uint8Array(3), cr = new Uint8Array(3);
25935
+ const c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
25936
+ const bRow = getB(splitYBy), bCol = getB(splitXBy);
25937
+ for (let row = 0; row <= splitYBy; row++) {
25938
+ cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
25939
+ cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
25940
+ cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
25941
+ cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
25942
+ cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
25943
+ cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
25944
+ for (let col = 0; col <= splitXBy; col++, k++) {
25945
+ if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
25946
+ continue;
25947
+ }
25948
+ let x = 0, y = 0;
25949
+ let q = 0;
25950
+ for (let i = 0; i <= 3; i++) {
25951
+ for (let j = 0; j <= 3; j++, q++) {
25952
+ const m = bRow[row][i] * bCol[col][j];
25953
+ x += coords[pi[q]][0] * m;
25954
+ y += coords[pi[q]][1] * m;
25955
+ }
25956
+ }
25957
+ figureCoords[k] = coords.length;
25958
+ coords.push([x, y]);
25959
+ figureColors[k] = colors.length;
25960
+ const newColor = new Uint8Array(3);
25961
+ newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
25962
+ newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
25963
+ newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
25964
+ colors.push(newColor);
25965
+ }
25966
+ }
25967
+ figureCoords[0] = pi[0];
25968
+ figureColors[0] = ci[0];
25969
+ figureCoords[splitXBy] = pi[3];
25970
+ figureColors[splitXBy] = ci[1];
25971
+ figureCoords[verticesPerRow * splitYBy] = pi[12];
25972
+ figureColors[verticesPerRow * splitYBy] = ci[2];
25973
+ figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
25974
+ figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
25975
+ this.figures[index] = {
25976
+ type: MeshFigureType.LATTICE,
25977
+ coords: figureCoords,
25978
+ colors: figureColors,
25979
+ verticesPerRow
25980
+ };
25981
+ }
25982
+ _updateBounds() {
25983
+ meshUpdateBounds(this);
25984
+ }
25985
+ _packData() {
25986
+ meshPackData(this);
25987
+ }
25988
+ getIR() {
25989
+ const { posData, colData, vertexCount } = buildMeshVertexData(
25990
+ this.coords,
25991
+ this.colors,
25992
+ this.figures
25993
+ );
25994
+ return [
25995
+ "Mesh",
25996
+ this.shadingType,
25997
+ posData,
25998
+ colData,
25999
+ vertexCount,
26000
+ this.bounds,
26001
+ this.bbox,
26002
+ this.background
26003
+ ];
26004
+ }
26005
+ };
25307
26006
 
25308
26007
  // src/errors.ts
25309
26008
  var PdfError = class extends Error {
@@ -28354,11 +29053,16 @@ function parseDictionaryStream(dictNode, lexer, bytes) {
28354
29053
  let streamEnd = streamStart;
28355
29054
  if (resolvedLength !== void 0 && resolvedLength >= 0 && streamStart + resolvedLength <= bytes.length) {
28356
29055
  const candidateEnd = streamStart + resolvedLength;
28357
- const tailSlice = bytes.subarray(candidateEnd, Math.min(bytes.length, candidateEnd + 32));
28358
- const tailStr = new TextDecoder("latin1").decode(tailSlice);
28359
- if (tailStr.includes("endstream")) {
29056
+ const tailLexer = new CosByteLexer(bytes, candidateEnd);
29057
+ let endToken;
29058
+ try {
29059
+ endToken = tailLexer.nextToken();
29060
+ } catch (error) {
29061
+ if (!(error instanceof PdfError) || error.code !== "E_PARSE") throw error;
29062
+ }
29063
+ if (endToken?.kind === "keyword" && endToken.value === "endstream") {
28360
29064
  rawStreamBytes = bytes.subarray(streamStart, candidateEnd);
28361
- streamEnd = candidateEnd + tailStr.indexOf("endstream") + "endstream".length;
29065
+ streamEnd = tailLexer.offset;
28362
29066
  }
28363
29067
  }
28364
29068
  if (!rawStreamBytes) {
@@ -37709,21 +38413,23 @@ function resolvePageFonts(doc, resourcesDict) {
37709
38413
  }
37710
38414
  }
37711
38415
  } else {
37712
- const stdName = normalizeStandard14FontName(baseFont);
37713
- const stdMetrics = STANDARD_14_FONTS[stdName];
37714
- defaultWidth = stdMetrics.defaultWidth;
37715
- for (const [codeStr, wVal] of Object.entries(stdMetrics.widthsByCode)) {
37716
- widths.set(Number(codeStr), wVal);
37717
- }
37718
38416
  const firstCharNode = doc.resolve(dictGet(fObj, "FirstChar"));
37719
38417
  const widthsArr = doc.resolveArray(dictGet(fObj, "Widths"));
37720
- if (firstCharNode?.kind === "number" && widthsArr) {
38418
+ if (widthsArr) {
38419
+ const descriptor = doc.resolveDict(dictGet(fObj, "FontDescriptor"));
38420
+ const missingWidth = descriptor ? doc.resolve(dictGet(descriptor, "MissingWidth")) : void 0;
38421
+ defaultWidth = (missingWidth?.kind === "number" ? missingWidth.value : 0) * type3Scale1000;
38422
+ const firstChar = firstCharNode?.kind === "number" ? firstCharNode.value : 0;
37721
38423
  for (let k = 0; k < widthsArr.items.length; k++) {
37722
38424
  const wItem = doc.resolve(widthsArr.items[k]);
37723
38425
  if (wItem?.kind === "number") {
37724
- widths.set(firstCharNode.value + k, wItem.value * type3Scale1000);
38426
+ widths.set(firstChar + k, wItem.value * type3Scale1000);
37725
38427
  }
37726
38428
  }
38429
+ } else {
38430
+ const stdMetrics = STANDARD_14_FONTS[normalizeStandard14FontName(baseFont)];
38431
+ defaultWidth = stdMetrics.defaultWidth;
38432
+ for (const [codeStr, wVal] of Object.entries(stdMetrics.widthsByCode)) widths.set(Number(codeStr), wVal);
37727
38433
  }
37728
38434
  }
37729
38435
  let embeddedCff;
@@ -38112,143 +38818,28 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
38112
38818
  const r = doc.resolve(it);
38113
38819
  return r?.kind === "number" ? r.value : 0;
38114
38820
  });
38115
- const xmin = decodeNums[0], xmax = decodeNums[1], ymin = decodeNums[2], ymax = decodeNums[3];
38116
- const numColorParams = Math.max(1, Math.floor((decodeNums.length - 4) / 2));
38117
38821
  const fnNode = dictGet(shDict, "Function");
38118
38822
  const csNode = doc.resolve(dictGet(shDict, "ColorSpace"));
38119
38823
  const csName = csNode?.kind === "name" ? csNode.decoded : "DeviceRGB";
38120
- let bitPos = 0;
38121
- const totalBits = bytes.length * 8;
38122
- const readBits = (n) => {
38123
- let val = 0;
38124
- for (let i = 0; i < n; i++) {
38125
- if (bitPos >= totalBits) return val;
38126
- const byteIdx = bitPos >> 3;
38127
- const bitIdx = 7 - (bitPos & 7);
38128
- val = val * 2 + (bytes[byteIdx] >> bitIdx & 1);
38129
- bitPos++;
38130
- }
38131
- return val;
38132
- };
38133
- const coordMax = Math.pow(2, bpcCoord) - 1 || 1;
38134
- const compMax = Math.pow(2, bpcComp) - 1 || 1;
38135
- const readCoord = () => {
38136
- const rx = readBits(bpcCoord) / coordMax;
38137
- const ry = readBits(bpcCoord) / coordMax;
38138
- return [xmin + rx * (xmax - xmin), ymin + ry * (ymax - ymin)];
38139
- };
38140
- const readColorRgb = () => {
38141
- const params = [];
38142
- for (let c = 0; c < numColorParams; c++) {
38143
- const rc = readBits(bpcComp) / compMax;
38144
- const cMin = decodeNums[4 + c * 2] ?? 0;
38145
- const cMax = decodeNums[4 + c * 2 + 1] ?? 1;
38146
- params.push(cMin + rc * (cMax - cMin));
38147
- }
38148
- const comps = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
38149
- return convertColorSpaceComponentsToRgb(doc, csNode, csName, comps);
38150
- };
38151
- const triangles = [];
38152
- if (shType === 4) {
38153
- const minBitsPerVert = bpcFlag + 2 * bpcCoord + numColorParams * bpcComp;
38154
- let triVerts;
38155
- while (bitPos + minBitsPerVert <= totalBits) {
38156
- const flag = readBits(bpcFlag) & 3;
38157
- const [x, y] = readCoord();
38158
- const rgb2 = readColorRgb();
38159
- const vNew = { x, y, rgb: rgb2 };
38160
- if (flag === 0 || !triVerts) {
38161
- if (bitPos + 2 * minBitsPerVert > totalBits) break;
38162
- readBits(bpcFlag);
38163
- const [x1, y1] = readCoord();
38164
- const rgb1 = readColorRgb();
38165
- readBits(bpcFlag);
38166
- const [x2, y2] = readCoord();
38167
- const rgb22 = readColorRgb();
38168
- triVerts = [vNew, { x: x1, y: y1, rgb: rgb1 }, { x: x2, y: y2, rgb: rgb22 }];
38169
- triangles.push(triVerts);
38170
- } else if (flag === 1) {
38171
- triVerts = [triVerts[1], triVerts[2], vNew];
38172
- triangles.push(triVerts);
38173
- } else if (flag === 2) {
38174
- triVerts = [triVerts[0], triVerts[2], vNew];
38175
- triangles.push(triVerts);
38176
- }
38177
- }
38178
- } else if (shType === 5) {
38179
- const minBitsPerVert = 2 * bpcCoord + numColorParams * bpcComp;
38180
- const verts = [];
38181
- while (bitPos + minBitsPerVert <= totalBits) {
38182
- const [x, y] = readCoord();
38183
- const rgb2 = readColorRgb();
38184
- verts.push({ x, y, rgb: rgb2 });
38185
- }
38186
- const numRows = Math.floor(verts.length / vPerRow);
38187
- for (let r = 0; r + 1 < numRows; r++) {
38188
- for (let c = 0; c + 1 < vPerRow; c++) {
38189
- const v00 = verts[r * vPerRow + c];
38190
- const v01 = verts[r * vPerRow + c + 1];
38191
- const v11 = verts[(r + 1) * vPerRow + c + 1];
38192
- const v10 = verts[(r + 1) * vPerRow + c];
38193
- triangles.push([v00, v01, v11], [v00, v11, v10]);
38194
- }
38195
- }
38196
- } else if (shType === 6 || shType === 7) {
38197
- const numCtrl = shType === 6 ? 12 : 16;
38198
- const minBitsPatch = bpcFlag + (numCtrl - 4) * 2 * bpcCoord + 2 * numColorParams * bpcComp;
38199
- let prevPts;
38200
- let prevColors;
38201
- while (bitPos + minBitsPatch <= totalBits) {
38202
- const flag = readBits(bpcFlag) & 3;
38203
- let pts = [];
38204
- let cols = [];
38205
- if (flag === 0 || !prevPts || !prevColors) {
38206
- for (let i = 0; i < numCtrl; i++) pts.push(readCoord());
38207
- for (let i = 0; i < 4; i++) cols.push(readColorRgb());
38208
- } else {
38209
- const extraCtrl = numCtrl - 4;
38210
- const readExtra = [];
38211
- for (let i = 0; i < extraCtrl; i++) readExtra.push(readCoord());
38212
- const c2 = readColorRgb();
38213
- const c3 = readColorRgb();
38214
- pts = [prevPts[3], prevPts[4], prevPts[5], prevPts[6], ...readExtra];
38215
- cols = [prevColors[1], prevColors[2], c2, c3];
38216
- }
38217
- prevPts = pts;
38218
- prevColors = cols;
38219
- const p00 = pts[0];
38220
- const p03 = pts[3];
38221
- const p33 = pts[6];
38222
- const p30 = pts[9];
38223
- const c00 = cols[0], c03 = cols[1], c33 = cols[2], c30 = cols[3];
38224
- const steps = 4;
38225
- const grid = [];
38226
- for (let iu = 0; iu <= steps; iu++) {
38227
- const u = iu / steps;
38228
- const row = [];
38229
- for (let iv = 0; iv <= steps; iv++) {
38230
- const v = iv / steps;
38231
- const x = (1 - u) * (1 - v) * p00[0] + (1 - u) * v * p03[0] + u * v * p33[0] + u * (1 - v) * p30[0];
38232
- const y = (1 - u) * (1 - v) * p00[1] + (1 - u) * v * p03[1] + u * v * p33[1] + u * (1 - v) * p30[1];
38233
- const r = (1 - u) * (1 - v) * c00[0] + (1 - u) * v * c03[0] + u * v * c33[0] + u * (1 - v) * c30[0];
38234
- const g = (1 - u) * (1 - v) * c00[1] + (1 - u) * v * c03[1] + u * v * c33[1] + u * (1 - v) * c30[1];
38235
- const b = (1 - u) * (1 - v) * c00[2] + (1 - u) * v * c03[2] + u * v * c33[2] + u * (1 - v) * c30[2];
38236
- row.push({ x, y, rgb: [r, g, b] });
38237
- }
38238
- grid.push(row);
38239
- }
38240
- for (let iu = 0; iu < steps; iu++) {
38241
- for (let iv = 0; iv < steps; iv++) {
38242
- const g00 = grid[iu][iv];
38243
- const g01 = grid[iu][iv + 1];
38244
- const g11 = grid[iu + 1][iv + 1];
38245
- const g10 = grid[iu + 1][iv];
38246
- triangles.push([g00, g01, g11], [g00, g11, g10]);
38247
- }
38248
- }
38249
- }
38250
- }
38251
- if (triangles.length === 0) return void 0;
38824
+ const numComps = fnNode ? 1 : getColorSpaceComponentCount(doc, csNode);
38825
+ const mesh = new MeshShading(shType, new Stream(bytes), {
38826
+ bitsPerCoordinate: bpcCoord,
38827
+ bitsPerComponent: bpcComp,
38828
+ bitsPerFlag: bpcFlag,
38829
+ decode: decodeNums,
38830
+ numComps,
38831
+ colorFn: null,
38832
+ colorSpace: {
38833
+ numComps,
38834
+ getRgb(components) {
38835
+ const params = Array.from(components);
38836
+ const values = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
38837
+ return new Uint8Array(convertColorSpaceComponentsToRgb(doc, csNode, csName, values).map((value) => Math.round(Math.max(0, Math.min(1, value)) * 255)));
38838
+ }
38839
+ }
38840
+ }, vPerRow);
38841
+ const [, , positions, colors, vertexCount] = mesh.getIR();
38842
+ if (vertexCount === 0) return void 0;
38252
38843
  const [bx0, by0, bx1, by1] = targetBox;
38253
38844
  const boxW = Math.max(1, bx1 - bx0);
38254
38845
  const boxH = Math.max(1, by1 - by0);
@@ -38260,10 +38851,10 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
38260
38851
  const [px, py] = transformPoint(effectiveCtm, vx, vy);
38261
38852
  return [(px - bx0) / boxW * imgW, (by1 - py) / boxH * imgH];
38262
38853
  };
38263
- for (const [v0, v1, v2] of triangles) {
38264
- const [x0, y0] = toImgCoords(v0.x, v0.y);
38265
- const [x1, y1] = toImgCoords(v1.x, v1.y);
38266
- const [x2, y2] = toImgCoords(v2.x, v2.y);
38854
+ for (let vertex = 0; vertex < vertexCount; vertex += 3) {
38855
+ const [x0, y0] = toImgCoords(positions[vertex * 2], positions[vertex * 2 + 1]);
38856
+ const [x1, y1] = toImgCoords(positions[vertex * 2 + 2], positions[vertex * 2 + 3]);
38857
+ const [x2, y2] = toImgCoords(positions[vertex * 2 + 4], positions[vertex * 2 + 5]);
38267
38858
  const denom = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2);
38268
38859
  if (Math.abs(denom) < 1e-6) continue;
38269
38860
  const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
@@ -38278,13 +38869,12 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
38278
38869
  const w1 = ((y2 - y0) * (px - x2) + (x0 - x2) * (py - y2)) / denom;
38279
38870
  const w2 = 1 - w0 - w1;
38280
38871
  if (w0 >= -1e-4 && w1 >= -1e-4 && w2 >= -1e-4) {
38281
- const r = w0 * v0.rgb[0] + w1 * v1.rgb[0] + w2 * v2.rgb[0];
38282
- const g = w0 * v0.rgb[1] + w1 * v1.rgb[1] + w2 * v2.rgb[1];
38283
- const b = w0 * v0.rgb[2] + w1 * v1.rgb[2] + w2 * v2.rgb[2];
38284
38872
  const pIdx = (iy * imgW + ix) * 4;
38285
- rgba[pIdx] = Math.round(Math.max(0, Math.min(1, r)) * 255);
38286
- rgba[pIdx + 1] = Math.round(Math.max(0, Math.min(1, g)) * 255);
38287
- rgba[pIdx + 2] = Math.round(Math.max(0, Math.min(1, b)) * 255);
38873
+ for (let channel = 0; channel < 3; channel++) {
38874
+ rgba[pIdx + channel] = Math.round(
38875
+ w0 * colors[vertex * 4 + channel] + w1 * colors[vertex * 4 + 4 + channel] + w2 * colors[vertex * 4 + 8 + channel]
38876
+ );
38877
+ }
38288
38878
  rgba[pIdx + 3] = a8;
38289
38879
  }
38290
38880
  }
@@ -38371,6 +38961,8 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
38371
38961
  const [a, b, c, d, e, f] = effectiveCtm;
38372
38962
  const det = a * d - b * c;
38373
38963
  if (Math.abs(det) <= 1e-8) return void 0;
38964
+ const [sa, sb, sc, sd, se, sf] = shadingCtm;
38965
+ const shadingDet = sa * sd - sb * sc;
38374
38966
  const t0Dom = shDomain[0] ?? 0;
38375
38967
  const t1Dom = shDomain[1] ?? 1;
38376
38968
  for (let iy = 0; iy < imgH; iy++) {
@@ -38381,8 +38973,10 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
38381
38973
  const dxPdf = xPdf - e;
38382
38974
  const xs = (d * dxPdf - c * dyPdf) / det;
38383
38975
  const ys = (-b * dxPdf + a * dyPdf) / det;
38384
- if (shBBox && (xs < shBBox[0] || xs > shBBox[2] || ys < shBBox[1] || ys > shBBox[3])) {
38385
- continue;
38976
+ if (shBBox) {
38977
+ const bboxX = (sd * (xPdf - se) - sc * (yPdf - sf)) / shadingDet;
38978
+ const bboxY = (-sb * (xPdf - se) + sa * (yPdf - sf)) / shadingDet;
38979
+ if (bboxX < shBBox[0] || bboxX > shBBox[2] || bboxY < shBBox[1] || bboxY > shBBox[3]) continue;
38386
38980
  }
38387
38981
  let comps;
38388
38982
  if (shType === 1) {
@@ -38591,13 +39185,11 @@ function evaluateContentStreamToDisplayList(params) {
38591
39185
  }
38592
39186
  if (font?.cmap) {
38593
39187
  if (!font.isTwoByteCid) {
38594
- const stdName2 = normalizeStandard14FontName(font.baseFont);
38595
- const stdMetrics2 = STANDARD_14_FONTS[stdName2];
38596
39188
  const out2 = [];
38597
39189
  for (let i = 0; i < bytes.length; i++) {
38598
39190
  const code = bytes[i];
38599
39191
  const unicode = font.cmap.map.get(code) ?? (font.differences.has(code) ? font.differences.get(code) : decodeWinAnsiByte(code));
38600
- const advance1000 = font.widths.get(code) ?? stdMetrics2.widthsByCode[code] ?? stdMetrics2.defaultWidth;
39192
+ const advance1000 = font.widths.get(code) ?? font.defaultWidth;
38601
39193
  out2.push({ charCode: code, isSpace: code === 32, unicode, advance1000 });
38602
39194
  }
38603
39195
  return out2;
@@ -38629,7 +39221,7 @@ function evaluateContentStreamToDisplayList(params) {
38629
39221
  for (let i = 0; i < bytes.length; i++) {
38630
39222
  const code = bytes[i];
38631
39223
  const unicode = font?.differences.get(code) ?? decodeWinAnsiByte(code);
38632
- const advance1000 = font?.widths.get(code) ?? stdMetrics.widthsByCode[code] ?? stdMetrics.defaultWidth;
39224
+ const advance1000 = font ? font.widths.get(code) ?? font.defaultWidth : stdMetrics.widthsByCode[code] ?? stdMetrics.defaultWidth;
38633
39225
  out.push({ charCode: code, isSpace: code === 32, unicode, advance1000 });
38634
39226
  }
38635
39227
  return out;