Compare commits
5 Commits
f93d34c38e
...
4e2443396c
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e2443396c | |||
| 2e2980f04f | |||
| 3efe0de52f | |||
| efbd133f0e | |||
| 4993e8a306 |
@ -193,15 +193,17 @@ async function renderPdfToImage(pdfBytes: Uint8Array) {
|
|||||||
const pdf = await loadingTask.promise;
|
const pdf = await loadingTask.promise;
|
||||||
|
|
||||||
// Increase for higher resolution
|
// Increase for higher resolution
|
||||||
const scale = 2;
|
const scale = 4;
|
||||||
|
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
Array.from({ length: pdf.numPages }, async (_, index) => {
|
Array.from({ length: pdf.numPages }, async (_, index) => {
|
||||||
const page = await pdf.getPage(index + 1);
|
const page = await pdf.getPage(index + 1);
|
||||||
|
|
||||||
const viewport = page.getViewport({ scale });
|
const viewport = page.getViewport({ scale });
|
||||||
|
|
||||||
const virtualCanvas = new Canvas(viewport.width, viewport.height);
|
const virtualCanvas = new Canvas(viewport.width, viewport.height);
|
||||||
const context = virtualCanvas.getContext('2d');
|
const context = virtualCanvas.getContext('2d');
|
||||||
|
context.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
// @ts-expect-error skia-canvas context satisfies runtime requirements for pdfjs
|
// @ts-expect-error skia-canvas context satisfies runtime requirements for pdfjs
|
||||||
await page.render({ canvasContext: context, viewport }).promise;
|
await page.render({ canvasContext: context, viewport }).promise;
|
||||||
@ -256,21 +258,25 @@ const compareSignedPdfWithImages = async ({
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
{
|
{
|
||||||
threshold: 0,
|
threshold: 0.25,
|
||||||
// includeAA: true, // This allows stricter testing.
|
// includeAA: true, // This allows stricter testing.
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
console.log(`${id}-${index}: ${comparison}`);
|
console.log(`${id}-${index}: ${comparison}`);
|
||||||
|
|
||||||
const filePath = path.join(testInfo.outputPath(), `diff-${id}-${index}.png`);
|
const diffFilePath = path.join(testInfo.outputPath(), `${id}-${index}-diff.png`);
|
||||||
|
const oldFilePath = path.join(testInfo.outputPath(), `${id}-${index}-old.png`);
|
||||||
|
const newFilePath = path.join(testInfo.outputPath(), `${id}-${index}-new.png`);
|
||||||
|
|
||||||
fs.writeFileSync(filePath, new Uint8Array(PNG.sync.write(diff)));
|
fs.writeFileSync(diffFilePath, new Uint8Array(PNG.sync.write(diff)));
|
||||||
|
fs.writeFileSync(oldFilePath, new Uint8Array(images[index]));
|
||||||
|
fs.writeFileSync(newFilePath, new Uint8Array(image));
|
||||||
|
|
||||||
if (isCertificate) {
|
if (isCertificate) {
|
||||||
// Expect the certificate to NOT be blank. Since the storedImage is blank.
|
// Expect the certificate to NOT be blank. Since the storedImage is blank.
|
||||||
expect(comparison).toBeGreaterThan(20000);
|
expect.soft(comparison).toBeGreaterThan(20000);
|
||||||
} else {
|
} else {
|
||||||
expect(comparison).toEqual(0);
|
expect.soft(comparison).toEqual(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 134 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 340 B After Width: | Height: | Size: 144 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 117 KiB |