diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json index 371da256f..4b8d68623 100644 --- a/extensions/chromium/preferences_schema.json +++ b/extensions/chromium/preferences_schema.json @@ -160,9 +160,9 @@ ], "default": 2 }, - "annotationEditorEnabled": { - "type": "boolean", - "default": false + "annotationEditorMode": { + "type": "integer", + "default": -1 }, "enablePermissions": { "type": "boolean", diff --git a/l10n/en-US/viewer.properties b/l10n/en-US/viewer.properties index 2b0c1bf82..99b884c2c 100644 --- a/l10n/en-US/viewer.properties +++ b/l10n/en-US/viewer.properties @@ -258,7 +258,7 @@ editor_free_text_label=FreeText Annotation editor_ink.title=Add Ink Annotation editor_ink_label=Ink Annotation -freetext_default_content=Enter some text… +freetext_default_content=Enter text… # Editor Parameters editor_free_text_font_color=Font Color diff --git a/src/shared/util.js b/src/shared/util.js index d82053890..2586bdc45 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -55,6 +55,7 @@ const AnnotationMode = { const AnnotationEditorPrefix = "pdfjs_internal_editor_"; const AnnotationEditorType = { + DISABLE: -1, NONE: 0, FREETEXT: 3, INK: 15, diff --git a/web/app.js b/web/app.js index cb5b4f7d9..5482ed7d6 100644 --- a/web/app.js +++ b/web/app.js @@ -34,9 +34,8 @@ import { SpreadMode, TextLayerMode, } from "./ui_utils.js"; -import { AppOptions, OptionKind } from "./app_options.js"; -import { AutomationEventBus, EventBus } from "./event_utils.js"; import { + AnnotationEditorType, build, createPromiseCapability, getDocument, @@ -54,6 +53,8 @@ import { UNSUPPORTED_FEATURES, version, } from "pdfjs-lib"; +import { AppOptions, OptionKind } from "./app_options.js"; +import { AutomationEventBus, EventBus } from "./event_utils.js"; import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js"; import { LinkTarget, PDFLinkService } from "./pdf_link_service.js"; import { AnnotationEditorParams } from "./annotation_editor_params.js"; @@ -510,7 +511,7 @@ const PDFViewerApplication = { const container = appConfig.mainContainer, viewer = appConfig.viewerContainer; - const annotationEditorEnabled = AppOptions.get("annotationEditorEnabled"); + const annotationEditorMode = AppOptions.get("annotationEditorMode"); const pageColors = { background: AppOptions.get("pageColorsBackground"), foreground: AppOptions.get("pageColorsForeground"), @@ -534,7 +535,7 @@ const PDFViewerApplication = { l10n: this.l10n, textLayerMode: AppOptions.get("textLayerMode"), annotationMode: AppOptions.get("annotationMode"), - annotationEditorEnabled, + annotationEditorMode, imageResourcesPath: AppOptions.get("imageResourcesPath"), enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"), useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"), @@ -570,7 +571,7 @@ const PDFViewerApplication = { this.findBar = new PDFFindBar(appConfig.findBar, eventBus, this.l10n); } - if (annotationEditorEnabled) { + if (annotationEditorMode !== AnnotationEditorType.DISABLE) { this.annotationEditorParams = new AnnotationEditorParams( appConfig.annotationEditorParams, eventBus diff --git a/web/app_options.js b/web/app_options.js index 220975859..3178b0434 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -59,11 +59,12 @@ const OptionKind = { * primitive types and cannot rely on any imported types. */ const defaultOptions = { - annotationEditorEnabled: { + annotationEditorMode: { /** @type {boolean} */ value: - typeof PDFJSDev === "undefined" || - PDFJSDev.test("!PRODUCTION || TESTING"), + typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING") + ? 0 + : -1, kind: OptionKind.VIEWER + OptionKind.PREFERENCE, }, annotationMode: { diff --git a/web/base_viewer.js b/web/base_viewer.js index d49db8093..1e5128ddb 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -86,7 +86,10 @@ const PagesCountLimit = { }; function isValidAnnotationEditorMode(mode) { - return Object.values(AnnotationEditorType).includes(mode); + return ( + Object.values(AnnotationEditorType).includes(mode) && + mode !== AnnotationEditorType.DISABLE + ); } /** @@ -113,8 +116,9 @@ function isValidAnnotationEditorMode(mode) { * being rendered. The constants from {@link AnnotationMode} should be used; * see also {@link RenderParameters} and {@link GetOperatorListParameters}. * The default value is `AnnotationMode.ENABLE_FORMS`. - * @property {boolean} [annotationEditorEnabled] - Enables the creation and - * editing of new Annotations. + * @property {boolean} [annotationEditorMode] - Enables the creation and editing + * of new Annotations. The constants from {@link AnnotationEditorType} should + * be used. The default value is `AnnotationEditorType.DISABLE`. * @property {string} [imageResourcesPath] - Path for image resources, mainly * mainly for annotation icons. Include trailing slash. * @property {boolean} [enablePrintAutoRotate] - Enables automatic rotation of @@ -213,7 +217,7 @@ class PDFPageViewBuffer { class BaseViewer { #buffer = null; - #annotationEditorMode = AnnotationEditorType.NONE; + #annotationEditorMode = AnnotationEditorType.DISABLE; #annotationEditorUIManager = null; @@ -273,9 +277,8 @@ class BaseViewer { this.textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE; this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS; - this.#annotationEditorMode = options.annotationEditorEnabled - ? AnnotationEditorType.NONE - : null; + this.#annotationEditorMode = + options.annotationEditorMode ?? AnnotationEditorType.DISABLE; this.imageResourcesPath = options.imageResourcesPath || ""; this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; this.renderer = options.renderer || RendererType.CANVAS; @@ -560,7 +563,7 @@ class BaseViewer { } if (!permissions.includes(PermissionFlag.MODIFY_CONTENTS)) { - params.annotationEditorMode = null; + params.annotationEditorMode = AnnotationEditorType.DISABLE; } if ( @@ -710,19 +713,26 @@ class BaseViewer { const { annotationEditorMode, annotationMode, textLayerMode } = this.#initializePermissions(permissions); - if (annotationEditorMode !== null) { + if (annotationEditorMode !== AnnotationEditorType.DISABLE) { + const mode = annotationEditorMode; + if (isPureXfa) { console.warn("Warning: XFA-editing is not implemented."); - } else { + } else if (isValidAnnotationEditorMode(mode)) { // Ensure that the Editor buttons, in the toolbar, are updated. this.eventBus.dispatch("annotationeditormodechanged", { source: this, - mode: annotationEditorMode, + mode, }); this.#annotationEditorUIManager = new AnnotationEditorUIManager( this.eventBus ); + if (mode !== AnnotationEditorType.NONE) { + this.#annotationEditorUIManager.updateMode(mode); + } + } else { + console.error(`Invalid AnnotationEditor mode: ${mode}`); } } @@ -885,9 +895,6 @@ class BaseViewer { } _resetView() { - if (this.#annotationEditorMode !== null) { - this.#annotationEditorMode = AnnotationEditorType.NONE; - } this.#annotationEditorUIManager = null; this._pages = []; this._currentPageNumber = 1; @@ -2142,7 +2149,7 @@ class BaseViewer { } /** - * @type {number | null} + * @type {number} */ get annotationEditorMode() { return this.#annotationEditorMode; diff --git a/web/l10n_utils.js b/web/l10n_utils.js index 2dbcd3db7..bc6d7a3ee 100644 --- a/web/l10n_utils.js +++ b/web/l10n_utils.js @@ -82,7 +82,7 @@ const DEFAULT_L10N_STRINGS = { web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.", - freetext_default_content: "Enter some text…", + freetext_default_content: "Enter text…", }; function getL10nFallback(key, args) { diff --git a/web/viewer.html b/web/viewer.html index e3fa5fc5c..b0e08921b 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -151,11 +151,11 @@ See https://github.com/adobe-type-tools/cmap-resources
- +
- +
@@ -164,11 +164,11 @@ See https://github.com/adobe-type-tools/cmap-resources
- +
- +