1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #14372 from Snuffleupagus/BaseViewer-Lang

Move the /Lang handling into the `BaseViewer` (PR 14114 follow-up)
This commit is contained in:
Tim van der Meij 2021-12-15 19:37:50 +01:00 committed by GitHub
commit 274989ab56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 12 deletions

View file

@ -809,7 +809,6 @@ const PDFViewerApplication = {
const { container } = this.appConfig.errorWrapper;
container.hidden = true;
}
this.appConfig.viewerContainer.removeAttribute("lang");
if (!this.pdfLoadingTask) {
return;
@ -1541,10 +1540,6 @@ const PDFViewerApplication = {
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
`(PDF.js: ${version || "-"})`
);
if (info.Language) {
this.appConfig.viewerContainer.lang = info.Language;
}
let pdfTitle = info?.Title;
const metadataTitle = metadata?.get("dc:title");

View file

@ -486,10 +486,7 @@ class BaseViewer {
/**
* Currently only *some* permissions are supported.
*/
#initializePermissions(permissions, pdfDocument) {
if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the permissions resolved.
}
#initializePermissions(permissions) {
if (!permissions) {
return;
}
@ -603,9 +600,12 @@ class BaseViewer {
// viewport for all pages
Promise.all([firstPagePromise, permissionsPromise])
.then(([firstPdfPage, permissions]) => {
if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the first page resolved.
}
this._firstPageCapability.resolve(firstPdfPage);
this._optionalContentConfigPromise = optionalContentConfigPromise;
this.#initializePermissions(permissions, pdfDocument);
this.#initializePermissions(permissions);
const viewerElement =
this._scrollMode === ScrollMode.PAGE ? null : this.viewer;
@ -719,6 +719,15 @@ class BaseViewer {
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) {
this.update();
}
@ -789,6 +798,7 @@ class BaseViewer {
// ... and reset the Scroll mode CSS class(es) afterwards.
this._updateScrollMode();
this.viewer.removeAttribute("lang");
// Reset all PDF document permissions.
this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);