From 983b269e267737c98042b51da9f95d01f7ffcaa2 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 17 Jul 2023 15:03:27 +0200 Subject: [PATCH] [Editor] Use 2 decimals for editor positions and dimensions I noticed that after adding an image in issue16278.pdf, the image was constantly resizing itself. It appears that it's because of rounding errors. --- src/display/editor/editor.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index 04aeea3b9..2c2aae175 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -367,9 +367,9 @@ class AnnotationEditor { */ setDims(width, height) { const [parentWidth, parentHeight] = this.parentDimensions; - this.div.style.width = `${(100 * width) / parentWidth}%`; + this.div.style.width = `${((100 * width) / parentWidth).toFixed(2)}%`; if (!this.#keepAspectRatio) { - this.div.style.height = `${(100 * height) / parentHeight}%`; + this.div.style.height = `${((100 * height) / parentHeight).toFixed(2)}%`; } } @@ -384,10 +384,12 @@ class AnnotationEditor { const [parentWidth, parentHeight] = this.parentDimensions; if (!widthPercent) { - style.width = `${(100 * parseFloat(width)) / parentWidth}%`; + style.width = `${((100 * parseFloat(width)) / parentWidth).toFixed(2)}%`; } if (!this.#keepAspectRatio && !heightPercent) { - style.height = `${(100 * parseFloat(height)) / parentHeight}%`; + style.height = `${((100 * parseFloat(height)) / parentHeight).toFixed( + 2 + )}%`; } }