1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #18296 from calixteman/bug1903589

[Editor] Correctly set the accessibility data when copying & pasting a stamp with an alt text (bug 1903589)
This commit is contained in:
calixteman 2024-06-20 15:35:22 +02:00 committed by GitHub
commit d09aed87d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 74 additions and 0 deletions

View file

@ -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(

View file

@ -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"]);
})
);
});
});
});

View file

@ -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,