Skip to content

Commit 48c10d8

Browse files
authored
Merge pull request #20285 from calixteman/editor_remove_useless_dim_stuff
[Editor] Remove useless computations when setting the dimensions of an editor
2 parents 225b07a + 0722faa commit 48c10d8

5 files changed

Lines changed: 18 additions & 61 deletions

File tree

src/display/editor/draw.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,7 @@ class DrawingEditor extends AnnotationEditor {
494494
this.#convertToParentSpace(bbox);
495495
if (this.div) {
496496
this.fixAndSetPosition();
497-
const [parentWidth, parentHeight] = this.parentDimensions;
498-
this.setDims(this.width * parentWidth, this.height * parentHeight);
497+
this.setDims();
499498
}
500499
this._onResized();
501500
}
@@ -655,8 +654,7 @@ class DrawingEditor extends AnnotationEditor {
655654
div.append(drawDiv);
656655
drawDiv.setAttribute("aria-hidden", "true");
657656
drawDiv.className = "internal";
658-
const [parentWidth, parentHeight] = this.parentDimensions;
659-
this.setDims(this.width * parentWidth, this.height * parentHeight);
657+
this.setDims();
660658
this._uiManager.addShouldRescale(this);
661659
this.disableEditing();
662660

src/display/editor/editor.js

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class AnnotationEditor {
6363

6464
#dragPointerType = "";
6565

66-
#keepAspectRatio = false;
67-
6866
#resizersDiv = null;
6967

7068
#lastPointerCoords = null;
@@ -736,34 +734,15 @@ class AnnotationEditor {
736734

737735
/**
738736
* Set the dimensions of this editor.
739-
* @param {number} width
740-
* @param {number} height
741737
*/
742-
setDims(width, height) {
743-
const [parentWidth, parentHeight] = this.parentDimensions;
744-
const { style } = this.div;
745-
style.width = `${((100 * width) / parentWidth).toFixed(2)}%`;
746-
if (!this.#keepAspectRatio) {
747-
style.height = `${((100 * height) / parentHeight).toFixed(2)}%`;
748-
}
749-
}
750-
751-
fixDims() {
752-
const { style } = this.div;
753-
const { height, width } = style;
754-
const widthPercent = width.endsWith("%");
755-
const heightPercent = !this.#keepAspectRatio && height.endsWith("%");
756-
if (widthPercent && heightPercent) {
757-
return;
758-
}
759-
760-
const [parentWidth, parentHeight] = this.parentDimensions;
761-
if (!widthPercent) {
762-
style.width = `${((100 * parseFloat(width)) / parentWidth).toFixed(2)}%`;
763-
}
764-
if (!this.#keepAspectRatio && !heightPercent) {
765-
style.height = `${((100 * parseFloat(height)) / parentHeight).toFixed(2)}%`;
766-
}
738+
setDims() {
739+
const {
740+
div: { style },
741+
width,
742+
height,
743+
} = this;
744+
style.width = `${(100 * width).toFixed(2)}%`;
745+
style.height = `${(100 * height).toFixed(2)}%`;
767746
}
768747

769748
/**
@@ -872,8 +851,7 @@ class AnnotationEditor {
872851
this.height = height;
873852
this.x = x;
874853
this.y = y;
875-
const [parentWidth, parentHeight] = this.parentDimensions;
876-
this.setDims(parentWidth * width, parentHeight * height);
854+
this.setDims();
877855
this.fixAndSetPosition();
878856
this._onResized();
879857
}
@@ -1050,7 +1028,7 @@ class AnnotationEditor {
10501028
this.x = newX;
10511029
this.y = newY;
10521030

1053-
this.setDims(parentWidth * newWidth, parentHeight * newHeight);
1031+
this.setDims();
10541032
this.fixAndSetPosition();
10551033

10561034
this._onResizing();
@@ -1417,7 +1395,7 @@ class AnnotationEditor {
14171395
this.width = newWidth;
14181396
this.height = newHeight;
14191397

1420-
this.setDims(parentWidth * newWidth, parentHeight * newHeight);
1398+
this.setDims();
14211399
this.fixAndSetPosition();
14221400

14231401
this._onResizing();
@@ -2260,19 +2238,6 @@ class AnnotationEditor {
22602238
}
22612239
}
22622240

2263-
/**
2264-
* Set the aspect ratio to use when resizing.
2265-
* @param {number} width
2266-
* @param {number} height
2267-
*/
2268-
setAspectRatio(width, height) {
2269-
this.#keepAspectRatio = true;
2270-
const aspectRatio = width / height;
2271-
const { style } = this.div;
2272-
style.aspectRatio = aspectRatio;
2273-
style.height = "auto";
2274-
}
2275-
22762241
static get MIN_SIZE() {
22772242
return 16;
22782243
}

src/display/editor/highlight.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,7 @@ class HighlightEditor extends AnnotationEditor {
525525
highlightOutlines: this.#highlightOutlines.getNewOutline(thickness / 2),
526526
});
527527
this.fixAndSetPosition();
528-
const [parentWidth, parentHeight] = this.parentDimensions;
529-
this.setDims(this.width * parentWidth, this.height * parentHeight);
528+
this.setDims(this.width, this.height);
530529
}
531530

532531
#cleanDrawLayer() {
@@ -645,8 +644,7 @@ class HighlightEditor extends AnnotationEditor {
645644
highlightDiv.setAttribute("aria-hidden", "true");
646645
highlightDiv.className = "internal";
647646
highlightDiv.style.clipPath = this.#clipPathId;
648-
const [parentWidth, parentHeight] = this.parentDimensions;
649-
this.setDims(this.width * parentWidth, this.height * parentHeight);
647+
this.setDims(this.width, this.height);
650648

651649
bindEvents(this, this.#highlightDiv, ["pointerover", "pointerleave"]);
652650
this.enableEditing();

src/display/editor/signature.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ class SignatureEditor extends DrawingEditor {
276276
drawOutlines: outline,
277277
drawingOptions,
278278
});
279-
const [parentWidth, parentHeight] = this.parentDimensions;
280279
const [, pageHeight] = this.pageDimensions;
281280
let newHeight = heightInPage / pageHeight;
282281
// Ensure the signature doesn't exceed the page height.
@@ -290,7 +289,7 @@ class SignatureEditor extends DrawingEditor {
290289
}
291290

292291
this.height = newHeight;
293-
this.setDims(parentWidth * this.width, parentHeight * this.height);
292+
this.setDims();
294293
this.x = savedX;
295294
this.y = savedY;
296295
this.center();

src/display/editor/stamp.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,6 @@ class StampEditor extends AnnotationEditor {
443443
width *= factor;
444444
height *= factor;
445445
}
446-
const [parentWidth, parentHeight] = this.parentDimensions;
447-
this.setDims(
448-
(width * parentWidth) / pageWidth,
449-
(height * parentHeight) / pageHeight
450-
);
451446

452447
this._uiManager.enableWaiting(false);
453448
const canvas = (this.#canvas = document.createElement("canvas"));
@@ -456,6 +451,8 @@ class StampEditor extends AnnotationEditor {
456451

457452
this.width = width / pageWidth;
458453
this.height = height / pageHeight;
454+
this.setDims();
455+
459456
if (this._initialOptions?.isCentered) {
460457
this.center();
461458
} else {

0 commit comments

Comments
 (0)