mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #12370 from timvandermeij/annotation-reset
Implement resetting of created streams for annotations
This commit is contained in:
commit
9d7b1d89ca
4 changed files with 43 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue