Merge pull request #11806 from Snuffleupagus/pr-10738-followup
[api-minor] Fix the return value of `PDFDocumentProxy.getViewerPreferences` when no viewer preferences are present (PR 10738 follow-up)
This commit is contained in:
commit
b9cce0e0c1
@ -479,7 +479,7 @@ class Catalog {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const obj = this.catDict.get("ViewerPreferences");
|
const obj = this.catDict.get("ViewerPreferences");
|
||||||
const prefs = Object.create(null);
|
let prefs = null;
|
||||||
|
|
||||||
if (isDict(obj)) {
|
if (isDict(obj)) {
|
||||||
for (const key in ViewerPreferencesValidators) {
|
for (const key in ViewerPreferencesValidators) {
|
||||||
@ -583,6 +583,9 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (prefValue !== undefined) {
|
if (prefValue !== undefined) {
|
||||||
|
if (!prefs) {
|
||||||
|
prefs = Object.create(null);
|
||||||
|
}
|
||||||
prefs[key] = prefValue;
|
prefs[key] = prefValue;
|
||||||
} else {
|
} else {
|
||||||
info(`Bad value in ViewerPreferences for "${key}".`);
|
info(`Bad value in ViewerPreferences for "${key}".`);
|
||||||
|
@ -663,7 +663,8 @@ class PDFDocumentProxy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Promise} A promise that is resolved with an {Object} containing
|
* @returns {Promise} A promise that is resolved with an {Object} containing
|
||||||
* the viewer preferences.
|
* the viewer preferences, or `null` when no viewer preferences are present
|
||||||
|
* in the PDF file.
|
||||||
*/
|
*/
|
||||||
getViewerPreferences() {
|
getViewerPreferences() {
|
||||||
return this._transport.getViewerPreferences();
|
return this._transport.getViewerPreferences();
|
||||||
|
@ -24,7 +24,6 @@ import {
|
|||||||
createPromiseCapability,
|
createPromiseCapability,
|
||||||
FontType,
|
FontType,
|
||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
isEmptyObj,
|
|
||||||
MissingPDFException,
|
MissingPDFException,
|
||||||
OPS,
|
OPS,
|
||||||
PasswordException,
|
PasswordException,
|
||||||
@ -846,9 +845,7 @@ describe("api", function () {
|
|||||||
return pdfDoc.getViewerPreferences();
|
return pdfDoc.getViewerPreferences();
|
||||||
})
|
})
|
||||||
.then(function (prefs) {
|
.then(function (prefs) {
|
||||||
expect(
|
expect(prefs).toEqual(null);
|
||||||
typeof prefs === "object" && prefs !== null && isEmptyObj(prefs)
|
|
||||||
).toEqual(true);
|
|
||||||
|
|
||||||
loadingTask.destroy().then(done);
|
loadingTask.destroy().then(done);
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user