@poe-platform/safe-bash 0.1.780 → 0.1.782
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 +200 -165
- package/dist/image-ast/index.js +200 -165
- package/dist/pdf-ast/index.js +200 -165
- package/dist/safe-bash/command-chunks/{chunk-ZY6PMCW5.js → chunk-ADBFNLLK.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-QLYJUVVM.js → chunk-GBHSE6ZO.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3444RZLY.js → chunk-GZXLPWT5.js} +200 -165
- package/dist/safe-bash-command-ffmpeg/index.js +5745 -5715
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- 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 +200 -165
- package/dist/safe-bash-command-pdfinfo/index.js +200 -165
- package/dist/safe-bash-command-pdftk/index.js +200 -165
- package/dist/safe-bash-command-pdftoppm/index.js +200 -165
- package/dist/safe-bash-command-pdftotext/index.js +200 -165
- package/dist/safe-bash-command-qpdf/index.js +200 -165
- 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 +200 -165
- package/dist/safe-bash-command-wkhtmltopdf/index.js +201 -165
- package/package.json +2 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +73 -5
|
@@ -26566,7 +26566,7 @@ function cosString(value, span) {
|
|
|
26566
26566
|
if (typeof value === "string") {
|
|
26567
26567
|
let needsUtf16 = false;
|
|
26568
26568
|
for (let i = 0; i < value.length; i++) {
|
|
26569
|
-
if (value.charCodeAt(i)
|
|
26569
|
+
if (!PDF_DOC_ENCODING_REVERSE.has(value.charCodeAt(i))) {
|
|
26570
26570
|
needsUtf16 = true;
|
|
26571
26571
|
break;
|
|
26572
26572
|
}
|
|
@@ -26584,7 +26584,7 @@ function cosString(value, span) {
|
|
|
26584
26584
|
}
|
|
26585
26585
|
const bytes = new Uint8Array(value.length);
|
|
26586
26586
|
for (let i = 0; i < value.length; i++) {
|
|
26587
|
-
bytes[i] = value.charCodeAt(i)
|
|
26587
|
+
bytes[i] = PDF_DOC_ENCODING_REVERSE.get(value.charCodeAt(i));
|
|
26588
26588
|
}
|
|
26589
26589
|
return { kind: "string", format: "literal", bytes, span };
|
|
26590
26590
|
}
|
|
@@ -26731,6 +26731,9 @@ var PDF_DOC_ENCODING_MAP = {
|
|
|
26731
26731
|
160: 8364,
|
|
26732
26732
|
173: 65533
|
|
26733
26733
|
};
|
|
26734
|
+
var PDF_DOC_ENCODING_REVERSE = new Map(
|
|
26735
|
+
Array.from({ length: 256 }, (_, byte) => [PDF_DOC_ENCODING_MAP[byte] ?? byte, byte])
|
|
26736
|
+
);
|
|
26734
26737
|
function decodeUtf16UnitsWithSurrogateCheck(units) {
|
|
26735
26738
|
let out = "";
|
|
26736
26739
|
for (let i = 0; i < units.length; i++) {
|
|
@@ -27022,6 +27025,7 @@ var CosByteLexer = class {
|
|
|
27022
27025
|
const start = this.pos;
|
|
27023
27026
|
this.pos++;
|
|
27024
27027
|
let depth = 1;
|
|
27028
|
+
let recovery;
|
|
27025
27029
|
const out = [];
|
|
27026
27030
|
while (this.pos < this.end && depth > 0) {
|
|
27027
27031
|
const b = this.bytes[this.pos++];
|
|
@@ -27056,7 +27060,15 @@ var CosByteLexer = class {
|
|
|
27056
27060
|
out.push(b);
|
|
27057
27061
|
} else if (b === 41) {
|
|
27058
27062
|
depth--;
|
|
27059
|
-
if (depth > 0)
|
|
27063
|
+
if (depth > 0) {
|
|
27064
|
+
const next = this.bytes[this.pos];
|
|
27065
|
+
const afterLine = next === 13 && this.bytes[this.pos + 1] === 10 ? this.pos + 2 : this.pos + 1;
|
|
27066
|
+
const delimiter = this.bytes[afterLine];
|
|
27067
|
+
if (!recovery && this.pos + 2 < this.end && (next === 10 || next === 13) && (delimiter === 47 || delimiter === 62)) {
|
|
27068
|
+
recovery = { offset: this.pos, length: out.length };
|
|
27069
|
+
}
|
|
27070
|
+
out.push(b);
|
|
27071
|
+
}
|
|
27060
27072
|
} else if (b === 13) {
|
|
27061
27073
|
if (this.pos < this.end && this.bytes[this.pos] === 10) this.pos++;
|
|
27062
27074
|
out.push(10);
|
|
@@ -27067,6 +27079,10 @@ var CosByteLexer = class {
|
|
|
27067
27079
|
throw new PdfError("E_LIMIT", "PDF literal string exceeds maximum byte length");
|
|
27068
27080
|
}
|
|
27069
27081
|
}
|
|
27082
|
+
if (depth > 0 && recovery) {
|
|
27083
|
+
this.pos = recovery.offset;
|
|
27084
|
+
out.length = recovery.length;
|
|
27085
|
+
}
|
|
27070
27086
|
return {
|
|
27071
27087
|
kind: "string",
|
|
27072
27088
|
bytes: Uint8Array.from(out),
|
|
@@ -38782,6 +38798,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
38782
38798
|
};
|
|
38783
38799
|
const initialState = {
|
|
38784
38800
|
ctm: [1, 0, 0, 1, 0, 0],
|
|
38801
|
+
initialCtm: [1, 0, 0, 1, 0, 0],
|
|
38785
38802
|
strokeColor: { r: 0, g: 0, b: 0 },
|
|
38786
38803
|
fillColor: { r: 0, g: 0, b: 0 },
|
|
38787
38804
|
strokeAlpha: 1,
|
|
@@ -39079,6 +39096,116 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
39079
39096
|
] }], void 0, void 0, resources, activeFonts, depth);
|
|
39080
39097
|
stateStack.pop();
|
|
39081
39098
|
};
|
|
39099
|
+
const paintPattern = (segments, fillRule, resources, activeFonts, depth, mcid, actualText) => {
|
|
39100
|
+
const st = curState(), doc = params.cosDoc;
|
|
39101
|
+
if (!st.fillPatternName || !doc || !resources) return false;
|
|
39102
|
+
if (depth >= 8) throw new PdfError("E_LIMIT", "Pattern nesting exceeds the form depth limit");
|
|
39103
|
+
const patterns = doc.resolveDict(dictGet(resources, "Pattern"));
|
|
39104
|
+
const pattern = patterns && doc.resolve(dictGet(patterns, st.fillPatternName));
|
|
39105
|
+
const dict = pattern?.kind === "stream" ? pattern.dict : pattern?.kind === "dict" ? pattern : void 0;
|
|
39106
|
+
if (!dict) return false;
|
|
39107
|
+
const nums = (key, fallback) => {
|
|
39108
|
+
const array = doc.resolveArray(dictGet(dict, key));
|
|
39109
|
+
return array ? array.items.map((item, i) => {
|
|
39110
|
+
const value = doc.resolve(item);
|
|
39111
|
+
return value?.kind === "number" ? value.value : fallback[i] ?? 0;
|
|
39112
|
+
}) : fallback;
|
|
39113
|
+
};
|
|
39114
|
+
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
39115
|
+
const include = (x, y) => {
|
|
39116
|
+
x0 = Math.min(x0, x);
|
|
39117
|
+
y0 = Math.min(y0, y);
|
|
39118
|
+
x1 = Math.max(x1, x);
|
|
39119
|
+
y1 = Math.max(y1, y);
|
|
39120
|
+
};
|
|
39121
|
+
for (const segment of segments) {
|
|
39122
|
+
if (segment.kind === "close") continue;
|
|
39123
|
+
include(segment.x, segment.y);
|
|
39124
|
+
if (segment.kind === "cubic") {
|
|
39125
|
+
include(segment.x1, segment.y1);
|
|
39126
|
+
include(segment.x2, segment.y2);
|
|
39127
|
+
}
|
|
39128
|
+
if (segment.kind === "rect") include(segment.x + segment.width, segment.y + segment.height);
|
|
39129
|
+
}
|
|
39130
|
+
const [originX, originY] = params.origin ?? [0, 0];
|
|
39131
|
+
const clip = st.clipRect ?? [originX, originY, originX + params.width, originY + params.height];
|
|
39132
|
+
const bounds = [Math.max(x0, clip[0]), Math.max(y0, clip[1]), Math.min(x1, clip[2]), Math.min(y1, clip[3])];
|
|
39133
|
+
if (!(bounds[2] > bounds[0] && bounds[3] > bounds[1])) return true;
|
|
39134
|
+
const matrix = multiplyMatrices(nums("Matrix", [1, 0, 0, 1, 0, 0]), st.initialCtm);
|
|
39135
|
+
const type = doc.resolve(dictGet(dict, "PatternType"));
|
|
39136
|
+
stateStack.push({ ...st, clipRect: bounds, clipPaths: [...st.clipPaths ?? [], { segments, fillRule }] });
|
|
39137
|
+
try {
|
|
39138
|
+
if (type?.kind === "number" && type.value === 2) {
|
|
39139
|
+
const shading = doc.resolve(dictGet(dict, "Shading"));
|
|
39140
|
+
const shadingDict = shading?.kind === "stream" ? shading.dict : shading?.kind === "dict" ? shading : void 0;
|
|
39141
|
+
if (!shadingDict) return false;
|
|
39142
|
+
const image = renderShadingDictToImage(
|
|
39143
|
+
doc,
|
|
39144
|
+
shadingDict,
|
|
39145
|
+
matrix,
|
|
39146
|
+
bounds,
|
|
39147
|
+
st.fillAlpha,
|
|
39148
|
+
"PatternShading_" + st.fillPatternName,
|
|
39149
|
+
bounds,
|
|
39150
|
+
shading?.kind === "stream" ? shading : void 0,
|
|
39151
|
+
st.blendMode
|
|
39152
|
+
);
|
|
39153
|
+
if (image) emit({ kind: "image", value: image });
|
|
39154
|
+
return !!image;
|
|
39155
|
+
}
|
|
39156
|
+
if (pattern?.kind !== "stream") return false;
|
|
39157
|
+
const xStepNode = doc.resolve(dictGet(dict, "XStep"));
|
|
39158
|
+
const yStepNode = doc.resolve(dictGet(dict, "YStep"));
|
|
39159
|
+
const xStep = xStepNode?.kind === "number" ? Math.abs(xStepNode.value) : 0;
|
|
39160
|
+
const yStep = yStepNode?.kind === "number" ? Math.abs(yStepNode.value) : 0;
|
|
39161
|
+
const determinant = matrix[0] * matrix[3] - matrix[1] * matrix[2];
|
|
39162
|
+
if (!xStep || !yStep || !determinant) return true;
|
|
39163
|
+
const inverse = [
|
|
39164
|
+
matrix[3] / determinant,
|
|
39165
|
+
-matrix[1] / determinant,
|
|
39166
|
+
-matrix[2] / determinant,
|
|
39167
|
+
matrix[0] / determinant,
|
|
39168
|
+
(matrix[2] * matrix[5] - matrix[3] * matrix[4]) / determinant,
|
|
39169
|
+
(matrix[1] * matrix[4] - matrix[0] * matrix[5]) / determinant
|
|
39170
|
+
];
|
|
39171
|
+
const corners = [[bounds[0], bounds[1]], [bounds[2], bounds[1]], [bounds[2], bounds[3]], [bounds[0], bounds[3]]].map(([x, y]) => transformPoint(inverse, x, y));
|
|
39172
|
+
const box = nums("BBox", [0, 0, xStep, yStep]);
|
|
39173
|
+
const ix0 = Math.floor((Math.min(...corners.map((p) => p[0])) - box[2]) / xStep) + 1;
|
|
39174
|
+
const ix1 = Math.ceil((Math.max(...corners.map((p) => p[0])) - box[0]) / xStep) - 1;
|
|
39175
|
+
const iy0 = Math.floor((Math.min(...corners.map((p) => p[1])) - box[3]) / yStep) + 1;
|
|
39176
|
+
const iy1 = Math.ceil((Math.max(...corners.map((p) => p[1])) - box[1]) / yStep) - 1;
|
|
39177
|
+
if ((ix1 - ix0 + 1) * (iy1 - iy0 + 1) > 2e4) throw new PdfError("E_LIMIT", "Pattern tile count exceeds 20000");
|
|
39178
|
+
const nodes = parseContentStream(doc.decodeStream(pattern));
|
|
39179
|
+
const patternResources = doc.resolveDict(dictGet(dict, "Resources")) ?? resources;
|
|
39180
|
+
const patternFonts = new Map(activeFonts);
|
|
39181
|
+
for (const [key, font] of resolvePageFonts(doc, patternResources)) patternFonts.set(key, font);
|
|
39182
|
+
for (let iy = iy0; iy <= iy1; iy++) {
|
|
39183
|
+
for (let ix = ix0; ix <= ix1; ix++) {
|
|
39184
|
+
const tileCtm = multiplyMatrices([1, 0, 0, 1, ix * xStep, iy * yStep], matrix);
|
|
39185
|
+
const points = [[box[0], box[1]], [box[2], box[1]], [box[2], box[3]], [box[0], box[3]]].map(([x, y]) => transformPoint(tileCtm, x, y));
|
|
39186
|
+
const tileClip = [
|
|
39187
|
+
...points.map(([x, y], i) => ({ kind: i === 0 ? "move" : "line", x, y })),
|
|
39188
|
+
{ kind: "close" }
|
|
39189
|
+
];
|
|
39190
|
+
stateStack.push({
|
|
39191
|
+
...curState(),
|
|
39192
|
+
fillPatternName: void 0,
|
|
39193
|
+
ctm: tileCtm,
|
|
39194
|
+
initialCtm: tileCtm,
|
|
39195
|
+
clipPaths: [...curState().clipPaths ?? [], tileClip]
|
|
39196
|
+
});
|
|
39197
|
+
try {
|
|
39198
|
+
walkNodes(nodes, mcid, actualText, patternResources, patternFonts, depth + 1);
|
|
39199
|
+
} finally {
|
|
39200
|
+
stateStack.pop();
|
|
39201
|
+
}
|
|
39202
|
+
}
|
|
39203
|
+
}
|
|
39204
|
+
return true;
|
|
39205
|
+
} finally {
|
|
39206
|
+
stateStack.pop();
|
|
39207
|
+
}
|
|
39208
|
+
};
|
|
39082
39209
|
const paintForm = (form, activeResources, activeFonts, depth, mcid, actualText, maskGroup = false) => {
|
|
39083
39210
|
const st = curState();
|
|
39084
39211
|
const group = params.cosDoc.resolveDict(dictGet(form.dict, "Group"));
|
|
@@ -39137,7 +39264,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
39137
39264
|
}
|
|
39138
39265
|
const parentOperations = capturedOperations;
|
|
39139
39266
|
const children = [];
|
|
39140
|
-
const nextState = { ...st, ctm: nextCtm };
|
|
39267
|
+
const nextState = { ...st, ctm: nextCtm, initialCtm: nextCtm };
|
|
39141
39268
|
if (compositeGroup) {
|
|
39142
39269
|
capturedOperations = children;
|
|
39143
39270
|
nextState.fillAlpha = nextState.strokeAlpha = 1;
|
|
@@ -39295,136 +39422,15 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
39295
39422
|
}
|
|
39296
39423
|
const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
|
|
39297
39424
|
const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
|
|
39298
|
-
|
|
39299
|
-
|
|
39300
|
-
|
|
39301
|
-
|
|
39302
|
-
|
|
39303
|
-
|
|
39304
|
-
|
|
39305
|
-
|
|
39306
|
-
|
|
39307
|
-
for (const s of transformedSegments) {
|
|
39308
|
-
if (s.kind === "move" || s.kind === "line") {
|
|
39309
|
-
pMinX = Math.min(pMinX, s.x);
|
|
39310
|
-
pMinY = Math.min(pMinY, s.y);
|
|
39311
|
-
pMaxX = Math.max(pMaxX, s.x);
|
|
39312
|
-
pMaxY = Math.max(pMaxY, s.y);
|
|
39313
|
-
} else if (s.kind === "cubic") {
|
|
39314
|
-
pMinX = Math.min(pMinX, s.x1, s.x2, s.x);
|
|
39315
|
-
pMinY = Math.min(pMinY, s.y1, s.y2, s.y);
|
|
39316
|
-
pMaxX = Math.max(pMaxX, s.x1, s.x2, s.x);
|
|
39317
|
-
pMaxY = Math.max(pMaxY, s.y1, s.y2, s.y);
|
|
39318
|
-
} else if (s.kind === "rect") {
|
|
39319
|
-
pMinX = Math.min(pMinX, s.x);
|
|
39320
|
-
pMinY = Math.min(pMinY, s.y);
|
|
39321
|
-
pMaxX = Math.max(pMaxX, s.x + s.width);
|
|
39322
|
-
pMaxY = Math.max(pMaxY, s.y + s.height);
|
|
39323
|
-
}
|
|
39324
|
-
}
|
|
39325
|
-
if (Number.isFinite(pMinX) && Number.isFinite(pMinY) && pMaxX > pMinX && pMaxY > pMinY) {
|
|
39326
|
-
const shading = params.cosDoc.resolve(dictGet(patDict, "Shading"));
|
|
39327
|
-
const shDict = shading?.kind === "stream" ? shading.dict : shading?.kind === "dict" ? shading : void 0;
|
|
39328
|
-
if (shDict) {
|
|
39329
|
-
let patMatrix = [1, 0, 0, 1, 0, 0];
|
|
39330
|
-
const pmArr = params.cosDoc.resolveArray(dictGet(patDict, "Matrix"));
|
|
39331
|
-
if (pmArr && pmArr.items.length >= 6) {
|
|
39332
|
-
const mn = (idx, fb = 0) => {
|
|
39333
|
-
const r = params.cosDoc.resolve(pmArr.items[idx]);
|
|
39334
|
-
return r?.kind === "number" ? r.value : fb;
|
|
39335
|
-
};
|
|
39336
|
-
patMatrix = [mn(0, 1), mn(1, 0), mn(2, 0), mn(3, 1), mn(4, 0), mn(5, 0)];
|
|
39337
|
-
}
|
|
39338
|
-
const patClip = st.clipRect ? [
|
|
39339
|
-
Math.max(st.clipRect[0], pMinX),
|
|
39340
|
-
Math.max(st.clipRect[1], pMinY),
|
|
39341
|
-
Math.min(st.clipRect[2], pMaxX),
|
|
39342
|
-
Math.min(st.clipRect[3], pMaxY)
|
|
39343
|
-
] : [pMinX, pMinY, pMaxX, pMaxY];
|
|
39344
|
-
const shImg = renderShadingDictToImage(
|
|
39345
|
-
params.cosDoc,
|
|
39346
|
-
shDict,
|
|
39347
|
-
patMatrix,
|
|
39348
|
-
patClip,
|
|
39349
|
-
st.fillAlpha,
|
|
39350
|
-
"PatternShading_" + st.fillPatternName,
|
|
39351
|
-
patClip,
|
|
39352
|
-
shading?.kind === "stream" ? shading : void 0,
|
|
39353
|
-
st.blendMode
|
|
39354
|
-
);
|
|
39355
|
-
if (shImg) {
|
|
39356
|
-
emit({ kind: "image", value: shImg });
|
|
39357
|
-
evaluatedFillPattern = true;
|
|
39358
|
-
}
|
|
39359
|
-
}
|
|
39360
|
-
}
|
|
39361
|
-
} else if (patNode?.kind === "stream") {
|
|
39362
|
-
let pMinX = Infinity, pMinY = Infinity, pMaxX = -Infinity, pMaxY = -Infinity;
|
|
39363
|
-
for (const s of transformedSegments) {
|
|
39364
|
-
if (s.kind === "move" || s.kind === "line") {
|
|
39365
|
-
pMinX = Math.min(pMinX, s.x);
|
|
39366
|
-
pMinY = Math.min(pMinY, s.y);
|
|
39367
|
-
pMaxX = Math.max(pMaxX, s.x);
|
|
39368
|
-
pMaxY = Math.max(pMaxY, s.y);
|
|
39369
|
-
} else if (s.kind === "cubic") {
|
|
39370
|
-
pMinX = Math.min(pMinX, s.x1, s.x2, s.x);
|
|
39371
|
-
pMinY = Math.min(pMinY, s.y1, s.y2, s.y);
|
|
39372
|
-
pMaxX = Math.max(pMaxX, s.x1, s.x2, s.x);
|
|
39373
|
-
pMaxY = Math.max(pMaxY, s.y1, s.y2, s.y);
|
|
39374
|
-
} else if (s.kind === "rect") {
|
|
39375
|
-
pMinX = Math.min(pMinX, s.x);
|
|
39376
|
-
pMinY = Math.min(pMinY, s.y);
|
|
39377
|
-
pMaxX = Math.max(pMaxX, s.x + s.width);
|
|
39378
|
-
pMaxY = Math.max(pMaxY, s.y + s.height);
|
|
39379
|
-
}
|
|
39380
|
-
}
|
|
39381
|
-
if (Number.isFinite(pMinX) && Number.isFinite(pMinY) && pMaxX > pMinX && pMaxY > pMinY) {
|
|
39382
|
-
const xsNode = params.cosDoc.resolve(dictGet(patNode.dict, "XStep"));
|
|
39383
|
-
const ysNode = params.cosDoc.resolve(dictGet(patNode.dict, "YStep"));
|
|
39384
|
-
const xStep = xsNode?.kind === "number" && Math.abs(xsNode.value) > 1e-3 ? Math.abs(xsNode.value) : 40;
|
|
39385
|
-
const yStep = ysNode?.kind === "number" && Math.abs(ysNode.value) > 1e-3 ? Math.abs(ysNode.value) : 40;
|
|
39386
|
-
let patMatrix = [1, 0, 0, 1, 0, 0];
|
|
39387
|
-
const pmArr = params.cosDoc.resolveArray(dictGet(patNode.dict, "Matrix"));
|
|
39388
|
-
if (pmArr && pmArr.items.length >= 6) {
|
|
39389
|
-
const mn = (idx, fb = 0) => {
|
|
39390
|
-
const r = params.cosDoc.resolve(pmArr.items[idx]);
|
|
39391
|
-
return r?.kind === "number" ? r.value : fb;
|
|
39392
|
-
};
|
|
39393
|
-
patMatrix = [mn(0, 1), mn(1, 0), mn(2, 0), mn(3, 1), mn(4, 0), mn(5, 0)];
|
|
39394
|
-
}
|
|
39395
|
-
const tileClip = st.clipRect ? [
|
|
39396
|
-
Math.max(st.clipRect[0], pMinX),
|
|
39397
|
-
Math.max(st.clipRect[1], pMinY),
|
|
39398
|
-
Math.min(st.clipRect[2], pMaxX),
|
|
39399
|
-
Math.min(st.clipRect[3], pMaxY)
|
|
39400
|
-
] : [pMinX, pMinY, pMaxX, pMaxY];
|
|
39401
|
-
const patNodes = parseContentStream(params.cosDoc.decodeStream(patNode));
|
|
39402
|
-
const patResDict = params.cosDoc.resolveDict(dictGet(patNode.dict, "Resources")) ?? activeResources;
|
|
39403
|
-
const patFonts = new Map(activeFonts);
|
|
39404
|
-
for (const [fk, fv] of resolvePageFonts(params.cosDoc, patResDict).entries()) {
|
|
39405
|
-
patFonts.set(fk, fv);
|
|
39406
|
-
}
|
|
39407
|
-
const ixStart = Math.floor(pMinX / xStep);
|
|
39408
|
-
const ixEnd = Math.min(ixStart + 8, Math.ceil(pMaxX / xStep) - 1);
|
|
39409
|
-
const iyStart = Math.floor(pMinY / yStep);
|
|
39410
|
-
const iyEnd = Math.min(iyStart + 8, Math.ceil(pMaxY / yStep) - 1);
|
|
39411
|
-
for (let iy = iyStart; iy <= iyEnd; iy++) {
|
|
39412
|
-
for (let ix = ixStart; ix <= ixEnd; ix++) {
|
|
39413
|
-
const tileCtm = multiplyMatrices([1, 0, 0, 1, ix * xStep, iy * yStep], patMatrix);
|
|
39414
|
-
stateStack.push({
|
|
39415
|
-
...st,
|
|
39416
|
-
fillPatternName: void 0,
|
|
39417
|
-
ctm: tileCtm,
|
|
39418
|
-
clipRect: tileClip
|
|
39419
|
-
});
|
|
39420
|
-
walkNodes(patNodes, mcid, actualText, patResDict, patFonts, depth + 1);
|
|
39421
|
-
if (stateStack.length > 1) stateStack.pop();
|
|
39422
|
-
}
|
|
39423
|
-
}
|
|
39424
|
-
evaluatedFillPattern = true;
|
|
39425
|
-
}
|
|
39426
|
-
}
|
|
39427
|
-
}
|
|
39425
|
+
const evaluatedFillPattern = isFill && paintPattern(
|
|
39426
|
+
transformedSegments,
|
|
39427
|
+
node.paint.includes("*") ? "evenodd" : "nonzero",
|
|
39428
|
+
activeResources,
|
|
39429
|
+
activeFonts,
|
|
39430
|
+
depth,
|
|
39431
|
+
mcid,
|
|
39432
|
+
actualText
|
|
39433
|
+
);
|
|
39428
39434
|
if (evaluatedFillPattern && !isStroke) {
|
|
39429
39435
|
applyClip();
|
|
39430
39436
|
break;
|
|
@@ -39625,10 +39631,19 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
39625
39631
|
if (st.textRenderMode >= 4 && st.textRenderMode <= 7) pendingTextClip.push(...transformedGlyphSegs);
|
|
39626
39632
|
const isFillGlyph = st.textRenderMode === 0 || st.textRenderMode === 2 || st.textRenderMode === 4 || st.textRenderMode === 6;
|
|
39627
39633
|
const isStrokeGlyph = st.textRenderMode === 1 || st.textRenderMode === 2 || st.textRenderMode === 5 || st.textRenderMode === 6;
|
|
39634
|
+
const patterned = isFillGlyph && paintPattern(
|
|
39635
|
+
transformedGlyphSegs,
|
|
39636
|
+
"nonzero",
|
|
39637
|
+
activeResources,
|
|
39638
|
+
activeFonts,
|
|
39639
|
+
depth,
|
|
39640
|
+
mcid,
|
|
39641
|
+
actualText
|
|
39642
|
+
);
|
|
39628
39643
|
const paint = {
|
|
39629
39644
|
segments: transformedGlyphSegs,
|
|
39630
|
-
fillColor: isFillGlyph ? st.fillColor : void 0,
|
|
39631
|
-
fillAlpha: isFillGlyph ? st.fillAlpha : void 0,
|
|
39645
|
+
fillColor: isFillGlyph && !patterned ? st.fillColor : void 0,
|
|
39646
|
+
fillAlpha: isFillGlyph && !patterned ? st.fillAlpha : void 0,
|
|
39632
39647
|
strokeColor: isStrokeGlyph ? st.strokeColor : void 0,
|
|
39633
39648
|
strokeAlpha: isStrokeGlyph ? st.strokeAlpha : void 0,
|
|
39634
39649
|
strokeWidth: isStrokeGlyph ? st.strokeWidth : 0,
|
|
@@ -43099,10 +43114,14 @@ function computePdfBlendRgb(cbR, cbG, cbB, csR, csG, csB, mode) {
|
|
|
43099
43114
|
blendChannelSeparable(cbB, csB, mode)
|
|
43100
43115
|
];
|
|
43101
43116
|
}
|
|
43102
|
-
function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMask) {
|
|
43117
|
+
function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMask, groupAlpha) {
|
|
43103
43118
|
if (px < 0 || py < 0 || px >= width || py >= height || alpha <= 0) return;
|
|
43104
43119
|
const a = Math.min(1, Math.max(0, alpha)) * (clipMask ? clipMask[(py * width + px) * 4 + 3] / 255 : 1);
|
|
43105
43120
|
const idx = (py * width + px) * 4;
|
|
43121
|
+
if (groupAlpha) {
|
|
43122
|
+
const pixel = py * width + px;
|
|
43123
|
+
groupAlpha[pixel] = a + groupAlpha[pixel] * (1 - a);
|
|
43124
|
+
}
|
|
43106
43125
|
const csR = Math.min(1, Math.max(0, color.r));
|
|
43107
43126
|
const csG = Math.min(1, Math.max(0, color.g));
|
|
43108
43127
|
const csB = Math.min(1, Math.max(0, color.b));
|
|
@@ -43234,7 +43253,7 @@ function pathsToEdges(paths, closeSubpaths = false) {
|
|
|
43234
43253
|
}
|
|
43235
43254
|
return edges;
|
|
43236
43255
|
}
|
|
43237
|
-
function fillEdgesScanline4x4(rgba, width, height, edges, color, alpha = 1, fillRule = "nonzero", clipScreen, antialias = true, blendMode, clipMask) {
|
|
43256
|
+
function fillEdgesScanline4x4(rgba, width, height, edges, color, alpha = 1, fillRule = "nonzero", clipScreen, antialias = true, blendMode, clipMask, groupAlpha) {
|
|
43238
43257
|
if (edges.length === 0) return;
|
|
43239
43258
|
let minY = Infinity;
|
|
43240
43259
|
let maxY = -Infinity;
|
|
@@ -43300,7 +43319,7 @@ function fillEdgesScanline4x4(rgba, width, height, edges, color, alpha = 1, fill
|
|
|
43300
43319
|
const count = rowCounts[px];
|
|
43301
43320
|
if (count > 0) {
|
|
43302
43321
|
const cov = antialias ? count / 16 : count >= 8 ? 1 : 0;
|
|
43303
|
-
blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
|
|
43322
|
+
blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask, groupAlpha);
|
|
43304
43323
|
}
|
|
43305
43324
|
}
|
|
43306
43325
|
}
|
|
@@ -43379,19 +43398,16 @@ function hasCompositingEffects(operations, includeSoftMasks = false) {
|
|
|
43379
43398
|
return operations.some((operation) => includeSoftMasks && !!operation.value.softMask || !!operation.value.blendMode && operation.value.blendMode !== "Normal" && operation.value.blendMode !== "Compatible" || operation.kind === "group" && hasCompositingEffects(operation.value.operations, includeSoftMasks));
|
|
43380
43399
|
}
|
|
43381
43400
|
function needsGroupBackdrop(group) {
|
|
43382
|
-
return group.isolated === false &&
|
|
43401
|
+
return group.isolated === false && hasCompositingEffects(group.operations, true);
|
|
43383
43402
|
}
|
|
43384
|
-
function
|
|
43385
|
-
const baseScale = options.scale ?? (options.dpi ? options.dpi / 72 : 1.5);
|
|
43386
|
-
const scaleX = options.dpiX !== void 0 ? options.dpiX / 72 : baseScale;
|
|
43387
|
-
const scaleY = options.dpiY !== void 0 ? options.dpiY / 72 : baseScale;
|
|
43388
|
-
const scale = scaleX;
|
|
43403
|
+
function renderDisplayListLayer(displayList, options, scale, backdrop) {
|
|
43389
43404
|
const [originX, originY] = displayList.origin ?? [0, 0];
|
|
43390
43405
|
const pageTop = originY + displayList.height;
|
|
43391
43406
|
const toScreen = (x, y) => [(x - originX) * scale, (pageTop - y) * scale];
|
|
43392
43407
|
const width = Math.max(1, Math.round(displayList.width * scale));
|
|
43393
43408
|
const height = Math.max(1, Math.round(displayList.height * scale));
|
|
43394
|
-
const rgba = new Uint8Array(width * height * 4);
|
|
43409
|
+
const rgba = backdrop ? backdrop.slice() : new Uint8Array(width * height * 4);
|
|
43410
|
+
const groupAlpha = backdrop ? new Float32Array(width * height) : void 0;
|
|
43395
43411
|
const deferBackground = !options.transparent && hasCompositingEffects(paintOperations(displayList));
|
|
43396
43412
|
const transparent = options.transparent || deferBackground;
|
|
43397
43413
|
const bg = options.background ?? { r: 1, g: 1, b: 1 };
|
|
@@ -43399,7 +43415,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
43399
43415
|
const bgG = transparent ? 0 : Math.round(bg.g * 255);
|
|
43400
43416
|
const bgB = transparent ? 0 : Math.round(bg.b * 255);
|
|
43401
43417
|
const bgA = transparent ? 0 : 255;
|
|
43402
|
-
for (let i = 0; i < width * height; i++) {
|
|
43418
|
+
for (let i = 0; !backdrop && i < width * height; i++) {
|
|
43403
43419
|
rgba[i * 4] = bgR;
|
|
43404
43420
|
rgba[i * 4 + 1] = bgG;
|
|
43405
43421
|
rgba[i * 4 + 2] = bgB;
|
|
@@ -43417,20 +43433,12 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
43417
43433
|
let operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
43418
43434
|
if (operation.kind === "group") {
|
|
43419
43435
|
const group = operation.value;
|
|
43420
|
-
|
|
43421
|
-
|
|
43422
|
-
|
|
43423
|
-
|
|
43424
|
-
|
|
43425
|
-
|
|
43426
|
-
decodedRgba: rgba.slice(),
|
|
43427
|
-
matrix: [width / scale, 0, 0, height / scale, originX, pageTop - height / scale],
|
|
43428
|
-
colorSpace: "DeviceRGB",
|
|
43429
|
-
bitsPerComponent: 8,
|
|
43430
|
-
...group.bboxClip ? { clipPaths: [group.bboxClip] } : {}
|
|
43431
|
-
} }, ...operations];
|
|
43432
|
-
}
|
|
43433
|
-
const bitmap = renderDisplayListToBitmap({ ...displayList, rotation: 0, operations }, { ...options, scale, dpiX: void 0, dpiY: void 0, cropRect: void 0, useCropBox: false, transparent: true });
|
|
43436
|
+
const bitmap = renderDisplayListLayer(
|
|
43437
|
+
{ ...displayList, operations: group.operations },
|
|
43438
|
+
{ ...options, transparent: true },
|
|
43439
|
+
scale,
|
|
43440
|
+
needsGroupBackdrop(group) ? rgba : void 0
|
|
43441
|
+
);
|
|
43434
43442
|
for (let i = 3; i < bitmap.data.length; i += 4) bitmap.data[i] = Math.round(bitmap.data[i] * group.alpha);
|
|
43435
43443
|
operation = { kind: "image", value: {
|
|
43436
43444
|
name: "TransparencyGroup",
|
|
@@ -43500,7 +43508,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
43500
43508
|
if (path.fillColor) {
|
|
43501
43509
|
const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale, toScreen), true);
|
|
43502
43510
|
const clipScreen = path.clipRect ? [(path.clipRect[0] - originX) * scale, (pageTop - path.clipRect[3]) * scale, (path.clipRect[2] - originX) * scale, (pageTop - path.clipRect[1]) * scale] : void 0;
|
|
43503
|
-
fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
|
|
43511
|
+
fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask, groupAlpha);
|
|
43504
43512
|
}
|
|
43505
43513
|
if (path.strokeColor) {
|
|
43506
43514
|
const rawSw = path.strokeWidth * scale * (path.strokeMatrix ? Math.hypot(path.strokeMatrix[0], path.strokeMatrix[1]) : 1);
|
|
@@ -43518,7 +43526,8 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
43518
43526
|
clipScreen,
|
|
43519
43527
|
original.kind === "glyph" ? aaTxt : aaVec,
|
|
43520
43528
|
path.blendMode,
|
|
43521
|
-
clipMask
|
|
43529
|
+
clipMask,
|
|
43530
|
+
groupAlpha
|
|
43522
43531
|
);
|
|
43523
43532
|
}
|
|
43524
43533
|
} else if (operation.kind === "image") {
|
|
@@ -43582,12 +43591,31 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
43582
43591
|
},
|
|
43583
43592
|
sample[3] / 255,
|
|
43584
43593
|
img.blendMode,
|
|
43585
|
-
clipMask
|
|
43594
|
+
clipMask,
|
|
43595
|
+
groupAlpha
|
|
43586
43596
|
);
|
|
43587
43597
|
}
|
|
43588
43598
|
}
|
|
43589
43599
|
}
|
|
43590
43600
|
}
|
|
43601
|
+
if (backdrop && groupAlpha) {
|
|
43602
|
+
for (let i = 0; i < rgba.length; i += 4) {
|
|
43603
|
+
const alpha = groupAlpha[i / 4];
|
|
43604
|
+
if (alpha === 0) {
|
|
43605
|
+
rgba.fill(0, i, i + 4);
|
|
43606
|
+
continue;
|
|
43607
|
+
}
|
|
43608
|
+
const factor = backdrop[i + 3] / 255 * (1 / alpha - 1);
|
|
43609
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
43610
|
+
const color = rgba[i + channel];
|
|
43611
|
+
rgba[i + channel] = Math.max(0, Math.min(
|
|
43612
|
+
255,
|
|
43613
|
+
Math.round(color + (color - backdrop[i + channel]) * factor)
|
|
43614
|
+
));
|
|
43615
|
+
}
|
|
43616
|
+
rgba[i + 3] = Math.round(alpha * 255);
|
|
43617
|
+
}
|
|
43618
|
+
}
|
|
43591
43619
|
if (deferBackground) {
|
|
43592
43620
|
for (let i = 0; i < rgba.length; i += 4) {
|
|
43593
43621
|
const alpha = rgba[i + 3] / 255;
|
|
@@ -43597,7 +43625,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
43597
43625
|
rgba[i + 3] = 255;
|
|
43598
43626
|
}
|
|
43599
43627
|
}
|
|
43600
|
-
|
|
43628
|
+
return { width, height, data: rgba };
|
|
43629
|
+
}
|
|
43630
|
+
function renderDisplayListToBitmap(displayList, options = {}) {
|
|
43631
|
+
const baseScale = options.scale ?? (options.dpi ? options.dpi / 72 : 1.5);
|
|
43632
|
+
const scaleX = options.dpiX !== void 0 ? options.dpiX / 72 : baseScale;
|
|
43633
|
+
const scaleY = options.dpiY !== void 0 ? options.dpiY / 72 : baseScale;
|
|
43634
|
+
let result = renderDisplayListLayer(displayList, options, scaleX);
|
|
43635
|
+
const { width, height, data: rgba } = result;
|
|
43601
43636
|
if (Math.abs(scaleX - scaleY) > 1e-6) {
|
|
43602
43637
|
const targetW = Math.max(1, Math.round(displayList.width * scaleX));
|
|
43603
43638
|
const targetH = Math.max(1, Math.round(displayList.height * scaleY));
|