Reset all the canvas states after rendering each annotations (#14105)

- each annotation must be rendered independently of the others. So
  after having rendered each annotation, the canvas states are reset
  in order to have something clean to render the next one.
This commit is contained in:
Calixte Denizet 2022-06-06 17:24:38 +02:00
parent 135b9fbcfb
commit 96d0d22d66
3 changed files with 30 additions and 12 deletions

View File

@ -1453,7 +1453,7 @@ class CanvasGraphics {
}
}
endDrawing() {
#restoreInitialState() {
// Finishing all opened operations such as SMask group painting.
while (this.stateStack.length || this.inSMaskMode) {
this.restore();
@ -1469,6 +1469,10 @@ class CanvasGraphics {
this.ctx.restore();
this.transparentCanvas = null;
}
}
endDrawing() {
this.#restoreInitialState();
this.cachedCanvases.clear();
this.cachedPatterns.clear();
@ -2972,19 +2976,24 @@ class CanvasGraphics {
}
}
beginAnnotations() {
beginAnnotations() {}
endAnnotations() {}
beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
// The annotations are drawn just after the page content.
// The page content drawing can potentially have set a transform,
// a clipping path, whatever...
// So in order to have something clean, we restore the initial state.
this.#restoreInitialState();
resetCtxToDefault(this.ctx, this.foregroundColor);
this.ctx.save();
this.save();
if (this.baseTransform) {
this.ctx.setTransform.apply(this.ctx, this.baseTransform);
}
}
endAnnotations() {
this.restore();
}
beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
this.save();
if (Array.isArray(rect) && rect.length === 4) {
const width = rect[2] - rect[0];
@ -3022,8 +3031,8 @@ class CanvasGraphics {
this.annotationCanvasMap.set(id, canvas);
this.annotationCanvas.savedCtx = this.ctx;
this.ctx = context;
this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
addContextCurrentTransform(this.ctx);
this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
resetCtxToDefault(this.ctx, this.foregroundColor);
} else {
@ -3050,7 +3059,6 @@ class CanvasGraphics {
delete this.annotationCanvas.savedCtx;
delete this.annotationCanvas;
}
this.restore();
}
paintImageMaskXObject(img) {

View File

@ -0,0 +1,2 @@
https://github.com/mozilla/pdf.js/files/7291567/Stamp_Problem.pdf

View File

@ -6545,5 +6545,13 @@
"link": true,
"type": "eq",
"annotations": true
},
{ "id": "issue14105",
"file": "pdfs/issue14105.pdf",
"md5": "554174cd461180cbe46c137e846dd527",
"rounds": 1,
"link": true,
"type": "eq",
"annotations": true
}
]