Merge pull request #16053 from Snuffleupagus/test-set-annotationStorage
Reduce duplication for reference tests with an `annotationStorage` entry
This commit is contained in:
commit
546902df63
@ -120,10 +120,22 @@ class AnnotationStorage {
|
|||||||
return this.#storage.has(key);
|
return this.#storage.has(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Object | null}
|
||||||
|
*/
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.#storage.size > 0 ? objectFromMap(this.#storage) : null;
|
return this.#storage.size > 0 ? objectFromMap(this.#storage) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} obj
|
||||||
|
*/
|
||||||
|
setAll(obj) {
|
||||||
|
for (const [key, val] of Object.entries(obj)) {
|
||||||
|
this.setValue(key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get size() {
|
get size() {
|
||||||
return this.#storage.size;
|
return this.#storage.size;
|
||||||
}
|
}
|
||||||
|
@ -486,17 +486,12 @@ class Driver {
|
|||||||
let promise = loadingTask.promise;
|
let promise = loadingTask.promise;
|
||||||
|
|
||||||
if (task.save) {
|
if (task.save) {
|
||||||
if (!task.annotationStorage) {
|
|
||||||
promise = Promise.reject(
|
|
||||||
new Error("Missing `annotationStorage` entry.")
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
promise = loadingTask.promise.then(async doc => {
|
promise = loadingTask.promise.then(async doc => {
|
||||||
for (const [key, value] of Object.entries(
|
if (!task.annotationStorage) {
|
||||||
task.annotationStorage
|
throw new Error("Missing `annotationStorage` entry.");
|
||||||
)) {
|
|
||||||
doc.annotationStorage.setValue(key, value);
|
|
||||||
}
|
}
|
||||||
|
doc.annotationStorage.setAll(task.annotationStorage);
|
||||||
|
|
||||||
const data = await doc.saveDocument();
|
const data = await doc.saveDocument();
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
delete task.annotationStorage;
|
delete task.annotationStorage;
|
||||||
@ -504,7 +499,6 @@ class Driver {
|
|||||||
return getDocument(data).promise;
|
return getDocument(data).promise;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
promise.then(
|
promise.then(
|
||||||
async doc => {
|
async doc => {
|
||||||
@ -668,11 +662,7 @@ class Driver {
|
|||||||
pageColors = null;
|
pageColors = null;
|
||||||
|
|
||||||
if (task.annotationStorage) {
|
if (task.annotationStorage) {
|
||||||
const entries = Object.entries(task.annotationStorage),
|
task.pdfDoc.annotationStorage.setAll(task.annotationStorage);
|
||||||
docAnnotationStorage = task.pdfDoc.annotationStorage;
|
|
||||||
for (const [key, value] of entries) {
|
|
||||||
docAnnotationStorage.setValue(key, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let textLayerCanvas, annotationLayerCanvas, annotationLayerContext;
|
let textLayerCanvas, annotationLayerCanvas, annotationLayerContext;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user