diff --git a/src/core/annotation.js b/src/core/annotation.js index b43ae5a7b..50b26dac8 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -26,6 +26,7 @@ import { isString, OPS, stringToPDFString, + unreachable, Util, warn, } from "../shared/util.js"; @@ -250,6 +251,11 @@ class Annotation { this.setBorderStyle(dict); this.setAppearance(dict); + this._streams = []; + if (this.appearance) { + this._streams.push(this.appearance); + } + // Expose public properties using a data object. this.data = { annotationFlags: this.flags, @@ -554,7 +560,7 @@ class Annotation { }) .then(() => { opList.addOp(OPS.endAnnotation, []); - appearance.reset(); + this.reset(); return opList; }); }); @@ -563,6 +569,30 @@ class Annotation { async save(evaluator, task, annotationStorage) { return null; } + + /** + * Reset the annotation. + * + * This involves resetting the various streams that are either cached on the + * annotation instance or created during its construction. + * + * @public + * @memberof Annotation + */ + reset() { + if ( + (typeof PDFJSDev === "undefined" || + PDFJSDev.test("!PRODUCTION || TESTING")) && + this.appearance && + !this._streams.includes(this.appearance) + ) { + unreachable("The appearance stream should always be reset."); + } + + for (const stream of this._streams) { + stream.reset(); + } + } } /** @@ -857,6 +887,10 @@ class MarkupAnnotation extends Annotation { this.appearance = new StringStream("/GS0 gs /Fm0 Do"); this.appearance.dict = appearanceDict; + + // This method is only called if there is no appearance for the annotation, + // so `this.appearance` is not pushed yet in the `Annotation` constructor. + this._streams.push(this.appearance, appearanceStream); } } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 2b3b76d08..f3f92aae5 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -395,3 +395,4 @@ !tiling-pattern-box.pdf !tiling-pattern-large-steps.pdf !issue11555.pdf +!issue12337.pdf diff --git a/test/pdfs/issue12337.pdf b/test/pdfs/issue12337.pdf new file mode 100644 index 000000000..531bd9049 Binary files /dev/null and b/test/pdfs/issue12337.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 68124264e..32c8c5160 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -4702,5 +4702,12 @@ "md5": "f84ce8b7414f6a18e75a6ce69c902501", "rounds": 1, "type": "eq" + }, + { "id": "issue12337", + "file": "pdfs/issue12337.pdf", + "md5": "9165772d5b860bcbcc2478f32e311eb0", + "rounds": 2, + "lastPage": 1, + "type": "fbf" } ]