@@ -27,6 +27,7 @@ import {
27
27
getModificationDate ,
28
28
IDENTITY_MATRIX ,
29
29
info ,
30
+ isArrayEqual ,
30
31
LINE_DESCENT_FACTOR ,
31
32
LINE_FACTOR ,
32
33
OPS ,
@@ -723,6 +724,38 @@ class Annotation {
723
724
return ! ! ( flags & flag ) ;
724
725
}
725
726
727
+ _buildFlags ( noView , noPrint ) {
728
+ let { flags } = this ;
729
+ if ( noView === undefined ) {
730
+ if ( noPrint === undefined ) {
731
+ return undefined ;
732
+ }
733
+ if ( noPrint ) {
734
+ return flags & ~ AnnotationFlag . PRINT ;
735
+ }
736
+ return ( flags & ~ AnnotationFlag . HIDDEN ) | AnnotationFlag . PRINT ;
737
+ }
738
+
739
+ if ( noView ) {
740
+ flags |= AnnotationFlag . PRINT ;
741
+ if ( noPrint ) {
742
+ // display === 1.
743
+ return ( flags & ~ AnnotationFlag . NOVIEW ) | AnnotationFlag . HIDDEN ;
744
+ }
745
+ // display === 3.
746
+ return ( flags & ~ AnnotationFlag . HIDDEN ) | AnnotationFlag . NOVIEW ;
747
+ }
748
+
749
+ flags &= ~ ( AnnotationFlag . HIDDEN | AnnotationFlag . NOVIEW ) ;
750
+ if ( noPrint ) {
751
+ // display === 2.
752
+ return flags & ~ AnnotationFlag . PRINT ;
753
+ }
754
+
755
+ // display === 0.
756
+ return flags | AnnotationFlag . PRINT ;
757
+ }
758
+
726
759
/**
727
760
* @private
728
761
*/
@@ -2073,10 +2106,15 @@ class WidgetAnnotation extends Annotation {
2073
2106
2074
2107
async save ( evaluator , task , annotationStorage ) {
2075
2108
const storageEntry = annotationStorage ?. get ( this . data . id ) ;
2109
+ const flags = this . _buildFlags ( storageEntry ?. noView , storageEntry ?. noPrint ) ;
2076
2110
let value = storageEntry ?. value ,
2077
2111
rotation = storageEntry ?. rotation ;
2078
2112
if ( value === this . data . fieldValue || value === undefined ) {
2079
- if ( ! this . _hasValueFromXFA && rotation === undefined ) {
2113
+ if (
2114
+ ! this . _hasValueFromXFA &&
2115
+ rotation === undefined &&
2116
+ flags === undefined
2117
+ ) {
2080
2118
return null ;
2081
2119
}
2082
2120
value ||= this . data . fieldValue ;
@@ -2088,8 +2126,8 @@ class WidgetAnnotation extends Annotation {
2088
2126
! this . _hasValueFromXFA &&
2089
2127
Array . isArray ( value ) &&
2090
2128
Array . isArray ( this . data . fieldValue ) &&
2091
- value . length === this . data . fieldValue . length &&
2092
- value . every ( ( x , i ) => x === this . data . fieldValue [ i ] )
2129
+ isArrayEqual ( value , this . data . fieldValue ) &&
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