From 3fc6b1321f9d01db9486c6a32fff5632af3e3046 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 17 Feb 2025 20:20:26 +0100 Subject: [PATCH] [Editor] Scale the signature editor when it's too large (bug 1948741) --- src/display/editor/signature.js | 5 +++ test/integration/signature_editor_spec.mjs | 43 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/display/editor/signature.js b/src/display/editor/signature.js index bdcbf4523..8aceb8b3d 100644 --- a/src/display/editor/signature.js +++ b/src/display/editor/signature.js @@ -248,6 +248,11 @@ class SignatureEditor extends DrawingEditor { newHeight = newHeight >= 1 ? 0.5 : newHeight; this.width *= newHeight / this.height; + if (this.width >= 1) { + newHeight *= 0.9 / this.width; + this.width = 0.9; + } + this.height = newHeight; this.setDims(parentWidth * this.width, parentHeight * this.height); this.x = savedX; diff --git a/test/integration/signature_editor_spec.mjs b/test/integration/signature_editor_spec.mjs index 60ac12c80..8586572a8 100644 --- a/test/integration/signature_editor_spec.mjs +++ b/test/integration/signature_editor_spec.mjs @@ -16,6 +16,7 @@ import { closePages, getEditorSelector, + getRect, loadAndWait, switchToEditor, waitForTimeout, @@ -207,4 +208,46 @@ describe("Signature Editor", () => { ); }); }); + + describe("Bug 1948741", () => { + let pages; + + beforeEach(async () => { + pages = await loadAndWait("empty.pdf", ".annotationEditorLayer"); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("must check that the editor isn't too large", async () => { + await Promise.all( + pages.map(async ([_, page]) => { + await switchToSignature(page); + await page.click("#editorSignatureAddSignature"); + + await page.waitForSelector("#addSignatureDialog", { + visible: true, + }); + await page.type( + "#addSignatureTypeInput", + "[18:50:03] asset pdf.scripting.mjs 105 KiB [emitted] [javascript module] (name: main)" + ); + await page.waitForSelector(`${addButtonSelector}:not(:disabled)`); + await page.click("#addSignatureAddButton"); + + const editorSelector = getEditorSelector(0); + await page.waitForSelector(editorSelector, { visible: true }); + await page.waitForSelector( + `.canvasWrapper > svg use[href="#path_p1_0"]`, + { visible: true } + ); + + const { width } = await getRect(page, editorSelector); + const { width: pageWidth } = await getRect(page, ".page"); + expect(width).toBeLessThanOrEqual(pageWidth); + }) + ); + }); + }); });