@@ -723,6 +723,38 @@ class Annotation {
723
723
return ! ! ( flags & flag ) ;
724
724
}
725
725
726
+ _buildFlags ( noView , noPrint ) {
727
+ let { flags } = this ;
728
+ if ( noView === undefined ) {
729
+ if ( noPrint === undefined ) {
730
+ return undefined ;
731
+ }
732
+ if ( noPrint ) {
733
+ return flags & ~ AnnotationFlag . PRINT ;
734
+ }
735
+ return ( flags & ~ AnnotationFlag . HIDDEN ) | AnnotationFlag . PRINT ;
736
+ }
737
+
738
+ if ( noView ) {
739
+ flags |= AnnotationFlag . PRINT ;
740
+ if ( noPrint ) {
741
+ // display === 1.
742
+ return ( flags & ~ AnnotationFlag . NOVIEW ) | AnnotationFlag . HIDDEN ;
743
+ }
744
+ // display === 3.
745
+ return ( flags & ~ AnnotationFlag . HIDDEN ) | AnnotationFlag . NOVIEW ;
746
+ }
747
+
748
+ flags &= ~ ( AnnotationFlag . HIDDEN | AnnotationFlag . NOVIEW ) ;
749
+ if ( noPrint ) {
750
+ // display === 2.
751
+ return flags & ~ AnnotationFlag . PRINT ;
752
+ }
753
+
754
+ // display === 0.
755
+ return flags | AnnotationFlag . PRINT ;
756
+ }
757
+
726
758
/**
727
759
* @private
728
760
*/
@@ -2073,10 +2105,15 @@ class WidgetAnnotation extends Annotation {
2073
2105
2074
2106
async save ( evaluator , task , annotationStorage ) {
2075
2107
const storageEntry = annotationStorage ?. get ( this . data . id ) ;
2108
+ const flags = this . _buildFlags ( storageEntry ?. noView , storageEntry ?. noPrint ) ;
2076
2109
let value = storageEntry ?. value ,
2077
2110
rotation = storageEntry ?. rotation ;
2078
2111
if ( value === this . data . fieldValue || value === undefined ) {
2079
- if ( ! this . _hasValueFromXFA && rotation === undefined ) {
2112
+ if (
2113
+ ! this . _hasValueFromXFA &&
2114
+ rotation === undefined &&
2115
+ flags === undefined
2116
+ ) {
2080
2117
return null ;
2081
2118
}
2082
2119
value ||= this . data . fieldValue ;
@@ -2089,7 +2126,8 @@ class WidgetAnnotation extends Annotation {
2089
2126
Array . isArray ( value ) &&
2090
2127
Array . isArray ( this . data . fieldValue ) &&
2091
2128
value . length === this . data . fieldValue . length &&
2092
- value . every ( ( x , i ) => x === this . data . fieldValue [ i ] )
2129
+ value . every ( ( x , i ) => x === this . data . fieldValue [ i ] ) &&
2130
+ flags === undefined
2093
2131
) {
2094
2132
return null ;
2095
2133
}
@@ -2106,7 +2144,7 @@ class WidgetAnnotation extends Annotation {
2106
2144
RenderingIntentFlag . SAVE ,
2107
2145
annotationStorage
2108
2146
) ;
2109
- if ( appearance === null ) {
2147
+ if ( appearance === null && flags === undefined ) {
2110
2148
// Appearance didn't change.
2111
2149
return null ;
2112
2150
}
@@ -2134,6 +2172,15 @@ class WidgetAnnotation extends Annotation {
2134
2172
dict . set ( key , originalDict . getRaw ( key ) ) ;
2135
2173
}
2136
2174
}
2175
+ if ( flags !== undefined ) {
2176
+ dict . set ( "F" , flags ) ;
2177
+ if ( appearance === null && ! needAppearances ) {
2178
+ const ap = originalDict . getRaw ( "AP" ) ;
2179
+ if ( ap ) {
2180
+ dict . set ( "AP" , ap ) ;
2181
+ }
2182
+ }
2183
+ }
2137
2184
2138
2185
const xfa = {
2139
2186
path : this . data . fieldName ,
@@ -3019,10 +3066,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
3019
3066
return null ;
3020
3067
}
3021
3068
const storageEntry = annotationStorage . get ( this . data . id ) ;
3069
+ const flags = this . _buildFlags ( storageEntry ?. noView , storageEntry ?. noPrint ) ;
3022
3070
let rotation = storageEntry ?. rotation ,
3023
3071
value = storageEntry ?. value ;
3024
3072
3025
- if ( rotation === undefined ) {
3073
+ if ( rotation === undefined && flags === undefined ) {
3026
3074
if ( value === undefined ) {
3027
3075
return null ;
3028
3076
}
@@ -3033,10 +3081,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
3033
3081
}
3034
3082
}
3035
3083
3036
- const dict = evaluator . xref . fetchIfRef ( this . ref ) ;
3084
+ let dict = evaluator . xref . fetchIfRef ( this . ref ) ;
3037
3085
if ( ! ( dict instanceof Dict ) ) {
3038
3086
return null ;
3039
3087
}
3088
+ dict = dict . clone ( ) ;
3040
3089
3041
3090
if ( rotation === undefined ) {
3042
3091
rotation = this . rotation ;
@@ -3054,6 +3103,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
3054
3103
dict . set ( "V" , name ) ;
3055
3104
dict . set ( "AS" , name ) ;
3056
3105
dict . set ( "M" , `D:${ getModificationDate ( ) } ` ) ;
3106
+ if ( flags !== undefined ) {
3107
+ dict . set ( "F" , flags ) ;
3108
+ }
3057
3109
3058
3110
const maybeMK = this . _getMKDict ( rotation ) ;
3059
3111
if ( maybeMK ) {
@@ -3071,10 +3123,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
3071
3123
return null ;
3072
3124
}
3073
3125
const storageEntry = annotationStorage . get ( this . data . id ) ;
3126
+ const flags = this . _buildFlags ( storageEntry ?. noView , storageEntry ?. noPrint ) ;
3074
3127
let rotation = storageEntry ?. rotation ,
3075
3128
value = storageEntry ?. value ;
3076
3129
3077
- if ( rotation === undefined ) {
3130
+ if ( rotation === undefined && flags === undefined ) {
3078
3131
if ( value === undefined ) {
3079
3132
return null ;
3080
3133
}
@@ -3085,10 +3138,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
3085
3138
}
3086
3139
}
3087
3140
3088
- const dict = evaluator . xref . fetchIfRef ( this . ref ) ;
3141
+ let dict = evaluator . xref . fetchIfRef ( this . ref ) ;
3089
3142
if ( ! ( dict instanceof Dict ) ) {
3090
3143
return null ;
3091
3144
}
3145
+ dict = dict . clone ( ) ;
3092
3146
3093
3147
if ( value === undefined ) {
3094
3148
value = this . data . fieldValue === this . data . buttonValue ;
@@ -3121,6 +3175,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
3121
3175
3122
3176
dict . set ( "AS" , name ) ;
3123
3177
dict . set ( "M" , `D:${ getModificationDate ( ) } ` ) ;
3178
+ if ( flags !== undefined ) {
3179
+ dict . set ( "F" , flags ) ;
3180
+ }
3124
3181
3125
3182
const maybeMK = this . _getMKDict ( rotation ) ;
3126
3183
if ( maybeMK ) {
0 commit comments