@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.
- package/dist/image-ast/index.browser.js +754 -162
- package/dist/image-ast/index.js +754 -162
- package/dist/pdf-ast/index.js +754 -162
- package/dist/pdf-ast/vendor/pdfjs-fonts.d.mts +12 -0
- package/dist/pdf-ast/vendor/pdfjs-fonts.mjs +702 -0
- package/dist/safe-bash/command-chunks/{chunk-B2MM5DIT.js → chunk-3444RZLY.js} +754 -162
- package/dist/safe-bash/command-chunks/{chunk-G3NVK25P.js → chunk-QLYJUVVM.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-5VXZSNM2.js → chunk-ZY6PMCW5.js} +2 -2
- package/dist/safe-bash/core.browser.js +63 -7
- package/dist/safe-bash/shell/runtime.js +17 -9
- package/dist/safe-bash/shell/sync-posix-regex.d.ts +3 -0
- package/dist/safe-bash/shell/sync-posix-regex.js +48 -0
- package/dist/safe-bash-command-ffmpeg/index.js +7249 -7039
- package/dist/safe-bash-command-gpg/index.js +28 -7
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-openssl/index.js +24 -6
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +754 -162
- package/dist/safe-bash-command-pdfinfo/index.js +754 -162
- package/dist/safe-bash-command-pdftk/index.js +754 -162
- package/dist/safe-bash-command-pdftoppm/index.js +754 -162
- package/dist/safe-bash-command-pdftotext/index.js +754 -162
- package/dist/safe-bash-command-qpdf/index.js +754 -162
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/index.js +754 -162
- package/dist/safe-bash-command-ssh/index.js +124 -23
- package/dist/safe-bash-command-wkhtmltopdf/index.js +760 -162
- package/package.json +2 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +29 -0
|
@@ -2787,6 +2787,103 @@ function buildPostScriptJsFunction(source, domain, range, forceInterpreter = fal
|
|
|
2787
2787
|
}
|
|
2788
2788
|
return PSStackBasedInterpreter.build(program, domain, range);
|
|
2789
2789
|
}
|
|
2790
|
+
function meshUpdateBounds(self) {
|
|
2791
|
+
let minX = self.coords[0][0], minY = self.coords[0][1], maxX = minX, maxY = minY;
|
|
2792
|
+
for (let i = 1, ii = self.coords.length; i < ii; i++) {
|
|
2793
|
+
const x = self.coords[i][0], y = self.coords[i][1];
|
|
2794
|
+
minX = minX > x ? x : minX;
|
|
2795
|
+
minY = minY > y ? y : minY;
|
|
2796
|
+
maxX = maxX < x ? x : maxX;
|
|
2797
|
+
maxY = maxY < y ? y : maxY;
|
|
2798
|
+
}
|
|
2799
|
+
self.bounds = [minX, minY, maxX, maxY];
|
|
2800
|
+
}
|
|
2801
|
+
function meshPackData(self) {
|
|
2802
|
+
let i, j, ii;
|
|
2803
|
+
const coords = self.coords;
|
|
2804
|
+
const coordsPacked = new Float32Array(coords.length * 2);
|
|
2805
|
+
for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
|
|
2806
|
+
const xy = coords[i];
|
|
2807
|
+
coordsPacked[j++] = xy[0];
|
|
2808
|
+
coordsPacked[j++] = xy[1];
|
|
2809
|
+
}
|
|
2810
|
+
self.coords = coordsPacked;
|
|
2811
|
+
const colors = self.colors;
|
|
2812
|
+
const colorsPacked = new Uint8Array(colors.length * 4);
|
|
2813
|
+
for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
|
|
2814
|
+
const c = colors[i];
|
|
2815
|
+
colorsPacked[j++] = c[0];
|
|
2816
|
+
colorsPacked[j++] = c[1];
|
|
2817
|
+
colorsPacked[j++] = c[2];
|
|
2818
|
+
j++;
|
|
2819
|
+
}
|
|
2820
|
+
self.colors = colorsPacked;
|
|
2821
|
+
for (const figure of self.figures) {
|
|
2822
|
+
figure.coords = new Uint32Array(figure.coords);
|
|
2823
|
+
figure.colors = new Uint32Array(figure.colors);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
function buildMeshVertexData(coords, colors, figures) {
|
|
2827
|
+
let vertexCount = 0;
|
|
2828
|
+
for (const figure of figures) {
|
|
2829
|
+
if (figure.type === MeshFigureType.TRIANGLES) {
|
|
2830
|
+
vertexCount += figure.coords.length;
|
|
2831
|
+
} else if (figure.type === MeshFigureType.LATTICE) {
|
|
2832
|
+
const vpr = figure.verticesPerRow;
|
|
2833
|
+
vertexCount += (Math.floor(figure.coords.length / vpr) - 1) * (vpr - 1) * 6;
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
const posData = new Float32Array(vertexCount * 2);
|
|
2837
|
+
const colData = new Uint8Array(vertexCount * 4);
|
|
2838
|
+
let pOff = 0, cOff = 0;
|
|
2839
|
+
const addVertex = (pi, ci) => {
|
|
2840
|
+
posData[pOff++] = coords[pi * 2];
|
|
2841
|
+
posData[pOff++] = coords[pi * 2 + 1];
|
|
2842
|
+
colData[cOff++] = colors[ci * 4];
|
|
2843
|
+
colData[cOff++] = colors[ci * 4 + 1];
|
|
2844
|
+
colData[cOff++] = colors[ci * 4 + 2];
|
|
2845
|
+
cOff++;
|
|
2846
|
+
};
|
|
2847
|
+
for (const figure of figures) {
|
|
2848
|
+
const ps = figure.coords;
|
|
2849
|
+
const cs = figure.colors;
|
|
2850
|
+
if (figure.type === MeshFigureType.TRIANGLES) {
|
|
2851
|
+
for (let i = 0, ii = ps.length; i < ii; i++) {
|
|
2852
|
+
addVertex(ps[i], cs[i]);
|
|
2853
|
+
}
|
|
2854
|
+
} else if (figure.type === MeshFigureType.LATTICE) {
|
|
2855
|
+
const vpr = figure.verticesPerRow;
|
|
2856
|
+
const rows = Math.floor(ps.length / vpr) - 1;
|
|
2857
|
+
const cols = vpr - 1;
|
|
2858
|
+
for (let i = 0; i < rows; i++) {
|
|
2859
|
+
let q = i * vpr;
|
|
2860
|
+
for (let j = 0; j < cols; j++, q++) {
|
|
2861
|
+
addVertex(ps[q], cs[q]);
|
|
2862
|
+
addVertex(ps[q + 1], cs[q + 1]);
|
|
2863
|
+
addVertex(ps[q + vpr], cs[q + vpr]);
|
|
2864
|
+
addVertex(ps[q + vpr + 1], cs[q + vpr + 1]);
|
|
2865
|
+
addVertex(ps[q + 1], cs[q + 1]);
|
|
2866
|
+
addVertex(ps[q + vpr], cs[q + vpr]);
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
return { posData, colData, vertexCount };
|
|
2872
|
+
}
|
|
2873
|
+
function getB(count) {
|
|
2874
|
+
if (bCache?.has(count)) return bCache.get(count);
|
|
2875
|
+
const values = Array.from({ length: count + 1 }, (_, i) => {
|
|
2876
|
+
const t = i / count, t_ = 1 - t;
|
|
2877
|
+
return new Float32Array([
|
|
2878
|
+
t_ ** 3,
|
|
2879
|
+
3 * t * t_ ** 2,
|
|
2880
|
+
3 * t ** 2 * t_,
|
|
2881
|
+
t ** 3
|
|
2882
|
+
]);
|
|
2883
|
+
});
|
|
2884
|
+
(bCache ??= /* @__PURE__ */ new Map()).set(count, values);
|
|
2885
|
+
return values;
|
|
2886
|
+
}
|
|
2790
2887
|
function encodeFlate(bytes) {
|
|
2791
2888
|
return deflate(bytes);
|
|
2792
2889
|
}
|
|
@@ -4874,11 +4971,16 @@ function parseDictionaryStream(dictNode, lexer, bytes) {
|
|
|
4874
4971
|
let streamEnd = streamStart;
|
|
4875
4972
|
if (resolvedLength !== void 0 && resolvedLength >= 0 && streamStart + resolvedLength <= bytes.length) {
|
|
4876
4973
|
const candidateEnd = streamStart + resolvedLength;
|
|
4877
|
-
const
|
|
4878
|
-
|
|
4879
|
-
|
|
4974
|
+
const tailLexer = new CosByteLexer(bytes, candidateEnd);
|
|
4975
|
+
let endToken;
|
|
4976
|
+
try {
|
|
4977
|
+
endToken = tailLexer.nextToken();
|
|
4978
|
+
} catch (error) {
|
|
4979
|
+
if (!(error instanceof PdfError) || error.code !== "E_PARSE") throw error;
|
|
4980
|
+
}
|
|
4981
|
+
if (endToken?.kind === "keyword" && endToken.value === "endstream") {
|
|
4880
4982
|
rawStreamBytes = bytes.subarray(streamStart, candidateEnd);
|
|
4881
|
-
streamEnd =
|
|
4983
|
+
streamEnd = tailLexer.offset;
|
|
4882
4984
|
}
|
|
4883
4985
|
}
|
|
4884
4986
|
if (!rawStreamBytes) {
|
|
@@ -10614,21 +10716,23 @@ function resolvePageFonts(doc, resourcesDict) {
|
|
|
10614
10716
|
}
|
|
10615
10717
|
}
|
|
10616
10718
|
} else {
|
|
10617
|
-
const stdName = normalizeStandard14FontName(baseFont);
|
|
10618
|
-
const stdMetrics = STANDARD_14_FONTS[stdName];
|
|
10619
|
-
defaultWidth = stdMetrics.defaultWidth;
|
|
10620
|
-
for (const [codeStr, wVal] of Object.entries(stdMetrics.widthsByCode)) {
|
|
10621
|
-
widths.set(Number(codeStr), wVal);
|
|
10622
|
-
}
|
|
10623
10719
|
const firstCharNode = doc.resolve(dictGet(fObj, "FirstChar"));
|
|
10624
10720
|
const widthsArr = doc.resolveArray(dictGet(fObj, "Widths"));
|
|
10625
|
-
if (
|
|
10721
|
+
if (widthsArr) {
|
|
10722
|
+
const descriptor = doc.resolveDict(dictGet(fObj, "FontDescriptor"));
|
|
10723
|
+
const missingWidth = descriptor ? doc.resolve(dictGet(descriptor, "MissingWidth")) : void 0;
|
|
10724
|
+
defaultWidth = (missingWidth?.kind === "number" ? missingWidth.value : 0) * type3Scale1000;
|
|
10725
|
+
const firstChar = firstCharNode?.kind === "number" ? firstCharNode.value : 0;
|
|
10626
10726
|
for (let k = 0; k < widthsArr.items.length; k++) {
|
|
10627
10727
|
const wItem = doc.resolve(widthsArr.items[k]);
|
|
10628
10728
|
if (wItem?.kind === "number") {
|
|
10629
|
-
widths.set(
|
|
10729
|
+
widths.set(firstChar + k, wItem.value * type3Scale1000);
|
|
10630
10730
|
}
|
|
10631
10731
|
}
|
|
10732
|
+
} else {
|
|
10733
|
+
const stdMetrics = STANDARD_14_FONTS[normalizeStandard14FontName(baseFont)];
|
|
10734
|
+
defaultWidth = stdMetrics.defaultWidth;
|
|
10735
|
+
for (const [codeStr, wVal] of Object.entries(stdMetrics.widthsByCode)) widths.set(Number(codeStr), wVal);
|
|
10632
10736
|
}
|
|
10633
10737
|
}
|
|
10634
10738
|
let embeddedCff;
|
|
@@ -11016,143 +11120,28 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
11016
11120
|
const r = doc.resolve(it);
|
|
11017
11121
|
return r?.kind === "number" ? r.value : 0;
|
|
11018
11122
|
});
|
|
11019
|
-
const xmin = decodeNums[0], xmax = decodeNums[1], ymin = decodeNums[2], ymax = decodeNums[3];
|
|
11020
|
-
const numColorParams = Math.max(1, Math.floor((decodeNums.length - 4) / 2));
|
|
11021
11123
|
const fnNode = dictGet(shDict, "Function");
|
|
11022
11124
|
const csNode = doc.resolve(dictGet(shDict, "ColorSpace"));
|
|
11023
11125
|
const csName = csNode?.kind === "name" ? csNode.decoded : "DeviceRGB";
|
|
11024
|
-
|
|
11025
|
-
const
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
};
|
|
11044
|
-
const readColorRgb = () => {
|
|
11045
|
-
const params = [];
|
|
11046
|
-
for (let c = 0; c < numColorParams; c++) {
|
|
11047
|
-
const rc = readBits(bpcComp) / compMax;
|
|
11048
|
-
const cMin = decodeNums[4 + c * 2] ?? 0;
|
|
11049
|
-
const cMax = decodeNums[4 + c * 2 + 1] ?? 1;
|
|
11050
|
-
params.push(cMin + rc * (cMax - cMin));
|
|
11051
|
-
}
|
|
11052
|
-
const comps = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
|
|
11053
|
-
return convertColorSpaceComponentsToRgb(doc, csNode, csName, comps);
|
|
11054
|
-
};
|
|
11055
|
-
const triangles = [];
|
|
11056
|
-
if (shType === 4) {
|
|
11057
|
-
const minBitsPerVert = bpcFlag + 2 * bpcCoord + numColorParams * bpcComp;
|
|
11058
|
-
let triVerts;
|
|
11059
|
-
while (bitPos + minBitsPerVert <= totalBits) {
|
|
11060
|
-
const flag = readBits(bpcFlag) & 3;
|
|
11061
|
-
const [x, y] = readCoord();
|
|
11062
|
-
const rgb2 = readColorRgb();
|
|
11063
|
-
const vNew = { x, y, rgb: rgb2 };
|
|
11064
|
-
if (flag === 0 || !triVerts) {
|
|
11065
|
-
if (bitPos + 2 * minBitsPerVert > totalBits) break;
|
|
11066
|
-
readBits(bpcFlag);
|
|
11067
|
-
const [x1, y1] = readCoord();
|
|
11068
|
-
const rgb1 = readColorRgb();
|
|
11069
|
-
readBits(bpcFlag);
|
|
11070
|
-
const [x2, y2] = readCoord();
|
|
11071
|
-
const rgb22 = readColorRgb();
|
|
11072
|
-
triVerts = [vNew, { x: x1, y: y1, rgb: rgb1 }, { x: x2, y: y2, rgb: rgb22 }];
|
|
11073
|
-
triangles.push(triVerts);
|
|
11074
|
-
} else if (flag === 1) {
|
|
11075
|
-
triVerts = [triVerts[1], triVerts[2], vNew];
|
|
11076
|
-
triangles.push(triVerts);
|
|
11077
|
-
} else if (flag === 2) {
|
|
11078
|
-
triVerts = [triVerts[0], triVerts[2], vNew];
|
|
11079
|
-
triangles.push(triVerts);
|
|
11080
|
-
}
|
|
11081
|
-
}
|
|
11082
|
-
} else if (shType === 5) {
|
|
11083
|
-
const minBitsPerVert = 2 * bpcCoord + numColorParams * bpcComp;
|
|
11084
|
-
const verts = [];
|
|
11085
|
-
while (bitPos + minBitsPerVert <= totalBits) {
|
|
11086
|
-
const [x, y] = readCoord();
|
|
11087
|
-
const rgb2 = readColorRgb();
|
|
11088
|
-
verts.push({ x, y, rgb: rgb2 });
|
|
11089
|
-
}
|
|
11090
|
-
const numRows = Math.floor(verts.length / vPerRow);
|
|
11091
|
-
for (let r = 0; r + 1 < numRows; r++) {
|
|
11092
|
-
for (let c = 0; c + 1 < vPerRow; c++) {
|
|
11093
|
-
const v00 = verts[r * vPerRow + c];
|
|
11094
|
-
const v01 = verts[r * vPerRow + c + 1];
|
|
11095
|
-
const v11 = verts[(r + 1) * vPerRow + c + 1];
|
|
11096
|
-
const v10 = verts[(r + 1) * vPerRow + c];
|
|
11097
|
-
triangles.push([v00, v01, v11], [v00, v11, v10]);
|
|
11098
|
-
}
|
|
11099
|
-
}
|
|
11100
|
-
} else if (shType === 6 || shType === 7) {
|
|
11101
|
-
const numCtrl = shType === 6 ? 12 : 16;
|
|
11102
|
-
const minBitsPatch = bpcFlag + (numCtrl - 4) * 2 * bpcCoord + 2 * numColorParams * bpcComp;
|
|
11103
|
-
let prevPts;
|
|
11104
|
-
let prevColors;
|
|
11105
|
-
while (bitPos + minBitsPatch <= totalBits) {
|
|
11106
|
-
const flag = readBits(bpcFlag) & 3;
|
|
11107
|
-
let pts = [];
|
|
11108
|
-
let cols = [];
|
|
11109
|
-
if (flag === 0 || !prevPts || !prevColors) {
|
|
11110
|
-
for (let i = 0; i < numCtrl; i++) pts.push(readCoord());
|
|
11111
|
-
for (let i = 0; i < 4; i++) cols.push(readColorRgb());
|
|
11112
|
-
} else {
|
|
11113
|
-
const extraCtrl = numCtrl - 4;
|
|
11114
|
-
const readExtra = [];
|
|
11115
|
-
for (let i = 0; i < extraCtrl; i++) readExtra.push(readCoord());
|
|
11116
|
-
const c2 = readColorRgb();
|
|
11117
|
-
const c3 = readColorRgb();
|
|
11118
|
-
pts = [prevPts[3], prevPts[4], prevPts[5], prevPts[6], ...readExtra];
|
|
11119
|
-
cols = [prevColors[1], prevColors[2], c2, c3];
|
|
11120
|
-
}
|
|
11121
|
-
prevPts = pts;
|
|
11122
|
-
prevColors = cols;
|
|
11123
|
-
const p00 = pts[0];
|
|
11124
|
-
const p03 = pts[3];
|
|
11125
|
-
const p33 = pts[6];
|
|
11126
|
-
const p30 = pts[9];
|
|
11127
|
-
const c00 = cols[0], c03 = cols[1], c33 = cols[2], c30 = cols[3];
|
|
11128
|
-
const steps = 4;
|
|
11129
|
-
const grid = [];
|
|
11130
|
-
for (let iu = 0; iu <= steps; iu++) {
|
|
11131
|
-
const u = iu / steps;
|
|
11132
|
-
const row = [];
|
|
11133
|
-
for (let iv = 0; iv <= steps; iv++) {
|
|
11134
|
-
const v = iv / steps;
|
|
11135
|
-
const x = (1 - u) * (1 - v) * p00[0] + (1 - u) * v * p03[0] + u * v * p33[0] + u * (1 - v) * p30[0];
|
|
11136
|
-
const y = (1 - u) * (1 - v) * p00[1] + (1 - u) * v * p03[1] + u * v * p33[1] + u * (1 - v) * p30[1];
|
|
11137
|
-
const r = (1 - u) * (1 - v) * c00[0] + (1 - u) * v * c03[0] + u * v * c33[0] + u * (1 - v) * c30[0];
|
|
11138
|
-
const g = (1 - u) * (1 - v) * c00[1] + (1 - u) * v * c03[1] + u * v * c33[1] + u * (1 - v) * c30[1];
|
|
11139
|
-
const b = (1 - u) * (1 - v) * c00[2] + (1 - u) * v * c03[2] + u * v * c33[2] + u * (1 - v) * c30[2];
|
|
11140
|
-
row.push({ x, y, rgb: [r, g, b] });
|
|
11141
|
-
}
|
|
11142
|
-
grid.push(row);
|
|
11143
|
-
}
|
|
11144
|
-
for (let iu = 0; iu < steps; iu++) {
|
|
11145
|
-
for (let iv = 0; iv < steps; iv++) {
|
|
11146
|
-
const g00 = grid[iu][iv];
|
|
11147
|
-
const g01 = grid[iu][iv + 1];
|
|
11148
|
-
const g11 = grid[iu + 1][iv + 1];
|
|
11149
|
-
const g10 = grid[iu + 1][iv];
|
|
11150
|
-
triangles.push([g00, g01, g11], [g00, g11, g10]);
|
|
11151
|
-
}
|
|
11152
|
-
}
|
|
11153
|
-
}
|
|
11154
|
-
}
|
|
11155
|
-
if (triangles.length === 0) return void 0;
|
|
11126
|
+
const numComps = fnNode ? 1 : getColorSpaceComponentCount(doc, csNode);
|
|
11127
|
+
const mesh = new MeshShading(shType, new Stream(bytes), {
|
|
11128
|
+
bitsPerCoordinate: bpcCoord,
|
|
11129
|
+
bitsPerComponent: bpcComp,
|
|
11130
|
+
bitsPerFlag: bpcFlag,
|
|
11131
|
+
decode: decodeNums,
|
|
11132
|
+
numComps,
|
|
11133
|
+
colorFn: null,
|
|
11134
|
+
colorSpace: {
|
|
11135
|
+
numComps,
|
|
11136
|
+
getRgb(components) {
|
|
11137
|
+
const params = Array.from(components);
|
|
11138
|
+
const values = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
|
|
11139
|
+
return new Uint8Array(convertColorSpaceComponentsToRgb(doc, csNode, csName, values).map((value) => Math.round(Math.max(0, Math.min(1, value)) * 255)));
|
|
11140
|
+
}
|
|
11141
|
+
}
|
|
11142
|
+
}, vPerRow);
|
|
11143
|
+
const [, , positions, colors, vertexCount] = mesh.getIR();
|
|
11144
|
+
if (vertexCount === 0) return void 0;
|
|
11156
11145
|
const [bx0, by0, bx1, by1] = targetBox;
|
|
11157
11146
|
const boxW = Math.max(1, bx1 - bx0);
|
|
11158
11147
|
const boxH = Math.max(1, by1 - by0);
|
|
@@ -11164,10 +11153,10 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
11164
11153
|
const [px, py] = transformPoint(effectiveCtm, vx, vy);
|
|
11165
11154
|
return [(px - bx0) / boxW * imgW, (by1 - py) / boxH * imgH];
|
|
11166
11155
|
};
|
|
11167
|
-
for (
|
|
11168
|
-
const [x0, y0] = toImgCoords(
|
|
11169
|
-
const [x1, y1] = toImgCoords(
|
|
11170
|
-
const [x2, y2] = toImgCoords(
|
|
11156
|
+
for (let vertex = 0; vertex < vertexCount; vertex += 3) {
|
|
11157
|
+
const [x0, y0] = toImgCoords(positions[vertex * 2], positions[vertex * 2 + 1]);
|
|
11158
|
+
const [x1, y1] = toImgCoords(positions[vertex * 2 + 2], positions[vertex * 2 + 3]);
|
|
11159
|
+
const [x2, y2] = toImgCoords(positions[vertex * 2 + 4], positions[vertex * 2 + 5]);
|
|
11171
11160
|
const denom = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2);
|
|
11172
11161
|
if (Math.abs(denom) < 1e-6) continue;
|
|
11173
11162
|
const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
|
|
@@ -11182,13 +11171,12 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
|
|
|
11182
11171
|
const w1 = ((y2 - y0) * (px - x2) + (x0 - x2) * (py - y2)) / denom;
|
|
11183
11172
|
const w2 = 1 - w0 - w1;
|
|
11184
11173
|
if (w0 >= -1e-4 && w1 >= -1e-4 && w2 >= -1e-4) {
|
|
11185
|
-
const r = w0 * v0.rgb[0] + w1 * v1.rgb[0] + w2 * v2.rgb[0];
|
|
11186
|
-
const g = w0 * v0.rgb[1] + w1 * v1.rgb[1] + w2 * v2.rgb[1];
|
|
11187
|
-
const b = w0 * v0.rgb[2] + w1 * v1.rgb[2] + w2 * v2.rgb[2];
|
|
11188
11174
|
const pIdx = (iy * imgW + ix) * 4;
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11175
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
11176
|
+
rgba[pIdx + channel] = Math.round(
|
|
11177
|
+
w0 * colors[vertex * 4 + channel] + w1 * colors[vertex * 4 + 4 + channel] + w2 * colors[vertex * 4 + 8 + channel]
|
|
11178
|
+
);
|
|
11179
|
+
}
|
|
11192
11180
|
rgba[pIdx + 3] = a8;
|
|
11193
11181
|
}
|
|
11194
11182
|
}
|
|
@@ -11275,6 +11263,8 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
|
|
|
11275
11263
|
const [a, b, c, d, e, f] = effectiveCtm;
|
|
11276
11264
|
const det = a * d - b * c;
|
|
11277
11265
|
if (Math.abs(det) <= 1e-8) return void 0;
|
|
11266
|
+
const [sa, sb, sc, sd, se, sf] = shadingCtm;
|
|
11267
|
+
const shadingDet = sa * sd - sb * sc;
|
|
11278
11268
|
const t0Dom = shDomain[0] ?? 0;
|
|
11279
11269
|
const t1Dom = shDomain[1] ?? 1;
|
|
11280
11270
|
for (let iy = 0; iy < imgH; iy++) {
|
|
@@ -11285,8 +11275,10 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
|
|
|
11285
11275
|
const dxPdf = xPdf - e;
|
|
11286
11276
|
const xs = (d * dxPdf - c * dyPdf) / det;
|
|
11287
11277
|
const ys = (-b * dxPdf + a * dyPdf) / det;
|
|
11288
|
-
if (shBBox
|
|
11289
|
-
|
|
11278
|
+
if (shBBox) {
|
|
11279
|
+
const bboxX = (sd * (xPdf - se) - sc * (yPdf - sf)) / shadingDet;
|
|
11280
|
+
const bboxY = (-sb * (xPdf - se) + sa * (yPdf - sf)) / shadingDet;
|
|
11281
|
+
if (bboxX < shBBox[0] || bboxX > shBBox[2] || bboxY < shBBox[1] || bboxY > shBBox[3]) continue;
|
|
11290
11282
|
}
|
|
11291
11283
|
let comps;
|
|
11292
11284
|
if (shType === 1) {
|
|
@@ -11495,13 +11487,11 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
11495
11487
|
}
|
|
11496
11488
|
if (font?.cmap) {
|
|
11497
11489
|
if (!font.isTwoByteCid) {
|
|
11498
|
-
const stdName2 = normalizeStandard14FontName(font.baseFont);
|
|
11499
|
-
const stdMetrics2 = STANDARD_14_FONTS[stdName2];
|
|
11500
11490
|
const out2 = [];
|
|
11501
11491
|
for (let i = 0; i < bytes.length; i++) {
|
|
11502
11492
|
const code = bytes[i];
|
|
11503
11493
|
const unicode = font.cmap.map.get(code) ?? (font.differences.has(code) ? font.differences.get(code) : decodeWinAnsiByte(code));
|
|
11504
|
-
const advance1000 = font.widths.get(code) ??
|
|
11494
|
+
const advance1000 = font.widths.get(code) ?? font.defaultWidth;
|
|
11505
11495
|
out2.push({ charCode: code, isSpace: code === 32, unicode, advance1000 });
|
|
11506
11496
|
}
|
|
11507
11497
|
return out2;
|
|
@@ -11533,7 +11523,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
11533
11523
|
for (let i = 0; i < bytes.length; i++) {
|
|
11534
11524
|
const code = bytes[i];
|
|
11535
11525
|
const unicode = font?.differences.get(code) ?? decodeWinAnsiByte(code);
|
|
11536
|
-
const advance1000 = font
|
|
11526
|
+
const advance1000 = font ? font.widths.get(code) ?? font.defaultWidth : stdMetrics.widthsByCode[code] ?? stdMetrics.defaultWidth;
|
|
11537
11527
|
out.push({ charCode: code, isSpace: code === 32, unicode, advance1000 });
|
|
11538
11528
|
}
|
|
11539
11529
|
return out;
|
|
@@ -15338,6 +15328,7 @@ var FONT_IDENTITY_MATRIX;
|
|
|
15338
15328
|
var LINE_FACTOR;
|
|
15339
15329
|
var LINE_DESCENT_FACTOR;
|
|
15340
15330
|
var BASELINE_FACTOR;
|
|
15331
|
+
var MeshFigureType;
|
|
15341
15332
|
var VerbosityLevel;
|
|
15342
15333
|
var DrawOPS;
|
|
15343
15334
|
var PasswordResponses;
|
|
@@ -15469,6 +15460,11 @@ var _DEG_TO_RAD;
|
|
|
15469
15460
|
var _RAD_TO_DEG;
|
|
15470
15461
|
var PsJsCompiler;
|
|
15471
15462
|
var PSStackBasedInterpreter;
|
|
15463
|
+
var ShadingType;
|
|
15464
|
+
var BaseShading;
|
|
15465
|
+
var MeshStreamReader;
|
|
15466
|
+
var bCache;
|
|
15467
|
+
var MeshShading;
|
|
15472
15468
|
var PdfError;
|
|
15473
15469
|
var DEFAULT_MAX_DECODED_BYTES;
|
|
15474
15470
|
var BoundedFlateStream;
|
|
@@ -18958,6 +18954,11 @@ var init_dist = __esm({
|
|
|
18958
18954
|
LINE_FACTOR = 1.35;
|
|
18959
18955
|
LINE_DESCENT_FACTOR = 0.35;
|
|
18960
18956
|
BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
|
|
18957
|
+
MeshFigureType = {
|
|
18958
|
+
TRIANGLES: 1,
|
|
18959
|
+
LATTICE: 2,
|
|
18960
|
+
PATCH: 3
|
|
18961
|
+
};
|
|
18961
18962
|
VerbosityLevel = {
|
|
18962
18963
|
ERRORS: 0,
|
|
18963
18964
|
WARNINGS: 1,
|
|
@@ -39111,6 +39112,603 @@ var init_dist = __esm({
|
|
|
39111
39112
|
};
|
|
39112
39113
|
}
|
|
39113
39114
|
};
|
|
39115
|
+
ShadingType = {
|
|
39116
|
+
FUNCTION_BASED: 1,
|
|
39117
|
+
AXIAL: 2,
|
|
39118
|
+
RADIAL: 3,
|
|
39119
|
+
FREE_FORM_MESH: 4,
|
|
39120
|
+
LATTICE_FORM_MESH: 5,
|
|
39121
|
+
COONS_PATCH_MESH: 6,
|
|
39122
|
+
TENSOR_PATCH_MESH: 7
|
|
39123
|
+
};
|
|
39124
|
+
BaseShading = class _BaseShading {
|
|
39125
|
+
// A small number to offset the first/last color stops so we can insert ones
|
|
39126
|
+
// to support extend. Number.MIN_VALUE is too small and breaks the extend.
|
|
39127
|
+
static SMALL_NUMBER = 1e-6;
|
|
39128
|
+
constructor() {
|
|
39129
|
+
if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === _BaseShading) {
|
|
39130
|
+
unreachable2("Cannot initialize BaseShading.");
|
|
39131
|
+
}
|
|
39132
|
+
}
|
|
39133
|
+
getIR() {
|
|
39134
|
+
unreachable2("Abstract method `getIR` called.");
|
|
39135
|
+
}
|
|
39136
|
+
};
|
|
39137
|
+
MeshStreamReader = class {
|
|
39138
|
+
constructor(stream, context) {
|
|
39139
|
+
this.stream = stream;
|
|
39140
|
+
this.context = context;
|
|
39141
|
+
this.buffer = 0;
|
|
39142
|
+
this.bufferLength = 0;
|
|
39143
|
+
const numComps = context.numComps;
|
|
39144
|
+
this.tmpCompsBuf = new Float32Array(numComps);
|
|
39145
|
+
const csNumComps = context.colorSpace.numComps;
|
|
39146
|
+
this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
|
|
39147
|
+
}
|
|
39148
|
+
get hasData() {
|
|
39149
|
+
if (this.stream.end) {
|
|
39150
|
+
return this.stream.pos < this.stream.end;
|
|
39151
|
+
}
|
|
39152
|
+
if (this.bufferLength > 0) {
|
|
39153
|
+
return true;
|
|
39154
|
+
}
|
|
39155
|
+
const nextByte = this.stream.getByte();
|
|
39156
|
+
if (nextByte < 0) {
|
|
39157
|
+
return false;
|
|
39158
|
+
}
|
|
39159
|
+
this.buffer = nextByte;
|
|
39160
|
+
this.bufferLength = 8;
|
|
39161
|
+
return true;
|
|
39162
|
+
}
|
|
39163
|
+
readBits(n) {
|
|
39164
|
+
const { stream } = this;
|
|
39165
|
+
let { buffer, bufferLength } = this;
|
|
39166
|
+
if (n === 32) {
|
|
39167
|
+
if (bufferLength === 0) {
|
|
39168
|
+
return stream.getInt32() >>> 0;
|
|
39169
|
+
}
|
|
39170
|
+
buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte();
|
|
39171
|
+
const nextByte = stream.getByte();
|
|
39172
|
+
this.buffer = nextByte & (1 << bufferLength) - 1;
|
|
39173
|
+
return (buffer << 8 - bufferLength | (nextByte & 255) >> bufferLength) >>> 0;
|
|
39174
|
+
}
|
|
39175
|
+
if (n === 8 && bufferLength === 0) {
|
|
39176
|
+
return stream.getByte();
|
|
39177
|
+
}
|
|
39178
|
+
while (bufferLength < n) {
|
|
39179
|
+
buffer = buffer << 8 | stream.getByte();
|
|
39180
|
+
bufferLength += 8;
|
|
39181
|
+
}
|
|
39182
|
+
bufferLength -= n;
|
|
39183
|
+
this.bufferLength = bufferLength;
|
|
39184
|
+
this.buffer = buffer & (1 << bufferLength) - 1;
|
|
39185
|
+
return buffer >> bufferLength;
|
|
39186
|
+
}
|
|
39187
|
+
align() {
|
|
39188
|
+
this.buffer = 0;
|
|
39189
|
+
this.bufferLength = 0;
|
|
39190
|
+
}
|
|
39191
|
+
readFlag() {
|
|
39192
|
+
return this.readBits(this.context.bitsPerFlag);
|
|
39193
|
+
}
|
|
39194
|
+
readCoordinate() {
|
|
39195
|
+
const { bitsPerCoordinate, decode } = this.context;
|
|
39196
|
+
const xi = this.readBits(bitsPerCoordinate);
|
|
39197
|
+
const yi = this.readBits(bitsPerCoordinate);
|
|
39198
|
+
const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 23283064365386963e-26;
|
|
39199
|
+
return [
|
|
39200
|
+
xi * scale * (decode[1] - decode[0]) + decode[0],
|
|
39201
|
+
yi * scale * (decode[3] - decode[2]) + decode[2]
|
|
39202
|
+
];
|
|
39203
|
+
}
|
|
39204
|
+
readComponents() {
|
|
39205
|
+
const { bitsPerComponent, colorFn, colorSpace, decode, numComps } = this.context;
|
|
39206
|
+
const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 23283064365386963e-26;
|
|
39207
|
+
const components = this.tmpCompsBuf;
|
|
39208
|
+
for (let i = 0, j = 4; i < numComps; i++, j += 2) {
|
|
39209
|
+
const ci = this.readBits(bitsPerComponent);
|
|
39210
|
+
components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
|
|
39211
|
+
}
|
|
39212
|
+
const color = this.tmpCsCompsBuf;
|
|
39213
|
+
colorFn?.(components, 0, color, 0);
|
|
39214
|
+
return colorSpace.getRgb(color, 0);
|
|
39215
|
+
}
|
|
39216
|
+
};
|
|
39217
|
+
bCache = null;
|
|
39218
|
+
MeshShading = class _MeshShading extends BaseShading {
|
|
39219
|
+
static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
|
|
39220
|
+
static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
|
|
39221
|
+
// Count of triangles per entire mesh bounds.
|
|
39222
|
+
static TRIANGLE_DENSITY = 20;
|
|
39223
|
+
constructor(shadingType, stream, context, rowVertices) {
|
|
39224
|
+
super();
|
|
39225
|
+
this.shadingType = shadingType;
|
|
39226
|
+
this.bbox = this.background = null;
|
|
39227
|
+
this.coords = [];
|
|
39228
|
+
this.colors = [];
|
|
39229
|
+
this.figures = [];
|
|
39230
|
+
const reader = new MeshStreamReader(stream, context);
|
|
39231
|
+
let patchMesh = false;
|
|
39232
|
+
switch (this.shadingType) {
|
|
39233
|
+
case ShadingType.FREE_FORM_MESH:
|
|
39234
|
+
this._decodeType4Shading(reader);
|
|
39235
|
+
break;
|
|
39236
|
+
case ShadingType.LATTICE_FORM_MESH:
|
|
39237
|
+
const verticesPerRow = rowVertices | 0;
|
|
39238
|
+
if (verticesPerRow < 2) {
|
|
39239
|
+
throw new FormatError("Invalid VerticesPerRow");
|
|
39240
|
+
}
|
|
39241
|
+
this._decodeType5Shading(reader, verticesPerRow);
|
|
39242
|
+
break;
|
|
39243
|
+
case ShadingType.COONS_PATCH_MESH:
|
|
39244
|
+
this._decodeType6Shading(reader);
|
|
39245
|
+
patchMesh = true;
|
|
39246
|
+
break;
|
|
39247
|
+
case ShadingType.TENSOR_PATCH_MESH:
|
|
39248
|
+
this._decodeType7Shading(reader);
|
|
39249
|
+
patchMesh = true;
|
|
39250
|
+
break;
|
|
39251
|
+
default:
|
|
39252
|
+
unreachable2("Unsupported mesh type.");
|
|
39253
|
+
break;
|
|
39254
|
+
}
|
|
39255
|
+
if (patchMesh) {
|
|
39256
|
+
this._updateBounds();
|
|
39257
|
+
for (let i = 0, ii = this.figures.length; i < ii; i++) {
|
|
39258
|
+
this._buildFigureFromPatch(i);
|
|
39259
|
+
}
|
|
39260
|
+
}
|
|
39261
|
+
this._updateBounds();
|
|
39262
|
+
this._packData();
|
|
39263
|
+
}
|
|
39264
|
+
_decodeType4Shading(reader) {
|
|
39265
|
+
const coords = this.coords;
|
|
39266
|
+
const colors = this.colors;
|
|
39267
|
+
const operators = [];
|
|
39268
|
+
const ps = [];
|
|
39269
|
+
let verticesLeft = 0;
|
|
39270
|
+
while (reader.hasData) {
|
|
39271
|
+
const f = reader.readFlag();
|
|
39272
|
+
const coord = reader.readCoordinate();
|
|
39273
|
+
const color = reader.readComponents();
|
|
39274
|
+
if (verticesLeft === 0) {
|
|
39275
|
+
if (!(0 <= f && f <= 2)) {
|
|
39276
|
+
throw new FormatError("Unknown type4 flag");
|
|
39277
|
+
}
|
|
39278
|
+
switch (f) {
|
|
39279
|
+
case 0:
|
|
39280
|
+
verticesLeft = 3;
|
|
39281
|
+
break;
|
|
39282
|
+
case 1:
|
|
39283
|
+
ps.push(ps.at(-2), ps.at(-1));
|
|
39284
|
+
verticesLeft = 1;
|
|
39285
|
+
break;
|
|
39286
|
+
case 2:
|
|
39287
|
+
ps.push(ps.at(-3), ps.at(-1));
|
|
39288
|
+
verticesLeft = 1;
|
|
39289
|
+
break;
|
|
39290
|
+
}
|
|
39291
|
+
operators.push(f);
|
|
39292
|
+
}
|
|
39293
|
+
ps.push(coords.length);
|
|
39294
|
+
coords.push(coord);
|
|
39295
|
+
colors.push(color);
|
|
39296
|
+
verticesLeft--;
|
|
39297
|
+
reader.align();
|
|
39298
|
+
}
|
|
39299
|
+
this.figures.push({
|
|
39300
|
+
type: MeshFigureType.TRIANGLES,
|
|
39301
|
+
coords: new Int32Array(ps),
|
|
39302
|
+
colors: new Int32Array(ps)
|
|
39303
|
+
});
|
|
39304
|
+
}
|
|
39305
|
+
_decodeType5Shading(reader, verticesPerRow) {
|
|
39306
|
+
const coords = this.coords;
|
|
39307
|
+
const colors = this.colors;
|
|
39308
|
+
const ps = [];
|
|
39309
|
+
while (reader.hasData) {
|
|
39310
|
+
const coord = reader.readCoordinate();
|
|
39311
|
+
const color = reader.readComponents();
|
|
39312
|
+
ps.push(coords.length);
|
|
39313
|
+
coords.push(coord);
|
|
39314
|
+
colors.push(color);
|
|
39315
|
+
}
|
|
39316
|
+
this.figures.push({
|
|
39317
|
+
type: MeshFigureType.LATTICE,
|
|
39318
|
+
coords: new Int32Array(ps),
|
|
39319
|
+
colors: new Int32Array(ps),
|
|
39320
|
+
verticesPerRow
|
|
39321
|
+
});
|
|
39322
|
+
}
|
|
39323
|
+
_decodeType6Shading(reader) {
|
|
39324
|
+
const coords = this.coords;
|
|
39325
|
+
const colors = this.colors;
|
|
39326
|
+
const ps = new Int32Array(16);
|
|
39327
|
+
const cs = new Int32Array(4);
|
|
39328
|
+
while (reader.hasData) {
|
|
39329
|
+
const f = reader.readFlag();
|
|
39330
|
+
if (!(0 <= f && f <= 3)) {
|
|
39331
|
+
throw new FormatError("Unknown type6 flag");
|
|
39332
|
+
}
|
|
39333
|
+
const pi = coords.length;
|
|
39334
|
+
for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
|
|
39335
|
+
coords.push(reader.readCoordinate());
|
|
39336
|
+
}
|
|
39337
|
+
const ci = colors.length;
|
|
39338
|
+
for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
|
39339
|
+
colors.push(reader.readComponents());
|
|
39340
|
+
}
|
|
39341
|
+
let tmp1, tmp2, tmp3, tmp4;
|
|
39342
|
+
switch (f) {
|
|
39343
|
+
// prettier-ignore
|
|
39344
|
+
case 0:
|
|
39345
|
+
ps[12] = pi + 3;
|
|
39346
|
+
ps[13] = pi + 4;
|
|
39347
|
+
ps[14] = pi + 5;
|
|
39348
|
+
ps[15] = pi + 6;
|
|
39349
|
+
ps[8] = pi + 2;
|
|
39350
|
+
ps[11] = pi + 7;
|
|
39351
|
+
ps[4] = pi + 1;
|
|
39352
|
+
ps[7] = pi + 8;
|
|
39353
|
+
ps[0] = pi;
|
|
39354
|
+
ps[1] = pi + 11;
|
|
39355
|
+
ps[2] = pi + 10;
|
|
39356
|
+
ps[3] = pi + 9;
|
|
39357
|
+
cs[2] = ci + 1;
|
|
39358
|
+
cs[3] = ci + 2;
|
|
39359
|
+
cs[0] = ci;
|
|
39360
|
+
cs[1] = ci + 3;
|
|
39361
|
+
break;
|
|
39362
|
+
// prettier-ignore
|
|
39363
|
+
case 1:
|
|
39364
|
+
tmp1 = ps[12];
|
|
39365
|
+
tmp2 = ps[13];
|
|
39366
|
+
tmp3 = ps[14];
|
|
39367
|
+
tmp4 = ps[15];
|
|
39368
|
+
ps[12] = tmp4;
|
|
39369
|
+
ps[13] = pi + 0;
|
|
39370
|
+
ps[14] = pi + 1;
|
|
39371
|
+
ps[15] = pi + 2;
|
|
39372
|
+
ps[8] = tmp3;
|
|
39373
|
+
ps[11] = pi + 3;
|
|
39374
|
+
ps[4] = tmp2;
|
|
39375
|
+
ps[7] = pi + 4;
|
|
39376
|
+
ps[0] = tmp1;
|
|
39377
|
+
ps[1] = pi + 7;
|
|
39378
|
+
ps[2] = pi + 6;
|
|
39379
|
+
ps[3] = pi + 5;
|
|
39380
|
+
tmp1 = cs[2];
|
|
39381
|
+
tmp2 = cs[3];
|
|
39382
|
+
cs[2] = tmp2;
|
|
39383
|
+
cs[3] = ci;
|
|
39384
|
+
cs[0] = tmp1;
|
|
39385
|
+
cs[1] = ci + 1;
|
|
39386
|
+
break;
|
|
39387
|
+
// prettier-ignore
|
|
39388
|
+
case 2:
|
|
39389
|
+
tmp1 = ps[15];
|
|
39390
|
+
tmp2 = ps[11];
|
|
39391
|
+
ps[12] = ps[3];
|
|
39392
|
+
ps[13] = pi + 0;
|
|
39393
|
+
ps[14] = pi + 1;
|
|
39394
|
+
ps[15] = pi + 2;
|
|
39395
|
+
ps[8] = ps[7];
|
|
39396
|
+
ps[11] = pi + 3;
|
|
39397
|
+
ps[4] = tmp2;
|
|
39398
|
+
ps[7] = pi + 4;
|
|
39399
|
+
ps[0] = tmp1;
|
|
39400
|
+
ps[1] = pi + 7;
|
|
39401
|
+
ps[2] = pi + 6;
|
|
39402
|
+
ps[3] = pi + 5;
|
|
39403
|
+
tmp1 = cs[3];
|
|
39404
|
+
cs[2] = cs[1];
|
|
39405
|
+
cs[3] = ci;
|
|
39406
|
+
cs[0] = tmp1;
|
|
39407
|
+
cs[1] = ci + 1;
|
|
39408
|
+
break;
|
|
39409
|
+
// prettier-ignore
|
|
39410
|
+
case 3:
|
|
39411
|
+
ps[12] = ps[0];
|
|
39412
|
+
ps[13] = pi + 0;
|
|
39413
|
+
ps[14] = pi + 1;
|
|
39414
|
+
ps[15] = pi + 2;
|
|
39415
|
+
ps[8] = ps[1];
|
|
39416
|
+
ps[11] = pi + 3;
|
|
39417
|
+
ps[4] = ps[2];
|
|
39418
|
+
ps[7] = pi + 4;
|
|
39419
|
+
ps[0] = ps[3];
|
|
39420
|
+
ps[1] = pi + 7;
|
|
39421
|
+
ps[2] = pi + 6;
|
|
39422
|
+
ps[3] = pi + 5;
|
|
39423
|
+
cs[2] = cs[0];
|
|
39424
|
+
cs[3] = ci;
|
|
39425
|
+
cs[0] = cs[1];
|
|
39426
|
+
cs[1] = ci + 1;
|
|
39427
|
+
break;
|
|
39428
|
+
}
|
|
39429
|
+
ps[5] = coords.length;
|
|
39430
|
+
coords.push([
|
|
39431
|
+
(-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,
|
|
39432
|
+
(-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
|
|
39433
|
+
]);
|
|
39434
|
+
ps[6] = coords.length;
|
|
39435
|
+
coords.push([
|
|
39436
|
+
(-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,
|
|
39437
|
+
(-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
|
|
39438
|
+
]);
|
|
39439
|
+
ps[9] = coords.length;
|
|
39440
|
+
coords.push([
|
|
39441
|
+
(-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,
|
|
39442
|
+
(-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
|
|
39443
|
+
]);
|
|
39444
|
+
ps[10] = coords.length;
|
|
39445
|
+
coords.push([
|
|
39446
|
+
(-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,
|
|
39447
|
+
(-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
|
|
39448
|
+
]);
|
|
39449
|
+
this.figures.push({
|
|
39450
|
+
type: MeshFigureType.PATCH,
|
|
39451
|
+
coords: new Int32Array(ps),
|
|
39452
|
+
// making copies of ps and cs
|
|
39453
|
+
colors: new Int32Array(cs)
|
|
39454
|
+
});
|
|
39455
|
+
}
|
|
39456
|
+
}
|
|
39457
|
+
_decodeType7Shading(reader) {
|
|
39458
|
+
const coords = this.coords;
|
|
39459
|
+
const colors = this.colors;
|
|
39460
|
+
const ps = new Int32Array(16);
|
|
39461
|
+
const cs = new Int32Array(4);
|
|
39462
|
+
while (reader.hasData) {
|
|
39463
|
+
const f = reader.readFlag();
|
|
39464
|
+
if (!(0 <= f && f <= 3)) {
|
|
39465
|
+
throw new FormatError("Unknown type7 flag");
|
|
39466
|
+
}
|
|
39467
|
+
const pi = coords.length;
|
|
39468
|
+
for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
|
|
39469
|
+
coords.push(reader.readCoordinate());
|
|
39470
|
+
}
|
|
39471
|
+
const ci = colors.length;
|
|
39472
|
+
for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
|
39473
|
+
colors.push(reader.readComponents());
|
|
39474
|
+
}
|
|
39475
|
+
let tmp1, tmp2, tmp3, tmp4;
|
|
39476
|
+
switch (f) {
|
|
39477
|
+
// prettier-ignore
|
|
39478
|
+
case 0:
|
|
39479
|
+
ps[12] = pi + 3;
|
|
39480
|
+
ps[13] = pi + 4;
|
|
39481
|
+
ps[14] = pi + 5;
|
|
39482
|
+
ps[15] = pi + 6;
|
|
39483
|
+
ps[8] = pi + 2;
|
|
39484
|
+
ps[9] = pi + 13;
|
|
39485
|
+
ps[10] = pi + 14;
|
|
39486
|
+
ps[11] = pi + 7;
|
|
39487
|
+
ps[4] = pi + 1;
|
|
39488
|
+
ps[5] = pi + 12;
|
|
39489
|
+
ps[6] = pi + 15;
|
|
39490
|
+
ps[7] = pi + 8;
|
|
39491
|
+
ps[0] = pi;
|
|
39492
|
+
ps[1] = pi + 11;
|
|
39493
|
+
ps[2] = pi + 10;
|
|
39494
|
+
ps[3] = pi + 9;
|
|
39495
|
+
cs[2] = ci + 1;
|
|
39496
|
+
cs[3] = ci + 2;
|
|
39497
|
+
cs[0] = ci;
|
|
39498
|
+
cs[1] = ci + 3;
|
|
39499
|
+
break;
|
|
39500
|
+
// prettier-ignore
|
|
39501
|
+
case 1:
|
|
39502
|
+
tmp1 = ps[12];
|
|
39503
|
+
tmp2 = ps[13];
|
|
39504
|
+
tmp3 = ps[14];
|
|
39505
|
+
tmp4 = ps[15];
|
|
39506
|
+
ps[12] = tmp4;
|
|
39507
|
+
ps[13] = pi + 0;
|
|
39508
|
+
ps[14] = pi + 1;
|
|
39509
|
+
ps[15] = pi + 2;
|
|
39510
|
+
ps[8] = tmp3;
|
|
39511
|
+
ps[9] = pi + 9;
|
|
39512
|
+
ps[10] = pi + 10;
|
|
39513
|
+
ps[11] = pi + 3;
|
|
39514
|
+
ps[4] = tmp2;
|
|
39515
|
+
ps[5] = pi + 8;
|
|
39516
|
+
ps[6] = pi + 11;
|
|
39517
|
+
ps[7] = pi + 4;
|
|
39518
|
+
ps[0] = tmp1;
|
|
39519
|
+
ps[1] = pi + 7;
|
|
39520
|
+
ps[2] = pi + 6;
|
|
39521
|
+
ps[3] = pi + 5;
|
|
39522
|
+
tmp1 = cs[2];
|
|
39523
|
+
tmp2 = cs[3];
|
|
39524
|
+
cs[2] = tmp2;
|
|
39525
|
+
cs[3] = ci;
|
|
39526
|
+
cs[0] = tmp1;
|
|
39527
|
+
cs[1] = ci + 1;
|
|
39528
|
+
break;
|
|
39529
|
+
// prettier-ignore
|
|
39530
|
+
case 2:
|
|
39531
|
+
tmp1 = ps[15];
|
|
39532
|
+
tmp2 = ps[11];
|
|
39533
|
+
ps[12] = ps[3];
|
|
39534
|
+
ps[13] = pi + 0;
|
|
39535
|
+
ps[14] = pi + 1;
|
|
39536
|
+
ps[15] = pi + 2;
|
|
39537
|
+
ps[8] = ps[7];
|
|
39538
|
+
ps[9] = pi + 9;
|
|
39539
|
+
ps[10] = pi + 10;
|
|
39540
|
+
ps[11] = pi + 3;
|
|
39541
|
+
ps[4] = tmp2;
|
|
39542
|
+
ps[5] = pi + 8;
|
|
39543
|
+
ps[6] = pi + 11;
|
|
39544
|
+
ps[7] = pi + 4;
|
|
39545
|
+
ps[0] = tmp1;
|
|
39546
|
+
ps[1] = pi + 7;
|
|
39547
|
+
ps[2] = pi + 6;
|
|
39548
|
+
ps[3] = pi + 5;
|
|
39549
|
+
tmp1 = cs[3];
|
|
39550
|
+
cs[2] = cs[1];
|
|
39551
|
+
cs[3] = ci;
|
|
39552
|
+
cs[0] = tmp1;
|
|
39553
|
+
cs[1] = ci + 1;
|
|
39554
|
+
break;
|
|
39555
|
+
// prettier-ignore
|
|
39556
|
+
case 3:
|
|
39557
|
+
ps[12] = ps[0];
|
|
39558
|
+
ps[13] = pi + 0;
|
|
39559
|
+
ps[14] = pi + 1;
|
|
39560
|
+
ps[15] = pi + 2;
|
|
39561
|
+
ps[8] = ps[1];
|
|
39562
|
+
ps[9] = pi + 9;
|
|
39563
|
+
ps[10] = pi + 10;
|
|
39564
|
+
ps[11] = pi + 3;
|
|
39565
|
+
ps[4] = ps[2];
|
|
39566
|
+
ps[5] = pi + 8;
|
|
39567
|
+
ps[6] = pi + 11;
|
|
39568
|
+
ps[7] = pi + 4;
|
|
39569
|
+
ps[0] = ps[3];
|
|
39570
|
+
ps[1] = pi + 7;
|
|
39571
|
+
ps[2] = pi + 6;
|
|
39572
|
+
ps[3] = pi + 5;
|
|
39573
|
+
cs[2] = cs[0];
|
|
39574
|
+
cs[3] = ci;
|
|
39575
|
+
cs[0] = cs[1];
|
|
39576
|
+
cs[1] = ci + 1;
|
|
39577
|
+
break;
|
|
39578
|
+
}
|
|
39579
|
+
this.figures.push({
|
|
39580
|
+
type: MeshFigureType.PATCH,
|
|
39581
|
+
coords: new Int32Array(ps),
|
|
39582
|
+
// making copies of ps and cs
|
|
39583
|
+
colors: new Int32Array(cs)
|
|
39584
|
+
});
|
|
39585
|
+
}
|
|
39586
|
+
}
|
|
39587
|
+
_buildFigureFromPatch(index) {
|
|
39588
|
+
const figure = this.figures[index];
|
|
39589
|
+
assert2(
|
|
39590
|
+
figure.type === MeshFigureType.PATCH,
|
|
39591
|
+
"Unexpected patch mesh figure"
|
|
39592
|
+
);
|
|
39593
|
+
const coords = this.coords, colors = this.colors;
|
|
39594
|
+
const pi = figure.coords;
|
|
39595
|
+
const ci = figure.colors;
|
|
39596
|
+
const figureMinX = Math.min(
|
|
39597
|
+
coords[pi[0]][0],
|
|
39598
|
+
coords[pi[3]][0],
|
|
39599
|
+
coords[pi[12]][0],
|
|
39600
|
+
coords[pi[15]][0]
|
|
39601
|
+
);
|
|
39602
|
+
const figureMinY = Math.min(
|
|
39603
|
+
coords[pi[0]][1],
|
|
39604
|
+
coords[pi[3]][1],
|
|
39605
|
+
coords[pi[12]][1],
|
|
39606
|
+
coords[pi[15]][1]
|
|
39607
|
+
);
|
|
39608
|
+
const figureMaxX = Math.max(
|
|
39609
|
+
coords[pi[0]][0],
|
|
39610
|
+
coords[pi[3]][0],
|
|
39611
|
+
coords[pi[12]][0],
|
|
39612
|
+
coords[pi[15]][0]
|
|
39613
|
+
);
|
|
39614
|
+
const figureMaxY = Math.max(
|
|
39615
|
+
coords[pi[0]][1],
|
|
39616
|
+
coords[pi[3]][1],
|
|
39617
|
+
coords[pi[12]][1],
|
|
39618
|
+
coords[pi[15]][1]
|
|
39619
|
+
);
|
|
39620
|
+
let splitXBy = Math.ceil(
|
|
39621
|
+
(figureMaxX - figureMinX) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])
|
|
39622
|
+
);
|
|
39623
|
+
splitXBy = MathClamp(
|
|
39624
|
+
splitXBy,
|
|
39625
|
+
_MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
|
39626
|
+
_MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
|
|
39627
|
+
);
|
|
39628
|
+
let splitYBy = Math.ceil(
|
|
39629
|
+
(figureMaxY - figureMinY) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])
|
|
39630
|
+
);
|
|
39631
|
+
splitYBy = MathClamp(
|
|
39632
|
+
splitYBy,
|
|
39633
|
+
_MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
|
39634
|
+
_MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
|
|
39635
|
+
);
|
|
39636
|
+
const verticesPerRow = splitXBy + 1;
|
|
39637
|
+
const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
|
|
39638
|
+
const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
|
|
39639
|
+
let k = 0;
|
|
39640
|
+
const cl = new Uint8Array(3), cr = new Uint8Array(3);
|
|
39641
|
+
const c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
|
|
39642
|
+
const bRow = getB(splitYBy), bCol = getB(splitXBy);
|
|
39643
|
+
for (let row = 0; row <= splitYBy; row++) {
|
|
39644
|
+
cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
|
|
39645
|
+
cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
|
|
39646
|
+
cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
|
|
39647
|
+
cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
|
|
39648
|
+
cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
|
|
39649
|
+
cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
|
|
39650
|
+
for (let col = 0; col <= splitXBy; col++, k++) {
|
|
39651
|
+
if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
|
|
39652
|
+
continue;
|
|
39653
|
+
}
|
|
39654
|
+
let x = 0, y = 0;
|
|
39655
|
+
let q = 0;
|
|
39656
|
+
for (let i = 0; i <= 3; i++) {
|
|
39657
|
+
for (let j = 0; j <= 3; j++, q++) {
|
|
39658
|
+
const m = bRow[row][i] * bCol[col][j];
|
|
39659
|
+
x += coords[pi[q]][0] * m;
|
|
39660
|
+
y += coords[pi[q]][1] * m;
|
|
39661
|
+
}
|
|
39662
|
+
}
|
|
39663
|
+
figureCoords[k] = coords.length;
|
|
39664
|
+
coords.push([x, y]);
|
|
39665
|
+
figureColors[k] = colors.length;
|
|
39666
|
+
const newColor = new Uint8Array(3);
|
|
39667
|
+
newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
|
|
39668
|
+
newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
|
|
39669
|
+
newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
|
|
39670
|
+
colors.push(newColor);
|
|
39671
|
+
}
|
|
39672
|
+
}
|
|
39673
|
+
figureCoords[0] = pi[0];
|
|
39674
|
+
figureColors[0] = ci[0];
|
|
39675
|
+
figureCoords[splitXBy] = pi[3];
|
|
39676
|
+
figureColors[splitXBy] = ci[1];
|
|
39677
|
+
figureCoords[verticesPerRow * splitYBy] = pi[12];
|
|
39678
|
+
figureColors[verticesPerRow * splitYBy] = ci[2];
|
|
39679
|
+
figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
|
|
39680
|
+
figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
|
|
39681
|
+
this.figures[index] = {
|
|
39682
|
+
type: MeshFigureType.LATTICE,
|
|
39683
|
+
coords: figureCoords,
|
|
39684
|
+
colors: figureColors,
|
|
39685
|
+
verticesPerRow
|
|
39686
|
+
};
|
|
39687
|
+
}
|
|
39688
|
+
_updateBounds() {
|
|
39689
|
+
meshUpdateBounds(this);
|
|
39690
|
+
}
|
|
39691
|
+
_packData() {
|
|
39692
|
+
meshPackData(this);
|
|
39693
|
+
}
|
|
39694
|
+
getIR() {
|
|
39695
|
+
const { posData, colData, vertexCount } = buildMeshVertexData(
|
|
39696
|
+
this.coords,
|
|
39697
|
+
this.colors,
|
|
39698
|
+
this.figures
|
|
39699
|
+
);
|
|
39700
|
+
return [
|
|
39701
|
+
"Mesh",
|
|
39702
|
+
this.shadingType,
|
|
39703
|
+
posData,
|
|
39704
|
+
colData,
|
|
39705
|
+
vertexCount,
|
|
39706
|
+
this.bounds,
|
|
39707
|
+
this.bbox,
|
|
39708
|
+
this.background
|
|
39709
|
+
];
|
|
39710
|
+
}
|
|
39711
|
+
};
|
|
39114
39712
|
PdfError = class extends Error {
|
|
39115
39713
|
constructor(code, message) {
|
|
39116
39714
|
super(message);
|