mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #18361 from calixteman/issue18360.pdf
[Editor] Take into account the page translation when computing the quadpoints when saving an highlight
This commit is contained in:
commit
75129fd61a
4 changed files with 39 additions and 2 deletions
|
@ -671,12 +671,13 @@ class HighlightEditor extends AnnotationEditor {
|
|||
return null;
|
||||
}
|
||||
const [pageWidth, pageHeight] = this.pageDimensions;
|
||||
const [pageX, pageY] = this.pageTranslation;
|
||||
const boxes = this.#boxes;
|
||||
const quadPoints = new Float32Array(boxes.length * 8);
|
||||
let i = 0;
|
||||
for (const { x, y, width, height } of boxes) {
|
||||
const sx = x * pageWidth;
|
||||
const sy = (1 - y - height) * pageHeight;
|
||||
const sx = x * pageWidth + pageX;
|
||||
const sy = (1 - y - height) * pageHeight + pageY;
|
||||
// The specifications say that the rectangle should start from the bottom
|
||||
// left corner and go counter-clockwise.
|
||||
// But when opening the file in Adobe Acrobat it appears that this isn't
|
||||
|
|
|
@ -1302,6 +1302,41 @@ describe("Highlight Editor", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("Quadpoints must be correct when they're in a translated page", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("issue18360.pdf", ".annotationEditorLayer");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check that the quadpoints for an highlight are almost correct", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await switchToHighlight(page);
|
||||
|
||||
const rect = await getSpanRectFromText(page, 1, "Hello World");
|
||||
await page.mouse.click(
|
||||
rect.x + rect.width / 4,
|
||||
rect.y + rect.height / 2,
|
||||
{ count: 2, delay: 100 }
|
||||
);
|
||||
|
||||
await page.waitForSelector(getEditorSelector(0));
|
||||
await waitForSerialized(page, 1);
|
||||
const quadPoints = await getFirstSerialized(page, e => e.quadPoints);
|
||||
const expected = [148, 624, 176, 624, 148, 637, 176, 637];
|
||||
expect(quadPoints.every((x, i) => Math.abs(x - expected[i]) <= 5))
|
||||
.withContext(`In ${browserName} (got ${quadPoints})`)
|
||||
.toBeTrue();
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Editor must be unselected when the color picker is Escaped", () => {
|
||||
let pages;
|
||||
|
||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -652,3 +652,4 @@
|
|||
!bug1539074.pdf
|
||||
!bug1539074.1.pdf
|
||||
!issue18305.pdf
|
||||
!issue18360.pdf
|
||||
|
|
BIN
test/pdfs/issue18360.pdf
Executable file
BIN
test/pdfs/issue18360.pdf
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue