Skip to content

Commit

Permalink
Merge pull request mozilla#16301 from calixteman/issue16278
Browse files Browse the repository at this point in the history
[Editor] Take into account the initial rotation (issue mozilla#16278)
  • Loading branch information
calixteman authored Apr 17, 2023
2 parents 1503701 + 8e5f4c0 commit 3e08eee
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
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.

0 comments on commit 3e08eee

Please sign in to comment.