Skip to content

Send the AnnotationStorage-data to the worker-thread as a Map #13001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ class Annotation {
}

isHidden(annotationStorage) {
const data = annotationStorage && annotationStorage[this.data.id];
if (data && "hidden" in data) {
return data.hidden;
const storageEntry =
annotationStorage && annotationStorage.get(this.data.id);
if (storageEntry && storageEntry.hidden !== undefined) {
return storageEntry.hidden;
}
return this._hasFlag(this.flags, AnnotationFlag.HIDDEN);
}
Expand Down Expand Up @@ -1206,8 +1207,11 @@ class WidgetAnnotation extends Annotation {
}

async save(evaluator, task, annotationStorage) {
const value =
annotationStorage[this.data.id] && annotationStorage[this.data.id].value;
if (!annotationStorage) {
return null;
}
const storageEntry = annotationStorage.get(this.data.id);
const value = storageEntry && storageEntry.value;
if (value === this.data.fieldValue || value === undefined) {
return null;
}
Expand Down Expand Up @@ -1289,8 +1293,8 @@ class WidgetAnnotation extends Annotation {
if (!annotationStorage || isPassword) {
return null;
}
let value =
annotationStorage[this.data.id] && annotationStorage[this.data.id].value;
const storageEntry = annotationStorage.get(this.data.id);
let value = storageEntry && storageEntry.value;
if (value === undefined) {
// The annotation hasn't been rendered so use the appearance
return null;
Expand Down Expand Up @@ -1769,9 +1773,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}

if (annotationStorage) {
const value =
annotationStorage[this.data.id] &&
annotationStorage[this.data.id].value;
const storageEntry = annotationStorage.get(this.data.id);
const value = storageEntry && storageEntry.value;
if (value === undefined) {
return super.getOperatorList(
evaluator,
Expand Down Expand Up @@ -1826,8 +1829,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}

async _saveCheckbox(evaluator, task, annotationStorage) {
const value =
annotationStorage[this.data.id] && annotationStorage[this.data.id].value;
if (!annotationStorage) {
return null;
}
const storageEntry = annotationStorage.get(this.data.id);
const value = storageEntry && storageEntry.value;
if (value === undefined) {
return null;
}
Expand Down Expand Up @@ -1869,8 +1875,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}

async _saveRadioButton(evaluator, task, annotationStorage) {
const value =
annotationStorage[this.data.id] && annotationStorage[this.data.id].value;
if (!annotationStorage) {
return null;
}
const storageEntry = annotationStorage.get(this.data.id);
const value = storageEntry && storageEntry.value;
if (value === undefined) {
return null;
}
Expand Down
13 changes: 9 additions & 4 deletions src/display/annotation_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ class AnnotationStorage {
}

getAll() {
if (this._storage.size === 0) {
return null;
}
return objectFromEntries(this._storage);
return this._storage.size > 0 ? objectFromEntries(this._storage) : null;
}

get size() {
Expand All @@ -121,6 +118,14 @@ class AnnotationStorage {
}
}
}

/**
* PLEASE NOTE: Only intended for usage within the API itself.
* @ignore
*/
get serializable() {
return this._storage.size > 0 ? this._storage : null;
}
}

export { AnnotationStorage };
4 changes: 2 additions & 2 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ class PDFPageProxy {
pageIndex: this._pageIndex,
intent: renderingIntent,
renderInteractiveForms: renderInteractiveForms === true,
annotationStorage: annotationStorage?.getAll() || null,
annotationStorage: annotationStorage?.serializable || null,
});
}

Expand Down Expand Up @@ -2613,7 +2613,7 @@ class WorkerTransport {
return this.messageHandler
.sendWithPromise("SaveDocument", {
numPages: this._numPages,
annotationStorage: annotationStorage?.getAll() || null,
annotationStorage: annotationStorage?.serializable || null,
filename: this._fullReader?.filename ?? null,
})
.finally(() => {
Expand Down
Loading