mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
[Editor] In edit mode, a non-editable stamp must be visible after the page is rendered
This commit is contained in:
parent
dea35aed4a
commit
f3454a738d
7 changed files with 74 additions and 12 deletions
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -710,3 +710,4 @@
|
|||
!bug1019475_2.pdf
|
||||
!issue19505.pdf
|
||||
!colors.pdf
|
||||
!red_stamp.pdf
|
||||
|
|
BIN
test/pdfs/red_stamp.pdf
Executable file
BIN
test/pdfs/red_stamp.pdf
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue