mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Move the isEvalSupported
option from the global PDFJS
object and into getDocument
instead
This commit is contained in:
parent
3c2fbdffe6
commit
f3900c4e57
5 changed files with 27 additions and 31 deletions
|
@ -157,6 +157,9 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||
* @property {number} maxImageSize - (optional) The maximum allowed image size
|
||||
* 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.
|
||||
* @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)) {
|
||||
params.maxImageSize = -1;
|
||||
}
|
||||
if (typeof params.isEvalSupported !== 'boolean') {
|
||||
params.isEvalSupported = true;
|
||||
}
|
||||
|
||||
// Set the main-thread verbosity level.
|
||||
setVerbosityLevel(params.verbosity);
|
||||
|
@ -344,7 +350,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||
docBaseUrl: source.docBaseUrl,
|
||||
nativeImageDecoderSupport: source.nativeImageDecoderSupport,
|
||||
ignoreErrors: source.ignoreErrors,
|
||||
isEvalSupported: getDefaultSetting('isEvalSupported'),
|
||||
isEvalSupported: source.isEvalSupported,
|
||||
}).then(function (workerId) {
|
||||
if (worker.destroyed) {
|
||||
throw new Error('Worker was destroyed');
|
||||
|
@ -1806,6 +1812,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
switch (type) {
|
||||
case 'Font':
|
||||
var exportedData = data[2];
|
||||
let params = this._params;
|
||||
|
||||
if ('error' in exportedData) {
|
||||
var exportedError = exportedData.error;
|
||||
|
@ -1823,7 +1830,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
};
|
||||
}
|
||||
var font = new FontFaceObject(exportedData, {
|
||||
isEvalSupported: getDefaultSetting('isEvalSupported'),
|
||||
isEvalSupported: params.isEvalSupported,
|
||||
disableFontFace: getDefaultSetting('disableFontFace'),
|
||||
fontRegistry,
|
||||
});
|
||||
|
|
|
@ -346,8 +346,6 @@ function getDefaultSetting(id) {
|
|||
return globalSettings ? globalSettings.disableFontFace : false;
|
||||
case 'disableCreateObjectURL':
|
||||
return globalSettings ? globalSettings.disableCreateObjectURL : false;
|
||||
case 'isEvalSupported':
|
||||
return globalSettings ? globalSettings.isEvalSupported : true;
|
||||
default:
|
||||
throw new Error('Unknown default setting: ' + id);
|
||||
}
|
||||
|
|
|
@ -336,13 +336,17 @@ var IsEvalSupportedCached = {
|
|||
};
|
||||
|
||||
var FontFaceObject = (function FontFaceObjectClosure() {
|
||||
function FontFaceObject(translatedData, options) {
|
||||
function FontFaceObject(translatedData, { isEvalSupported = true,
|
||||
disableFontFace = false,
|
||||
fontRegistry = null, }) {
|
||||
this.compiledGlyphs = Object.create(null);
|
||||
// importing translated data
|
||||
for (var i in translatedData) {
|
||||
this[i] = translatedData[i];
|
||||
}
|
||||
this.options = options;
|
||||
this.isEvalSupported = isEvalSupported !== false;
|
||||
this.disableFontFace = disableFontFace === true;
|
||||
this.fontRegistry = fontRegistry;
|
||||
}
|
||||
FontFaceObject.prototype = {
|
||||
createNativeFontFace: function FontFaceObject_createNativeFontFace() {
|
||||
|
@ -350,30 +354,20 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
|||
throw new Error('Not implemented: createNativeFontFace');
|
||||
}
|
||||
|
||||
if (!this.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.options.disableFontFace) {
|
||||
this.disableFontFace = true;
|
||||
if (!this.data || this.disableFontFace) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var nativeFontFace = new FontFace(this.loadedName, this.data, {});
|
||||
|
||||
if (this.options.fontRegistry) {
|
||||
this.options.fontRegistry.registerFont(this);
|
||||
if (this.fontRegistry) {
|
||||
this.fontRegistry.registerFont(this);
|
||||
}
|
||||
return nativeFontFace;
|
||||
},
|
||||
|
||||
createFontFaceRule: function FontFaceObject_createFontFaceRule() {
|
||||
if (!this.data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.options.disableFontFace) {
|
||||
this.disableFontFace = true;
|
||||
if (!this.data || this.disableFontFace) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -384,8 +378,8 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
|||
var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
|
||||
var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
|
||||
|
||||
if (this.options.fontRegistry) {
|
||||
this.options.fontRegistry.registerFont(this, url);
|
||||
if (this.fontRegistry) {
|
||||
this.fontRegistry.registerFont(this, url);
|
||||
}
|
||||
|
||||
return rule;
|
||||
|
@ -398,7 +392,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
|||
var current, i, len;
|
||||
|
||||
// If we can, compile cmds into JS for MAXIMUM SPEED
|
||||
if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
|
||||
if (this.isEvalSupported && IsEvalSupportedCached.value) {
|
||||
var args, js = '';
|
||||
for (i = 0, len = cmds.length; i < len; i++) {
|
||||
current = cmds[i];
|
||||
|
|
|
@ -116,14 +116,6 @@ PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
|
|||
PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
|
||||
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.LoopbackPort = LoopbackPort;
|
||||
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue