Implement resetting of created streams for annotations

This commit is contained in:
Tim van der Meij 2020-09-12 16:52:38 +02:00
parent 741ce4f7fc
commit 3ecd984758
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
4 changed files with 43 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -395,3 +395,4 @@
!tiling-pattern-box.pdf
!tiling-pattern-large-steps.pdf
!issue11555.pdf
!issue12337.pdf

BIN
test/pdfs/issue12337.pdf Normal file

Binary file not shown.

View File

@ -4702,5 +4702,12 @@
"md5": "f84ce8b7414f6a18e75a6ce69c902501",
"rounds": 1,
"type": "eq"
},
{ "id": "issue12337",
"file": "pdfs/issue12337.pdf",
"md5": "9165772d5b860bcbcc2478f32e311eb0",
"rounds": 2,
"lastPage": 1,
"type": "fbf"
}
]