Skip to content

Commit fca53a8

Browse files
committed
Compute the transformOrigin correctly, for negative values, when rendering AnnotationElements (bug 1627030)
This changes the `transformOrigin` calculations in `AnnotationElement._createContainer` and `PopupAnnotationElement.render`, to ensure that e.g. the clickable area of annotations and/or popups are both positioned correctly. The problem occurs for *negative* values, since they're not negated correctly because of how the `transformOrigin` strings were build; see issue 12406 for a more in-depth explanation. Previously, for negative values, the `transformOrigin` strings would thus be ignored since they're not valid.
1 parent 139c8a8 commit fca53a8

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/display/annotation_layer.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class AnnotationElement {
177177
]);
178178

179179
container.style.transform = `matrix(${viewport.transform.join(",")})`;
180-
container.style.transformOrigin = `-${rect[0]}px -${rect[1]}px`;
180+
container.style.transformOrigin = `${-rect[0]}px ${-rect[1]}px`;
181181

182182
if (!ignoreBorder && data.borderStyle.width > 0) {
183183
container.style.borderWidth = `${data.borderStyle.width}px`;
@@ -763,12 +763,13 @@ class PopupAnnotationElement extends AnnotationElement {
763763

764764
// Position the popup next to the parent annotation's container.
765765
// PDF viewers ignore a popup annotation's rectangle.
766-
const parentLeft = parseFloat(parentElement.style.left);
767-
const parentWidth = parseFloat(parentElement.style.width);
768-
this.container.style.transformOrigin = `-${parentLeft + parentWidth}px -${
769-
parentElement.style.top
770-
}`;
771-
this.container.style.left = `${parentLeft + parentWidth}px`;
766+
const parentTop = parseFloat(parentElement.style.top),
767+
parentLeft = parseFloat(parentElement.style.left),
768+
parentWidth = parseFloat(parentElement.style.width);
769+
const popupLeft = parentLeft + parentWidth;
770+
771+
this.container.style.transformOrigin = `${-popupLeft}px ${-parentTop}px`;
772+
this.container.style.left = `${popupLeft}px`;
772773

773774
this.container.appendChild(popup.render());
774775
return this.container;

test/pdfs/bug1627030.pdf.link

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://bug1627030.bmoattachments.org/attachment.cgi?id=9137808

test/test_manifest.json

+10
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,16 @@
780780
"annotations": true,
781781
"about": "Annotation with (ridiculously) large border width."
782782
},
783+
{ "id": "bug1627030",
784+
"file": "pdfs/bug1627030.pdf",
785+
"md5": "4cde6134daa80449c43defd02c1393e2",
786+
"rounds": 1,
787+
"link": true,
788+
"firstPage": 3,
789+
"lastPage": 3,
790+
"type": "eq",
791+
"annotations": true
792+
},
783793
{ "id": "issue4934",
784794
"file": "pdfs/issue4934.pdf",
785795
"md5": "6099da44f677702ae65a648b51a2226d",

0 commit comments

Comments
 (0)