@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
@@ -148,6 +148,11 @@ var FONT_IDENTITY_MATRIX = [1e-3, 0, 0, 1e-3, 0, 0];
148
148
  var LINE_FACTOR = 1.35;
149
149
  var LINE_DESCENT_FACTOR = 0.35;
150
150
  var BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
151
+ var MeshFigureType = {
152
+ TRIANGLES: 1,
153
+ LATTICE: 2,
154
+ PATCH: 3
155
+ };
151
156
  var VerbosityLevel = {
152
157
  ERRORS: 0,
153
158
  WARNINGS: 1,
@@ -21680,6 +21685,700 @@ function buildPostScriptJsFunction(source, domain, range, forceInterpreter = fal
21680
21685
  }
21681
21686
  return PSStackBasedInterpreter.build(program, domain, range);
21682
21687
  }
21688
+ var ShadingType = {
21689
+ FUNCTION_BASED: 1,
21690
+ AXIAL: 2,
21691
+ RADIAL: 3,
21692
+ FREE_FORM_MESH: 4,
21693
+ LATTICE_FORM_MESH: 5,
21694
+ COONS_PATCH_MESH: 6,
21695
+ TENSOR_PATCH_MESH: 7
21696
+ };
21697
+ var BaseShading = class _BaseShading {
21698
+ // A small number to offset the first/last color stops so we can insert ones
21699
+ // to support extend. Number.MIN_VALUE is too small and breaks the extend.
21700
+ static SMALL_NUMBER = 1e-6;
21701
+ constructor() {
21702
+ if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === _BaseShading) {
21703
+ unreachable2("Cannot initialize BaseShading.");
21704
+ }
21705
+ }
21706
+ getIR() {
21707
+ unreachable2("Abstract method `getIR` called.");
21708
+ }
21709
+ };
21710
+ function meshUpdateBounds(self) {
21711
+ let minX = self.coords[0][0], minY = self.coords[0][1], maxX = minX, maxY = minY;
21712
+ for (let i = 1, ii = self.coords.length; i < ii; i++) {
21713
+ const x = self.coords[i][0], y = self.coords[i][1];
21714
+ minX = minX > x ? x : minX;
21715
+ minY = minY > y ? y : minY;
21716
+ maxX = maxX < x ? x : maxX;
21717
+ maxY = maxY < y ? y : maxY;
21718
+ }
21719
+ self.bounds = [minX, minY, maxX, maxY];
21720
+ }
21721
+ function meshPackData(self) {
21722
+ let i, j, ii;
21723
+ const coords = self.coords;
21724
+ const coordsPacked = new Float32Array(coords.length * 2);
21725
+ for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
21726
+ const xy = coords[i];
21727
+ coordsPacked[j++] = xy[0];
21728
+ coordsPacked[j++] = xy[1];
21729
+ }
21730
+ self.coords = coordsPacked;
21731
+ const colors = self.colors;
21732
+ const colorsPacked = new Uint8Array(colors.length * 4);
21733
+ for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
21734
+ const c = colors[i];
21735
+ colorsPacked[j++] = c[0];
21736
+ colorsPacked[j++] = c[1];
21737
+ colorsPacked[j++] = c[2];
21738
+ j++;
21739
+ }
21740
+ self.colors = colorsPacked;
21741
+ for (const figure of self.figures) {
21742
+ figure.coords = new Uint32Array(figure.coords);
21743
+ figure.colors = new Uint32Array(figure.colors);
21744
+ }
21745
+ }
21746
+ function buildMeshVertexData(coords, colors, figures) {
21747
+ let vertexCount = 0;
21748
+ for (const figure of figures) {
21749
+ if (figure.type === MeshFigureType.TRIANGLES) {
21750
+ vertexCount += figure.coords.length;
21751
+ } else if (figure.type === MeshFigureType.LATTICE) {
21752
+ const vpr = figure.verticesPerRow;
21753
+ vertexCount += (Math.floor(figure.coords.length / vpr) - 1) * (vpr - 1) * 6;
21754
+ }
21755
+ }
21756
+ const posData = new Float32Array(vertexCount * 2);
21757
+ const colData = new Uint8Array(vertexCount * 4);
21758
+ let pOff = 0, cOff = 0;
21759
+ const addVertex = (pi, ci) => {
21760
+ posData[pOff++] = coords[pi * 2];
21761
+ posData[pOff++] = coords[pi * 2 + 1];
21762
+ colData[cOff++] = colors[ci * 4];
21763
+ colData[cOff++] = colors[ci * 4 + 1];
21764
+ colData[cOff++] = colors[ci * 4 + 2];
21765
+ cOff++;
21766
+ };
21767
+ for (const figure of figures) {
21768
+ const ps = figure.coords;
21769
+ const cs = figure.colors;
21770
+ if (figure.type === MeshFigureType.TRIANGLES) {
21771
+ for (let i = 0, ii = ps.length; i < ii; i++) {
21772
+ addVertex(ps[i], cs[i]);
21773
+ }
21774
+ } else if (figure.type === MeshFigureType.LATTICE) {
21775
+ const vpr = figure.verticesPerRow;
21776
+ const rows = Math.floor(ps.length / vpr) - 1;
21777
+ const cols = vpr - 1;
21778
+ for (let i = 0; i < rows; i++) {
21779
+ let q = i * vpr;
21780
+ for (let j = 0; j < cols; j++, q++) {
21781
+ addVertex(ps[q], cs[q]);
21782
+ addVertex(ps[q + 1], cs[q + 1]);
21783
+ addVertex(ps[q + vpr], cs[q + vpr]);
21784
+ addVertex(ps[q + vpr + 1], cs[q + vpr + 1]);
21785
+ addVertex(ps[q + 1], cs[q + 1]);
21786
+ addVertex(ps[q + vpr], cs[q + vpr]);
21787
+ }
21788
+ }
21789
+ }
21790
+ }
21791
+ return { posData, colData, vertexCount };
21792
+ }
21793
+ var MeshStreamReader = class {
21794
+ constructor(stream, context) {
21795
+ this.stream = stream;
21796
+ this.context = context;
21797
+ this.buffer = 0;
21798
+ this.bufferLength = 0;
21799
+ const numComps = context.numComps;
21800
+ this.tmpCompsBuf = new Float32Array(numComps);
21801
+ const csNumComps = context.colorSpace.numComps;
21802
+ this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
21803
+ }
21804
+ get hasData() {
21805
+ if (this.stream.end) {
21806
+ return this.stream.pos < this.stream.end;
21807
+ }
21808
+ if (this.bufferLength > 0) {
21809
+ return true;
21810
+ }
21811
+ const nextByte = this.stream.getByte();
21812
+ if (nextByte < 0) {
21813
+ return false;
21814
+ }
21815
+ this.buffer = nextByte;
21816
+ this.bufferLength = 8;
21817
+ return true;
21818
+ }
21819
+ readBits(n) {
21820
+ const { stream } = this;
21821
+ let { buffer, bufferLength } = this;
21822
+ if (n === 32) {
21823
+ if (bufferLength === 0) {
21824
+ return stream.getInt32() >>> 0;
21825
+ }
21826
+ buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte();
21827
+ const nextByte = stream.getByte();
21828
+ this.buffer = nextByte & (1 << bufferLength) - 1;
21829
+ return (buffer << 8 - bufferLength | (nextByte & 255) >> bufferLength) >>> 0;
21830
+ }
21831
+ if (n === 8 && bufferLength === 0) {
21832
+ return stream.getByte();
21833
+ }
21834
+ while (bufferLength < n) {
21835
+ buffer = buffer << 8 | stream.getByte();
21836
+ bufferLength += 8;
21837
+ }
21838
+ bufferLength -= n;
21839
+ this.bufferLength = bufferLength;
21840
+ this.buffer = buffer & (1 << bufferLength) - 1;
21841
+ return buffer >> bufferLength;
21842
+ }
21843
+ align() {
21844
+ this.buffer = 0;
21845
+ this.bufferLength = 0;
21846
+ }
21847
+ readFlag() {
21848
+ return this.readBits(this.context.bitsPerFlag);
21849
+ }
21850
+ readCoordinate() {
21851
+ const { bitsPerCoordinate, decode } = this.context;
21852
+ const xi = this.readBits(bitsPerCoordinate);
21853
+ const yi = this.readBits(bitsPerCoordinate);
21854
+ const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 23283064365386963e-26;
21855
+ return [
21856
+ xi * scale * (decode[1] - decode[0]) + decode[0],
21857
+ yi * scale * (decode[3] - decode[2]) + decode[2]
21858
+ ];
21859
+ }
21860
+ readComponents() {
21861
+ const { bitsPerComponent, colorFn, colorSpace, decode, numComps } = this.context;
21862
+ const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 23283064365386963e-26;
21863
+ const components = this.tmpCompsBuf;
21864
+ for (let i = 0, j = 4; i < numComps; i++, j += 2) {
21865
+ const ci = this.readBits(bitsPerComponent);
21866
+ components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
21867
+ }
21868
+ const color = this.tmpCsCompsBuf;
21869
+ colorFn?.(components, 0, color, 0);
21870
+ return colorSpace.getRgb(color, 0);
21871
+ }
21872
+ };
21873
+ var bCache = null;
21874
+ function getB(count) {
21875
+ if (bCache?.has(count)) return bCache.get(count);
21876
+ const values = Array.from({ length: count + 1 }, (_, i) => {
21877
+ const t = i / count, t_ = 1 - t;
21878
+ return new Float32Array([
21879
+ t_ ** 3,
21880
+ 3 * t * t_ ** 2,
21881
+ 3 * t ** 2 * t_,
21882
+ t ** 3
21883
+ ]);
21884
+ });
21885
+ (bCache ??= /* @__PURE__ */ new Map()).set(count, values);
21886
+ return values;
21887
+ }
21888
+ var MeshShading = class _MeshShading extends BaseShading {
21889
+ static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
21890
+ static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
21891
+ // Count of triangles per entire mesh bounds.
21892
+ static TRIANGLE_DENSITY = 20;
21893
+ constructor(shadingType, stream, context, rowVertices) {
21894
+ super();
21895
+ this.shadingType = shadingType;
21896
+ this.bbox = this.background = null;
21897
+ this.coords = [];
21898
+ this.colors = [];
21899
+ this.figures = [];
21900
+ const reader = new MeshStreamReader(stream, context);
21901
+ let patchMesh = false;
21902
+ switch (this.shadingType) {
21903
+ case ShadingType.FREE_FORM_MESH:
21904
+ this._decodeType4Shading(reader);
21905
+ break;
21906
+ case ShadingType.LATTICE_FORM_MESH:
21907
+ const verticesPerRow = rowVertices | 0;
21908
+ if (verticesPerRow < 2) {
21909
+ throw new FormatError("Invalid VerticesPerRow");
21910
+ }
21911
+ this._decodeType5Shading(reader, verticesPerRow);
21912
+ break;
21913
+ case ShadingType.COONS_PATCH_MESH:
21914
+ this._decodeType6Shading(reader);
21915
+ patchMesh = true;
21916
+ break;
21917
+ case ShadingType.TENSOR_PATCH_MESH:
21918
+ this._decodeType7Shading(reader);
21919
+ patchMesh = true;
21920
+ break;
21921
+ default:
21922
+ unreachable2("Unsupported mesh type.");
21923
+ break;
21924
+ }
21925
+ if (patchMesh) {
21926
+ this._updateBounds();
21927
+ for (let i = 0, ii = this.figures.length; i < ii; i++) {
21928
+ this._buildFigureFromPatch(i);
21929
+ }
21930
+ }
21931
+ this._updateBounds();
21932
+ this._packData();
21933
+ }
21934
+ _decodeType4Shading(reader) {
21935
+ const coords = this.coords;
21936
+ const colors = this.colors;
21937
+ const operators = [];
21938
+ const ps = [];
21939
+ let verticesLeft = 0;
21940
+ while (reader.hasData) {
21941
+ const f = reader.readFlag();
21942
+ const coord = reader.readCoordinate();
21943
+ const color = reader.readComponents();
21944
+ if (verticesLeft === 0) {
21945
+ if (!(0 <= f && f <= 2)) {
21946
+ throw new FormatError("Unknown type4 flag");
21947
+ }
21948
+ switch (f) {
21949
+ case 0:
21950
+ verticesLeft = 3;
21951
+ break;
21952
+ case 1:
21953
+ ps.push(ps.at(-2), ps.at(-1));
21954
+ verticesLeft = 1;
21955
+ break;
21956
+ case 2:
21957
+ ps.push(ps.at(-3), ps.at(-1));
21958
+ verticesLeft = 1;
21959
+ break;
21960
+ }
21961
+ operators.push(f);
21962
+ }
21963
+ ps.push(coords.length);
21964
+ coords.push(coord);
21965
+ colors.push(color);
21966
+ verticesLeft--;
21967
+ reader.align();
21968
+ }
21969
+ this.figures.push({
21970
+ type: MeshFigureType.TRIANGLES,
21971
+ coords: new Int32Array(ps),
21972
+ colors: new Int32Array(ps)
21973
+ });
21974
+ }
21975
+ _decodeType5Shading(reader, verticesPerRow) {
21976
+ const coords = this.coords;
21977
+ const colors = this.colors;
21978
+ const ps = [];
21979
+ while (reader.hasData) {
21980
+ const coord = reader.readCoordinate();
21981
+ const color = reader.readComponents();
21982
+ ps.push(coords.length);
21983
+ coords.push(coord);
21984
+ colors.push(color);
21985
+ }
21986
+ this.figures.push({
21987
+ type: MeshFigureType.LATTICE,
21988
+ coords: new Int32Array(ps),
21989
+ colors: new Int32Array(ps),
21990
+ verticesPerRow
21991
+ });
21992
+ }
21993
+ _decodeType6Shading(reader) {
21994
+ const coords = this.coords;
21995
+ const colors = this.colors;
21996
+ const ps = new Int32Array(16);
21997
+ const cs = new Int32Array(4);
21998
+ while (reader.hasData) {
21999
+ const f = reader.readFlag();
22000
+ if (!(0 <= f && f <= 3)) {
22001
+ throw new FormatError("Unknown type6 flag");
22002
+ }
22003
+ const pi = coords.length;
22004
+ for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
22005
+ coords.push(reader.readCoordinate());
22006
+ }
22007
+ const ci = colors.length;
22008
+ for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
22009
+ colors.push(reader.readComponents());
22010
+ }
22011
+ let tmp1, tmp2, tmp3, tmp4;
22012
+ switch (f) {
22013
+ // prettier-ignore
22014
+ case 0:
22015
+ ps[12] = pi + 3;
22016
+ ps[13] = pi + 4;
22017
+ ps[14] = pi + 5;
22018
+ ps[15] = pi + 6;
22019
+ ps[8] = pi + 2;
22020
+ ps[11] = pi + 7;
22021
+ ps[4] = pi + 1;
22022
+ ps[7] = pi + 8;
22023
+ ps[0] = pi;
22024
+ ps[1] = pi + 11;
22025
+ ps[2] = pi + 10;
22026
+ ps[3] = pi + 9;
22027
+ cs[2] = ci + 1;
22028
+ cs[3] = ci + 2;
22029
+ cs[0] = ci;
22030
+ cs[1] = ci + 3;
22031
+ break;
22032
+ // prettier-ignore
22033
+ case 1:
22034
+ tmp1 = ps[12];
22035
+ tmp2 = ps[13];
22036
+ tmp3 = ps[14];
22037
+ tmp4 = ps[15];
22038
+ ps[12] = tmp4;
22039
+ ps[13] = pi + 0;
22040
+ ps[14] = pi + 1;
22041
+ ps[15] = pi + 2;
22042
+ ps[8] = tmp3;
22043
+ ps[11] = pi + 3;
22044
+ ps[4] = tmp2;
22045
+ ps[7] = pi + 4;
22046
+ ps[0] = tmp1;
22047
+ ps[1] = pi + 7;
22048
+ ps[2] = pi + 6;
22049
+ ps[3] = pi + 5;
22050
+ tmp1 = cs[2];
22051
+ tmp2 = cs[3];
22052
+ cs[2] = tmp2;
22053
+ cs[3] = ci;
22054
+ cs[0] = tmp1;
22055
+ cs[1] = ci + 1;
22056
+ break;
22057
+ // prettier-ignore
22058
+ case 2:
22059
+ tmp1 = ps[15];
22060
+ tmp2 = ps[11];
22061
+ ps[12] = ps[3];
22062
+ ps[13] = pi + 0;
22063
+ ps[14] = pi + 1;
22064
+ ps[15] = pi + 2;
22065
+ ps[8] = ps[7];
22066
+ ps[11] = pi + 3;
22067
+ ps[4] = tmp2;
22068
+ ps[7] = pi + 4;
22069
+ ps[0] = tmp1;
22070
+ ps[1] = pi + 7;
22071
+ ps[2] = pi + 6;
22072
+ ps[3] = pi + 5;
22073
+ tmp1 = cs[3];
22074
+ cs[2] = cs[1];
22075
+ cs[3] = ci;
22076
+ cs[0] = tmp1;
22077
+ cs[1] = ci + 1;
22078
+ break;
22079
+ // prettier-ignore
22080
+ case 3:
22081
+ ps[12] = ps[0];
22082
+ ps[13] = pi + 0;
22083
+ ps[14] = pi + 1;
22084
+ ps[15] = pi + 2;
22085
+ ps[8] = ps[1];
22086
+ ps[11] = pi + 3;
22087
+ ps[4] = ps[2];
22088
+ ps[7] = pi + 4;
22089
+ ps[0] = ps[3];
22090
+ ps[1] = pi + 7;
22091
+ ps[2] = pi + 6;
22092
+ ps[3] = pi + 5;
22093
+ cs[2] = cs[0];
22094
+ cs[3] = ci;
22095
+ cs[0] = cs[1];
22096
+ cs[1] = ci + 1;
22097
+ break;
22098
+ }
22099
+ ps[5] = coords.length;
22100
+ coords.push([
22101
+ (-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,
22102
+ (-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
22103
+ ]);
22104
+ ps[6] = coords.length;
22105
+ coords.push([
22106
+ (-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,
22107
+ (-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
22108
+ ]);
22109
+ ps[9] = coords.length;
22110
+ coords.push([
22111
+ (-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,
22112
+ (-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
22113
+ ]);
22114
+ ps[10] = coords.length;
22115
+ coords.push([
22116
+ (-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,
22117
+ (-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
22118
+ ]);
22119
+ this.figures.push({
22120
+ type: MeshFigureType.PATCH,
22121
+ coords: new Int32Array(ps),
22122
+ // making copies of ps and cs
22123
+ colors: new Int32Array(cs)
22124
+ });
22125
+ }
22126
+ }
22127
+ _decodeType7Shading(reader) {
22128
+ const coords = this.coords;
22129
+ const colors = this.colors;
22130
+ const ps = new Int32Array(16);
22131
+ const cs = new Int32Array(4);
22132
+ while (reader.hasData) {
22133
+ const f = reader.readFlag();
22134
+ if (!(0 <= f && f <= 3)) {
22135
+ throw new FormatError("Unknown type7 flag");
22136
+ }
22137
+ const pi = coords.length;
22138
+ for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
22139
+ coords.push(reader.readCoordinate());
22140
+ }
22141
+ const ci = colors.length;
22142
+ for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
22143
+ colors.push(reader.readComponents());
22144
+ }
22145
+ let tmp1, tmp2, tmp3, tmp4;
22146
+ switch (f) {
22147
+ // prettier-ignore
22148
+ case 0:
22149
+ ps[12] = pi + 3;
22150
+ ps[13] = pi + 4;
22151
+ ps[14] = pi + 5;
22152
+ ps[15] = pi + 6;
22153
+ ps[8] = pi + 2;
22154
+ ps[9] = pi + 13;
22155
+ ps[10] = pi + 14;
22156
+ ps[11] = pi + 7;
22157
+ ps[4] = pi + 1;
22158
+ ps[5] = pi + 12;
22159
+ ps[6] = pi + 15;
22160
+ ps[7] = pi + 8;
22161
+ ps[0] = pi;
22162
+ ps[1] = pi + 11;
22163
+ ps[2] = pi + 10;
22164
+ ps[3] = pi + 9;
22165
+ cs[2] = ci + 1;
22166
+ cs[3] = ci + 2;
22167
+ cs[0] = ci;
22168
+ cs[1] = ci + 3;
22169
+ break;
22170
+ // prettier-ignore
22171
+ case 1:
22172
+ tmp1 = ps[12];
22173
+ tmp2 = ps[13];
22174
+ tmp3 = ps[14];
22175
+ tmp4 = ps[15];
22176
+ ps[12] = tmp4;
22177
+ ps[13] = pi + 0;
22178
+ ps[14] = pi + 1;
22179
+ ps[15] = pi + 2;
22180
+ ps[8] = tmp3;
22181
+ ps[9] = pi + 9;
22182
+ ps[10] = pi + 10;
22183
+ ps[11] = pi + 3;
22184
+ ps[4] = tmp2;
22185
+ ps[5] = pi + 8;
22186
+ ps[6] = pi + 11;
22187
+ ps[7] = pi + 4;
22188
+ ps[0] = tmp1;
22189
+ ps[1] = pi + 7;
22190
+ ps[2] = pi + 6;
22191
+ ps[3] = pi + 5;
22192
+ tmp1 = cs[2];
22193
+ tmp2 = cs[3];
22194
+ cs[2] = tmp2;
22195
+ cs[3] = ci;
22196
+ cs[0] = tmp1;
22197
+ cs[1] = ci + 1;
22198
+ break;
22199
+ // prettier-ignore
22200
+ case 2:
22201
+ tmp1 = ps[15];
22202
+ tmp2 = ps[11];
22203
+ ps[12] = ps[3];
22204
+ ps[13] = pi + 0;
22205
+ ps[14] = pi + 1;
22206
+ ps[15] = pi + 2;
22207
+ ps[8] = ps[7];
22208
+ ps[9] = pi + 9;
22209
+ ps[10] = pi + 10;
22210
+ ps[11] = pi + 3;
22211
+ ps[4] = tmp2;
22212
+ ps[5] = pi + 8;
22213
+ ps[6] = pi + 11;
22214
+ ps[7] = pi + 4;
22215
+ ps[0] = tmp1;
22216
+ ps[1] = pi + 7;
22217
+ ps[2] = pi + 6;
22218
+ ps[3] = pi + 5;
22219
+ tmp1 = cs[3];
22220
+ cs[2] = cs[1];
22221
+ cs[3] = ci;
22222
+ cs[0] = tmp1;
22223
+ cs[1] = ci + 1;
22224
+ break;
22225
+ // prettier-ignore
22226
+ case 3:
22227
+ ps[12] = ps[0];
22228
+ ps[13] = pi + 0;
22229
+ ps[14] = pi + 1;
22230
+ ps[15] = pi + 2;
22231
+ ps[8] = ps[1];
22232
+ ps[9] = pi + 9;
22233
+ ps[10] = pi + 10;
22234
+ ps[11] = pi + 3;
22235
+ ps[4] = ps[2];
22236
+ ps[5] = pi + 8;
22237
+ ps[6] = pi + 11;
22238
+ ps[7] = pi + 4;
22239
+ ps[0] = ps[3];
22240
+ ps[1] = pi + 7;
22241
+ ps[2] = pi + 6;
22242
+ ps[3] = pi + 5;
22243
+ cs[2] = cs[0];
22244
+ cs[3] = ci;
22245
+ cs[0] = cs[1];
22246
+ cs[1] = ci + 1;
22247
+ break;
22248
+ }
22249
+ this.figures.push({
22250
+ type: MeshFigureType.PATCH,
22251
+ coords: new Int32Array(ps),
22252
+ // making copies of ps and cs
22253
+ colors: new Int32Array(cs)
22254
+ });
22255
+ }
22256
+ }
22257
+ _buildFigureFromPatch(index) {
22258
+ const figure = this.figures[index];
22259
+ assert2(
22260
+ figure.type === MeshFigureType.PATCH,
22261
+ "Unexpected patch mesh figure"
22262
+ );
22263
+ const coords = this.coords, colors = this.colors;
22264
+ const pi = figure.coords;
22265
+ const ci = figure.colors;
22266
+ const figureMinX = Math.min(
22267
+ coords[pi[0]][0],
22268
+ coords[pi[3]][0],
22269
+ coords[pi[12]][0],
22270
+ coords[pi[15]][0]
22271
+ );
22272
+ const figureMinY = Math.min(
22273
+ coords[pi[0]][1],
22274
+ coords[pi[3]][1],
22275
+ coords[pi[12]][1],
22276
+ coords[pi[15]][1]
22277
+ );
22278
+ const figureMaxX = Math.max(
22279
+ coords[pi[0]][0],
22280
+ coords[pi[3]][0],
22281
+ coords[pi[12]][0],
22282
+ coords[pi[15]][0]
22283
+ );
22284
+ const figureMaxY = Math.max(
22285
+ coords[pi[0]][1],
22286
+ coords[pi[3]][1],
22287
+ coords[pi[12]][1],
22288
+ coords[pi[15]][1]
22289
+ );
22290
+ let splitXBy = Math.ceil(
22291
+ (figureMaxX - figureMinX) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])
22292
+ );
22293
+ splitXBy = MathClamp(
22294
+ splitXBy,
22295
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
22296
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
22297
+ );
22298
+ let splitYBy = Math.ceil(
22299
+ (figureMaxY - figureMinY) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])
22300
+ );
22301
+ splitYBy = MathClamp(
22302
+ splitYBy,
22303
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
22304
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
22305
+ );
22306
+ const verticesPerRow = splitXBy + 1;
22307
+ const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
22308
+ const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
22309
+ let k = 0;
22310
+ const cl = new Uint8Array(3), cr = new Uint8Array(3);
22311
+ const c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
22312
+ const bRow = getB(splitYBy), bCol = getB(splitXBy);
22313
+ for (let row = 0; row <= splitYBy; row++) {
22314
+ cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
22315
+ cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
22316
+ cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
22317
+ cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
22318
+ cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
22319
+ cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
22320
+ for (let col = 0; col <= splitXBy; col++, k++) {
22321
+ if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
22322
+ continue;
22323
+ }
22324
+ let x = 0, y = 0;
22325
+ let q = 0;
22326
+ for (let i = 0; i <= 3; i++) {
22327
+ for (let j = 0; j <= 3; j++, q++) {
22328
+ const m = bRow[row][i] * bCol[col][j];
22329
+ x += coords[pi[q]][0] * m;
22330
+ y += coords[pi[q]][1] * m;
22331
+ }
22332
+ }
22333
+ figureCoords[k] = coords.length;
22334
+ coords.push([x, y]);
22335
+ figureColors[k] = colors.length;
22336
+ const newColor = new Uint8Array(3);
22337
+ newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
22338
+ newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
22339
+ newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
22340
+ colors.push(newColor);
22341
+ }
22342
+ }
22343
+ figureCoords[0] = pi[0];
22344
+ figureColors[0] = ci[0];
22345
+ figureCoords[splitXBy] = pi[3];
22346
+ figureColors[splitXBy] = ci[1];
22347
+ figureCoords[verticesPerRow * splitYBy] = pi[12];
22348
+ figureColors[verticesPerRow * splitYBy] = ci[2];
22349
+ figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
22350
+ figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
22351
+ this.figures[index] = {
22352
+ type: MeshFigureType.LATTICE,
22353
+ coords: figureCoords,
22354
+ colors: figureColors,
22355
+ verticesPerRow
22356
+ };
22357
+ }
22358
+ _updateBounds() {
22359
+ meshUpdateBounds(this);
22360
+ }
22361
+ _packData() {
22362
+ meshPackData(this);
22363
+ }
22364
+ getIR() {
22365
+ const { posData, colData, vertexCount } = buildMeshVertexData(
22366
+ this.coords,
22367
+ this.colors,
22368
+ this.figures
22369
+ );
22370
+ return [
22371
+ "Mesh",
22372
+ this.shadingType,
22373
+ posData,
22374
+ colData,
22375
+ vertexCount,
22376
+ this.bounds,
22377
+ this.bbox,
22378
+ this.background
22379
+ ];
22380
+ }
22381
+ };
21683
22382
 
21684
22383
  // packages/pdf-ast/src/ast.ts
21685
22384
  init_buffer();
@@ -31518,11 +32217,16 @@ function parseDictionaryStream(dictNode, lexer, bytes) {
31518
32217
  let streamEnd = streamStart;
31519
32218
  if (resolvedLength !== void 0 && resolvedLength >= 0 && streamStart + resolvedLength <= bytes.length) {
31520
32219
  const candidateEnd = streamStart + resolvedLength;
31521
- const tailSlice = bytes.subarray(candidateEnd, Math.min(bytes.length, candidateEnd + 32));
31522
- const tailStr = new TextDecoder("latin1").decode(tailSlice);
31523
- if (tailStr.includes("endstream")) {
32220
+ const tailLexer = new CosByteLexer(bytes, candidateEnd);
32221
+ let endToken;
32222
+ try {
32223
+ endToken = tailLexer.nextToken();
32224
+ } catch (error) {
32225
+ if (!(error instanceof PdfError) || error.code !== "E_PARSE") throw error;
32226
+ }
32227
+ if (endToken?.kind === "keyword" && endToken.value === "endstream") {
31524
32228
  rawStreamBytes = bytes.subarray(streamStart, candidateEnd);
31525
- streamEnd = candidateEnd + tailStr.indexOf("endstream") + "endstream".length;
32229
+ streamEnd = tailLexer.offset;
31526
32230
  }
31527
32231
  }
31528
32232
  if (!rawStreamBytes) {
@@ -33505,21 +34209,23 @@ function resolvePageFonts(doc, resourcesDict) {
33505
34209
  }
33506
34210
  }
33507
34211
  } else {
33508
- const stdName = normalizeStandard14FontName(baseFont);
33509
- const stdMetrics = STANDARD_14_FONTS[stdName];
33510
- defaultWidth = stdMetrics.defaultWidth;
33511
- for (const [codeStr, wVal] of Object.entries(stdMetrics.widthsByCode)) {
33512
- widths.set(Number(codeStr), wVal);
33513
- }
33514
34212
  const firstCharNode = doc.resolve(dictGet(fObj, "FirstChar"));
33515
34213
  const widthsArr = doc.resolveArray(dictGet(fObj, "Widths"));
33516
- if (firstCharNode?.kind === "number" && widthsArr) {
34214
+ if (widthsArr) {
34215
+ const descriptor = doc.resolveDict(dictGet(fObj, "FontDescriptor"));
34216
+ const missingWidth = descriptor ? doc.resolve(dictGet(descriptor, "MissingWidth")) : void 0;
34217
+ defaultWidth = (missingWidth?.kind === "number" ? missingWidth.value : 0) * type3Scale1000;
34218
+ const firstChar = firstCharNode?.kind === "number" ? firstCharNode.value : 0;
33517
34219
  for (let k = 0; k < widthsArr.items.length; k++) {
33518
34220
  const wItem = doc.resolve(widthsArr.items[k]);
33519
34221
  if (wItem?.kind === "number") {
33520
- widths.set(firstCharNode.value + k, wItem.value * type3Scale1000);
34222
+ widths.set(firstChar + k, wItem.value * type3Scale1000);
33521
34223
  }
33522
34224
  }
34225
+ } else {
34226
+ const stdMetrics = STANDARD_14_FONTS[normalizeStandard14FontName(baseFont)];
34227
+ defaultWidth = stdMetrics.defaultWidth;
34228
+ for (const [codeStr, wVal] of Object.entries(stdMetrics.widthsByCode)) widths.set(Number(codeStr), wVal);
33523
34229
  }
33524
34230
  }
33525
34231
  let embeddedCff;
@@ -33908,143 +34614,28 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
33908
34614
  const r = doc.resolve(it);
33909
34615
  return r?.kind === "number" ? r.value : 0;
33910
34616
  });
33911
- const xmin = decodeNums[0], xmax = decodeNums[1], ymin = decodeNums[2], ymax = decodeNums[3];
33912
- const numColorParams = Math.max(1, Math.floor((decodeNums.length - 4) / 2));
33913
34617
  const fnNode = dictGet(shDict, "Function");
33914
34618
  const csNode = doc.resolve(dictGet(shDict, "ColorSpace"));
33915
34619
  const csName = csNode?.kind === "name" ? csNode.decoded : "DeviceRGB";
33916
- let bitPos = 0;
33917
- const totalBits = bytes.length * 8;
33918
- const readBits = (n) => {
33919
- let val = 0;
33920
- for (let i = 0; i < n; i++) {
33921
- if (bitPos >= totalBits) return val;
33922
- const byteIdx = bitPos >> 3;
33923
- const bitIdx = 7 - (bitPos & 7);
33924
- val = val * 2 + (bytes[byteIdx] >> bitIdx & 1);
33925
- bitPos++;
33926
- }
33927
- return val;
33928
- };
33929
- const coordMax = Math.pow(2, bpcCoord) - 1 || 1;
33930
- const compMax = Math.pow(2, bpcComp) - 1 || 1;
33931
- const readCoord = () => {
33932
- const rx = readBits(bpcCoord) / coordMax;
33933
- const ry = readBits(bpcCoord) / coordMax;
33934
- return [xmin + rx * (xmax - xmin), ymin + ry * (ymax - ymin)];
33935
- };
33936
- const readColorRgb = () => {
33937
- const params = [];
33938
- for (let c = 0; c < numColorParams; c++) {
33939
- const rc = readBits(bpcComp) / compMax;
33940
- const cMin = decodeNums[4 + c * 2] ?? 0;
33941
- const cMax = decodeNums[4 + c * 2 + 1] ?? 1;
33942
- params.push(cMin + rc * (cMax - cMin));
33943
- }
33944
- const comps = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
33945
- return convertColorSpaceComponentsToRgb(doc, csNode, csName, comps);
33946
- };
33947
- const triangles = [];
33948
- if (shType === 4) {
33949
- const minBitsPerVert = bpcFlag + 2 * bpcCoord + numColorParams * bpcComp;
33950
- let triVerts;
33951
- while (bitPos + minBitsPerVert <= totalBits) {
33952
- const flag = readBits(bpcFlag) & 3;
33953
- const [x, y] = readCoord();
33954
- const rgb2 = readColorRgb();
33955
- const vNew = { x, y, rgb: rgb2 };
33956
- if (flag === 0 || !triVerts) {
33957
- if (bitPos + 2 * minBitsPerVert > totalBits) break;
33958
- readBits(bpcFlag);
33959
- const [x1, y1] = readCoord();
33960
- const rgb1 = readColorRgb();
33961
- readBits(bpcFlag);
33962
- const [x2, y2] = readCoord();
33963
- const rgb22 = readColorRgb();
33964
- triVerts = [vNew, { x: x1, y: y1, rgb: rgb1 }, { x: x2, y: y2, rgb: rgb22 }];
33965
- triangles.push(triVerts);
33966
- } else if (flag === 1) {
33967
- triVerts = [triVerts[1], triVerts[2], vNew];
33968
- triangles.push(triVerts);
33969
- } else if (flag === 2) {
33970
- triVerts = [triVerts[0], triVerts[2], vNew];
33971
- triangles.push(triVerts);
33972
- }
33973
- }
33974
- } else if (shType === 5) {
33975
- const minBitsPerVert = 2 * bpcCoord + numColorParams * bpcComp;
33976
- const verts = [];
33977
- while (bitPos + minBitsPerVert <= totalBits) {
33978
- const [x, y] = readCoord();
33979
- const rgb2 = readColorRgb();
33980
- verts.push({ x, y, rgb: rgb2 });
33981
- }
33982
- const numRows = Math.floor(verts.length / vPerRow);
33983
- for (let r = 0; r + 1 < numRows; r++) {
33984
- for (let c = 0; c + 1 < vPerRow; c++) {
33985
- const v00 = verts[r * vPerRow + c];
33986
- const v01 = verts[r * vPerRow + c + 1];
33987
- const v11 = verts[(r + 1) * vPerRow + c + 1];
33988
- const v10 = verts[(r + 1) * vPerRow + c];
33989
- triangles.push([v00, v01, v11], [v00, v11, v10]);
33990
- }
33991
- }
33992
- } else if (shType === 6 || shType === 7) {
33993
- const numCtrl = shType === 6 ? 12 : 16;
33994
- const minBitsPatch = bpcFlag + (numCtrl - 4) * 2 * bpcCoord + 2 * numColorParams * bpcComp;
33995
- let prevPts;
33996
- let prevColors;
33997
- while (bitPos + minBitsPatch <= totalBits) {
33998
- const flag = readBits(bpcFlag) & 3;
33999
- let pts = [];
34000
- let cols = [];
34001
- if (flag === 0 || !prevPts || !prevColors) {
34002
- for (let i = 0; i < numCtrl; i++) pts.push(readCoord());
34003
- for (let i = 0; i < 4; i++) cols.push(readColorRgb());
34004
- } else {
34005
- const extraCtrl = numCtrl - 4;
34006
- const readExtra = [];
34007
- for (let i = 0; i < extraCtrl; i++) readExtra.push(readCoord());
34008
- const c2 = readColorRgb();
34009
- const c3 = readColorRgb();
34010
- pts = [prevPts[3], prevPts[4], prevPts[5], prevPts[6], ...readExtra];
34011
- cols = [prevColors[1], prevColors[2], c2, c3];
34012
- }
34013
- prevPts = pts;
34014
- prevColors = cols;
34015
- const p00 = pts[0];
34016
- const p03 = pts[3];
34017
- const p33 = pts[6];
34018
- const p30 = pts[9];
34019
- const c00 = cols[0], c03 = cols[1], c33 = cols[2], c30 = cols[3];
34020
- const steps = 4;
34021
- const grid = [];
34022
- for (let iu = 0; iu <= steps; iu++) {
34023
- const u = iu / steps;
34024
- const row = [];
34025
- for (let iv = 0; iv <= steps; iv++) {
34026
- const v = iv / steps;
34027
- const x = (1 - u) * (1 - v) * p00[0] + (1 - u) * v * p03[0] + u * v * p33[0] + u * (1 - v) * p30[0];
34028
- const y = (1 - u) * (1 - v) * p00[1] + (1 - u) * v * p03[1] + u * v * p33[1] + u * (1 - v) * p30[1];
34029
- const r = (1 - u) * (1 - v) * c00[0] + (1 - u) * v * c03[0] + u * v * c33[0] + u * (1 - v) * c30[0];
34030
- const g = (1 - u) * (1 - v) * c00[1] + (1 - u) * v * c03[1] + u * v * c33[1] + u * (1 - v) * c30[1];
34031
- const b = (1 - u) * (1 - v) * c00[2] + (1 - u) * v * c03[2] + u * v * c33[2] + u * (1 - v) * c30[2];
34032
- row.push({ x, y, rgb: [r, g, b] });
34033
- }
34034
- grid.push(row);
34035
- }
34036
- for (let iu = 0; iu < steps; iu++) {
34037
- for (let iv = 0; iv < steps; iv++) {
34038
- const g00 = grid[iu][iv];
34039
- const g01 = grid[iu][iv + 1];
34040
- const g11 = grid[iu + 1][iv + 1];
34041
- const g10 = grid[iu + 1][iv];
34042
- triangles.push([g00, g01, g11], [g00, g11, g10]);
34043
- }
34044
- }
34045
- }
34046
- }
34047
- if (triangles.length === 0) return void 0;
34620
+ const numComps = fnNode ? 1 : getColorSpaceComponentCount(doc, csNode);
34621
+ const mesh = new MeshShading(shType, new Stream(bytes), {
34622
+ bitsPerCoordinate: bpcCoord,
34623
+ bitsPerComponent: bpcComp,
34624
+ bitsPerFlag: bpcFlag,
34625
+ decode: decodeNums,
34626
+ numComps,
34627
+ colorFn: null,
34628
+ colorSpace: {
34629
+ numComps,
34630
+ getRgb(components) {
34631
+ const params = Array.from(components);
34632
+ const values = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
34633
+ return new Uint8Array(convertColorSpaceComponentsToRgb(doc, csNode, csName, values).map((value) => Math.round(Math.max(0, Math.min(1, value)) * 255)));
34634
+ }
34635
+ }
34636
+ }, vPerRow);
34637
+ const [, , positions, colors, vertexCount] = mesh.getIR();
34638
+ if (vertexCount === 0) return void 0;
34048
34639
  const [bx0, by0, bx1, by1] = targetBox;
34049
34640
  const boxW = Math.max(1, bx1 - bx0);
34050
34641
  const boxH = Math.max(1, by1 - by0);
@@ -34056,10 +34647,10 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
34056
34647
  const [px, py] = transformPoint(effectiveCtm, vx, vy);
34057
34648
  return [(px - bx0) / boxW * imgW, (by1 - py) / boxH * imgH];
34058
34649
  };
34059
- for (const [v0, v1, v2] of triangles) {
34060
- const [x0, y0] = toImgCoords(v0.x, v0.y);
34061
- const [x1, y1] = toImgCoords(v1.x, v1.y);
34062
- const [x2, y2] = toImgCoords(v2.x, v2.y);
34650
+ for (let vertex = 0; vertex < vertexCount; vertex += 3) {
34651
+ const [x0, y0] = toImgCoords(positions[vertex * 2], positions[vertex * 2 + 1]);
34652
+ const [x1, y1] = toImgCoords(positions[vertex * 2 + 2], positions[vertex * 2 + 3]);
34653
+ const [x2, y2] = toImgCoords(positions[vertex * 2 + 4], positions[vertex * 2 + 5]);
34063
34654
  const denom = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2);
34064
34655
  if (Math.abs(denom) < 1e-6) continue;
34065
34656
  const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
@@ -34074,13 +34665,12 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
34074
34665
  const w1 = ((y2 - y0) * (px - x2) + (x0 - x2) * (py - y2)) / denom;
34075
34666
  const w2 = 1 - w0 - w1;
34076
34667
  if (w0 >= -1e-4 && w1 >= -1e-4 && w2 >= -1e-4) {
34077
- const r = w0 * v0.rgb[0] + w1 * v1.rgb[0] + w2 * v2.rgb[0];
34078
- const g = w0 * v0.rgb[1] + w1 * v1.rgb[1] + w2 * v2.rgb[1];
34079
- const b = w0 * v0.rgb[2] + w1 * v1.rgb[2] + w2 * v2.rgb[2];
34080
34668
  const pIdx = (iy * imgW + ix) * 4;
34081
- rgba[pIdx] = Math.round(Math.max(0, Math.min(1, r)) * 255);
34082
- rgba[pIdx + 1] = Math.round(Math.max(0, Math.min(1, g)) * 255);
34083
- rgba[pIdx + 2] = Math.round(Math.max(0, Math.min(1, b)) * 255);
34669
+ for (let channel = 0; channel < 3; channel++) {
34670
+ rgba[pIdx + channel] = Math.round(
34671
+ w0 * colors[vertex * 4 + channel] + w1 * colors[vertex * 4 + 4 + channel] + w2 * colors[vertex * 4 + 8 + channel]
34672
+ );
34673
+ }
34084
34674
  rgba[pIdx + 3] = a8;
34085
34675
  }
34086
34676
  }
@@ -34167,6 +34757,8 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
34167
34757
  const [a, b, c, d, e, f] = effectiveCtm;
34168
34758
  const det = a * d - b * c;
34169
34759
  if (Math.abs(det) <= 1e-8) return void 0;
34760
+ const [sa, sb, sc, sd, se, sf] = shadingCtm;
34761
+ const shadingDet = sa * sd - sb * sc;
34170
34762
  const t0Dom = shDomain[0] ?? 0;
34171
34763
  const t1Dom = shDomain[1] ?? 1;
34172
34764
  for (let iy = 0; iy < imgH; iy++) {
@@ -34177,8 +34769,10 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
34177
34769
  const dxPdf = xPdf - e;
34178
34770
  const xs = (d * dxPdf - c * dyPdf) / det;
34179
34771
  const ys = (-b * dxPdf + a * dyPdf) / det;
34180
- if (shBBox && (xs < shBBox[0] || xs > shBBox[2] || ys < shBBox[1] || ys > shBBox[3])) {
34181
- continue;
34772
+ if (shBBox) {
34773
+ const bboxX = (sd * (xPdf - se) - sc * (yPdf - sf)) / shadingDet;
34774
+ const bboxY = (-sb * (xPdf - se) + sa * (yPdf - sf)) / shadingDet;
34775
+ if (bboxX < shBBox[0] || bboxX > shBBox[2] || bboxY < shBBox[1] || bboxY > shBBox[3]) continue;
34182
34776
  }
34183
34777
  let comps;
34184
34778
  if (shType === 1) {
@@ -34387,13 +34981,11 @@ function evaluateContentStreamToDisplayList(params) {
34387
34981
  }
34388
34982
  if (font?.cmap) {
34389
34983
  if (!font.isTwoByteCid) {
34390
- const stdName2 = normalizeStandard14FontName(font.baseFont);
34391
- const stdMetrics2 = STANDARD_14_FONTS[stdName2];
34392
34984
  const out2 = [];
34393
34985
  for (let i = 0; i < bytes.length; i++) {
34394
34986
  const code = bytes[i];
34395
34987
  const unicode = font.cmap.map.get(code) ?? (font.differences.has(code) ? font.differences.get(code) : decodeWinAnsiByte(code));
34396
- const advance1000 = font.widths.get(code) ?? stdMetrics2.widthsByCode[code] ?? stdMetrics2.defaultWidth;
34988
+ const advance1000 = font.widths.get(code) ?? font.defaultWidth;
34397
34989
  out2.push({ charCode: code, isSpace: code === 32, unicode, advance1000 });
34398
34990
  }
34399
34991
  return out2;
@@ -34425,7 +35017,7 @@ function evaluateContentStreamToDisplayList(params) {
34425
35017
  for (let i = 0; i < bytes.length; i++) {
34426
35018
  const code = bytes[i];
34427
35019
  const unicode = font?.differences.get(code) ?? decodeWinAnsiByte(code);
34428
- const advance1000 = font?.widths.get(code) ?? stdMetrics.widthsByCode[code] ?? stdMetrics.defaultWidth;
35020
+ const advance1000 = font ? font.widths.get(code) ?? font.defaultWidth : stdMetrics.widthsByCode[code] ?? stdMetrics.defaultWidth;
34429
35021
  out.push({ charCode: code, isSpace: code === 32, unicode, advance1000 });
34430
35022
  }
34431
35023
  return out;