Move all PDFJS.xxx settings into display/global.

This commit is contained in:
Yury Delendik 2016-03-28 14:49:22 -05:00
parent 6c9f418aae
commit 1d12aed5ca
17 changed files with 538 additions and 403 deletions

View file

@ -21,23 +21,23 @@
define('pdfjs/display/api', ['exports', 'pdfjs/shared/util',
'pdfjs/display/font_loader', 'pdfjs/display/canvas',
'pdfjs/display/metadata', 'pdfjs/display/dom_utils',
'pdfjs/display/global', 'require'], factory);
'require'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), require('./font_loader.js'),
require('./canvas.js'), require('./metadata.js'),
require('./dom_utils.js'), require('./global.js'));
require('./dom_utils.js'));
} else {
factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils,
root.pdfjsDisplayGlobal);
root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils);
}
}(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
displayMetadata, displayDOMUtils, displayGlobal, amdRequire) {
displayMetadata, displayDOMUtils, amdRequire) {
var InvalidPDFException = sharedUtil.InvalidPDFException;
var MessageHandler = sharedUtil.MessageHandler;
var MissingPDFException = sharedUtil.MissingPDFException;
var PageViewport = sharedUtil.PageViewport;
var PasswordResponses = sharedUtil.PasswordResponses;
var PasswordException = sharedUtil.PasswordException;
var StatTimer = sharedUtil.StatTimer;
@ -54,17 +54,21 @@ var isArrayBuffer = sharedUtil.isArrayBuffer;
var isSameOrigin = sharedUtil.isSameOrigin;
var loadJpegStream = sharedUtil.loadJpegStream;
var stringToBytes = sharedUtil.stringToBytes;
var globalScope = sharedUtil.globalScope;
var warn = sharedUtil.warn;
var FontFaceObject = displayFontLoader.FontFaceObject;
var FontLoader = displayFontLoader.FontLoader;
var CanvasGraphics = displayCanvas.CanvasGraphics;
var createScratchCanvas = displayCanvas.createScratchCanvas;
var Metadata = displayMetadata.Metadata;
var PDFJS = displayGlobal.PDFJS;
var globalScope = displayGlobal.globalScope;
var getDefaultSetting = displayDOMUtils.getDefaultSetting;
var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
var isWorkerDisabled = false;
var workerSrc;
var isPostMessageTransfersDisabled = false;
//#if PRODUCTION && !SINGLE_FILE
//#if GENERIC
//#include ../src/frameworks.js
@ -73,183 +77,6 @@ var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
//#endif
//#endif
/**
* The maximum allowed image size in total pixels e.g. width * height. Images
* above this value will not be drawn. Use -1 for no limit.
* @var {number}
*/
PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
-1 : PDFJS.maxImageSize);
/**
* The url of where the predefined Adobe CMaps are located. Include trailing
* slash.
* @var {string}
*/
PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
/**
* Specifies if CMaps are binary packed.
* @var {boolean}
*/
PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
/**
* 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);
/**
* Path for image resources, mainly for annotation icons. Include trailing
* slash.
* @var {string}
*/
PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
'' : PDFJS.imageResourcesPath);
/**
* Disable the web worker and run all code on the main thread. This will happen
* automatically if the browser doesn't support workers or sending typed arrays
* to workers.
* @var {boolean}
*/
PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
false : PDFJS.disableWorker);
/**
* Path and filename of the worker file. Required when the worker is enabled in
* development mode. If unspecified in the production build, the worker will be
* loaded based on the location of the pdf.js file. It is recommended that
* the workerSrc is set in a custom application to prevent issues caused by
* third-party frameworks and libraries.
* @var {string}
*/
PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
/**
* 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.
* Enabled (false) by default.
* @var {boolean}
*/
PDFJS.disableRange = (PDFJS.disableRange === undefined ?
false : PDFJS.disableRange);
/**
* Disable streaming of PDF file data. By default PDF.js attempts to load PDF
* in chunks. This default behavior can be disabled.
* @var {boolean}
*/
PDFJS.disableStream = (PDFJS.disableStream === undefined ?
false : PDFJS.disableStream);
/**
* Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
* will automatically keep fetching more data even if it isn't needed to display
* the current page. This default behavior can be disabled.
*
* NOTE: It is also necessary to disable streaming, see above,
* in order for disabling of pre-fetching to work correctly.
* @var {boolean}
*/
PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
false : PDFJS.disableAutoFetch);
/**
* Enables special hooks for debugging PDF.js.
* @var {boolean}
*/
PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
/**
* Enables transfer usage in postMessage for ArrayBuffers.
* @var {boolean}
*/
PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
true : PDFJS.postMessageTransfers);
/**
* Disables URL.createObjectURL usage.
* @var {boolean}
*/
PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
false : PDFJS.disableCreateObjectURL);
/**
* Disables WebGL usage.
* @var {boolean}
*/
PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
true : PDFJS.disableWebGL);
/**
* Disables fullscreen support, and by extension Presentation Mode,
* in browsers which support the fullscreen API.
* @var {boolean}
*/
PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
false : PDFJS.disableFullscreen);
/**
* Enables CSS only zooming.
* @var {boolean}
*/
PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
false : PDFJS.useOnlyCssZoom);
/**
* The maximum supported canvas size in total pixels e.g. width * height.
* The default value is 4096 * 4096. Use -1 for no limit.
* @var {number}
*/
PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
16777216 : PDFJS.maxCanvasPixels);
/**
* (Deprecated) Opens external links in a new window if enabled.
* The default behavior opens external links in the PDF.js window.
*
* NOTE: This property has been deprecated, please use
* `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
* @var {boolean}
*/
PDFJS.openExternalLinksInNewWindow = (
PDFJS.openExternalLinksInNewWindow === undefined ?
false : PDFJS.openExternalLinksInNewWindow);
/**
* Specifies the |target| attribute for external links.
* The constants from PDFJS.LinkTarget should be used:
* - NONE [default]
* - SELF
* - BLANK
* - PARENT
* - TOP
* @var {number}
*/
PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
/**
* Specifies the |rel| attribute for external links. Defaults to stripping
* the referrer.
* @var {string}
*/
PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
'noreferrer' : PDFJS.externalLinkRel);
/**
* 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);
/**
* Document initialization / loading parameters object.
*
@ -309,10 +136,8 @@ PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
*
* @return {PDFDocumentLoadingTask}
*/
PDFJS.getDocument = function getDocument(src,
pdfDataRangeTransport,
passwordCallback,
progressCallback) {
function getDocument(src, pdfDataRangeTransport,
passwordCallback, progressCallback) {
var task = new PDFDocumentLoadingTask();
// Support of the obsolete arguments (for compatibility with API v1.0)
@ -413,7 +238,7 @@ PDFJS.getDocument = function getDocument(src,
}).catch(task._capability.reject);
return task;
};
}
/**
* Starts fetching of specified PDF document/data.
@ -430,8 +255,8 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
return Promise.reject(new Error('Worker was destroyed'));
}
source.disableAutoFetch = PDFJS.disableAutoFetch;
source.disableStream = PDFJS.disableStream;
source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
source.disableStream = getDefaultSetting('disableStream');
source.chunkedViewerLoading = !!pdfDataRangeTransport;
if (pdfDataRangeTransport) {
source.length = pdfDataRangeTransport.length;
@ -440,13 +265,14 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
return worker.messageHandler.sendWithPromise('GetDocRequest', {
docId: docId,
source: source,
disableRange: PDFJS.disableRange,
maxImageSize: PDFJS.maxImageSize,
cMapUrl: PDFJS.cMapUrl,
cMapPacked: PDFJS.cMapPacked,
disableFontFace: PDFJS.disableFontFace,
disableCreateObjectURL: PDFJS.disableCreateObjectURL,
postMessageTransfers: PDFJS.postMessageTransfers,
disableRange: getDefaultSetting('disableRange'),
maxImageSize: getDefaultSetting('maxImageSize'),
cMapUrl: getDefaultSetting('cMapUrl'),
cMapPacked: getDefaultSetting('cMapPacked'),
disableFontFace: getDefaultSetting('disableFontFace'),
disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
!isPostMessageTransfersDisabled,
}).then(function (workerId) {
if (worker.destroyed) {
throw new Error('Worker was destroyed');
@ -497,7 +323,7 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
/**
* Callback to when unsupported feature is used. The callback receives
* an {PDFJS.UNSUPPORTED_FEATURES} argument.
* an {UNSUPPORTED_FEATURES} argument.
*/
this.onUnsupportedFeature = null;
}
@ -549,7 +375,7 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
/**
* Abstract class to support range requests file loading.
* @class
* @alias PDFJS.PDFDataRangeTransport
* @alias PDFDataRangeTransport
* @param {number} length
* @param {Uint8Array} initialData
*/
@ -621,8 +447,6 @@ var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
return PDFDataRangeTransport;
})();
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
/**
* Proxy to a PDFDocument in the worker thread. Also, contains commonly used
* properties that can be read synchronously.
@ -825,7 +649,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
*
* @typedef {Object} RenderParameters
* @property {Object} canvasContext - A 2D context of a DOM Canvas object.
* @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
* @property {PageViewport} viewport - Rendering viewport obtained by
* calling of PDFPage.getViewport method.
* @property {string} intent - Rendering intent, can be 'display' or 'print'
* (default value is 'display').
@ -859,7 +683,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
this.pageInfo = pageInfo;
this.transport = transport;
this.stats = new StatTimer();
this.stats.enabled = !!globalScope.PDFJS.enableStats;
this.stats.enabled = getDefaultSetting('enableStats');
this.commonObjs = transport.commonObjs;
this.objs = new PDFObjects();
this.cleanupAfterRender = false;
@ -898,14 +722,14 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @param {number} scale The desired scale of the viewport.
* @param {number} rotate Degrees to rotate the viewport. If omitted this
* defaults to the page rotation.
* @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
* @return {PageViewport} Contains 'width' and 'height' properties
* along with transforms required for rendering.
*/
getViewport: function PDFPageProxy_getViewport(scale, rotate) {
if (arguments.length < 2) {
rotate = this.rotate;
}
return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
return new PageViewport(this.view, scale, rotate, 0, 0);
},
/**
* @param {GetAnnotationsParameters} params - Annotation parameters.
@ -1193,8 +1017,11 @@ var PDFWorker = (function PDFWorkerClosure() {
var nextFakeWorkerId = 0;
function getWorkerSrc() {
if (PDFJS.workerSrc) {
return PDFJS.workerSrc;
if (typeof workerSrc !== 'undefined') {
return workerSrc;
}
if (getDefaultSetting('workerSrc')) {
return getDefaultSetting('workerSrc');
}
//#if PRODUCTION && !(MOZCENTRAL || FIREFOX)
// if (pdfjsFilePath) {
@ -1284,7 +1111,8 @@ var PDFWorker = (function PDFWorkerClosure() {
// Right now, the requirement is, that an Uint8Array is still an
// Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
//#if !SINGLE_FILE
if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {
if (!isWorkerDisabled && !getDefaultSetting('disableWorker') &&
typeof Worker !== 'undefined') {
var workerSrc = getWorkerSrc();
try {
@ -1334,10 +1162,10 @@ var PDFWorker = (function PDFWorkerClosure() {
this._port = worker;
this._webWorker = worker;
if (!data.supportTransfers) {
PDFJS.postMessageTransfers = false;
isPostMessageTransfersDisabled = true;
}
this._readyCapability.resolve();
// Send global PDFJS setting, e.g. verbosity level.
// Send global setting, e.g. verbosity level.
messageHandler.send('configure', {
verbosity: getVerbosityLevel()
});
@ -1370,8 +1198,10 @@ var PDFWorker = (function PDFWorkerClosure() {
}.bind(this));
var sendTest = function () {
var testObj = new Uint8Array(
[PDFJS.postMessageTransfers ? 255 : 0]);
var postMessageTransfers =
getDefaultSetting('postMessageTransfers') &&
!isPostMessageTransfersDisabled;
var testObj = new Uint8Array([postMessageTransfers ? 255 : 0]);
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
// typed array. Also, checking if we can use transfers.
try {
@ -1400,9 +1230,9 @@ var PDFWorker = (function PDFWorkerClosure() {
},
_setupFakeWorker: function PDFWorker_setupFakeWorker() {
if (!globalScope.PDFJS.disableWorker) {
if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
warn('Setting up fake worker.');
globalScope.PDFJS.disableWorker = true;
isWorkerDisabled = true;
}
setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
@ -1465,7 +1295,6 @@ var PDFWorker = (function PDFWorkerClosure() {
return PDFWorker;
})();
PDFJS.PDFWorker = PDFWorker;
/**
* For internal use only.
@ -1665,7 +1494,20 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.commonObjs.resolve(id, error);
break;
} else {
font = new FontFaceObject(exportedData);
var fontRegistry = null;
if (getDefaultSetting('pdfBug') && globalScope.FontInspector &&
globalScope['FontInspector'].enabled) {
fontRegistry = {
registerFont: function (font, url) {
globalScope['FontInspector'].fontAdded(font, url);
}
};
}
font = new FontFaceObject(exportedData, {
isEvalSuported: getDefaultSetting('isEvalSupported'),
disableFontFace: getDefaultSetting('disableFontFace'),
fontRegistry: fontRegistry
});
}
this.fontLoader.bind(
@ -1765,7 +1607,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
if (loadingTask.onUnsupportedFeature) {
loadingTask.onUnsupportedFeature(featureId);
}
PDFJS.UnsupportedManager.notify(featureId);
_UnsupportedManager.notify(featureId);
}, this);
messageHandler.on('JpegDecode', function(data) {
@ -2104,7 +1946,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
if (this.cancelled) {
return;
}
if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
if (getDefaultSetting('pdfBug') && globalScope.StepperManager &&
globalScope.StepperManager.enabled) {
this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
this.stepper.init(this.operatorList);
@ -2193,7 +2035,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
* (Deprecated) Global observer of unsupported feature usages. Use
* onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
*/
PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
var _UnsupportedManager = (function UnsupportedManagerClosure() {
var listeners = [];
return {
listen: function (cb) {
@ -2209,8 +2051,10 @@ PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
};
})();
exports.getDocument = PDFJS.getDocument;
exports.getDocument = getDocument;
exports.PDFDataRangeTransport = PDFDataRangeTransport;
exports.PDFWorker = PDFWorker;
exports.PDFDocumentProxy = PDFDocumentProxy;
exports.PDFPageProxy = PDFPageProxy;
exports._UnsupportedManager = _UnsupportedManager;
}));