Skip to content

Implement resetting of created streams for annotations #12370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isString,
OPS,
stringToPDFString,
unreachable,
Util,
warn,
} from "../shared/util.js";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -554,7 +560,7 @@ class Annotation {
})
.then(() => {
opList.addOp(OPS.endAnnotation, []);
appearance.reset();
this.reset();
return opList;
});
});
Expand All @@ -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();
}
}
}

/**
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,4 @@
!tiling-pattern-box.pdf
!tiling-pattern-large-steps.pdf
!issue11555.pdf
!issue12337.pdf
Binary file added test/pdfs/issue12337.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4702,5 +4702,12 @@
"md5": "f84ce8b7414f6a18e75a6ce69c902501",
"rounds": 1,
"type": "eq"
},
{ "id": "issue12337",
"file": "pdfs/issue12337.pdf",
"md5": "9165772d5b860bcbcc2478f32e311eb0",
"rounds": 2,
"lastPage": 1,
"type": "fbf"
}
]