@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
@@ -11586,6 +11586,11 @@ var FONT_IDENTITY_MATRIX = [1e-3, 0, 0, 1e-3, 0, 0];
11586
11586
  var LINE_FACTOR = 1.35;
11587
11587
  var LINE_DESCENT_FACTOR = 0.35;
11588
11588
  var BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
11589
+ var MeshFigureType = {
11590
+ TRIANGLES: 1,
11591
+ LATTICE: 2,
11592
+ PATCH: 3
11593
+ };
11589
11594
  var VerbosityLevel = {
11590
11595
  ERRORS: 0,
11591
11596
  WARNINGS: 1,
@@ -33118,6 +33123,700 @@ function buildPostScriptJsFunction(source, domain, range, forceInterpreter = fal
33118
33123
  }
33119
33124
  return PSStackBasedInterpreter.build(program, domain, range);
33120
33125
  }
33126
+ var ShadingType = {
33127
+ FUNCTION_BASED: 1,
33128
+ AXIAL: 2,
33129
+ RADIAL: 3,
33130
+ FREE_FORM_MESH: 4,
33131
+ LATTICE_FORM_MESH: 5,
33132
+ COONS_PATCH_MESH: 6,
33133
+ TENSOR_PATCH_MESH: 7
33134
+ };
33135
+ var BaseShading = class _BaseShading {
33136
+ // A small number to offset the first/last color stops so we can insert ones
33137
+ // to support extend. Number.MIN_VALUE is too small and breaks the extend.
33138
+ static SMALL_NUMBER = 1e-6;
33139
+ constructor() {
33140
+ if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === _BaseShading) {
33141
+ unreachable2("Cannot initialize BaseShading.");
33142
+ }
33143
+ }
33144
+ getIR() {
33145
+ unreachable2("Abstract method `getIR` called.");
33146
+ }
33147
+ };
33148
+ function meshUpdateBounds(self) {
33149
+ let minX = self.coords[0][0], minY = self.coords[0][1], maxX = minX, maxY = minY;
33150
+ for (let i = 1, ii = self.coords.length; i < ii; i++) {
33151
+ const x = self.coords[i][0], y = self.coords[i][1];
33152
+ minX = minX > x ? x : minX;
33153
+ minY = minY > y ? y : minY;
33154
+ maxX = maxX < x ? x : maxX;
33155
+ maxY = maxY < y ? y : maxY;
33156
+ }
33157
+ self.bounds = [minX, minY, maxX, maxY];
33158
+ }
33159
+ function meshPackData(self) {
33160
+ let i, j, ii;
33161
+ const coords = self.coords;
33162
+ const coordsPacked = new Float32Array(coords.length * 2);
33163
+ for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
33164
+ const xy = coords[i];
33165
+ coordsPacked[j++] = xy[0];
33166
+ coordsPacked[j++] = xy[1];
33167
+ }
33168
+ self.coords = coordsPacked;
33169
+ const colors = self.colors;
33170
+ const colorsPacked = new Uint8Array(colors.length * 4);
33171
+ for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
33172
+ const c = colors[i];
33173
+ colorsPacked[j++] = c[0];
33174
+ colorsPacked[j++] = c[1];
33175
+ colorsPacked[j++] = c[2];
33176
+ j++;
33177
+ }
33178
+ self.colors = colorsPacked;
33179
+ for (const figure of self.figures) {
33180
+ figure.coords = new Uint32Array(figure.coords);
33181
+ figure.colors = new Uint32Array(figure.colors);
33182
+ }
33183
+ }
33184
+ function buildMeshVertexData(coords, colors, figures) {
33185
+ let vertexCount = 0;
33186
+ for (const figure of figures) {
33187
+ if (figure.type === MeshFigureType.TRIANGLES) {
33188
+ vertexCount += figure.coords.length;
33189
+ } else if (figure.type === MeshFigureType.LATTICE) {
33190
+ const vpr = figure.verticesPerRow;
33191
+ vertexCount += (Math.floor(figure.coords.length / vpr) - 1) * (vpr - 1) * 6;
33192
+ }
33193
+ }
33194
+ const posData = new Float32Array(vertexCount * 2);
33195
+ const colData = new Uint8Array(vertexCount * 4);
33196
+ let pOff = 0, cOff = 0;
33197
+ const addVertex = (pi, ci) => {
33198
+ posData[pOff++] = coords[pi * 2];
33199
+ posData[pOff++] = coords[pi * 2 + 1];
33200
+ colData[cOff++] = colors[ci * 4];
33201
+ colData[cOff++] = colors[ci * 4 + 1];
33202
+ colData[cOff++] = colors[ci * 4 + 2];
33203
+ cOff++;
33204
+ };
33205
+ for (const figure of figures) {
33206
+ const ps = figure.coords;
33207
+ const cs = figure.colors;
33208
+ if (figure.type === MeshFigureType.TRIANGLES) {
33209
+ for (let i = 0, ii = ps.length; i < ii; i++) {
33210
+ addVertex(ps[i], cs[i]);
33211
+ }
33212
+ } else if (figure.type === MeshFigureType.LATTICE) {
33213
+ const vpr = figure.verticesPerRow;
33214
+ const rows = Math.floor(ps.length / vpr) - 1;
33215
+ const cols = vpr - 1;
33216
+ for (let i = 0; i < rows; i++) {
33217
+ let q = i * vpr;
33218
+ for (let j = 0; j < cols; j++, q++) {
33219
+ addVertex(ps[q], cs[q]);
33220
+ addVertex(ps[q + 1], cs[q + 1]);
33221
+ addVertex(ps[q + vpr], cs[q + vpr]);
33222
+ addVertex(ps[q + vpr + 1], cs[q + vpr + 1]);
33223
+ addVertex(ps[q + 1], cs[q + 1]);
33224
+ addVertex(ps[q + vpr], cs[q + vpr]);
33225
+ }
33226
+ }
33227
+ }
33228
+ }
33229
+ return { posData, colData, vertexCount };
33230
+ }
33231
+ var MeshStreamReader = class {
33232
+ constructor(stream, context) {
33233
+ this.stream = stream;
33234
+ this.context = context;
33235
+ this.buffer = 0;
33236
+ this.bufferLength = 0;
33237
+ const numComps = context.numComps;
33238
+ this.tmpCompsBuf = new Float32Array(numComps);
33239
+ const csNumComps = context.colorSpace.numComps;
33240
+ this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
33241
+ }
33242
+ get hasData() {
33243
+ if (this.stream.end) {
33244
+ return this.stream.pos < this.stream.end;
33245
+ }
33246
+ if (this.bufferLength > 0) {
33247
+ return true;
33248
+ }
33249
+ const nextByte = this.stream.getByte();
33250
+ if (nextByte < 0) {
33251
+ return false;
33252
+ }
33253
+ this.buffer = nextByte;
33254
+ this.bufferLength = 8;
33255
+ return true;
33256
+ }
33257
+ readBits(n) {
33258
+ const { stream } = this;
33259
+ let { buffer, bufferLength } = this;
33260
+ if (n === 32) {
33261
+ if (bufferLength === 0) {
33262
+ return stream.getInt32() >>> 0;
33263
+ }
33264
+ buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte();
33265
+ const nextByte = stream.getByte();
33266
+ this.buffer = nextByte & (1 << bufferLength) - 1;
33267
+ return (buffer << 8 - bufferLength | (nextByte & 255) >> bufferLength) >>> 0;
33268
+ }
33269
+ if (n === 8 && bufferLength === 0) {
33270
+ return stream.getByte();
33271
+ }
33272
+ while (bufferLength < n) {
33273
+ buffer = buffer << 8 | stream.getByte();
33274
+ bufferLength += 8;
33275
+ }
33276
+ bufferLength -= n;
33277
+ this.bufferLength = bufferLength;
33278
+ this.buffer = buffer & (1 << bufferLength) - 1;
33279
+ return buffer >> bufferLength;
33280
+ }
33281
+ align() {
33282
+ this.buffer = 0;
33283
+ this.bufferLength = 0;
33284
+ }
33285
+ readFlag() {
33286
+ return this.readBits(this.context.bitsPerFlag);
33287
+ }
33288
+ readCoordinate() {
33289
+ const { bitsPerCoordinate, decode } = this.context;
33290
+ const xi = this.readBits(bitsPerCoordinate);
33291
+ const yi = this.readBits(bitsPerCoordinate);
33292
+ const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 23283064365386963e-26;
33293
+ return [
33294
+ xi * scale * (decode[1] - decode[0]) + decode[0],
33295
+ yi * scale * (decode[3] - decode[2]) + decode[2]
33296
+ ];
33297
+ }
33298
+ readComponents() {
33299
+ const { bitsPerComponent, colorFn, colorSpace, decode, numComps } = this.context;
33300
+ const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 23283064365386963e-26;
33301
+ const components2 = this.tmpCompsBuf;
33302
+ for (let i = 0, j = 4; i < numComps; i++, j += 2) {
33303
+ const ci = this.readBits(bitsPerComponent);
33304
+ components2[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
33305
+ }
33306
+ const color = this.tmpCsCompsBuf;
33307
+ colorFn?.(components2, 0, color, 0);
33308
+ return colorSpace.getRgb(color, 0);
33309
+ }
33310
+ };
33311
+ var bCache = null;
33312
+ function getB(count) {
33313
+ if (bCache?.has(count)) return bCache.get(count);
33314
+ const values = Array.from({ length: count + 1 }, (_, i) => {
33315
+ const t = i / count, t_ = 1 - t;
33316
+ return new Float32Array([
33317
+ t_ ** 3,
33318
+ 3 * t * t_ ** 2,
33319
+ 3 * t ** 2 * t_,
33320
+ t ** 3
33321
+ ]);
33322
+ });
33323
+ (bCache ??= /* @__PURE__ */ new Map()).set(count, values);
33324
+ return values;
33325
+ }
33326
+ var MeshShading = class _MeshShading extends BaseShading {
33327
+ static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
33328
+ static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
33329
+ // Count of triangles per entire mesh bounds.
33330
+ static TRIANGLE_DENSITY = 20;
33331
+ constructor(shadingType, stream, context, rowVertices) {
33332
+ super();
33333
+ this.shadingType = shadingType;
33334
+ this.bbox = this.background = null;
33335
+ this.coords = [];
33336
+ this.colors = [];
33337
+ this.figures = [];
33338
+ const reader = new MeshStreamReader(stream, context);
33339
+ let patchMesh = false;
33340
+ switch (this.shadingType) {
33341
+ case ShadingType.FREE_FORM_MESH:
33342
+ this._decodeType4Shading(reader);
33343
+ break;
33344
+ case ShadingType.LATTICE_FORM_MESH:
33345
+ const verticesPerRow = rowVertices | 0;
33346
+ if (verticesPerRow < 2) {
33347
+ throw new FormatError("Invalid VerticesPerRow");
33348
+ }
33349
+ this._decodeType5Shading(reader, verticesPerRow);
33350
+ break;
33351
+ case ShadingType.COONS_PATCH_MESH:
33352
+ this._decodeType6Shading(reader);
33353
+ patchMesh = true;
33354
+ break;
33355
+ case ShadingType.TENSOR_PATCH_MESH:
33356
+ this._decodeType7Shading(reader);
33357
+ patchMesh = true;
33358
+ break;
33359
+ default:
33360
+ unreachable2("Unsupported mesh type.");
33361
+ break;
33362
+ }
33363
+ if (patchMesh) {
33364
+ this._updateBounds();
33365
+ for (let i = 0, ii = this.figures.length; i < ii; i++) {
33366
+ this._buildFigureFromPatch(i);
33367
+ }
33368
+ }
33369
+ this._updateBounds();
33370
+ this._packData();
33371
+ }
33372
+ _decodeType4Shading(reader) {
33373
+ const coords = this.coords;
33374
+ const colors = this.colors;
33375
+ const operators = [];
33376
+ const ps = [];
33377
+ let verticesLeft = 0;
33378
+ while (reader.hasData) {
33379
+ const f = reader.readFlag();
33380
+ const coord = reader.readCoordinate();
33381
+ const color = reader.readComponents();
33382
+ if (verticesLeft === 0) {
33383
+ if (!(0 <= f && f <= 2)) {
33384
+ throw new FormatError("Unknown type4 flag");
33385
+ }
33386
+ switch (f) {
33387
+ case 0:
33388
+ verticesLeft = 3;
33389
+ break;
33390
+ case 1:
33391
+ ps.push(ps.at(-2), ps.at(-1));
33392
+ verticesLeft = 1;
33393
+ break;
33394
+ case 2:
33395
+ ps.push(ps.at(-3), ps.at(-1));
33396
+ verticesLeft = 1;
33397
+ break;
33398
+ }
33399
+ operators.push(f);
33400
+ }
33401
+ ps.push(coords.length);
33402
+ coords.push(coord);
33403
+ colors.push(color);
33404
+ verticesLeft--;
33405
+ reader.align();
33406
+ }
33407
+ this.figures.push({
33408
+ type: MeshFigureType.TRIANGLES,
33409
+ coords: new Int32Array(ps),
33410
+ colors: new Int32Array(ps)
33411
+ });
33412
+ }
33413
+ _decodeType5Shading(reader, verticesPerRow) {
33414
+ const coords = this.coords;
33415
+ const colors = this.colors;
33416
+ const ps = [];
33417
+ while (reader.hasData) {
33418
+ const coord = reader.readCoordinate();
33419
+ const color = reader.readComponents();
33420
+ ps.push(coords.length);
33421
+ coords.push(coord);
33422
+ colors.push(color);
33423
+ }
33424
+ this.figures.push({
33425
+ type: MeshFigureType.LATTICE,
33426
+ coords: new Int32Array(ps),
33427
+ colors: new Int32Array(ps),
33428
+ verticesPerRow
33429
+ });
33430
+ }
33431
+ _decodeType6Shading(reader) {
33432
+ const coords = this.coords;
33433
+ const colors = this.colors;
33434
+ const ps = new Int32Array(16);
33435
+ const cs = new Int32Array(4);
33436
+ while (reader.hasData) {
33437
+ const f = reader.readFlag();
33438
+ if (!(0 <= f && f <= 3)) {
33439
+ throw new FormatError("Unknown type6 flag");
33440
+ }
33441
+ const pi = coords.length;
33442
+ for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
33443
+ coords.push(reader.readCoordinate());
33444
+ }
33445
+ const ci = colors.length;
33446
+ for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
33447
+ colors.push(reader.readComponents());
33448
+ }
33449
+ let tmp1, tmp2, tmp3, tmp4;
33450
+ switch (f) {
33451
+ // prettier-ignore
33452
+ case 0:
33453
+ ps[12] = pi + 3;
33454
+ ps[13] = pi + 4;
33455
+ ps[14] = pi + 5;
33456
+ ps[15] = pi + 6;
33457
+ ps[8] = pi + 2;
33458
+ ps[11] = pi + 7;
33459
+ ps[4] = pi + 1;
33460
+ ps[7] = pi + 8;
33461
+ ps[0] = pi;
33462
+ ps[1] = pi + 11;
33463
+ ps[2] = pi + 10;
33464
+ ps[3] = pi + 9;
33465
+ cs[2] = ci + 1;
33466
+ cs[3] = ci + 2;
33467
+ cs[0] = ci;
33468
+ cs[1] = ci + 3;
33469
+ break;
33470
+ // prettier-ignore
33471
+ case 1:
33472
+ tmp1 = ps[12];
33473
+ tmp2 = ps[13];
33474
+ tmp3 = ps[14];
33475
+ tmp4 = ps[15];
33476
+ ps[12] = tmp4;
33477
+ ps[13] = pi + 0;
33478
+ ps[14] = pi + 1;
33479
+ ps[15] = pi + 2;
33480
+ ps[8] = tmp3;
33481
+ ps[11] = pi + 3;
33482
+ ps[4] = tmp2;
33483
+ ps[7] = pi + 4;
33484
+ ps[0] = tmp1;
33485
+ ps[1] = pi + 7;
33486
+ ps[2] = pi + 6;
33487
+ ps[3] = pi + 5;
33488
+ tmp1 = cs[2];
33489
+ tmp2 = cs[3];
33490
+ cs[2] = tmp2;
33491
+ cs[3] = ci;
33492
+ cs[0] = tmp1;
33493
+ cs[1] = ci + 1;
33494
+ break;
33495
+ // prettier-ignore
33496
+ case 2:
33497
+ tmp1 = ps[15];
33498
+ tmp2 = ps[11];
33499
+ ps[12] = ps[3];
33500
+ ps[13] = pi + 0;
33501
+ ps[14] = pi + 1;
33502
+ ps[15] = pi + 2;
33503
+ ps[8] = ps[7];
33504
+ ps[11] = pi + 3;
33505
+ ps[4] = tmp2;
33506
+ ps[7] = pi + 4;
33507
+ ps[0] = tmp1;
33508
+ ps[1] = pi + 7;
33509
+ ps[2] = pi + 6;
33510
+ ps[3] = pi + 5;
33511
+ tmp1 = cs[3];
33512
+ cs[2] = cs[1];
33513
+ cs[3] = ci;
33514
+ cs[0] = tmp1;
33515
+ cs[1] = ci + 1;
33516
+ break;
33517
+ // prettier-ignore
33518
+ case 3:
33519
+ ps[12] = ps[0];
33520
+ ps[13] = pi + 0;
33521
+ ps[14] = pi + 1;
33522
+ ps[15] = pi + 2;
33523
+ ps[8] = ps[1];
33524
+ ps[11] = pi + 3;
33525
+ ps[4] = ps[2];
33526
+ ps[7] = pi + 4;
33527
+ ps[0] = ps[3];
33528
+ ps[1] = pi + 7;
33529
+ ps[2] = pi + 6;
33530
+ ps[3] = pi + 5;
33531
+ cs[2] = cs[0];
33532
+ cs[3] = ci;
33533
+ cs[0] = cs[1];
33534
+ cs[1] = ci + 1;
33535
+ break;
33536
+ }
33537
+ ps[5] = coords.length;
33538
+ coords.push([
33539
+ (-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,
33540
+ (-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
33541
+ ]);
33542
+ ps[6] = coords.length;
33543
+ coords.push([
33544
+ (-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,
33545
+ (-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
33546
+ ]);
33547
+ ps[9] = coords.length;
33548
+ coords.push([
33549
+ (-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,
33550
+ (-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
33551
+ ]);
33552
+ ps[10] = coords.length;
33553
+ coords.push([
33554
+ (-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,
33555
+ (-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
33556
+ ]);
33557
+ this.figures.push({
33558
+ type: MeshFigureType.PATCH,
33559
+ coords: new Int32Array(ps),
33560
+ // making copies of ps and cs
33561
+ colors: new Int32Array(cs)
33562
+ });
33563
+ }
33564
+ }
33565
+ _decodeType7Shading(reader) {
33566
+ const coords = this.coords;
33567
+ const colors = this.colors;
33568
+ const ps = new Int32Array(16);
33569
+ const cs = new Int32Array(4);
33570
+ while (reader.hasData) {
33571
+ const f = reader.readFlag();
33572
+ if (!(0 <= f && f <= 3)) {
33573
+ throw new FormatError("Unknown type7 flag");
33574
+ }
33575
+ const pi = coords.length;
33576
+ for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
33577
+ coords.push(reader.readCoordinate());
33578
+ }
33579
+ const ci = colors.length;
33580
+ for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
33581
+ colors.push(reader.readComponents());
33582
+ }
33583
+ let tmp1, tmp2, tmp3, tmp4;
33584
+ switch (f) {
33585
+ // prettier-ignore
33586
+ case 0:
33587
+ ps[12] = pi + 3;
33588
+ ps[13] = pi + 4;
33589
+ ps[14] = pi + 5;
33590
+ ps[15] = pi + 6;
33591
+ ps[8] = pi + 2;
33592
+ ps[9] = pi + 13;
33593
+ ps[10] = pi + 14;
33594
+ ps[11] = pi + 7;
33595
+ ps[4] = pi + 1;
33596
+ ps[5] = pi + 12;
33597
+ ps[6] = pi + 15;
33598
+ ps[7] = pi + 8;
33599
+ ps[0] = pi;
33600
+ ps[1] = pi + 11;
33601
+ ps[2] = pi + 10;
33602
+ ps[3] = pi + 9;
33603
+ cs[2] = ci + 1;
33604
+ cs[3] = ci + 2;
33605
+ cs[0] = ci;
33606
+ cs[1] = ci + 3;
33607
+ break;
33608
+ // prettier-ignore
33609
+ case 1:
33610
+ tmp1 = ps[12];
33611
+ tmp2 = ps[13];
33612
+ tmp3 = ps[14];
33613
+ tmp4 = ps[15];
33614
+ ps[12] = tmp4;
33615
+ ps[13] = pi + 0;
33616
+ ps[14] = pi + 1;
33617
+ ps[15] = pi + 2;
33618
+ ps[8] = tmp3;
33619
+ ps[9] = pi + 9;
33620
+ ps[10] = pi + 10;
33621
+ ps[11] = pi + 3;
33622
+ ps[4] = tmp2;
33623
+ ps[5] = pi + 8;
33624
+ ps[6] = pi + 11;
33625
+ ps[7] = pi + 4;
33626
+ ps[0] = tmp1;
33627
+ ps[1] = pi + 7;
33628
+ ps[2] = pi + 6;
33629
+ ps[3] = pi + 5;
33630
+ tmp1 = cs[2];
33631
+ tmp2 = cs[3];
33632
+ cs[2] = tmp2;
33633
+ cs[3] = ci;
33634
+ cs[0] = tmp1;
33635
+ cs[1] = ci + 1;
33636
+ break;
33637
+ // prettier-ignore
33638
+ case 2:
33639
+ tmp1 = ps[15];
33640
+ tmp2 = ps[11];
33641
+ ps[12] = ps[3];
33642
+ ps[13] = pi + 0;
33643
+ ps[14] = pi + 1;
33644
+ ps[15] = pi + 2;
33645
+ ps[8] = ps[7];
33646
+ ps[9] = pi + 9;
33647
+ ps[10] = pi + 10;
33648
+ ps[11] = pi + 3;
33649
+ ps[4] = tmp2;
33650
+ ps[5] = pi + 8;
33651
+ ps[6] = pi + 11;
33652
+ ps[7] = pi + 4;
33653
+ ps[0] = tmp1;
33654
+ ps[1] = pi + 7;
33655
+ ps[2] = pi + 6;
33656
+ ps[3] = pi + 5;
33657
+ tmp1 = cs[3];
33658
+ cs[2] = cs[1];
33659
+ cs[3] = ci;
33660
+ cs[0] = tmp1;
33661
+ cs[1] = ci + 1;
33662
+ break;
33663
+ // prettier-ignore
33664
+ case 3:
33665
+ ps[12] = ps[0];
33666
+ ps[13] = pi + 0;
33667
+ ps[14] = pi + 1;
33668
+ ps[15] = pi + 2;
33669
+ ps[8] = ps[1];
33670
+ ps[9] = pi + 9;
33671
+ ps[10] = pi + 10;
33672
+ ps[11] = pi + 3;
33673
+ ps[4] = ps[2];
33674
+ ps[5] = pi + 8;
33675
+ ps[6] = pi + 11;
33676
+ ps[7] = pi + 4;
33677
+ ps[0] = ps[3];
33678
+ ps[1] = pi + 7;
33679
+ ps[2] = pi + 6;
33680
+ ps[3] = pi + 5;
33681
+ cs[2] = cs[0];
33682
+ cs[3] = ci;
33683
+ cs[0] = cs[1];
33684
+ cs[1] = ci + 1;
33685
+ break;
33686
+ }
33687
+ this.figures.push({
33688
+ type: MeshFigureType.PATCH,
33689
+ coords: new Int32Array(ps),
33690
+ // making copies of ps and cs
33691
+ colors: new Int32Array(cs)
33692
+ });
33693
+ }
33694
+ }
33695
+ _buildFigureFromPatch(index) {
33696
+ const figure = this.figures[index];
33697
+ assert2(
33698
+ figure.type === MeshFigureType.PATCH,
33699
+ "Unexpected patch mesh figure"
33700
+ );
33701
+ const coords = this.coords, colors = this.colors;
33702
+ const pi = figure.coords;
33703
+ const ci = figure.colors;
33704
+ const figureMinX = Math.min(
33705
+ coords[pi[0]][0],
33706
+ coords[pi[3]][0],
33707
+ coords[pi[12]][0],
33708
+ coords[pi[15]][0]
33709
+ );
33710
+ const figureMinY = Math.min(
33711
+ coords[pi[0]][1],
33712
+ coords[pi[3]][1],
33713
+ coords[pi[12]][1],
33714
+ coords[pi[15]][1]
33715
+ );
33716
+ const figureMaxX = Math.max(
33717
+ coords[pi[0]][0],
33718
+ coords[pi[3]][0],
33719
+ coords[pi[12]][0],
33720
+ coords[pi[15]][0]
33721
+ );
33722
+ const figureMaxY = Math.max(
33723
+ coords[pi[0]][1],
33724
+ coords[pi[3]][1],
33725
+ coords[pi[12]][1],
33726
+ coords[pi[15]][1]
33727
+ );
33728
+ let splitXBy = Math.ceil(
33729
+ (figureMaxX - figureMinX) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])
33730
+ );
33731
+ splitXBy = MathClamp(
33732
+ splitXBy,
33733
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
33734
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
33735
+ );
33736
+ let splitYBy = Math.ceil(
33737
+ (figureMaxY - figureMinY) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])
33738
+ );
33739
+ splitYBy = MathClamp(
33740
+ splitYBy,
33741
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
33742
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
33743
+ );
33744
+ const verticesPerRow = splitXBy + 1;
33745
+ const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
33746
+ const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
33747
+ let k = 0;
33748
+ const cl = new Uint8Array(3), cr = new Uint8Array(3);
33749
+ const c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
33750
+ const bRow = getB(splitYBy), bCol = getB(splitXBy);
33751
+ for (let row = 0; row <= splitYBy; row++) {
33752
+ cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
33753
+ cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
33754
+ cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
33755
+ cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
33756
+ cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
33757
+ cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
33758
+ for (let col = 0; col <= splitXBy; col++, k++) {
33759
+ if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
33760
+ continue;
33761
+ }
33762
+ let x = 0, y = 0;
33763
+ let q = 0;
33764
+ for (let i = 0; i <= 3; i++) {
33765
+ for (let j = 0; j <= 3; j++, q++) {
33766
+ const m = bRow[row][i] * bCol[col][j];
33767
+ x += coords[pi[q]][0] * m;
33768
+ y += coords[pi[q]][1] * m;
33769
+ }
33770
+ }
33771
+ figureCoords[k] = coords.length;
33772
+ coords.push([x, y]);
33773
+ figureColors[k] = colors.length;
33774
+ const newColor = new Uint8Array(3);
33775
+ newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
33776
+ newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
33777
+ newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
33778
+ colors.push(newColor);
33779
+ }
33780
+ }
33781
+ figureCoords[0] = pi[0];
33782
+ figureColors[0] = ci[0];
33783
+ figureCoords[splitXBy] = pi[3];
33784
+ figureColors[splitXBy] = ci[1];
33785
+ figureCoords[verticesPerRow * splitYBy] = pi[12];
33786
+ figureColors[verticesPerRow * splitYBy] = ci[2];
33787
+ figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
33788
+ figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
33789
+ this.figures[index] = {
33790
+ type: MeshFigureType.LATTICE,
33791
+ coords: figureCoords,
33792
+ colors: figureColors,
33793
+ verticesPerRow
33794
+ };
33795
+ }
33796
+ _updateBounds() {
33797
+ meshUpdateBounds(this);
33798
+ }
33799
+ _packData() {
33800
+ meshPackData(this);
33801
+ }
33802
+ getIR() {
33803
+ const { posData, colData, vertexCount } = buildMeshVertexData(
33804
+ this.coords,
33805
+ this.colors,
33806
+ this.figures
33807
+ );
33808
+ return [
33809
+ "Mesh",
33810
+ this.shadingType,
33811
+ posData,
33812
+ colData,
33813
+ vertexCount,
33814
+ this.bounds,
33815
+ this.bbox,
33816
+ this.background
33817
+ ];
33818
+ }
33819
+ };
33121
33820
  var PdfError = class extends Error {
33122
33821
  constructor(code, message) {
33123
33822
  super(message);
@@ -36023,11 +36722,16 @@ function parseDictionaryStream(dictNode, lexer, bytes) {
36023
36722
  let streamEnd = streamStart;
36024
36723
  if (resolvedLength !== void 0 && resolvedLength >= 0 && streamStart + resolvedLength <= bytes.length) {
36025
36724
  const candidateEnd = streamStart + resolvedLength;
36026
- const tailSlice = bytes.subarray(candidateEnd, Math.min(bytes.length, candidateEnd + 32));
36027
- const tailStr = new TextDecoder("latin1").decode(tailSlice);
36028
- if (tailStr.includes("endstream")) {
36725
+ const tailLexer = new CosByteLexer(bytes, candidateEnd);
36726
+ let endToken;
36727
+ try {
36728
+ endToken = tailLexer.nextToken();
36729
+ } catch (error) {
36730
+ if (!(error instanceof PdfError) || error.code !== "E_PARSE") throw error;
36731
+ }
36732
+ if (endToken?.kind === "keyword" && endToken.value === "endstream") {
36029
36733
  rawStreamBytes = bytes.subarray(streamStart, candidateEnd);
36030
- streamEnd = candidateEnd + tailStr.indexOf("endstream") + "endstream".length;
36734
+ streamEnd = tailLexer.offset;
36031
36735
  }
36032
36736
  }
36033
36737
  if (!rawStreamBytes) {
@@ -44993,21 +45697,23 @@ function resolvePageFonts(doc, resourcesDict) {
44993
45697
  }
44994
45698
  }
44995
45699
  } else {
44996
- const stdName = normalizeStandard14FontName(baseFont);
44997
- const stdMetrics = STANDARD_14_FONTS[stdName];
44998
- defaultWidth = stdMetrics.defaultWidth;
44999
- for (const [codeStr, wVal] of Object.entries(stdMetrics.widthsByCode)) {
45000
- widths.set(Number(codeStr), wVal);
45001
- }
45002
45700
  const firstCharNode = doc.resolve(dictGet(fObj, "FirstChar"));
45003
45701
  const widthsArr = doc.resolveArray(dictGet(fObj, "Widths"));
45004
- if (firstCharNode?.kind === "number" && widthsArr) {
45702
+ if (widthsArr) {
45703
+ const descriptor = doc.resolveDict(dictGet(fObj, "FontDescriptor"));
45704
+ const missingWidth = descriptor ? doc.resolve(dictGet(descriptor, "MissingWidth")) : void 0;
45705
+ defaultWidth = (missingWidth?.kind === "number" ? missingWidth.value : 0) * type3Scale1000;
45706
+ const firstChar = firstCharNode?.kind === "number" ? firstCharNode.value : 0;
45005
45707
  for (let k = 0; k < widthsArr.items.length; k++) {
45006
45708
  const wItem = doc.resolve(widthsArr.items[k]);
45007
45709
  if (wItem?.kind === "number") {
45008
- widths.set(firstCharNode.value + k, wItem.value * type3Scale1000);
45710
+ widths.set(firstChar + k, wItem.value * type3Scale1000);
45009
45711
  }
45010
45712
  }
45713
+ } else {
45714
+ const stdMetrics = STANDARD_14_FONTS[normalizeStandard14FontName(baseFont)];
45715
+ defaultWidth = stdMetrics.defaultWidth;
45716
+ for (const [codeStr, wVal] of Object.entries(stdMetrics.widthsByCode)) widths.set(Number(codeStr), wVal);
45011
45717
  }
45012
45718
  }
45013
45719
  let embeddedCff;
@@ -45396,143 +46102,28 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
45396
46102
  const r = doc.resolve(it);
45397
46103
  return r?.kind === "number" ? r.value : 0;
45398
46104
  });
45399
- const xmin = decodeNums[0], xmax = decodeNums[1], ymin = decodeNums[2], ymax = decodeNums[3];
45400
- const numColorParams = Math.max(1, Math.floor((decodeNums.length - 4) / 2));
45401
46105
  const fnNode = dictGet(shDict, "Function");
45402
46106
  const csNode = doc.resolve(dictGet(shDict, "ColorSpace"));
45403
46107
  const csName = csNode?.kind === "name" ? csNode.decoded : "DeviceRGB";
45404
- let bitPos = 0;
45405
- const totalBits = bytes.length * 8;
45406
- const readBits = (n) => {
45407
- let val = 0;
45408
- for (let i = 0; i < n; i++) {
45409
- if (bitPos >= totalBits) return val;
45410
- const byteIdx = bitPos >> 3;
45411
- const bitIdx = 7 - (bitPos & 7);
45412
- val = val * 2 + (bytes[byteIdx] >> bitIdx & 1);
45413
- bitPos++;
45414
- }
45415
- return val;
45416
- };
45417
- const coordMax = Math.pow(2, bpcCoord) - 1 || 1;
45418
- const compMax = Math.pow(2, bpcComp) - 1 || 1;
45419
- const readCoord = () => {
45420
- const rx = readBits(bpcCoord) / coordMax;
45421
- const ry = readBits(bpcCoord) / coordMax;
45422
- return [xmin + rx * (xmax - xmin), ymin + ry * (ymax - ymin)];
45423
- };
45424
- const readColorRgb = () => {
45425
- const params = [];
45426
- for (let c = 0; c < numColorParams; c++) {
45427
- const rc = readBits(bpcComp) / compMax;
45428
- const cMin = decodeNums[4 + c * 2] ?? 0;
45429
- const cMax = decodeNums[4 + c * 2 + 1] ?? 1;
45430
- params.push(cMin + rc * (cMax - cMin));
45431
- }
45432
- const comps = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
45433
- return convertColorSpaceComponentsToRgb(doc, csNode, csName, comps);
45434
- };
45435
- const triangles = [];
45436
- if (shType === 4) {
45437
- const minBitsPerVert = bpcFlag + 2 * bpcCoord + numColorParams * bpcComp;
45438
- let triVerts;
45439
- while (bitPos + minBitsPerVert <= totalBits) {
45440
- const flag = readBits(bpcFlag) & 3;
45441
- const [x, y] = readCoord();
45442
- const rgb2 = readColorRgb();
45443
- const vNew = { x, y, rgb: rgb2 };
45444
- if (flag === 0 || !triVerts) {
45445
- if (bitPos + 2 * minBitsPerVert > totalBits) break;
45446
- readBits(bpcFlag);
45447
- const [x1, y1] = readCoord();
45448
- const rgb1 = readColorRgb();
45449
- readBits(bpcFlag);
45450
- const [x2, y2] = readCoord();
45451
- const rgb22 = readColorRgb();
45452
- triVerts = [vNew, { x: x1, y: y1, rgb: rgb1 }, { x: x2, y: y2, rgb: rgb22 }];
45453
- triangles.push(triVerts);
45454
- } else if (flag === 1) {
45455
- triVerts = [triVerts[1], triVerts[2], vNew];
45456
- triangles.push(triVerts);
45457
- } else if (flag === 2) {
45458
- triVerts = [triVerts[0], triVerts[2], vNew];
45459
- triangles.push(triVerts);
45460
- }
45461
- }
45462
- } else if (shType === 5) {
45463
- const minBitsPerVert = 2 * bpcCoord + numColorParams * bpcComp;
45464
- const verts = [];
45465
- while (bitPos + minBitsPerVert <= totalBits) {
45466
- const [x, y] = readCoord();
45467
- const rgb2 = readColorRgb();
45468
- verts.push({ x, y, rgb: rgb2 });
45469
- }
45470
- const numRows = Math.floor(verts.length / vPerRow);
45471
- for (let r = 0; r + 1 < numRows; r++) {
45472
- for (let c = 0; c + 1 < vPerRow; c++) {
45473
- const v00 = verts[r * vPerRow + c];
45474
- const v01 = verts[r * vPerRow + c + 1];
45475
- const v11 = verts[(r + 1) * vPerRow + c + 1];
45476
- const v10 = verts[(r + 1) * vPerRow + c];
45477
- triangles.push([v00, v01, v11], [v00, v11, v10]);
45478
- }
45479
- }
45480
- } else if (shType === 6 || shType === 7) {
45481
- const numCtrl = shType === 6 ? 12 : 16;
45482
- const minBitsPatch = bpcFlag + (numCtrl - 4) * 2 * bpcCoord + 2 * numColorParams * bpcComp;
45483
- let prevPts;
45484
- let prevColors;
45485
- while (bitPos + minBitsPatch <= totalBits) {
45486
- const flag = readBits(bpcFlag) & 3;
45487
- let pts = [];
45488
- let cols = [];
45489
- if (flag === 0 || !prevPts || !prevColors) {
45490
- for (let i = 0; i < numCtrl; i++) pts.push(readCoord());
45491
- for (let i = 0; i < 4; i++) cols.push(readColorRgb());
45492
- } else {
45493
- const extraCtrl = numCtrl - 4;
45494
- const readExtra = [];
45495
- for (let i = 0; i < extraCtrl; i++) readExtra.push(readCoord());
45496
- const c2 = readColorRgb();
45497
- const c3 = readColorRgb();
45498
- pts = [prevPts[3], prevPts[4], prevPts[5], prevPts[6], ...readExtra];
45499
- cols = [prevColors[1], prevColors[2], c2, c3];
45500
- }
45501
- prevPts = pts;
45502
- prevColors = cols;
45503
- const p00 = pts[0];
45504
- const p03 = pts[3];
45505
- const p33 = pts[6];
45506
- const p30 = pts[9];
45507
- const c00 = cols[0], c03 = cols[1], c33 = cols[2], c30 = cols[3];
45508
- const steps = 4;
45509
- const grid = [];
45510
- for (let iu = 0; iu <= steps; iu++) {
45511
- const u = iu / steps;
45512
- const row = [];
45513
- for (let iv = 0; iv <= steps; iv++) {
45514
- const v = iv / steps;
45515
- const x = (1 - u) * (1 - v) * p00[0] + (1 - u) * v * p03[0] + u * v * p33[0] + u * (1 - v) * p30[0];
45516
- const y = (1 - u) * (1 - v) * p00[1] + (1 - u) * v * p03[1] + u * v * p33[1] + u * (1 - v) * p30[1];
45517
- const r = (1 - u) * (1 - v) * c00[0] + (1 - u) * v * c03[0] + u * v * c33[0] + u * (1 - v) * c30[0];
45518
- const g = (1 - u) * (1 - v) * c00[1] + (1 - u) * v * c03[1] + u * v * c33[1] + u * (1 - v) * c30[1];
45519
- const b = (1 - u) * (1 - v) * c00[2] + (1 - u) * v * c03[2] + u * v * c33[2] + u * (1 - v) * c30[2];
45520
- row.push({ x, y, rgb: [r, g, b] });
45521
- }
45522
- grid.push(row);
45523
- }
45524
- for (let iu = 0; iu < steps; iu++) {
45525
- for (let iv = 0; iv < steps; iv++) {
45526
- const g00 = grid[iu][iv];
45527
- const g01 = grid[iu][iv + 1];
45528
- const g11 = grid[iu + 1][iv + 1];
45529
- const g10 = grid[iu + 1][iv];
45530
- triangles.push([g00, g01, g11], [g00, g11, g10]);
45531
- }
45532
- }
45533
- }
45534
- }
45535
- if (triangles.length === 0) return void 0;
46108
+ const numComps = fnNode ? 1 : getColorSpaceComponentCount(doc, csNode);
46109
+ const mesh = new MeshShading(shType, new Stream(bytes), {
46110
+ bitsPerCoordinate: bpcCoord,
46111
+ bitsPerComponent: bpcComp,
46112
+ bitsPerFlag: bpcFlag,
46113
+ decode: decodeNums,
46114
+ numComps,
46115
+ colorFn: null,
46116
+ colorSpace: {
46117
+ numComps,
46118
+ getRgb(components2) {
46119
+ const params = Array.from(components2);
46120
+ const values = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
46121
+ return new Uint8Array(convertColorSpaceComponentsToRgb(doc, csNode, csName, values).map((value) => Math.round(Math.max(0, Math.min(1, value)) * 255)));
46122
+ }
46123
+ }
46124
+ }, vPerRow);
46125
+ const [, , positions, colors, vertexCount] = mesh.getIR();
46126
+ if (vertexCount === 0) return void 0;
45536
46127
  const [bx0, by0, bx1, by1] = targetBox;
45537
46128
  const boxW = Math.max(1, bx1 - bx0);
45538
46129
  const boxH = Math.max(1, by1 - by0);
@@ -45544,10 +46135,10 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
45544
46135
  const [px, py] = transformPoint(effectiveCtm, vx, vy);
45545
46136
  return [(px - bx0) / boxW * imgW, (by1 - py) / boxH * imgH];
45546
46137
  };
45547
- for (const [v0, v1, v2] of triangles) {
45548
- const [x0, y0] = toImgCoords(v0.x, v0.y);
45549
- const [x1, y1] = toImgCoords(v1.x, v1.y);
45550
- const [x2, y2] = toImgCoords(v2.x, v2.y);
46138
+ for (let vertex = 0; vertex < vertexCount; vertex += 3) {
46139
+ const [x0, y0] = toImgCoords(positions[vertex * 2], positions[vertex * 2 + 1]);
46140
+ const [x1, y1] = toImgCoords(positions[vertex * 2 + 2], positions[vertex * 2 + 3]);
46141
+ const [x2, y2] = toImgCoords(positions[vertex * 2 + 4], positions[vertex * 2 + 5]);
45551
46142
  const denom = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2);
45552
46143
  if (Math.abs(denom) < 1e-6) continue;
45553
46144
  const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
@@ -45562,13 +46153,12 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
45562
46153
  const w1 = ((y2 - y0) * (px - x2) + (x0 - x2) * (py - y2)) / denom;
45563
46154
  const w2 = 1 - w0 - w1;
45564
46155
  if (w0 >= -1e-4 && w1 >= -1e-4 && w2 >= -1e-4) {
45565
- const r = w0 * v0.rgb[0] + w1 * v1.rgb[0] + w2 * v2.rgb[0];
45566
- const g = w0 * v0.rgb[1] + w1 * v1.rgb[1] + w2 * v2.rgb[1];
45567
- const b = w0 * v0.rgb[2] + w1 * v1.rgb[2] + w2 * v2.rgb[2];
45568
46156
  const pIdx = (iy * imgW + ix) * 4;
45569
- rgba[pIdx] = Math.round(Math.max(0, Math.min(1, r)) * 255);
45570
- rgba[pIdx + 1] = Math.round(Math.max(0, Math.min(1, g)) * 255);
45571
- rgba[pIdx + 2] = Math.round(Math.max(0, Math.min(1, b)) * 255);
46157
+ for (let channel = 0; channel < 3; channel++) {
46158
+ rgba[pIdx + channel] = Math.round(
46159
+ w0 * colors[vertex * 4 + channel] + w1 * colors[vertex * 4 + 4 + channel] + w2 * colors[vertex * 4 + 8 + channel]
46160
+ );
46161
+ }
45572
46162
  rgba[pIdx + 3] = a8;
45573
46163
  }
45574
46164
  }
@@ -45655,6 +46245,8 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
45655
46245
  const [a, b, c, d, e, f] = effectiveCtm;
45656
46246
  const det = a * d - b * c;
45657
46247
  if (Math.abs(det) <= 1e-8) return void 0;
46248
+ const [sa, sb, sc, sd, se, sf] = shadingCtm;
46249
+ const shadingDet = sa * sd - sb * sc;
45658
46250
  const t0Dom = shDomain[0] ?? 0;
45659
46251
  const t1Dom = shDomain[1] ?? 1;
45660
46252
  for (let iy = 0; iy < imgH; iy++) {
@@ -45665,8 +46257,10 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
45665
46257
  const dxPdf = xPdf - e;
45666
46258
  const xs = (d * dxPdf - c * dyPdf) / det;
45667
46259
  const ys = (-b * dxPdf + a * dyPdf) / det;
45668
- if (shBBox && (xs < shBBox[0] || xs > shBBox[2] || ys < shBBox[1] || ys > shBBox[3])) {
45669
- continue;
46260
+ if (shBBox) {
46261
+ const bboxX = (sd * (xPdf - se) - sc * (yPdf - sf)) / shadingDet;
46262
+ const bboxY = (-sb * (xPdf - se) + sa * (yPdf - sf)) / shadingDet;
46263
+ if (bboxX < shBBox[0] || bboxX > shBBox[2] || bboxY < shBBox[1] || bboxY > shBBox[3]) continue;
45670
46264
  }
45671
46265
  let comps;
45672
46266
  if (shType === 1) {
@@ -45875,13 +46469,11 @@ function evaluateContentStreamToDisplayList(params) {
45875
46469
  }
45876
46470
  if (font?.cmap) {
45877
46471
  if (!font.isTwoByteCid) {
45878
- const stdName2 = normalizeStandard14FontName(font.baseFont);
45879
- const stdMetrics2 = STANDARD_14_FONTS[stdName2];
45880
46472
  const out2 = [];
45881
46473
  for (let i = 0; i < bytes.length; i++) {
45882
46474
  const code = bytes[i];
45883
46475
  const unicode = font.cmap.map.get(code) ?? (font.differences.has(code) ? font.differences.get(code) : decodeWinAnsiByte(code));
45884
- const advance1000 = font.widths.get(code) ?? stdMetrics2.widthsByCode[code] ?? stdMetrics2.defaultWidth;
46476
+ const advance1000 = font.widths.get(code) ?? font.defaultWidth;
45885
46477
  out2.push({ charCode: code, isSpace: code === 32, unicode, advance1000 });
45886
46478
  }
45887
46479
  return out2;
@@ -45913,7 +46505,7 @@ function evaluateContentStreamToDisplayList(params) {
45913
46505
  for (let i = 0; i < bytes.length; i++) {
45914
46506
  const code = bytes[i];
45915
46507
  const unicode = font?.differences.get(code) ?? decodeWinAnsiByte(code);
45916
- const advance1000 = font?.widths.get(code) ?? stdMetrics.widthsByCode[code] ?? stdMetrics.defaultWidth;
46508
+ const advance1000 = font ? font.widths.get(code) ?? font.defaultWidth : stdMetrics.widthsByCode[code] ?? stdMetrics.defaultWidth;
45917
46509
  out.push({ charCode: code, isSpace: code === 32, unicode, advance1000 });
45918
46510
  }
45919
46511
  return out;