1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

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);

View file

@ -17,7 +17,6 @@ import {
assert, CMapCompressionType, removeNullCharacters, stringToBytes,
unreachable, warn
} from '../shared/util';
import globalScope from '../shared/global_scope';
const DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
const SVG_NS = 'http://www.w3.org/2000/svg';
@ -329,18 +328,6 @@ function getFilenameFromUrl(url) {
return url.substring(url.lastIndexOf('/', end) + 1, end);
}
function getDefaultSetting(id) {
// The list of the settings and their default is maintained for backward
// compatibility and shall not be extended or modified. See also global.js.
var globalSettings = globalScope.PDFJS;
switch (id) {
case 'pdfBug':
return globalSettings ? globalSettings.pdfBug : false;
default:
throw new Error('Unknown default setting: ' + id);
}
}
class StatTimer {
constructor(enable = true) {
this.enabled = !!enable;
@ -420,7 +407,6 @@ export {
addLinkAttributes,
getFilenameFromUrl,
LinkTarget,
getDefaultSetting,
DEFAULT_LINK_REL,
DOMCanvasFactory,
DOMCMapReaderFactory,

View file

@ -39,8 +39,6 @@ if (!globalScope.PDFJS) {
}
var PDFJS = globalScope.PDFJS;
PDFJS.pdfBug = false;
PDFJS.OPS = OPS;
PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
PDFJS.shadow = shadow;
@ -62,12 +60,6 @@ PDFJS.Util = Util;
PDFJS.PageViewport = PageViewport;
PDFJS.createPromiseCapability = createPromiseCapability;
/**
* Enables special hooks for debugging PDF.js.
* @var {boolean}
*/
PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
PDFJS.getDocument = getDocument;
PDFJS.LoopbackPort = LoopbackPort;
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;

View file

@ -14,7 +14,7 @@
*/
import { AbortException, createPromiseCapability, Util } from '../shared/util';
import { getDefaultSetting } from './dom_utils';
import globalScope from '../shared/global_scope';
/**
* Text layer render parameters.
@ -107,11 +107,9 @@ var renderTextLayer = (function renderTextLayerClosure() {
textDiv.setAttribute('style', textDivProperties.style);
textDiv.textContent = geom.str;
// |fontName| is only used by the Font Inspector. This test will succeed
// when e.g. the Font Inspector is off but the Stepper is on, but it's
// not worth the effort to do a more accurate test. We only use `dataset`
// here to make the font name available for the debugger.
if (getDefaultSetting('pdfBug')) {
// `fontName` is only used by the FontInspector, and we only use `dataset`
// here to make the font name available in the debugger.
if (task._fontInspectorEnabled) {
textDiv.dataset.fontName = geom.fontName;
}
if (angle !== 0) {
@ -479,6 +477,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
this._textDivs = textDivs || [];
this._textContentItemsStr = textContentItemsStr || [];
this._enhanceTextSelection = !!enhanceTextSelection;
this._fontInspectorEnabled = !!(globalScope.FontInspector &&
globalScope.FontInspector.enabled);
this._reader = null;
this._layoutTextLastFontSize = null;