Merge pull request #20285 from calixteman/editor_remove_useless_dim_stuff
[Editor] Remove useless computations when setting the dimensions of an editor
This commit is contained in:
commit
48c10d8938
@ -494,8 +494,7 @@ class DrawingEditor extends AnnotationEditor {
|
|||||||
this.#convertToParentSpace(bbox);
|
this.#convertToParentSpace(bbox);
|
||||||
if (this.div) {
|
if (this.div) {
|
||||||
this.fixAndSetPosition();
|
this.fixAndSetPosition();
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
this.setDims();
|
||||||
this.setDims(this.width * parentWidth, this.height * parentHeight);
|
|
||||||
}
|
}
|
||||||
this._onResized();
|
this._onResized();
|
||||||
}
|
}
|
||||||
@ -655,8 +654,7 @@ class DrawingEditor extends AnnotationEditor {
|
|||||||
div.append(drawDiv);
|
div.append(drawDiv);
|
||||||
drawDiv.setAttribute("aria-hidden", "true");
|
drawDiv.setAttribute("aria-hidden", "true");
|
||||||
drawDiv.className = "internal";
|
drawDiv.className = "internal";
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
this.setDims();
|
||||||
this.setDims(this.width * parentWidth, this.height * parentHeight);
|
|
||||||
this._uiManager.addShouldRescale(this);
|
this._uiManager.addShouldRescale(this);
|
||||||
this.disableEditing();
|
this.disableEditing();
|
||||||
|
|
||||||
|
|||||||
@ -63,8 +63,6 @@ class AnnotationEditor {
|
|||||||
|
|
||||||
#dragPointerType = "";
|
#dragPointerType = "";
|
||||||
|
|
||||||
#keepAspectRatio = false;
|
|
||||||
|
|
||||||
#resizersDiv = null;
|
#resizersDiv = null;
|
||||||
|
|
||||||
#lastPointerCoords = null;
|
#lastPointerCoords = null;
|
||||||
@ -736,34 +734,15 @@ class AnnotationEditor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the dimensions of this editor.
|
* Set the dimensions of this editor.
|
||||||
* @param {number} width
|
|
||||||
* @param {number} height
|
|
||||||
*/
|
*/
|
||||||
setDims(width, height) {
|
setDims() {
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
const {
|
||||||
const { style } = this.div;
|
div: { style },
|
||||||
style.width = `${((100 * width) / parentWidth).toFixed(2)}%`;
|
width,
|
||||||
if (!this.#keepAspectRatio) {
|
height,
|
||||||
style.height = `${((100 * height) / parentHeight).toFixed(2)}%`;
|
} = this;
|
||||||
}
|
style.width = `${(100 * width).toFixed(2)}%`;
|
||||||
}
|
style.height = `${(100 * height).toFixed(2)}%`;
|
||||||
|
|
||||||
fixDims() {
|
|
||||||
const { style } = this.div;
|
|
||||||
const { height, width } = style;
|
|
||||||
const widthPercent = width.endsWith("%");
|
|
||||||
const heightPercent = !this.#keepAspectRatio && height.endsWith("%");
|
|
||||||
if (widthPercent && heightPercent) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
|
||||||
if (!widthPercent) {
|
|
||||||
style.width = `${((100 * parseFloat(width)) / parentWidth).toFixed(2)}%`;
|
|
||||||
}
|
|
||||||
if (!this.#keepAspectRatio && !heightPercent) {
|
|
||||||
style.height = `${((100 * parseFloat(height)) / parentHeight).toFixed(2)}%`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -872,8 +851,7 @@ class AnnotationEditor {
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
this.setDims();
|
||||||
this.setDims(parentWidth * width, parentHeight * height);
|
|
||||||
this.fixAndSetPosition();
|
this.fixAndSetPosition();
|
||||||
this._onResized();
|
this._onResized();
|
||||||
}
|
}
|
||||||
@ -1050,7 +1028,7 @@ class AnnotationEditor {
|
|||||||
this.x = newX;
|
this.x = newX;
|
||||||
this.y = newY;
|
this.y = newY;
|
||||||
|
|
||||||
this.setDims(parentWidth * newWidth, parentHeight * newHeight);
|
this.setDims();
|
||||||
this.fixAndSetPosition();
|
this.fixAndSetPosition();
|
||||||
|
|
||||||
this._onResizing();
|
this._onResizing();
|
||||||
@ -1417,7 +1395,7 @@ class AnnotationEditor {
|
|||||||
this.width = newWidth;
|
this.width = newWidth;
|
||||||
this.height = newHeight;
|
this.height = newHeight;
|
||||||
|
|
||||||
this.setDims(parentWidth * newWidth, parentHeight * newHeight);
|
this.setDims();
|
||||||
this.fixAndSetPosition();
|
this.fixAndSetPosition();
|
||||||
|
|
||||||
this._onResizing();
|
this._onResizing();
|
||||||
@ -2260,19 +2238,6 @@ class AnnotationEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the aspect ratio to use when resizing.
|
|
||||||
* @param {number} width
|
|
||||||
* @param {number} height
|
|
||||||
*/
|
|
||||||
setAspectRatio(width, height) {
|
|
||||||
this.#keepAspectRatio = true;
|
|
||||||
const aspectRatio = width / height;
|
|
||||||
const { style } = this.div;
|
|
||||||
style.aspectRatio = aspectRatio;
|
|
||||||
style.height = "auto";
|
|
||||||
}
|
|
||||||
|
|
||||||
static get MIN_SIZE() {
|
static get MIN_SIZE() {
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -525,8 +525,7 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
highlightOutlines: this.#highlightOutlines.getNewOutline(thickness / 2),
|
highlightOutlines: this.#highlightOutlines.getNewOutline(thickness / 2),
|
||||||
});
|
});
|
||||||
this.fixAndSetPosition();
|
this.fixAndSetPosition();
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
this.setDims(this.width, this.height);
|
||||||
this.setDims(this.width * parentWidth, this.height * parentHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#cleanDrawLayer() {
|
#cleanDrawLayer() {
|
||||||
@ -645,8 +644,7 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
highlightDiv.setAttribute("aria-hidden", "true");
|
highlightDiv.setAttribute("aria-hidden", "true");
|
||||||
highlightDiv.className = "internal";
|
highlightDiv.className = "internal";
|
||||||
highlightDiv.style.clipPath = this.#clipPathId;
|
highlightDiv.style.clipPath = this.#clipPathId;
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
this.setDims(this.width, this.height);
|
||||||
this.setDims(this.width * parentWidth, this.height * parentHeight);
|
|
||||||
|
|
||||||
bindEvents(this, this.#highlightDiv, ["pointerover", "pointerleave"]);
|
bindEvents(this, this.#highlightDiv, ["pointerover", "pointerleave"]);
|
||||||
this.enableEditing();
|
this.enableEditing();
|
||||||
|
|||||||
@ -276,7 +276,6 @@ class SignatureEditor extends DrawingEditor {
|
|||||||
drawOutlines: outline,
|
drawOutlines: outline,
|
||||||
drawingOptions,
|
drawingOptions,
|
||||||
});
|
});
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
|
||||||
const [, pageHeight] = this.pageDimensions;
|
const [, pageHeight] = this.pageDimensions;
|
||||||
let newHeight = heightInPage / pageHeight;
|
let newHeight = heightInPage / pageHeight;
|
||||||
// Ensure the signature doesn't exceed the page height.
|
// Ensure the signature doesn't exceed the page height.
|
||||||
@ -290,7 +289,7 @@ class SignatureEditor extends DrawingEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.height = newHeight;
|
this.height = newHeight;
|
||||||
this.setDims(parentWidth * this.width, parentHeight * this.height);
|
this.setDims();
|
||||||
this.x = savedX;
|
this.x = savedX;
|
||||||
this.y = savedY;
|
this.y = savedY;
|
||||||
this.center();
|
this.center();
|
||||||
|
|||||||
@ -443,11 +443,6 @@ class StampEditor extends AnnotationEditor {
|
|||||||
width *= factor;
|
width *= factor;
|
||||||
height *= factor;
|
height *= factor;
|
||||||
}
|
}
|
||||||
const [parentWidth, parentHeight] = this.parentDimensions;
|
|
||||||
this.setDims(
|
|
||||||
(width * parentWidth) / pageWidth,
|
|
||||||
(height * parentHeight) / pageHeight
|
|
||||||
);
|
|
||||||
|
|
||||||
this._uiManager.enableWaiting(false);
|
this._uiManager.enableWaiting(false);
|
||||||
const canvas = (this.#canvas = document.createElement("canvas"));
|
const canvas = (this.#canvas = document.createElement("canvas"));
|
||||||
@ -456,6 +451,8 @@ class StampEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
this.width = width / pageWidth;
|
this.width = width / pageWidth;
|
||||||
this.height = height / pageHeight;
|
this.height = height / pageHeight;
|
||||||
|
this.setDims();
|
||||||
|
|
||||||
if (this._initialOptions?.isCentered) {
|
if (this._initialOptions?.isCentered) {
|
||||||
this.center();
|
this.center();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user