Move the isEvalSupported
option from the global PDFJS
object and into getDocument
instead
This commit is contained in:
parent
3c2fbdffe6
commit
f3900c4e57
@ -157,6 +157,9 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||||||
* @property {number} maxImageSize - (optional) The maximum allowed image size
|
* @property {number} maxImageSize - (optional) The maximum allowed image size
|
||||||
* in total pixels, i.e. width * height. Images above this value will not be
|
* in total pixels, i.e. width * height. Images above this value will not be
|
||||||
* rendered. Use -1 for no limit, which is also the default value.
|
* rendered. Use -1 for no limit, which is also the default value.
|
||||||
|
* @property {boolean} isEvalSupported - (optional) Determines if we can eval
|
||||||
|
* strings as JS. Primarily used to improve performance of font rendering,
|
||||||
|
* and when parsing PDF functions. The default value is `true`.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -252,6 +255,9 @@ function getDocument(src) {
|
|||||||
if (!Number.isInteger(params.maxImageSize)) {
|
if (!Number.isInteger(params.maxImageSize)) {
|
||||||
params.maxImageSize = -1;
|
params.maxImageSize = -1;
|
||||||
}
|
}
|
||||||
|
if (typeof params.isEvalSupported !== 'boolean') {
|
||||||
|
params.isEvalSupported = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the main-thread verbosity level.
|
// Set the main-thread verbosity level.
|
||||||
setVerbosityLevel(params.verbosity);
|
setVerbosityLevel(params.verbosity);
|
||||||
@ -344,7 +350,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||||||
docBaseUrl: source.docBaseUrl,
|
docBaseUrl: source.docBaseUrl,
|
||||||
nativeImageDecoderSupport: source.nativeImageDecoderSupport,
|
nativeImageDecoderSupport: source.nativeImageDecoderSupport,
|
||||||
ignoreErrors: source.ignoreErrors,
|
ignoreErrors: source.ignoreErrors,
|
||||||
isEvalSupported: getDefaultSetting('isEvalSupported'),
|
isEvalSupported: source.isEvalSupported,
|
||||||
}).then(function (workerId) {
|
}).then(function (workerId) {
|
||||||
if (worker.destroyed) {
|
if (worker.destroyed) {
|
||||||
throw new Error('Worker was destroyed');
|
throw new Error('Worker was destroyed');
|
||||||
@ -1806,6 +1812,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case 'Font':
|
case 'Font':
|
||||||
var exportedData = data[2];
|
var exportedData = data[2];
|
||||||
|
let params = this._params;
|
||||||
|
|
||||||
if ('error' in exportedData) {
|
if ('error' in exportedData) {
|
||||||
var exportedError = exportedData.error;
|
var exportedError = exportedData.error;
|
||||||
@ -1823,7 +1830,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
var font = new FontFaceObject(exportedData, {
|
var font = new FontFaceObject(exportedData, {
|
||||||
isEvalSupported: getDefaultSetting('isEvalSupported'),
|
isEvalSupported: params.isEvalSupported,
|
||||||
disableFontFace: getDefaultSetting('disableFontFace'),
|
disableFontFace: getDefaultSetting('disableFontFace'),
|
||||||
fontRegistry,
|
fontRegistry,
|
||||||
});
|
});
|
||||||
|
@ -346,8 +346,6 @@ function getDefaultSetting(id) {
|
|||||||
return globalSettings ? globalSettings.disableFontFace : false;
|
return globalSettings ? globalSettings.disableFontFace : false;
|
||||||
case 'disableCreateObjectURL':
|
case 'disableCreateObjectURL':
|
||||||
return globalSettings ? globalSettings.disableCreateObjectURL : false;
|
return globalSettings ? globalSettings.disableCreateObjectURL : false;
|
||||||
case 'isEvalSupported':
|
|
||||||
return globalSettings ? globalSettings.isEvalSupported : true;
|
|
||||||
default:
|
default:
|
||||||
throw new Error('Unknown default setting: ' + id);
|
throw new Error('Unknown default setting: ' + id);
|
||||||
}
|
}
|
||||||
|
@ -336,13 +336,17 @@ var IsEvalSupportedCached = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var FontFaceObject = (function FontFaceObjectClosure() {
|
var FontFaceObject = (function FontFaceObjectClosure() {
|
||||||
function FontFaceObject(translatedData, options) {
|
function FontFaceObject(translatedData, { isEvalSupported = true,
|
||||||
|
disableFontFace = false,
|
||||||
|
fontRegistry = null, }) {
|
||||||
this.compiledGlyphs = Object.create(null);
|
this.compiledGlyphs = Object.create(null);
|
||||||
// importing translated data
|
// importing translated data
|
||||||
for (var i in translatedData) {
|
for (var i in translatedData) {
|
||||||
this[i] = translatedData[i];
|
this[i] = translatedData[i];
|
||||||
}
|
}
|
||||||
this.options = options;
|
this.isEvalSupported = isEvalSupported !== false;
|
||||||
|
this.disableFontFace = disableFontFace === true;
|
||||||
|
this.fontRegistry = fontRegistry;
|
||||||
}
|
}
|
||||||
FontFaceObject.prototype = {
|
FontFaceObject.prototype = {
|
||||||
createNativeFontFace: function FontFaceObject_createNativeFontFace() {
|
createNativeFontFace: function FontFaceObject_createNativeFontFace() {
|
||||||
@ -350,30 +354,20 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
|||||||
throw new Error('Not implemented: createNativeFontFace');
|
throw new Error('Not implemented: createNativeFontFace');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.data) {
|
if (!this.data || this.disableFontFace) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.disableFontFace) {
|
|
||||||
this.disableFontFace = true;
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nativeFontFace = new FontFace(this.loadedName, this.data, {});
|
var nativeFontFace = new FontFace(this.loadedName, this.data, {});
|
||||||
|
|
||||||
if (this.options.fontRegistry) {
|
if (this.fontRegistry) {
|
||||||
this.options.fontRegistry.registerFont(this);
|
this.fontRegistry.registerFont(this);
|
||||||
}
|
}
|
||||||
return nativeFontFace;
|
return nativeFontFace;
|
||||||
},
|
},
|
||||||
|
|
||||||
createFontFaceRule: function FontFaceObject_createFontFaceRule() {
|
createFontFaceRule: function FontFaceObject_createFontFaceRule() {
|
||||||
if (!this.data) {
|
if (!this.data || this.disableFontFace) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.disableFontFace) {
|
|
||||||
this.disableFontFace = true;
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,8 +378,8 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
|||||||
var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
|
var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
|
||||||
var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
|
var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
|
||||||
|
|
||||||
if (this.options.fontRegistry) {
|
if (this.fontRegistry) {
|
||||||
this.options.fontRegistry.registerFont(this, url);
|
this.fontRegistry.registerFont(this, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rule;
|
return rule;
|
||||||
@ -398,7 +392,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
|||||||
var current, i, len;
|
var current, i, len;
|
||||||
|
|
||||||
// If we can, compile cmds into JS for MAXIMUM SPEED
|
// If we can, compile cmds into JS for MAXIMUM SPEED
|
||||||
if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
|
if (this.isEvalSupported && IsEvalSupportedCached.value) {
|
||||||
var args, js = '';
|
var args, js = '';
|
||||||
for (i = 0, len = cmds.length; i < len; i++) {
|
for (i = 0, len = cmds.length; i < len; i++) {
|
||||||
current = cmds[i];
|
current = cmds[i];
|
||||||
|
@ -116,14 +116,6 @@ PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
|
|||||||
PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
|
PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
|
||||||
false : PDFJS.disableCreateObjectURL);
|
false : PDFJS.disableCreateObjectURL);
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if we can eval strings as JS. Primarily used to improve
|
|
||||||
* performance for font rendering.
|
|
||||||
* @var {boolean}
|
|
||||||
*/
|
|
||||||
PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
|
|
||||||
true : PDFJS.isEvalSupported);
|
|
||||||
|
|
||||||
PDFJS.getDocument = getDocument;
|
PDFJS.getDocument = getDocument;
|
||||||
PDFJS.LoopbackPort = LoopbackPort;
|
PDFJS.LoopbackPort = LoopbackPort;
|
||||||
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
||||||
|
@ -139,6 +139,11 @@ const defaultOptions = {
|
|||||||
'../external/bcmaps/' : '../web/cmaps/'),
|
'../external/bcmaps/' : '../web/cmaps/'),
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API,
|
||||||
},
|
},
|
||||||
|
isEvalSupported: {
|
||||||
|
/** @type {boolean} */
|
||||||
|
value: true,
|
||||||
|
kind: OptionKind.API,
|
||||||
|
},
|
||||||
maxImageSize: {
|
maxImageSize: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: -1,
|
value: -1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user