mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[Editor] Avoid to have some part of an editor outside its page (bug 1843303)
This commit is contained in:
parent
717c766a42
commit
a8867cf68a
7 changed files with 105 additions and 5 deletions
|
@ -258,8 +258,7 @@ class AnnotationEditor {
|
|||
this.x = (x + tx) / width;
|
||||
this.y = (y + ty) / height;
|
||||
|
||||
this.div.style.left = `${100 * this.x}%`;
|
||||
this.div.style.top = `${100 * this.y}%`;
|
||||
this.fixAndSetPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,8 +273,41 @@ class AnnotationEditor {
|
|||
this.x += x / width;
|
||||
this.y += y / height;
|
||||
|
||||
this.div.style.left = `${100 * this.x}%`;
|
||||
this.div.style.top = `${100 * this.y}%`;
|
||||
this.fixAndSetPosition();
|
||||
}
|
||||
|
||||
fixAndSetPosition() {
|
||||
const [pageWidth, pageHeight] = this.pageDimensions;
|
||||
let { x, y, width, height } = this;
|
||||
width *= pageWidth;
|
||||
height *= pageHeight;
|
||||
x *= pageWidth;
|
||||
y *= pageHeight;
|
||||
|
||||
switch (this.rotation) {
|
||||
case 0:
|
||||
x = Math.max(0, Math.min(pageWidth - width, x));
|
||||
y = Math.max(0, Math.min(pageHeight - height, y));
|
||||
break;
|
||||
case 90:
|
||||
x = Math.max(0, Math.min(pageWidth - height, x));
|
||||
y = Math.min(pageHeight, Math.max(width, y));
|
||||
break;
|
||||
case 180:
|
||||
x = Math.min(pageWidth, Math.max(width, x));
|
||||
y = Math.min(pageHeight, Math.max(height, y));
|
||||
break;
|
||||
case 270:
|
||||
x = Math.min(pageWidth, Math.max(height, x));
|
||||
y = Math.max(0, Math.min(pageHeight - width, y));
|
||||
break;
|
||||
}
|
||||
|
||||
this.x = x / pageWidth;
|
||||
this.y = y / pageHeight;
|
||||
|
||||
this.div.style.left = `${(100 * this.x).toFixed(2)}%`;
|
||||
this.div.style.top = `${(100 * this.y).toFixed(2)}%`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -383,6 +415,17 @@ class AnnotationEditor {
|
|||
this.div.addEventListener("focusin", this.#boundFocusin);
|
||||
this.div.addEventListener("focusout", this.#boundFocusout);
|
||||
|
||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
||||
if (this.parentRotation % 180 !== 0) {
|
||||
this.div.style.maxWidth = `${((100 * parentHeight) / parentWidth).toFixed(
|
||||
2
|
||||
)}%`;
|
||||
this.div.style.maxHeight = `${(
|
||||
(100 * parentWidth) /
|
||||
parentHeight
|
||||
).toFixed(2)}%`;
|
||||
}
|
||||
|
||||
const [tx, ty] = this.getInitialTranslation();
|
||||
this.translate(tx, ty);
|
||||
|
||||
|
|
|
@ -357,6 +357,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
this.width = rect.height / parentWidth;
|
||||
this.height = rect.width / parentHeight;
|
||||
}
|
||||
this.fixAndSetPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -838,6 +838,7 @@ class InkEditor extends AnnotationEditor {
|
|||
const [parentWidth, parentHeight] = this.parentDimensions;
|
||||
this.width = width / parentWidth;
|
||||
this.height = height / parentHeight;
|
||||
this.fixAndSetPosition();
|
||||
|
||||
if (this.#disableEditing) {
|
||||
this.#setScaleFactor(width, height);
|
||||
|
|
|
@ -254,6 +254,7 @@ class StampEditor extends AnnotationEditor {
|
|||
this.width = width / parentWidth;
|
||||
this.height = height / parentHeight;
|
||||
this.setDims(width, height);
|
||||
this.fixAndSetPosition();
|
||||
if (this.#resizeTimeoutId !== null) {
|
||||
clearTimeout(this.#resizeTimeoutId);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue