Use a transparent color when setting fill/stroke colors in a pattern context but with no colorspace

This commit is contained in:
Calixte Denizet 2024-07-20 14:45:25 +02:00
parent 98e772727e
commit 482994cc04
5 changed files with 62 additions and 16 deletions

View File

@ -2007,9 +2007,8 @@ class PartialEvaluator {
localColorSpaceCache, localColorSpaceCache,
}) })
.then(function (colorSpace) { .then(function (colorSpace) {
if (colorSpace) { stateManager.state.fillColorSpace =
stateManager.state.fillColorSpace = colorSpace; colorSpace || ColorSpace.singletons.gray;
}
}) })
); );
return; return;
@ -2033,9 +2032,8 @@ class PartialEvaluator {
localColorSpaceCache, localColorSpaceCache,
}) })
.then(function (colorSpace) { .then(function (colorSpace) {
if (colorSpace) { stateManager.state.strokeColorSpace =
stateManager.state.strokeColorSpace = colorSpace; colorSpace || ColorSpace.singletons.gray;
}
}) })
); );
return; return;
@ -2079,7 +2077,12 @@ class PartialEvaluator {
args = ColorSpace.singletons.rgb.getRgb(args, 0); args = ColorSpace.singletons.rgb.getRgb(args, 0);
break; break;
case OPS.setFillColorN: case OPS.setFillColorN:
cs = stateManager.state.fillColorSpace; cs = stateManager.state.patternFillColorSpace;
if (!cs) {
args = [];
fn = OPS.setFillTransparent;
break;
}
if (cs.name === "Pattern") { if (cs.name === "Pattern") {
next( next(
self.handleColorN( self.handleColorN(
@ -2101,7 +2104,12 @@ class PartialEvaluator {
fn = OPS.setFillRGBColor; fn = OPS.setFillRGBColor;
break; break;
case OPS.setStrokeColorN: case OPS.setStrokeColorN:
cs = stateManager.state.strokeColorSpace; cs = stateManager.state.patternStrokeColorSpace;
if (!cs) {
args = [];
fn = OPS.setStrokeTransparent;
break;
}
if (cs.name === "Pattern") { if (cs.name === "Pattern") {
next( next(
self.handleColorN( self.handleColorN(
@ -4873,8 +4881,26 @@ class EvalState {
this.ctm = new Float32Array(IDENTITY_MATRIX); this.ctm = new Float32Array(IDENTITY_MATRIX);
this.font = null; this.font = null;
this.textRenderingMode = TextRenderingMode.FILL; this.textRenderingMode = TextRenderingMode.FILL;
this.fillColorSpace = ColorSpace.singletons.gray; this._fillColorSpace = ColorSpace.singletons.gray;
this.strokeColorSpace = ColorSpace.singletons.gray; this._strokeColorSpace = ColorSpace.singletons.gray;
this.patternFillColorSpace = null;
this.patternStrokeColorSpace = null;
}
get fillColorSpace() {
return this._fillColorSpace;
}
set fillColorSpace(colorSpace) {
this._fillColorSpace = this.patternFillColorSpace = colorSpace;
}
get strokeColorSpace() {
return this._strokeColorSpace;
}
set strokeColorSpace(colorSpace) {
this._strokeColorSpace = this.patternStrokeColorSpace = colorSpace;
} }
clone() { clone() {

View File

@ -2386,15 +2386,24 @@ class CanvasGraphics {
} }
setStrokeRGBColor(r, g, b) { setStrokeRGBColor(r, g, b) {
const color = Util.makeHexColor(r, g, b); this.ctx.strokeStyle = this.current.strokeColor = Util.makeHexColor(
this.ctx.strokeStyle = color; r,
this.current.strokeColor = color; g,
b
);
}
setStrokeTransparent() {
this.ctx.strokeStyle = this.current.strokeColor = "transparent";
} }
setFillRGBColor(r, g, b) { setFillRGBColor(r, g, b) {
const color = Util.makeHexColor(r, g, b); this.ctx.fillStyle = this.current.fillColor = Util.makeHexColor(r, g, b);
this.ctx.fillStyle = color; this.current.patternFill = false;
this.current.fillColor = color; }
setFillTransparent() {
this.ctx.fillStyle = this.current.fillColor = "transparent";
this.current.patternFill = false; this.current.patternFill = false;
} }

View File

@ -342,6 +342,8 @@ const OPS = {
paintImageMaskXObjectRepeat: 89, paintImageMaskXObjectRepeat: 89,
paintSolidColorImageMask: 90, paintSolidColorImageMask: 90,
constructPath: 91, constructPath: 91,
setStrokeTransparent: 92,
setFillTransparent: 93,
}; };
const PasswordResponses = { const PasswordResponses = {

View File

@ -0,0 +1 @@
https://github.com/user-attachments/files/16319966/image2.pdf

View File

@ -10170,5 +10170,13 @@
"firstPage": 1, "firstPage": 1,
"lastPage": 1, "lastPage": 1,
"type": "eq" "type": "eq"
},
{
"id": "issue18466",
"file": "pdfs/issue18466.pdf",
"md5": "251197bf19b237e084551d19f885c6b6",
"rounds": 1,
"link": true,
"type": "eq"
} }
] ]