mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Reduce duplication for reference tests with an annotationStorage
entry
Currently we duplicate the same code more than once in the `test/driver.js` file, which we can avoid by adding a new `AnnotationStorage` helper method instead.
This commit is contained in:
parent
f66cbb0b5e
commit
8026ed6b0a
2 changed files with 24 additions and 22 deletions
|
@ -486,24 +486,18 @@ class Driver {
|
|||
let promise = loadingTask.promise;
|
||||
|
||||
if (task.save) {
|
||||
if (!task.annotationStorage) {
|
||||
promise = Promise.reject(
|
||||
new Error("Missing `annotationStorage` entry.")
|
||||
);
|
||||
} else {
|
||||
promise = loadingTask.promise.then(async doc => {
|
||||
for (const [key, value] of Object.entries(
|
||||
task.annotationStorage
|
||||
)) {
|
||||
doc.annotationStorage.setValue(key, value);
|
||||
}
|
||||
const data = await doc.saveDocument();
|
||||
await loadingTask.destroy();
|
||||
delete task.annotationStorage;
|
||||
promise = loadingTask.promise.then(async doc => {
|
||||
if (!task.annotationStorage) {
|
||||
throw new Error("Missing `annotationStorage` entry.");
|
||||
}
|
||||
doc.annotationStorage.setAll(task.annotationStorage);
|
||||
|
||||
return getDocument(data).promise;
|
||||
});
|
||||
}
|
||||
const data = await doc.saveDocument();
|
||||
await loadingTask.destroy();
|
||||
delete task.annotationStorage;
|
||||
|
||||
return getDocument(data).promise;
|
||||
});
|
||||
}
|
||||
|
||||
promise.then(
|
||||
|
@ -668,11 +662,7 @@ class Driver {
|
|||
pageColors = null;
|
||||
|
||||
if (task.annotationStorage) {
|
||||
const entries = Object.entries(task.annotationStorage),
|
||||
docAnnotationStorage = task.pdfDoc.annotationStorage;
|
||||
for (const [key, value] of entries) {
|
||||
docAnnotationStorage.setValue(key, value);
|
||||
}
|
||||
task.pdfDoc.annotationStorage.setAll(task.annotationStorage);
|
||||
}
|
||||
|
||||
let textLayerCanvas, annotationLayerCanvas, annotationLayerContext;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue