Merge pull request #14372 from Snuffleupagus/BaseViewer-Lang
Move the /Lang handling into the `BaseViewer` (PR 14114 follow-up)
This commit is contained in:
commit
274989ab56
@ -2406,6 +2406,8 @@ class WorkerTransport {
|
|||||||
|
|
||||||
#pagePromises = new Map();
|
#pagePromises = new Map();
|
||||||
|
|
||||||
|
#metadataPromise = null;
|
||||||
|
|
||||||
constructor(messageHandler, loadingTask, networkStream, params) {
|
constructor(messageHandler, loadingTask, networkStream, params) {
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
this.loadingTask = loadingTask;
|
this.loadingTask = loadingTask;
|
||||||
@ -2530,6 +2532,7 @@ class WorkerTransport {
|
|||||||
Promise.all(waitOn).then(() => {
|
Promise.all(waitOn).then(() => {
|
||||||
this.commonObjs.clear();
|
this.commonObjs.clear();
|
||||||
this.fontLoader.clear();
|
this.fontLoader.clear();
|
||||||
|
this.#metadataPromise = null;
|
||||||
this._getFieldObjectsPromise = null;
|
this._getFieldObjectsPromise = null;
|
||||||
this._hasJSActionsPromise = null;
|
this._hasJSActionsPromise = null;
|
||||||
|
|
||||||
@ -3063,7 +3066,7 @@ class WorkerTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMetadata() {
|
getMetadata() {
|
||||||
return this.messageHandler
|
return (this.#metadataPromise ||= this.messageHandler
|
||||||
.sendWithPromise("GetMetadata", null)
|
.sendWithPromise("GetMetadata", null)
|
||||||
.then(results => {
|
.then(results => {
|
||||||
return {
|
return {
|
||||||
@ -3072,7 +3075,7 @@ class WorkerTransport {
|
|||||||
contentDispositionFilename: this._fullReader?.filename ?? null,
|
contentDispositionFilename: this._fullReader?.filename ?? null,
|
||||||
contentLength: this._fullReader?.contentLength ?? null,
|
contentLength: this._fullReader?.contentLength ?? null,
|
||||||
};
|
};
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
getMarkInfo() {
|
getMarkInfo() {
|
||||||
@ -3098,6 +3101,7 @@ class WorkerTransport {
|
|||||||
if (!keepLoadedFonts) {
|
if (!keepLoadedFonts) {
|
||||||
this.fontLoader.clear();
|
this.fontLoader.clear();
|
||||||
}
|
}
|
||||||
|
this.#metadataPromise = null;
|
||||||
this._getFieldObjectsPromise = null;
|
this._getFieldObjectsPromise = null;
|
||||||
this._hasJSActionsPromise = null;
|
this._hasJSActionsPromise = null;
|
||||||
}
|
}
|
||||||
|
@ -809,7 +809,6 @@ const PDFViewerApplication = {
|
|||||||
const { container } = this.appConfig.errorWrapper;
|
const { container } = this.appConfig.errorWrapper;
|
||||||
container.hidden = true;
|
container.hidden = true;
|
||||||
}
|
}
|
||||||
this.appConfig.viewerContainer.removeAttribute("lang");
|
|
||||||
|
|
||||||
if (!this.pdfLoadingTask) {
|
if (!this.pdfLoadingTask) {
|
||||||
return;
|
return;
|
||||||
@ -1541,10 +1540,6 @@ const PDFViewerApplication = {
|
|||||||
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
|
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
|
||||||
`(PDF.js: ${version || "-"})`
|
`(PDF.js: ${version || "-"})`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (info.Language) {
|
|
||||||
this.appConfig.viewerContainer.lang = info.Language;
|
|
||||||
}
|
|
||||||
let pdfTitle = info?.Title;
|
let pdfTitle = info?.Title;
|
||||||
|
|
||||||
const metadataTitle = metadata?.get("dc:title");
|
const metadataTitle = metadata?.get("dc:title");
|
||||||
|
@ -486,10 +486,7 @@ class BaseViewer {
|
|||||||
/**
|
/**
|
||||||
* Currently only *some* permissions are supported.
|
* Currently only *some* permissions are supported.
|
||||||
*/
|
*/
|
||||||
#initializePermissions(permissions, pdfDocument) {
|
#initializePermissions(permissions) {
|
||||||
if (pdfDocument !== this.pdfDocument) {
|
|
||||||
return; // The document was closed while the permissions resolved.
|
|
||||||
}
|
|
||||||
if (!permissions) {
|
if (!permissions) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -603,9 +600,12 @@ class BaseViewer {
|
|||||||
// viewport for all pages
|
// viewport for all pages
|
||||||
Promise.all([firstPagePromise, permissionsPromise])
|
Promise.all([firstPagePromise, permissionsPromise])
|
||||||
.then(([firstPdfPage, permissions]) => {
|
.then(([firstPdfPage, permissions]) => {
|
||||||
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
|
return; // The document was closed while the first page resolved.
|
||||||
|
}
|
||||||
this._firstPageCapability.resolve(firstPdfPage);
|
this._firstPageCapability.resolve(firstPdfPage);
|
||||||
this._optionalContentConfigPromise = optionalContentConfigPromise;
|
this._optionalContentConfigPromise = optionalContentConfigPromise;
|
||||||
this.#initializePermissions(permissions, pdfDocument);
|
this.#initializePermissions(permissions);
|
||||||
|
|
||||||
const viewerElement =
|
const viewerElement =
|
||||||
this._scrollMode === ScrollMode.PAGE ? null : this.viewer;
|
this._scrollMode === ScrollMode.PAGE ? null : this.viewer;
|
||||||
@ -719,6 +719,15 @@ class BaseViewer {
|
|||||||
|
|
||||||
this.eventBus.dispatch("pagesinit", { source: this });
|
this.eventBus.dispatch("pagesinit", { source: this });
|
||||||
|
|
||||||
|
pdfDocument.getMetadata().then(({ info }) => {
|
||||||
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
|
return; // The document was closed while the metadata resolved.
|
||||||
|
}
|
||||||
|
if (info.Language) {
|
||||||
|
this.viewer.lang = info.Language;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (this.defaultRenderingQueue) {
|
if (this.defaultRenderingQueue) {
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
@ -789,6 +798,7 @@ class BaseViewer {
|
|||||||
// ... and reset the Scroll mode CSS class(es) afterwards.
|
// ... and reset the Scroll mode CSS class(es) afterwards.
|
||||||
this._updateScrollMode();
|
this._updateScrollMode();
|
||||||
|
|
||||||
|
this.viewer.removeAttribute("lang");
|
||||||
// Reset all PDF document permissions.
|
// Reset all PDF document permissions.
|
||||||
this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user