diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index d33a15202aebf..69dee6f15cfb7 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -40,6 +40,8 @@ import { noContextMenu } from "../display_utils.js"; * Base class for editors. */ class AnnotationEditor { + #accessibilityData = null; + #allResizerDivs = null; #altText = null; @@ -993,6 +995,10 @@ class AnnotationEditor { } AltText.initialize(AnnotationEditor._l10nPromise); this.#altText = new AltText(this); + if (this.#accessibilityData) { + this.#altText.data = this.#accessibilityData; + this.#accessibilityData = null; + } await this.addEditToolbar(); } @@ -1330,6 +1336,7 @@ class AnnotationEditor { uiManager, }); editor.rotation = data.rotation; + editor.#accessibilityData = data.accessibilityData; const [pageWidth, pageHeight] = editor.pageDimensions; const [x, y, width, height] = editor.getRectInCurrentCoords( diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index ba3d53f062d19..fa07f33a25c70 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -14,12 +14,14 @@ */ import { + applyFunctionToEditor, awaitPromise, closePages, getEditorDimensions, getEditorSelector, getFirstSerialized, getRect, + getSerialized, kbBigMoveDown, kbBigMoveRight, kbCopy, @@ -798,4 +800,53 @@ describe("Stamp Editor", () => { ); }); }); + + describe("Copy and paste a stamp with an alt text", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("empty.pdf", ".annotationEditorLayer"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that the pasted image has an alt text", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await switchToStamp(page); + + await copyImage(page, "../images/firefox_logo.png", 0); + await page.waitForSelector(getEditorSelector(0)); + await waitForSerialized(page, 1); + await applyFunctionToEditor( + page, + "pdfjs_internal_editor_0", + editor => { + editor.altTextData = { + altText: "Hello World", + decorative: false, + }; + } + ); + await page.waitForSelector(`${getEditorSelector(0)} .altText.done`); + + await kbCopy(page); + await kbPaste(page); + await page.waitForSelector(`${getEditorSelector(1)} .altText.done`); + await waitForSerialized(page, 2); + + const serialized = await getSerialized( + page, + x => x.accessibilityData?.alt + ); + + expect(serialized) + .withContext(`In ${browserName}`) + .toEqual(["Hello World", "Hello World"]); + }) + ); + }); + }); }); diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index 8b958e8d2ac61..85c715acdb20f 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -233,6 +233,21 @@ async function waitForSerialized(page, nEntries) { ); } +async function applyFunctionToEditor(page, editorId, func) { + return page.evaluate( + (id, f) => { + const editor = + window.PDFViewerApplication.pdfDocument.annotationStorage.getRawValue( + id + ); + // eslint-disable-next-line no-eval + eval(`(${f})`)(editor); + }, + editorId, + func.toString() + ); +} + async function waitForSelectedEditor(page, selector) { return page.waitForSelector(`${selector}.selectedEditor`); } @@ -615,6 +630,7 @@ async function switchToEditor(name, page, disable = false) { } export { + applyFunctionToEditor, awaitPromise, clearInput, closePages,