diff --git a/src/core/annotation.js b/src/core/annotation.js index a3d05f278..8fe95d88f 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -4920,7 +4920,7 @@ class StampAnnotation extends MarkupAnnotation { mustBeViewedWhenEditing(isEditing, modifiedIds = null) { if (isEditing) { if (!this.data.isEditable) { - return false; + return true; } // When we're editing, we want to ensure that the stamp annotation is // drawn on a canvas in order to use it in the annotation editor layer. diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index 29c24a487..84b886b70 100644 --- a/test/integration/freetext_editor_spec.mjs +++ b/test/integration/freetext_editor_spec.mjs @@ -28,7 +28,7 @@ import { getRect, getSerialized, hover, - isCanvasWhite, + isCanvasMonochrome, kbBigMoveDown, kbBigMoveLeft, kbBigMoveRight, @@ -837,7 +837,7 @@ describe("FreeText Editor", () => { await switchToFreeText(page); // The page has been re-rendered but with no freetext annotations. - let isWhite = await isCanvasWhite(page, 1); + let isWhite = await isCanvasMonochrome(page, 1, null, 0xffffffff); expect(isWhite).withContext(`In ${browserName}`).toBeTrue(); let editorIds = await getEditors(page, "freeText"); @@ -880,7 +880,7 @@ describe("FreeText Editor", () => { editorIds = await getEditors(page, "freeText"); expect(editorIds.length).withContext(`In ${browserName}`).toEqual(1); - isWhite = await isCanvasWhite(page, 1, editorRect); + isWhite = await isCanvasMonochrome(page, 1, editorRect, 0xffffffff); expect(isWhite).withContext(`In ${browserName}`).toBeTrue(); // Check we've now a div containing the text. diff --git a/test/integration/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index ea6634a5a..13000bfc4 100644 --- a/test/integration/ink_editor_spec.mjs +++ b/test/integration/ink_editor_spec.mjs @@ -23,7 +23,7 @@ import { getEditorSelector, getRect, getSerialized, - isCanvasWhite, + isCanvasMonochrome, kbRedo, kbUndo, loadAndWait, @@ -747,7 +747,12 @@ describe("Ink Editor", () => { await switchToInk(page); // The page has been re-rendered but with no ink annotations. - let isWhite = await isCanvasWhite(page, 1, annotationsRect); + let isWhite = await isCanvasMonochrome( + page, + 1, + annotationsRect, + 0xffffffff + ); expect(isWhite).withContext(`In ${browserName}`).toBeTrue(); let editorIds = await getEditors(page, "ink"); @@ -781,7 +786,7 @@ describe("Ink Editor", () => { editorIds = await getEditors(page, "ink"); expect(editorIds.length).withContext(`In ${browserName}`).toEqual(1); - isWhite = await isCanvasWhite(page, 1, editorRect); + isWhite = await isCanvasMonochrome(page, 1, editorRect, 0xffffffff); expect(isWhite).withContext(`In ${browserName}`).toBeTrue(); // Check we've now a svg with a red stroke. diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index fbd153762..b76a84e79 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -30,6 +30,7 @@ import { getFirstSerialized, getRect, getSerialized, + isCanvasMonochrome, isVisible, kbBigMoveDown, kbBigMoveRight, @@ -45,6 +46,7 @@ import { waitForAnnotationEditorLayer, waitForAnnotationModeChanged, waitForEntryInStorage, + waitForPageRendered, waitForSelectedEditor, waitForSerialized, waitForTimeout, @@ -1819,4 +1821,57 @@ describe("Stamp Editor", () => { ); }); }); + + describe("Switch to edit mode, zoom and check that the non-editable stamp is still there", () => { + const annotationSelector = getAnnotationSelector("14R"); + + let pages; + + beforeAll(async () => { + pages = await loadAndWait("red_stamp.pdf", annotationSelector, 20); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check if the canvas is still red", async () => { + await Promise.all( + pages.map(async ([, page]) => { + expect( + await isCanvasMonochrome(page, 1, null, 0xff0000ff) + ).toBeTrue(); + + await switchToStamp(page); + + expect( + await isCanvasMonochrome(page, 1, null, 0xff0000ff) + ).toBeTrue(); + + const rectPage = await getRect( + page, + `.page[data-page-number = "1"] .annotationEditorLayer` + ); + + const handle = await waitForPageRendered(page, 1); + const originX = rectPage.x + rectPage.width / 2; + const originY = rectPage.y + rectPage.height / 2; + await page.evaluate( + origin => { + window.PDFViewerApplication.pdfViewer.increaseScale({ + scaleFactor: 2, + origin, + }); + }, + [originX, originY] + ); + await awaitPromise(handle); + + expect( + await isCanvasMonochrome(page, 1, null, 0xff0000ff) + ).toBeTrue(); + }) + ); + }); + }); }); diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index 3d67f7fcd..97081516b 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -838,9 +838,9 @@ function waitForNoElement(page, selector) { ); } -function isCanvasWhite(page, pageNumber, rectangle) { +function isCanvasMonochrome(page, pageNumber, rectangle, color) { return page.evaluate( - (rect, pageN) => { + (rect, pageN, col) => { const canvas = document.querySelector( `.page[data-page-number = "${pageN}"] .canvasWrapper canvas` ); @@ -853,10 +853,11 @@ function isCanvasWhite(page, pageNumber, rectangle) { rect.width, rect.height ); - return new Uint32Array(data.buffer).every(x => x === 0xffffffff); + return new Uint32Array(data.buffer).every(x => x === col); }, rectangle, - pageNumber + pageNumber, + color ); } @@ -925,7 +926,7 @@ export { getSpanRectFromText, getXY, hover, - isCanvasWhite, + isCanvasMonochrome, isVisible, kbBigMoveDown, kbBigMoveLeft, diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 624784981..900b36d08 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -710,3 +710,4 @@ !bug1019475_2.pdf !issue19505.pdf !colors.pdf +!red_stamp.pdf diff --git a/test/pdfs/red_stamp.pdf b/test/pdfs/red_stamp.pdf new file mode 100755 index 000000000..c76cdc942 Binary files /dev/null and b/test/pdfs/red_stamp.pdf differ