mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Move the /Lang handling into the BaseViewer
(PR 14114 follow-up)
In PR 14114 this was only added to the default viewer, which means that in the viewer components the user would need to *manually* implement /Lang handling. This was (obviously) a bad choice, since the viewer components already support e.g. structTrees by default; sorry about overlooking this! To avoid having to make *two* `getMetadata` API-calls[1] very early during initialization, in the default viewer, the API will now cache its result. This will also come in handy elsewhere in the default viewer, e.g. by reducing parsing when opening the "document properties" dialog. --- [1] This not only includes a round-trip to the worker-thread, but also having to re-parse the /Metadata-entry when it exists.
This commit is contained in:
parent
a425c9cfa5
commit
760f765e56
3 changed files with 21 additions and 12 deletions
|
@ -2406,6 +2406,8 @@ class WorkerTransport {
|
|||
|
||||
#pagePromises = new Map();
|
||||
|
||||
#metadataPromise = null;
|
||||
|
||||
constructor(messageHandler, loadingTask, networkStream, params) {
|
||||
this.messageHandler = messageHandler;
|
||||
this.loadingTask = loadingTask;
|
||||
|
@ -2530,6 +2532,7 @@ class WorkerTransport {
|
|||
Promise.all(waitOn).then(() => {
|
||||
this.commonObjs.clear();
|
||||
this.fontLoader.clear();
|
||||
this.#metadataPromise = null;
|
||||
this._getFieldObjectsPromise = null;
|
||||
this._hasJSActionsPromise = null;
|
||||
|
||||
|
@ -3063,7 +3066,7 @@ class WorkerTransport {
|
|||
}
|
||||
|
||||
getMetadata() {
|
||||
return this.messageHandler
|
||||
return (this.#metadataPromise ||= this.messageHandler
|
||||
.sendWithPromise("GetMetadata", null)
|
||||
.then(results => {
|
||||
return {
|
||||
|
@ -3072,7 +3075,7 @@ class WorkerTransport {
|
|||
contentDispositionFilename: this._fullReader?.filename ?? null,
|
||||
contentLength: this._fullReader?.contentLength ?? null,
|
||||
};
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
getMarkInfo() {
|
||||
|
@ -3098,6 +3101,7 @@ class WorkerTransport {
|
|||
if (!keepLoadedFonts) {
|
||||
this.fontLoader.clear();
|
||||
}
|
||||
this.#metadataPromise = null;
|
||||
this._getFieldObjectsPromise = null;
|
||||
this._hasJSActionsPromise = null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue