Skip to content

Commit

Permalink
Apply HCM filters on annotations which have their own canvas (bug 183…
Browse files Browse the repository at this point in the history
…0850)
  • Loading branch information
calixteman committed May 2, 2023
1 parent 797f8d3 commit 148e762
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3326,7 +3326,8 @@ class InternalRenderTask {
this.canvasFactory,
this.filterFactory,
{ optionalContentConfig },
this.annotationCanvasMap
this.annotationCanvasMap,
this.pageColors
);
this.gfx.beginDrawing({
transform,
Expand All @@ -3342,7 +3343,7 @@ class InternalRenderTask {
cancel(error = null, extraDelay = 0) {
this.running = false;
this.cancelled = true;
this.gfx?.endDrawing(this.pageColors);
this.gfx?.endDrawing();

if (this._canvas) {
InternalRenderTask.#canvasInUse.delete(this._canvas);
Expand Down
19 changes: 14 additions & 5 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@ class CanvasGraphics {
canvasFactory,
filterFactory,
{ optionalContentConfig, markedContentStack = null },
annotationCanvasMap
annotationCanvasMap,
pageColors
) {
this.ctx = canvasCtx;
this.current = new CanvasExtraState(
Expand Down Expand Up @@ -983,6 +984,7 @@ class CanvasGraphics {
this.viewportScale = 1;
this.outputScaleX = 1;
this.outputScaleY = 1;
this.pageColors = pageColors;

this._cachedScaleForStroking = null;
this._cachedGetSinglePixelWidth = null;
Expand Down Expand Up @@ -1135,7 +1137,7 @@ class CanvasGraphics {
}
}

endDrawing(pageColors = null) {
endDrawing() {
this.#restoreInitialState();

this.cachedCanvases.clear();
Expand All @@ -1153,11 +1155,14 @@ class CanvasGraphics {
cache.clear();
}
this._cachedBitmapsMap.clear();
this.#drawFilter();
}

if (pageColors) {
#drawFilter() {
if (this.pageColors) {
const hcmFilterId = this.filterFactory.addHCMFilter(
pageColors.foreground,
pageColors.background
this.pageColors.foreground,
this.pageColors.background
);
if (hcmFilterId !== "none") {
const savedFilter = this.ctx.filter;
Expand Down Expand Up @@ -2712,6 +2717,7 @@ class CanvasGraphics {
this.annotationCanvasMap.set(id, canvas);
this.annotationCanvas.savedCtx = this.ctx;
this.ctx = context;
this.ctx.save();
this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);

resetCtxToDefault(this.ctx);
Expand All @@ -2735,6 +2741,9 @@ class CanvasGraphics {

endAnnotation() {
if (this.annotationCanvas) {
this.ctx.restore();
this.#drawFilter();

this.ctx = this.annotationCanvas.savedCtx;
delete this.annotationCanvas.savedCtx;
delete this.annotationCanvas;
Expand Down
12 changes: 12 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7530,5 +7530,17 @@
"md5": "1aa34fbb2154f9a647c7fa9e90db0eff",
"rounds": 1,
"type": "text"
},
{
"id": "annotation-fileattachment-forced-colors-eq",
"file": "pdfs/annotation-fileattachment.pdf",
"md5": "9a192d8b1a7dc652a19835f6f08098bd",
"rounds": 1,
"pageColors": {
"background": "black",
"foreground": "#00FF00"
},
"annotations": true,
"type": "eq"
}
]

0 comments on commit 148e762

Please sign in to comment.