Merge pull request #15117 from calixteman/freetext_resize

[Editor] Set the freetext editor dimensions when the changing the font size
This commit is contained in:
calixteman 2022-06-29 16:38:15 +02:00 committed by GitHub
commit 2e83fa8e2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -145,6 +145,7 @@ class FreeTextEditor extends AnnotationEditor {
this.editorDiv.style.fontSize = `calc(${size}px * var(--scale-factor))`;
this.translate(0, -(size - this.#fontSize) * this.parent.scaleFactor);
this.#fontSize = size;
this.#setEditorDimensions();
};
const savedFontsize = this.#fontSize;
this.parent.addCommands({
@ -260,6 +261,14 @@ class FreeTextEditor extends AnnotationEditor {
return buffer.join("\n");
}
#setEditorDimensions() {
const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
const rect = this.div.getBoundingClientRect();
this.width = rect.width / parentWidth;
this.height = rect.height / parentHeight;
}
/**
* Commit the content we have in this editor.
* @returns {undefined}
@ -276,10 +285,7 @@ class FreeTextEditor extends AnnotationEditor {
this.#contentHTML = this.editorDiv.innerHTML;
this.#content = this.#extractText().trimEnd();
const [parentWidth, parentHeight] = this.parent.viewportBaseDimensions;
const style = getComputedStyle(this.div);
this.width = parseFloat(style.width) / parentWidth;
this.height = parseFloat(style.height) / parentHeight;
this.#setEditorDimensions();
}
/** @inheritdoc */