@@ -219,8 +219,6 @@ class BaseViewer {
219
219
220
220
#annotationMode = AnnotationMode . ENABLE_FORMS ;
221
221
222
- #previousAnnotationMode = null ;
223
-
224
222
#enablePermissions = false ;
225
223
226
224
#previousContainerHeight = 0 ;
@@ -275,6 +273,9 @@ class BaseViewer {
275
273
this . textLayerMode = options . textLayerMode ?? TextLayerMode . ENABLE ;
276
274
this . #annotationMode =
277
275
options . annotationMode ?? AnnotationMode . ENABLE_FORMS ;
276
+ this . #annotationEditorMode = options . annotationEditorEnabled
277
+ ? AnnotationEditorType . NONE
278
+ : null ;
278
279
this . imageResourcesPath = options . imageResourcesPath || "" ;
279
280
this . enablePrintAutoRotate = options . enablePrintAutoRotate || false ;
280
281
this . renderer = options . renderer || RendererType . CANVAS ;
@@ -284,10 +285,6 @@ class BaseViewer {
284
285
this . #enablePermissions = options . enablePermissions || false ;
285
286
this . pageColors = options . pageColors || null ;
286
287
287
- if ( options . annotationEditorEnabled === true ) {
288
- this . #annotationEditorUIManager = new AnnotationEditorUIManager ( ) ;
289
- }
290
-
291
288
if ( typeof PDFJSDev === "undefined" || ! PDFJSDev . test ( "MOZCENTRAL" ) ) {
292
289
if (
293
290
this . pageColors &&
@@ -354,13 +351,6 @@ class BaseViewer {
354
351
return this . #annotationMode === AnnotationMode . ENABLE_FORMS ;
355
352
}
356
353
357
- /**
358
- * @type {boolean }
359
- */
360
- get enableAnnotationEditor ( ) {
361
- return ! ! this . #annotationEditorUIManager;
362
- }
363
-
364
354
/**
365
355
* @type {boolean }
366
356
*/
@@ -553,25 +543,35 @@ class BaseViewer {
553
543
554
544
/**
555
545
* Currently only *some* permissions are supported.
546
+ * @returns {Object }
556
547
*/
557
548
#initializePermissions( permissions ) {
549
+ const params = {
550
+ annotationEditorMode : this . #annotationEditorMode,
551
+ annotationMode : this . #annotationMode,
552
+ textLayerMode : this . textLayerMode ,
553
+ } ;
558
554
if ( ! permissions ) {
559
- return ;
555
+ return params ;
560
556
}
561
557
562
558
if ( ! permissions . includes ( PermissionFlag . COPY ) ) {
563
559
this . viewer . classList . add ( ENABLE_PERMISSIONS_CLASS ) ;
564
560
}
565
561
562
+ if ( ! permissions . includes ( PermissionFlag . MODIFY_CONTENTS ) ) {
563
+ params . annotationEditorMode = null ;
564
+ }
565
+
566
566
if (
567
567
! permissions . includes ( PermissionFlag . MODIFY_ANNOTATIONS ) &&
568
- ! permissions . includes ( PermissionFlag . FILL_INTERACTIVE_FORMS )
568
+ ! permissions . includes ( PermissionFlag . FILL_INTERACTIVE_FORMS ) &&
569
+ this . #annotationMode === AnnotationMode . ENABLE_FORMS
569
570
) {
570
- if ( this . #annotationMode === AnnotationMode . ENABLE_FORMS ) {
571
- this . #previousAnnotationMode = this . #annotationMode; // Allow resetting.
572
- this . #annotationMode = AnnotationMode . ENABLE ;
573
- }
571
+ params . annotationMode = AnnotationMode . ENABLE ;
574
572
}
573
+
574
+ return params ;
575
575
}
576
576
577
577
#onePageRenderedOrForceFetch( ) {
@@ -706,7 +706,23 @@ class BaseViewer {
706
706
}
707
707
this . _firstPageCapability . resolve ( firstPdfPage ) ;
708
708
this . _optionalContentConfigPromise = optionalContentConfigPromise ;
709
- this . #initializePermissions( permissions ) ;
709
+
710
+ const { annotationEditorMode, annotationMode, textLayerMode } =
711
+ this . #initializePermissions( permissions ) ;
712
+
713
+ if ( annotationEditorMode !== null ) {
714
+ if ( isPureXfa ) {
715
+ console . warn ( "Warning: XFA-editing is not implemented." ) ;
716
+ } else {
717
+ // Ensure that the Editor buttons, in the toolbar, are updated.
718
+ this . eventBus . dispatch ( "annotationeditormodechanged" , {
719
+ source : this ,
720
+ mode : annotationEditorMode ,
721
+ } ) ;
722
+
723
+ this . #annotationEditorUIManager = new AnnotationEditorUIManager ( ) ;
724
+ }
725
+ }
710
726
711
727
const viewerElement =
712
728
this . _scrollMode === ScrollMode . PAGE ? null : this . viewer ;
@@ -715,14 +731,13 @@ class BaseViewer {
715
731
scale : scale * PixelsPerInch . PDF_TO_CSS_UNITS ,
716
732
} ) ;
717
733
const textLayerFactory =
718
- this . textLayerMode !== TextLayerMode . DISABLE && ! isPureXfa
719
- ? this
720
- : null ;
734
+ textLayerMode !== TextLayerMode . DISABLE && ! isPureXfa ? this : null ;
721
735
const annotationLayerFactory =
722
- this . # annotationMode !== AnnotationMode . DISABLE ? this : null ;
736
+ annotationMode !== AnnotationMode . DISABLE ? this : null ;
723
737
const xfaLayerFactory = isPureXfa ? this : null ;
724
- const annotationEditorLayerFactory =
725
- this . #annotationEditorUIManager && ! isPureXfa ? this : null ;
738
+ const annotationEditorLayerFactory = this . #annotationEditorUIManager
739
+ ? this
740
+ : null ;
726
741
727
742
for ( let pageNum = 1 ; pageNum <= pagesCount ; ++ pageNum ) {
728
743
const pageView = new PDFPageView ( {
@@ -734,9 +749,9 @@ class BaseViewer {
734
749
optionalContentConfigPromise,
735
750
renderingQueue : this . renderingQueue ,
736
751
textLayerFactory,
737
- textLayerMode : this . textLayerMode ,
752
+ textLayerMode,
738
753
annotationLayerFactory,
739
- annotationMode : this . #annotationMode ,
754
+ annotationMode,
740
755
xfaLayerFactory,
741
756
annotationEditorLayerFactory,
742
757
textHighlighterFactory : this ,
@@ -868,6 +883,10 @@ class BaseViewer {
868
883
}
869
884
870
885
_resetView ( ) {
886
+ if ( this . #annotationEditorMode !== null ) {
887
+ this . #annotationEditorMode = AnnotationEditorType . NONE ;
888
+ }
889
+ this . #annotationEditorUIManager = null ;
871
890
this . _pages = [ ] ;
872
891
this . _currentPageNumber = 1 ;
873
892
this . _currentScale = UNKNOWN_SCALE ;
@@ -913,11 +932,6 @@ class BaseViewer {
913
932
this . viewer . removeAttribute ( "lang" ) ;
914
933
// Reset all PDF document permissions.
915
934
this . viewer . classList . remove ( ENABLE_PERMISSIONS_CLASS ) ;
916
-
917
- if ( this . #previousAnnotationMode !== null ) {
918
- this . #annotationMode = this . #previousAnnotationMode;
919
- this . #previousAnnotationMode = null ;
920
- }
921
935
}
922
936
923
937
#ensurePageViewVisible( ) {
@@ -2125,6 +2139,9 @@ class BaseViewer {
2125
2139
}
2126
2140
}
2127
2141
2142
+ /**
2143
+ * @type {number | null }
2144
+ */
2128
2145
get annotationEditorMode ( ) {
2129
2146
return this . #annotationEditorMode;
2130
2147
}
@@ -2142,6 +2159,9 @@ class BaseViewer {
2142
2159
if ( ! isValidAnnotationEditorMode ( mode ) ) {
2143
2160
throw new Error ( `Invalid AnnotationEditor mode: ${ mode } ` ) ;
2144
2161
}
2162
+ if ( ! this . pdfDocument ) {
2163
+ return ;
2164
+ }
2145
2165
this . #annotationEditorMode = mode ;
2146
2166
this . eventBus . dispatch ( "annotationeditormodechanged" , {
2147
2167
source : this ,
0 commit comments