Merge pull request #15185 from calixteman/ink_translation

[Editor] Ink editor was too much translated after commit
This commit is contained in:
calixteman 2022-07-20 10:34:37 +02:00 committed by GitHub
commit 7a4b72ed11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,11 +137,11 @@ class InkEditor extends AnnotationEditor {
this.parent.addCommands({ this.parent.addCommands({
cmd: () => { cmd: () => {
this.thickness = thickness; this.thickness = thickness;
this.#fitToContent(); this.#fitToContent(/* thicknessChanged = */ true);
}, },
undo: () => { undo: () => {
this.thickness = savedThickness; this.thickness = savedThickness;
this.#fitToContent(); this.#fitToContent(/* thicknessChanged = */ true);
}, },
mustExec: true, mustExec: true,
type: AnnotationEditorParamsType.INK_THICKNESS, type: AnnotationEditorParamsType.INK_THICKNESS,
@ -829,7 +829,9 @@ class InkEditor extends AnnotationEditor {
* @returns {number} * @returns {number}
*/ */
#getPadding() { #getPadding() {
return Math.ceil(this.thickness * this.parent.scaleFactor); return this.#disableEditing
? Math.ceil(this.thickness * this.parent.scaleFactor)
: 0;
} }
/** /**
@ -837,7 +839,7 @@ class InkEditor extends AnnotationEditor {
* the bounding box of the contents. * the bounding box of the contents.
* @returns {undefined} * @returns {undefined}
*/ */
#fitToContent() { #fitToContent(thicknessChanged = false) {
if (this.isEmpty()) { if (this.isEmpty()) {
return; return;
} }
@ -849,8 +851,8 @@ class InkEditor extends AnnotationEditor {
const bbox = this.#getBbox(); const bbox = this.#getBbox();
const padding = this.#getPadding(); const padding = this.#getPadding();
this.#baseWidth = bbox[2] - bbox[0]; this.#baseWidth = Math.max(RESIZER_SIZE, bbox[2] - bbox[0]);
this.#baseHeight = bbox[3] - bbox[1]; this.#baseHeight = Math.max(RESIZER_SIZE, bbox[3] - bbox[1]);
const width = Math.ceil(padding + this.#baseWidth * this.scaleFactor); const width = Math.ceil(padding + this.#baseWidth * this.scaleFactor);
const height = Math.ceil(padding + this.#baseHeight * this.scaleFactor); const height = Math.ceil(padding + this.#baseHeight * this.scaleFactor);
@ -874,9 +876,12 @@ class InkEditor extends AnnotationEditor {
this.#realHeight = height; this.#realHeight = height;
this.setDims(width, height); this.setDims(width, height);
const unscaledPadding = thicknessChanged
? 0
: padding / this.scaleFactor / 2;
this.translate( this.translate(
prevTranslationX - this.translationX, prevTranslationX - this.translationX - unscaledPadding,
prevTranslationY - this.translationY prevTranslationY - this.translationY - unscaledPadding
); );
} }