Move the disableFontFace option from the global PDFJS object and into getDocument instead

This commit is contained in:
Jonas Jenwald 2018-02-17 21:57:20 +01:00
parent f3900c4e57
commit c7c583583b
5 changed files with 19 additions and 17 deletions

View File

@ -160,6 +160,10 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
* @property {boolean} isEvalSupported - (optional) Determines if we can eval * @property {boolean} isEvalSupported - (optional) Determines if we can eval
* strings as JS. Primarily used to improve performance of font rendering, * strings as JS. Primarily used to improve performance of font rendering,
* and when parsing PDF functions. The default value is `true`. * 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') { if (typeof params.isEvalSupported !== 'boolean') {
params.isEvalSupported = true; params.isEvalSupported = true;
} }
if (typeof params.disableFontFace !== 'boolean') {
params.disableFontFace = false;
}
// Set the main-thread verbosity level. // Set the main-thread verbosity level.
setVerbosityLevel(params.verbosity); setVerbosityLevel(params.verbosity);
@ -344,7 +351,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
length: source.length, length: source.length,
}, },
maxImageSize: source.maxImageSize, maxImageSize: source.maxImageSize,
disableFontFace: getDefaultSetting('disableFontFace'), disableFontFace: source.disableFontFace,
disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'), disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
postMessageTransfers: worker.postMessageTransfers, postMessageTransfers: worker.postMessageTransfers,
docBaseUrl: source.docBaseUrl, docBaseUrl: source.docBaseUrl,
@ -1831,7 +1838,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
} }
var font = new FontFaceObject(exportedData, { var font = new FontFaceObject(exportedData, {
isEvalSupported: params.isEvalSupported, isEvalSupported: params.isEvalSupported,
disableFontFace: getDefaultSetting('disableFontFace'), disableFontFace: params.disableFontFace,
fontRegistry, fontRegistry,
}); });
var fontReady = (fontObjs) => { var fontReady = (fontObjs) => {

View File

@ -342,8 +342,6 @@ function getDefaultSetting(id) {
return globalSettings ? globalSettings.disableStream : false; return globalSettings ? globalSettings.disableStream : false;
case 'disableRange': case 'disableRange':
return globalSettings ? globalSettings.disableRange : false; return globalSettings ? globalSettings.disableRange : false;
case 'disableFontFace':
return globalSettings ? globalSettings.disableFontFace : false;
case 'disableCreateObjectURL': case 'disableCreateObjectURL':
return globalSettings ? globalSettings.disableCreateObjectURL : false; return globalSettings ? globalSettings.disableCreateObjectURL : false;
default: default:

View File

@ -65,15 +65,6 @@ PDFJS.Util = Util;
PDFJS.PageViewport = PageViewport; PDFJS.PageViewport = PageViewport;
PDFJS.createPromiseCapability = createPromiseCapability; 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 * 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. * supports partial content requests then the PDF will be fetched in chunks.

View File

@ -210,10 +210,10 @@ let PDFViewerApplication = {
PDFJS.disableAutoFetch = value; PDFJS.disableAutoFetch = value;
}), }),
preferences.get('disableFontFace').then(function resolved(value) { preferences.get('disableFontFace').then(function resolved(value) {
if (PDFJS.disableFontFace === true) { if (AppOptions.get('disableFontFace') === true) {
return; return;
} }
PDFJS.disableFontFace = value; AppOptions.set('disableFontFace', value);
}), }),
preferences.get('useOnlyCssZoom').then(function resolved(value) { preferences.get('useOnlyCssZoom').then(function resolved(value) {
AppOptions.set('useOnlyCssZoom', value); AppOptions.set('useOnlyCssZoom', value);
@ -269,7 +269,8 @@ let PDFViewerApplication = {
PDFJS.disableAutoFetch = (hashParams['disableautofetch'] === 'true'); PDFJS.disableAutoFetch = (hashParams['disableautofetch'] === 'true');
} }
if ('disablefontface' in hashParams) { if ('disablefontface' in hashParams) {
PDFJS.disableFontFace = (hashParams['disablefontface'] === 'true'); AppOptions.set('disableFontFace',
hashParams['disablefontface'] === 'true');
} }
if ('disablehistory' in hashParams) { if ('disablehistory' in hashParams) {
AppOptions.set('disableHistory', AppOptions.set('disableHistory',
@ -1604,7 +1605,7 @@ function webViewerInitialized() {
if (typeof PDFJSDev !== 'undefined' && if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('FIREFOX || MOZCENTRAL') && PDFJSDev.test('FIREFOX || MOZCENTRAL') &&
!PDFViewerApplication.supportsDocumentFonts) { !PDFViewerApplication.supportsDocumentFonts) {
PDFJS.disableFontFace = true; AppOptions.set('disableFontFace', true);
PDFViewerApplication.l10n.get('web_fonts_disabled', null, PDFViewerApplication.l10n.get('web_fonts_disabled', null,
'Web fonts are disabled: unable to use embedded PDF fonts.'). 'Web fonts are disabled: unable to use embedded PDF fonts.').
then((msg) => { then((msg) => {

View File

@ -139,6 +139,11 @@ const defaultOptions = {
'../external/bcmaps/' : '../web/cmaps/'), '../external/bcmaps/' : '../web/cmaps/'),
kind: OptionKind.API, kind: OptionKind.API,
}, },
disableFontFace: {
/** @type {boolean} */
value: false,
kind: OptionKind.API,
},
isEvalSupported: { isEvalSupported: {
/** @type {boolean} */ /** @type {boolean} */
value: true, value: true,