From 3f23bcbeccce8a67bb2feafb6f34e4167099c6aa Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 9 Sep 2024 15:26:33 +0200 Subject: [PATCH] [Editor] Avoid to have a stamp editor resizing itself Fixes #18715. --- src/display/editor/editor.js | 6 +-- src/display/editor/stamp.js | 1 - test/integration/stamp_editor_spec.mjs | 51 +++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index a3006975df87f..e6cd333f96107 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -659,11 +659,7 @@ class AnnotationEditor { parentScale, pageDimensions: [pageWidth, pageHeight], } = this; - const scaledWidth = pageWidth * parentScale; - const scaledHeight = pageHeight * parentScale; - return FeatureTest.isCSSRoundSupported - ? [Math.round(scaledWidth), Math.round(scaledHeight)] - : [scaledWidth, scaledHeight]; + return [pageWidth * parentScale, pageHeight * parentScale]; } /** diff --git a/src/display/editor/stamp.js b/src/display/editor/stamp.js index c0ce61f28ade8..4b912c0a95447 100644 --- a/src/display/editor/stamp.js +++ b/src/display/editor/stamp.js @@ -553,7 +553,6 @@ class StampEditor extends AnnotationEditor { const [parentWidth, parentHeight] = this.parentDimensions; this.width = width / parentWidth; this.height = height / parentHeight; - this.setDims(width, height); if (this._initialOptions?.isCentered) { this.center(); } else { diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index c1b90b4dc08e8..9fc524f68266d 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -41,6 +41,7 @@ import { waitForSelectedEditor, waitForSerialized, waitForStorageEntries, + waitForTimeout, waitForUnselectedEditor, } from "./test_utils.mjs"; import { fileURLToPath } from "url"; @@ -150,8 +151,8 @@ describe("Stamp Editor", () => { const ratio = await page.evaluate( () => window.pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS ); - expect(bitmap.width).toEqual(Math.round(242 * ratio)); - expect(bitmap.height).toEqual(Math.round(80 * ratio)); + expect(Math.abs(bitmap.width - 242 * ratio) < 1).toBeTrue(); + expect(Math.abs(bitmap.height - 80 * ratio) < 1).toBeTrue(); await clearAll(page); }) @@ -1097,4 +1098,50 @@ describe("Stamp Editor", () => { } }); }); + + describe("No auto-resize", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 67); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that a stamp editor isn't resizing itself", async () => { + // Run sequentially to avoid clipboard issues. + const editorSelector = getEditorSelector(0); + + for (const [, page] of pages) { + await switchToStamp(page); + + await copyImage(page, "../images/firefox_logo.png", 0); + await page.waitForSelector(editorSelector); + await waitForSerialized(page, 1); + } + + await Promise.all( + pages.map(async ([browserName, page]) => { + const getDims = () => + page.evaluate(sel => { + const bbox = document.querySelector(sel).getBoundingClientRect(); + return `${bbox.width}::${bbox.height}`; + }, editorSelector); + const initialDims = await getDims(); + for (let i = 0; i < 50; i++) { + // We want to make sure that the editor doesn't resize itself, so we + // check every 10ms that the dimensions are the same. + + // eslint-disable-next-line no-restricted-syntax + await waitForTimeout(10); + + const dims = await getDims(); + expect(dims).withContext(`In ${browserName}`).toEqual(initialDims); + } + }) + ); + }); + }); });