Skip to content

Commit 1fc039e

Browse files
committed
[Editor] Add a method to get an editor rect in the pdf page coordinates
1 parent bde01f0 commit 1fc039e

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

src/display/editor/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ class DrawingEditor extends AnnotationEditor {
988988
/** @inheritdoc */
989989
renderAnnotationElement(annotation) {
990990
annotation.updateEdited({
991-
rect: this.getRect(0, 0),
991+
rect: this.getPDFRect(),
992992
});
993993

994994
return null;

src/display/editor/editor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,15 @@ class AnnotationEditor {
15721572
}
15731573
}
15741574

1575+
/**
1576+
* Get the rect in page coordinates without any translation.
1577+
* It's used when serializing the editor.
1578+
* @returns {Array<number>}
1579+
*/
1580+
getPDFRect() {
1581+
return this.getRect(0, 0);
1582+
}
1583+
15751584
/**
15761585
* Executed once this editor has been rendered.
15771586
* @param {boolean} focus - true if the editor should be focused.

src/display/editor/freetext.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,12 @@ class FreeTextEditor extends AnnotationEditor {
770770
return this.editorDiv;
771771
}
772772

773+
/** @inheritdoc */
774+
getPDFRect() {
775+
const padding = FreeTextEditor._internalPadding * this.parentScale;
776+
return this.getRect(padding, padding);
777+
}
778+
773779
/** @inheritdoc */
774780
static async deserialize(data, parent, uiManager) {
775781
let initialData = null;
@@ -833,8 +839,7 @@ class FreeTextEditor extends AnnotationEditor {
833839
return this.serializeDeleted();
834840
}
835841

836-
const padding = FreeTextEditor._internalPadding * this.parentScale;
837-
const rect = this.getRect(padding, padding);
842+
const rect = this.getPDFRect();
838843
const color = AnnotationEditor._colorManager.convert(
839844
this.isAttachedToDOM
840845
? getComputedStyle(this.editorDiv).color
@@ -901,9 +906,8 @@ class FreeTextEditor extends AnnotationEditor {
901906
content.append(div);
902907
}
903908

904-
const padding = FreeTextEditor._internalPadding * this.parentScale;
905909
const params = {
906-
rect: this.getRect(padding, padding),
910+
rect: this.getPDFRect(),
907911
};
908912
params.popup = this.hasEditedComment
909913
? this.comment

src/display/editor/highlight.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ class HighlightEditor extends AnnotationEditor {
10231023
return this.serializeDeleted();
10241024
}
10251025

1026-
const rect = this.getRect(0, 0);
1026+
const rect = this.getPDFRect();
10271027
const color = AnnotationEditor._colorManager.convert(
10281028
this._uiManager.getNonHCMColor(this.color)
10291029
);
@@ -1064,7 +1064,7 @@ class HighlightEditor extends AnnotationEditor {
10641064
return null;
10651065
}
10661066
const params = {
1067-
rect: this.getRect(0, 0),
1067+
rect: this.getPDFRect(),
10681068
};
10691069
if (this.hasEditedComment) {
10701070
params.popup = this.comment;

src/display/editor/stamp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ class StampEditor extends AnnotationEditor {
845845
annotationType: AnnotationEditorType.STAMP,
846846
bitmapId: this.#bitmapId,
847847
pageIndex: this.pageIndex,
848-
rect: this.getRect(0, 0),
848+
rect: this.getPDFRect(),
849849
rotation: this.rotation,
850850
isSvg: this.#isSvg,
851851
structTreeParentId: this._structTreeParentId,
@@ -935,7 +935,7 @@ class StampEditor extends AnnotationEditor {
935935
return null;
936936
}
937937
const params = {
938-
rect: this.getRect(0, 0),
938+
rect: this.getPDFRect(),
939939
};
940940
if (this.hasEditedComment) {
941941
params.popup = this.comment;

0 commit comments

Comments
 (0)