Skip to content

Commit 3ecd984

Browse files
committed
Implement resetting of created streams for annotations
1 parent 741ce4f commit 3ecd984

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

src/core/annotation.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
isString,
2727
OPS,
2828
stringToPDFString,
29+
unreachable,
2930
Util,
3031
warn,
3132
} from "../shared/util.js";
@@ -250,6 +251,11 @@ class Annotation {
250251
this.setBorderStyle(dict);
251252
this.setAppearance(dict);
252253

254+
this._streams = [];
255+
if (this.appearance) {
256+
this._streams.push(this.appearance);
257+
}
258+
253259
// Expose public properties using a data object.
254260
this.data = {
255261
annotationFlags: this.flags,
@@ -554,7 +560,7 @@ class Annotation {
554560
})
555561
.then(() => {
556562
opList.addOp(OPS.endAnnotation, []);
557-
appearance.reset();
563+
this.reset();
558564
return opList;
559565
});
560566
});
@@ -563,6 +569,30 @@ class Annotation {
563569
async save(evaluator, task, annotationStorage) {
564570
return null;
565571
}
572+
573+
/**
574+
* Reset the annotation.
575+
*
576+
* This involves resetting the various streams that are either cached on the
577+
* annotation instance or created during its construction.
578+
*
579+
* @public
580+
* @memberof Annotation
581+
*/
582+
reset() {
583+
if (
584+
(typeof PDFJSDev === "undefined" ||
585+
PDFJSDev.test("!PRODUCTION || TESTING")) &&
586+
this.appearance &&
587+
!this._streams.includes(this.appearance)
588+
) {
589+
unreachable("The appearance stream should always be reset.");
590+
}
591+
592+
for (const stream of this._streams) {
593+
stream.reset();
594+
}
595+
}
566596
}
567597

568598
/**
@@ -857,6 +887,10 @@ class MarkupAnnotation extends Annotation {
857887

858888
this.appearance = new StringStream("/GS0 gs /Fm0 Do");
859889
this.appearance.dict = appearanceDict;
890+
891+
// This method is only called if there is no appearance for the annotation,
892+
// so `this.appearance` is not pushed yet in the `Annotation` constructor.
893+
this._streams.push(this.appearance, appearanceStream);
860894
}
861895
}
862896

test/pdfs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,4 @@
395395
!tiling-pattern-box.pdf
396396
!tiling-pattern-large-steps.pdf
397397
!issue11555.pdf
398+
!issue12337.pdf

test/pdfs/issue12337.pdf

993 KB
Binary file not shown.

test/test_manifest.json

+7
Original file line numberDiff line numberDiff line change
@@ -4702,5 +4702,12 @@
47024702
"md5": "f84ce8b7414f6a18e75a6ce69c902501",
47034703
"rounds": 1,
47044704
"type": "eq"
4705+
},
4706+
{ "id": "issue12337",
4707+
"file": "pdfs/issue12337.pdf",
4708+
"md5": "9165772d5b860bcbcc2478f32e311eb0",
4709+
"rounds": 2,
4710+
"lastPage": 1,
4711+
"type": "fbf"
47054712
}
47064713
]

0 commit comments

Comments
 (0)