Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2007,9 +2007,8 @@ class PartialEvaluator {
localColorSpaceCache,
})
.then(function (colorSpace) {
if (colorSpace) {
stateManager.state.fillColorSpace = colorSpace;
}
stateManager.state.fillColorSpace =
colorSpace || ColorSpace.singletons.gray;
calixteman marked this conversation as resolved.
Show resolved Hide resolved
Snuffleupagus marked this conversation as resolved.
Show resolved Hide resolved
})
);
return;
Expand All @@ -2033,9 +2032,8 @@ class PartialEvaluator {
localColorSpaceCache,
})
.then(function (colorSpace) {
if (colorSpace) {
stateManager.state.strokeColorSpace = colorSpace;
}
stateManager.state.strokeColorSpace =
colorSpace || ColorSpace.singletons.gray;
Snuffleupagus marked this conversation as resolved.
Show resolved Hide resolved
})
);
return;
Expand Down Expand Up @@ -2079,7 +2077,12 @@ class PartialEvaluator {
args = ColorSpace.singletons.rgb.getRgb(args, 0);
break;
case OPS.setFillColorN:
cs = stateManager.state.fillColorSpace;
cs = stateManager.state.patternFillColorSpace;
if (!cs) {
args = [];
fn = OPS.setFillTransparent;
break;
}
if (cs.name === "Pattern") {
next(
self.handleColorN(
Expand All @@ -2101,7 +2104,12 @@ class PartialEvaluator {
fn = OPS.setFillRGBColor;
break;
case OPS.setStrokeColorN:
cs = stateManager.state.strokeColorSpace;
cs = stateManager.state.patternStrokeColorSpace;
if (!cs) {
args = [];
fn = OPS.setStrokeTransparent;
break;
}
if (cs.name === "Pattern") {
next(
self.handleColorN(
Expand Down Expand Up @@ -4873,8 +4881,26 @@ class EvalState {
this.ctm = new Float32Array(IDENTITY_MATRIX);
this.font = null;
this.textRenderingMode = TextRenderingMode.FILL;
this.fillColorSpace = ColorSpace.singletons.gray;
this.strokeColorSpace = ColorSpace.singletons.gray;
this._fillColorSpace = 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() {
Expand Down
21 changes: 15 additions & 6 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2386,15 +2386,24 @@ class CanvasGraphics {
}

setStrokeRGBColor(r, g, b) {
const color = Util.makeHexColor(r, g, b);
this.ctx.strokeStyle = color;
this.current.strokeColor = color;
this.ctx.strokeStyle = this.current.strokeColor = Util.makeHexColor(
r,
g,
b
);
}

setStrokeTransparent() {
this.ctx.strokeStyle = this.current.strokeColor = "transparent";
}

setFillRGBColor(r, g, b) {
const color = Util.makeHexColor(r, g, b);
this.ctx.fillStyle = color;
this.current.fillColor = color;
this.ctx.fillStyle = this.current.fillColor = Util.makeHexColor(r, g, b);
this.current.patternFill = false;
}

setFillTransparent() {
this.ctx.fillStyle = this.current.fillColor = "transparent";
this.current.patternFill = false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ const OPS = {
paintImageMaskXObjectRepeat: 89,
paintSolidColorImageMask: 90,
constructPath: 91,
setStrokeTransparent: 92,
setFillTransparent: 93,
};

const PasswordResponses = {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue18466.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/user-attachments/files/16319966/image2.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10170,5 +10170,13 @@
"firstPage": 1,
"lastPage": 1,
"type": "eq"
},
{
"id": "issue18466",
"file": "pdfs/issue18466.pdf",
"md5": "251197bf19b237e084551d19f885c6b6",
"rounds": 1,
"link": true,
"type": "eq"
}
]