mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[Editor] Let a free highlight be clipped when its bounding box exceeds the page limits (bug 1883632)
This commit is contained in:
parent
f1272ee435
commit
bd5875d066
3 changed files with 75 additions and 17 deletions
|
@ -512,6 +512,14 @@ class AnnotationEditor {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} true if position must be fixed (i.e. make the x and y
|
||||
* living in the page).
|
||||
*/
|
||||
get _mustFixPosition() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix the position of the editor in order to keep it inside its parent page.
|
||||
* @param {number} [rotation] - the rotation of the page.
|
||||
|
@ -524,23 +532,25 @@ class AnnotationEditor {
|
|||
x *= pageWidth;
|
||||
y *= pageHeight;
|
||||
|
||||
switch (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;
|
||||
if (this._mustFixPosition) {
|
||||
switch (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;
|
||||
|
|
|
@ -629,6 +629,11 @@ class HighlightEditor extends AnnotationEditor {
|
|||
}
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
get _mustFixPosition() {
|
||||
return !this.#isFreeHighlight;
|
||||
}
|
||||
|
||||
#getRotation() {
|
||||
// Highlight annotations are always drawn horizontally but if
|
||||
// a free highlight annotation can be rotated.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue