Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Editor] Avoid to have a stamp editor resizing itself #18716

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/display/editor/stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 49 additions & 2 deletions test/integration/stamp_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
waitForTimeout,
waitForUnselectedEditor,
} from "./test_utils.mjs";
import { fileURLToPath } from "url";
Expand Down Expand Up @@ -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);
})
Expand Down Expand Up @@ -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);
calixteman marked this conversation as resolved.
Show resolved Hide resolved

const dims = await getDims();
expect(dims).withContext(`In ${browserName}`).toEqual(initialDims);
}
})
);
});
});
});