From c7c583583bcd403da978508b90e9121801309cba Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 17 Feb 2018 21:57:20 +0100 Subject: [PATCH] Move the `disableFontFace` option from the global `PDFJS` object and into `getDocument` instead --- src/display/api.js | 11 +++++++++-- src/display/dom_utils.js | 2 -- src/display/global.js | 9 --------- web/app.js | 9 +++++---- web/app_options.js | 5 +++++ 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 7dc3cec67..4a32bd7c7 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -160,6 +160,10 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { * @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`. + * @property {boolean} disableFontFace - (optional) By default fonts are + * converted to OpenType fonts and loaded via font face rules. If disabled, + * fonts will be rendered using a built-in font renderer that constructs the + * glyphs with primitive path commands. The default value is `false`. */ /** @@ -258,6 +262,9 @@ function getDocument(src) { if (typeof params.isEvalSupported !== 'boolean') { params.isEvalSupported = true; } + if (typeof params.disableFontFace !== 'boolean') { + params.disableFontFace = false; + } // Set the main-thread verbosity level. setVerbosityLevel(params.verbosity); @@ -344,7 +351,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { length: source.length, }, maxImageSize: source.maxImageSize, - disableFontFace: getDefaultSetting('disableFontFace'), + disableFontFace: source.disableFontFace, disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'), postMessageTransfers: worker.postMessageTransfers, docBaseUrl: source.docBaseUrl, @@ -1831,7 +1838,7 @@ var WorkerTransport = (function WorkerTransportClosure() { } var font = new FontFaceObject(exportedData, { isEvalSupported: params.isEvalSupported, - disableFontFace: getDefaultSetting('disableFontFace'), + disableFontFace: params.disableFontFace, fontRegistry, }); var fontReady = (fontObjs) => { diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index ea88ad6f7..a2b9b6ebd 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -342,8 +342,6 @@ function getDefaultSetting(id) { return globalSettings ? globalSettings.disableStream : false; case 'disableRange': return globalSettings ? globalSettings.disableRange : false; - case 'disableFontFace': - return globalSettings ? globalSettings.disableFontFace : false; case 'disableCreateObjectURL': return globalSettings ? globalSettings.disableCreateObjectURL : false; default: diff --git a/src/display/global.js b/src/display/global.js index 725ace290..98b8b2dcf 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -65,15 +65,6 @@ PDFJS.Util = Util; PDFJS.PageViewport = PageViewport; PDFJS.createPromiseCapability = createPromiseCapability; -/** - * By default fonts are converted to OpenType fonts and loaded via font face - * rules. If disabled, the font will be rendered using a built in font - * renderer that constructs the glyphs with primitive path commands. - * @var {boolean} - */ -PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ? - false : PDFJS.disableFontFace); - /** * Disable range request loading of PDF files. When enabled and if the server * supports partial content requests then the PDF will be fetched in chunks. diff --git a/web/app.js b/web/app.js index cfcbdbaa7..88da0aaa9 100644 --- a/web/app.js +++ b/web/app.js @@ -210,10 +210,10 @@ let PDFViewerApplication = { PDFJS.disableAutoFetch = value; }), preferences.get('disableFontFace').then(function resolved(value) { - if (PDFJS.disableFontFace === true) { + if (AppOptions.get('disableFontFace') === true) { return; } - PDFJS.disableFontFace = value; + AppOptions.set('disableFontFace', value); }), preferences.get('useOnlyCssZoom').then(function resolved(value) { AppOptions.set('useOnlyCssZoom', value); @@ -269,7 +269,8 @@ let PDFViewerApplication = { PDFJS.disableAutoFetch = (hashParams['disableautofetch'] === 'true'); } if ('disablefontface' in hashParams) { - PDFJS.disableFontFace = (hashParams['disablefontface'] === 'true'); + AppOptions.set('disableFontFace', + hashParams['disablefontface'] === 'true'); } if ('disablehistory' in hashParams) { AppOptions.set('disableHistory', @@ -1604,7 +1605,7 @@ function webViewerInitialized() { if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL') && !PDFViewerApplication.supportsDocumentFonts) { - PDFJS.disableFontFace = true; + AppOptions.set('disableFontFace', true); PDFViewerApplication.l10n.get('web_fonts_disabled', null, 'Web fonts are disabled: unable to use embedded PDF fonts.'). then((msg) => { diff --git a/web/app_options.js b/web/app_options.js index 432e0c5e8..2e56a8b98 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -139,6 +139,11 @@ const defaultOptions = { '../external/bcmaps/' : '../web/cmaps/'), kind: OptionKind.API, }, + disableFontFace: { + /** @type {boolean} */ + value: false, + kind: OptionKind.API, + }, isEvalSupported: { /** @type {boolean} */ value: true,