Merge pull request #19674 from Snuffleupagus/core-document-more-async
Introduce more `async` code in the `src/core/document.js` file
This commit is contained in:
commit
00e3a4d87a
@ -251,8 +251,9 @@ class Page {
|
||||
/**
|
||||
* @returns {Promise<BaseStream>}
|
||||
*/
|
||||
getContentStream() {
|
||||
return this.pdfManager.ensure(this, "content").then(content => {
|
||||
async getContentStream() {
|
||||
const content = await this.pdfManager.ensure(this, "content");
|
||||
|
||||
if (content instanceof BaseStream) {
|
||||
return content;
|
||||
}
|
||||
@ -264,7 +265,6 @@ class Page {
|
||||
}
|
||||
// Replace non-existent page content with empty content.
|
||||
return new NullStream();
|
||||
});
|
||||
}
|
||||
|
||||
get xfaData() {
|
||||
@ -375,7 +375,7 @@ class Page {
|
||||
}
|
||||
}
|
||||
|
||||
save(handler, task, annotationStorage, changes) {
|
||||
async save(handler, task, annotationStorage, changes) {
|
||||
const partialEvaluator = new PartialEvaluator({
|
||||
xref: this.xref,
|
||||
handler,
|
||||
@ -392,7 +392,8 @@ class Page {
|
||||
|
||||
// Fetch the page's annotations and save the content
|
||||
// in case of interactive form fields.
|
||||
return this._parsedAnnotations.then(function (annotations) {
|
||||
const annotations = await this._parsedAnnotations;
|
||||
|
||||
const promises = [];
|
||||
for (const annotation of annotations) {
|
||||
promises.push(
|
||||
@ -407,22 +408,18 @@ class Page {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
});
|
||||
}
|
||||
|
||||
loadResources(keys) {
|
||||
async loadResources(keys) {
|
||||
// TODO: add async `_getInheritableProperty` and remove this.
|
||||
this.resourcesPromise ||= this.pdfManager.ensure(this, "resources");
|
||||
await (this.resourcesPromise ??= this.pdfManager.ensure(this, "resources"));
|
||||
|
||||
return this.resourcesPromise.then(() => {
|
||||
const objectLoader = new ObjectLoader(this.resources, keys, this.xref);
|
||||
return objectLoader.load();
|
||||
});
|
||||
await objectLoader.load();
|
||||
}
|
||||
|
||||
getOperatorList({
|
||||
async getOperatorList({
|
||||
handler,
|
||||
sink,
|
||||
task,
|
||||
@ -527,7 +524,7 @@ class Page {
|
||||
const pageListPromise = Promise.all([
|
||||
contentStreamPromise,
|
||||
resourcesPromise,
|
||||
]).then(([contentStream]) => {
|
||||
]).then(async ([contentStream]) => {
|
||||
const opList = new OperatorList(intent, sink);
|
||||
|
||||
handler.send("StartRenderPage", {
|
||||
@ -539,27 +536,27 @@ class Page {
|
||||
cacheKey,
|
||||
});
|
||||
|
||||
return partialEvaluator
|
||||
.getOperatorList({
|
||||
await partialEvaluator.getOperatorList({
|
||||
stream: contentStream,
|
||||
task,
|
||||
resources: this.resources,
|
||||
operatorList: opList,
|
||||
})
|
||||
.then(() => opList);
|
||||
});
|
||||
return opList;
|
||||
});
|
||||
|
||||
// Fetch the page's annotations and add their operator lists to the
|
||||
// page's operator list to render them.
|
||||
return Promise.all([
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [pageOpList, annotations, newAnnotations] = await Promise.all([
|
||||
pageListPromise,
|
||||
this._parsedAnnotations,
|
||||
newAnnotationsPromise,
|
||||
]).then(function ([pageOpList, annotations, newAnnotations]) {
|
||||
]);
|
||||
|
||||
if (newAnnotations) {
|
||||
// Some annotations can already exist (if it has the refToReplace
|
||||
// property). In this case, we replace the old annotation by the new
|
||||
// one.
|
||||
// property). In this case, we replace the old annotation by the new one.
|
||||
annotations = annotations.filter(
|
||||
a => !(a.ref && deletedAnnotations.has(a.ref))
|
||||
);
|
||||
@ -604,12 +601,7 @@ class Page {
|
||||
) {
|
||||
opListPromises.push(
|
||||
annotation
|
||||
.getOperatorList(
|
||||
partialEvaluator,
|
||||
task,
|
||||
intent,
|
||||
annotationStorage
|
||||
)
|
||||
.getOperatorList(partialEvaluator, task, intent, annotationStorage)
|
||||
.catch(function (reason) {
|
||||
warn(
|
||||
"getOperatorList - ignoring annotation data during " +
|
||||
@ -625,7 +617,7 @@ class Page {
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(opListPromises).then(function (opLists) {
|
||||
const opLists = await Promise.all(opListPromises);
|
||||
let form = false,
|
||||
canvas = false;
|
||||
|
||||
@ -640,8 +632,6 @@ class Page {
|
||||
/* separateAnnots = */ { form, canvas }
|
||||
);
|
||||
return { length: pageOpList.totalLength };
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async extractTextContent({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user