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

Also removes the now unused `getDefaultSetting` helper function.
This commit is contained in:
Jonas Jenwald 2018-02-17 23:13:49 +01:00
parent 1d03ad0060
commit 212553840f
7 changed files with 33 additions and 44 deletions

View file

@ -22,7 +22,7 @@ import {
unreachable, Util, warn
} from '../shared/util';
import {
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer,
RenderingCancelledException, StatTimer
} from './dom_utils';
import { FontFaceObject, FontLoader } from './font_loader';
@ -181,6 +181,8 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
* @property {boolean} disableCreateObjectURL - (optional) Disable the use of
* `URL.createObjectURL`, for compatibility with older browsers.
* The default value is `false`.
* @property {boolean} pdfBug - (optional) Enables special hooks for debugging
* PDF.js (see `web/debugger.js`). The default value is `false`.
*/
/**
@ -267,6 +269,7 @@ function getDocument(src) {
params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
params.ignoreErrors = params.stopAtErrors !== true;
params.pdfBug = params.pdfBug === true;
const NativeImageDecoderValues = Object.values(NativeImageDecoding);
if (params.nativeImageDecoderSupport === undefined ||
@ -812,12 +815,12 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* @alias PDFPageProxy
*/
var PDFPageProxy = (function PDFPageProxyClosure() {
function PDFPageProxy(pageIndex, pageInfo, transport) {
function PDFPageProxy(pageIndex, pageInfo, transport, pdfBug = false) {
this.pageIndex = pageIndex;
this.pageInfo = pageInfo;
this.transport = transport;
this._stats = (getDefaultSetting('pdfBug') ?
new StatTimer() : DummyStatTimer);
this._stats = (pdfBug ? new StatTimer() : DummyStatTimer);
this._pdfBug = pdfBug;
this.commonObjs = transport.commonObjs;
this.objs = new PDFObjects();
this.cleanupAfterRender = false;
@ -954,7 +957,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
intentState.operatorList,
this.pageNumber,
canvasFactory,
webGLContext);
webGLContext,
this._pdfBug);
internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
if (!intentState.renderTasks) {
intentState.renderTasks = [];
@ -1860,8 +1864,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
break;
}
var fontRegistry = null;
if (getDefaultSetting('pdfBug') && globalScope.FontInspector &&
globalScope['FontInspector'].enabled) {
if (params.pdfBug && globalScope.FontInspector &&
globalScope.FontInspector.enabled) {
fontRegistry = {
registerFont(font, url) {
globalScope['FontInspector'].fontAdded(font, url);
@ -2067,7 +2071,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
if (this.destroyed) {
throw new Error('Transport destroyed');
}
var page = new PDFPageProxy(pageIndex, pageInfo, this);
let page = new PDFPageProxy(pageIndex, pageInfo, this,
this._params.pdfBug);
this.pageCache[pageIndex] = page;
return page;
});
@ -2327,7 +2332,8 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
let canvasInRendering = new WeakMap();
function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
pageNumber, canvasFactory, webGLContext) {
pageNumber, canvasFactory, webGLContext,
pdfBug = false) {
this.callback = callback;
this.params = params;
this.objs = objs;
@ -2337,6 +2343,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
this.pageNumber = pageNumber;
this.canvasFactory = canvasFactory;
this.webGLContext = webGLContext;
this._pdfBug = pdfBug;
this.running = false;
this.graphicsReadyCallback = null;
@ -2370,7 +2377,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
if (this.cancelled) {
return;
}
if (getDefaultSetting('pdfBug') && globalScope.StepperManager &&
if (this._pdfBug && globalScope.StepperManager &&
globalScope.StepperManager.enabled) {
this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
this.stepper.init(this.operatorList);