Compare commits

...

6 Commits

Author SHA1 Message Date
Marco Castelluccio
2ed959d75a
Merge pull request #19897 from Snuffleupagus/ci-Node-24
Run CI tests in Node.js version 24
2025-05-14 00:09:06 +02:00
calixteman
a4b5b7c4bb
Merge pull request #19925 from calixteman/bug1962819
[Editor] Keep aspect ratio when rescaling an image before being processed for a signature (bug 1962819)
2025-05-13 20:07:11 +02:00
Calixte Denizet
d6605674dd [Editor] Keep aspect ratio when rescaling an image before being processed for a signature (bug 1962819) 2025-05-13 19:12:17 +02:00
calixteman
2bb8099831
Merge pull request #19924 from calixteman/update_qcms
Update qcms build
2025-05-13 17:49:54 +02:00
Calixte Denizet
09f0af5b83 Update qcms build
It's a follow-up of https://github.com/mozilla/pdf.js.qcms/pull/1.
2025-05-13 16:44:18 +02:00
Jonas Jenwald
384a09113c Run CI tests in Node.js version 24
Node.js version 24 was just released, see https://github.com/nodejs/release#release-schedule, hence we should run tests in that version in order to help catch any possible issues as soon as possible.
Also, since version 23 will reach EOL (end-of-life) in less than a month we stop running tests in that version.
2025-05-06 18:43:02 +02:00
6 changed files with 92 additions and 12 deletions

View File

@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [20, 22, 23]
node-version: [20, 22, 24]
steps:
- name: Checkout repository

View File

@ -235,9 +235,7 @@ async function __wbg_init(module_or_path) {
}
}
if (typeof module_or_path === 'undefined') {
module_or_path = new URL('qcms_bg.wasm', import.meta.url);
}
const imports = __wbg_get_imports();
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {

Binary file not shown.

View File

@ -436,14 +436,8 @@ class SignatureExtractor {
const isteps = Math.floor(steps);
steps = steps === isteps ? isteps - 1 : isteps;
for (let i = 0; i < steps; i++) {
newWidth = prevWidth;
newHeight = prevHeight;
if (newWidth > maxDim) {
newWidth = Math.ceil(newWidth / 2);
}
if (newHeight > maxDim) {
newHeight = Math.ceil(newHeight / 2);
}
newWidth = Math.ceil(prevWidth / 2);
newHeight = Math.ceil(prevHeight / 2);
const offscreen = new OffscreenCanvas(newWidth, newHeight);
const ctx = offscreen.getContext("2d");

BIN
test/images/samplesignature.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -27,7 +27,9 @@ import {
} from "./test_utils.mjs";
import { fileURLToPath } from "url";
import fs from "fs";
import path from "path";
import { PNG } from "pngjs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@ -583,4 +585,90 @@ describe("Signature Editor", () => {
);
});
});
describe("Check the aspect ratio (bug 1962819)", () => {
let pages, contentWidth, contentHeight;
function getContentAspectRatio(png) {
const { width, height } = png;
const buffer = new Uint32Array(png.data.buffer);
let x0 = width;
let y0 = height;
let x1 = 0;
let y1 = 0;
for (let i = 0; i < height; i++) {
for (let j = 0; j < width; j++) {
if (buffer[width * i + j] !== 0) {
x0 = Math.min(x0, j);
y0 = Math.min(y0, i);
x1 = Math.max(x1, j);
y1 = Math.max(y1, i);
}
}
}
contentWidth = x1 - x0;
contentHeight = y1 - y0;
}
beforeAll(() => {
const data = fs.readFileSync(
path.join(__dirname, "../images/samplesignature.png")
);
const png = PNG.sync.read(data);
getContentAspectRatio(png);
});
beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
});
afterEach(async () => {
await closePages(pages);
});
it("must check that the signature has the correct aspect ratio", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToSignature(page);
await page.click("#editorSignatureAddSignature");
await page.waitForSelector("#addSignatureDialog", {
visible: true,
});
await page.click("#addSignatureImageButton");
await page.waitForSelector("#addSignatureImagePlaceholder", {
visible: true,
});
await page.waitForSelector(`${addButtonSelector}:disabled`);
const input = await page.$("#addSignatureFilePicker");
await input.uploadFile(
`${path.join(__dirname, "../images/samplesignature.png")}`
);
await page.waitForSelector(`#addSignatureImage > path:not([d=""])`);
// The save button should be enabled now.
await page.waitForSelector(
"#addSignatureSaveContainer > input:not(:disabled)"
);
await page.click("#addSignatureAddButton");
await page.waitForSelector("#addSignatureDialog", {
visible: false,
});
const { width, height } = await getRect(
page,
".canvasWrapper > svg use[href='#path_p1_0']"
);
expect(Math.abs(contentWidth / width - contentHeight / height))
.withContext(
`In ${browserName} (${contentWidth}x${contentHeight} vs ${width}x${height})`
)
.toBeLessThan(0.25);
})
);
});
});
});