mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Attempt to provide better default values for the disableFontFace
/nativeImageDecoderSupport
API options in Node.js
This should provide a better out-of-the-box experience when using PDF.js in a Node.js environment, since it's missing native support for both `@font-face` and `Image`. Please note that this change *only* affects the default values, hence it's still possible for an API consumer to override those values when calling `getDocument`. Also, prevents "ReferenceError: document is not defined" errors, when running the unit-tests in Node.js/Travis.
This commit is contained in:
parent
dcc7f33ee7
commit
0ecc22cb04
4 changed files with 22 additions and 19 deletions
|
@ -274,7 +274,9 @@ function getDocument(src) {
|
|||
const NativeImageDecoderValues = Object.values(NativeImageDecoding);
|
||||
if (params.nativeImageDecoderSupport === undefined ||
|
||||
!NativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) {
|
||||
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
|
||||
params.nativeImageDecoderSupport =
|
||||
(apiCompatibilityParams.nativeImageDecoderSupport ||
|
||||
NativeImageDecoding.DECODE);
|
||||
}
|
||||
if (!Number.isInteger(params.maxImageSize)) {
|
||||
params.maxImageSize = -1;
|
||||
|
@ -283,7 +285,7 @@ function getDocument(src) {
|
|||
params.isEvalSupported = true;
|
||||
}
|
||||
if (typeof params.disableFontFace !== 'boolean') {
|
||||
params.disableFontFace = false;
|
||||
params.disableFontFace = apiCompatibilityParams.disableFontFace || false;
|
||||
}
|
||||
|
||||
if (typeof params.disableRange !== 'boolean') {
|
||||
|
@ -2168,6 +2170,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
disableStream: params.disableStream,
|
||||
disableAutoFetch: params.disableAutoFetch,
|
||||
disableCreateObjectURL: params.disableCreateObjectURL,
|
||||
disableFontFace: params.disableFontFace,
|
||||
nativeImageDecoderSupport: params.nativeImageDecoderSupport,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
let compatibilityParams = Object.create(null);
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
const isNodeJS = require('../shared/is_node');
|
||||
|
||||
const userAgent =
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent) || '';
|
||||
const isIE = /Trident/.test(userAgent);
|
||||
|
@ -42,9 +44,15 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||
compatibilityParams.disableStream = true;
|
||||
}
|
||||
})();
|
||||
}
|
||||
const apiCompatibilityParams = Object.freeze(compatibilityParams);
|
||||
|
||||
export {
|
||||
apiCompatibilityParams,
|
||||
};
|
||||
// Support: Node.js
|
||||
(function checkFontFaceAndImage() {
|
||||
// Node.js is missing native support for `@font-face` and `Image`.
|
||||
if (isNodeJS()) {
|
||||
compatibilityParams.disableFontFace = true;
|
||||
compatibilityParams.nativeImageDecoderSupport = 'none';
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
exports.apiCompatibilityParams = Object.freeze(compatibilityParams);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue