@@ -26,6 +26,7 @@ import {
26
26
isString ,
27
27
OPS ,
28
28
stringToPDFString ,
29
+ unreachable ,
29
30
Util ,
30
31
warn ,
31
32
} from "../shared/util.js" ;
@@ -250,6 +251,11 @@ class Annotation {
250
251
this . setBorderStyle ( dict ) ;
251
252
this . setAppearance ( dict ) ;
252
253
254
+ this . _streams = [ ] ;
255
+ if ( this . appearance ) {
256
+ this . _streams . push ( this . appearance ) ;
257
+ }
258
+
253
259
// Expose public properties using a data object.
254
260
this . data = {
255
261
annotationFlags : this . flags ,
@@ -554,7 +560,7 @@ class Annotation {
554
560
} )
555
561
. then ( ( ) => {
556
562
opList . addOp ( OPS . endAnnotation , [ ] ) ;
557
- appearance . reset ( ) ;
563
+ this . reset ( ) ;
558
564
return opList ;
559
565
} ) ;
560
566
} ) ;
@@ -563,6 +569,30 @@ class Annotation {
563
569
async save ( evaluator , task , annotationStorage ) {
564
570
return null ;
565
571
}
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
+ }
566
596
}
567
597
568
598
/**
@@ -857,6 +887,10 @@ class MarkupAnnotation extends Annotation {
857
887
858
888
this . appearance = new StringStream ( "/GS0 gs /Fm0 Do" ) ;
859
889
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 ) ;
860
894
}
861
895
}
862
896
0 commit comments