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] Take into account the initial rotation (issue #16278) #16301

Merged
merged 1 commit into from
Apr 17, 2023
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
4 changes: 3 additions & 1 deletion src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class AnnotationEditor {
} = this.parent.viewport;

this.rotation = rotation;
this.pageRotation =
(360 + rotation - this._uiManager.viewParameters.rotation) % 360;
this.pageDimensions = [pageWidth, pageHeight];
this.pageTranslation = [pageX, pageY];

Expand Down Expand Up @@ -250,7 +252,7 @@ class AnnotationEditor {
}

get parentRotation() {
return this._uiManager.viewParameters.rotation;
return (this._uiManager.viewParameters.rotation + this.pageRotation) % 360;
}

get parentDimensions() {
Expand Down
51 changes: 49 additions & 2 deletions test/integration/ink_editor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const {
loadAndWait,
} = require("./test_utils.js");

describe("Editor", () => {
describe("Ink", () => {
describe("Ink Editor", () => {
describe("Basic operations", () => {
let pages;

beforeAll(async () => {
Expand Down Expand Up @@ -135,4 +135,51 @@ describe("Editor", () => {
);
});
});

describe("with a rotated pdf", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("issue16278.pdf", ".annotationEditorLayer");
});

afterAll(async () => {
await closePages(pages);
});

it("must draw something", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.click("#editorInk");

const rect = await page.$eval(".annotationEditorLayer", el => {
// With Chrome something is wrong when serializing a DomRect,
// hence we extract the values and just return them.
const { x, y } = el.getBoundingClientRect();
return { x, y };
});

const x = rect.x + 20;
const y = rect.y + 20;
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + 50, y + 50);
await page.mouse.up();

await page.waitForTimeout(10);
await page.keyboard.press("Escape");
await page.waitForTimeout(10);

await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");
await page.waitForTimeout(10);

expect(await getSelectedEditors(page))
.withContext(`In ${browserName}`)
.toEqual([0]);
})
);
});
});
});
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,4 @@
!bug1820909.1.pdf
!issue16221.pdf
!issue16224.pdf
!issue16278.pdf
Binary file added test/pdfs/issue16278.pdf
Binary file not shown.