Merge pull request #20196 from calixteman/xy_getter

[Editor] Add a method to get an editor rect in the pdf page coordinates
This commit is contained in:
Tim van der Meij 2025-08-26 20:27:06 +02:00 committed by GitHub
commit d8c01bf70d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 9 deletions

View File

@ -988,7 +988,7 @@ class DrawingEditor extends AnnotationEditor {
/** @inheritdoc */ /** @inheritdoc */
renderAnnotationElement(annotation) { renderAnnotationElement(annotation) {
annotation.updateEdited({ annotation.updateEdited({
rect: this.getRect(0, 0), rect: this.getPDFRect(),
}); });
return null; return null;

View File

@ -1572,6 +1572,15 @@ class AnnotationEditor {
} }
} }
/**
* Get the rect in page coordinates without any translation.
* It's used when serializing the editor.
* @returns {Array<number>}
*/
getPDFRect() {
return this.getRect(0, 0);
}
/** /**
* Executed once this editor has been rendered. * Executed once this editor has been rendered.
* @param {boolean} focus - true if the editor should be focused. * @param {boolean} focus - true if the editor should be focused.

View File

@ -770,6 +770,12 @@ class FreeTextEditor extends AnnotationEditor {
return this.editorDiv; return this.editorDiv;
} }
/** @inheritdoc */
getPDFRect() {
const padding = FreeTextEditor._internalPadding * this.parentScale;
return this.getRect(padding, padding);
}
/** @inheritdoc */ /** @inheritdoc */
static async deserialize(data, parent, uiManager) { static async deserialize(data, parent, uiManager) {
let initialData = null; let initialData = null;
@ -833,8 +839,7 @@ class FreeTextEditor extends AnnotationEditor {
return this.serializeDeleted(); return this.serializeDeleted();
} }
const padding = FreeTextEditor._internalPadding * this.parentScale; const rect = this.getPDFRect();
const rect = this.getRect(padding, padding);
const color = AnnotationEditor._colorManager.convert( const color = AnnotationEditor._colorManager.convert(
this.isAttachedToDOM this.isAttachedToDOM
? getComputedStyle(this.editorDiv).color ? getComputedStyle(this.editorDiv).color
@ -901,9 +906,8 @@ class FreeTextEditor extends AnnotationEditor {
content.append(div); content.append(div);
} }
const padding = FreeTextEditor._internalPadding * this.parentScale;
const params = { const params = {
rect: this.getRect(padding, padding), rect: this.getPDFRect(),
}; };
params.popup = this.hasEditedComment params.popup = this.hasEditedComment
? this.comment ? this.comment

View File

@ -1023,7 +1023,7 @@ class HighlightEditor extends AnnotationEditor {
return this.serializeDeleted(); return this.serializeDeleted();
} }
const rect = this.getRect(0, 0); const rect = this.getPDFRect();
const color = AnnotationEditor._colorManager.convert( const color = AnnotationEditor._colorManager.convert(
this._uiManager.getNonHCMColor(this.color) this._uiManager.getNonHCMColor(this.color)
); );
@ -1064,7 +1064,7 @@ class HighlightEditor extends AnnotationEditor {
return null; return null;
} }
const params = { const params = {
rect: this.getRect(0, 0), rect: this.getPDFRect(),
}; };
if (this.hasEditedComment) { if (this.hasEditedComment) {
params.popup = this.comment; params.popup = this.comment;

View File

@ -845,7 +845,7 @@ class StampEditor extends AnnotationEditor {
annotationType: AnnotationEditorType.STAMP, annotationType: AnnotationEditorType.STAMP,
bitmapId: this.#bitmapId, bitmapId: this.#bitmapId,
pageIndex: this.pageIndex, pageIndex: this.pageIndex,
rect: this.getRect(0, 0), rect: this.getPDFRect(),
rotation: this.rotation, rotation: this.rotation,
isSvg: this.#isSvg, isSvg: this.#isSvg,
structTreeParentId: this._structTreeParentId, structTreeParentId: this._structTreeParentId,
@ -935,7 +935,7 @@ class StampEditor extends AnnotationEditor {
return null; return null;
} }
const params = { const params = {
rect: this.getRect(0, 0), rect: this.getPDFRect(),
}; };
if (this.hasEditedComment) { if (this.hasEditedComment) {
params.popup = this.comment; params.popup = this.comment;