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:
parent
1d03ad0060
commit
212553840f
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -273,8 +273,6 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
||||
// Configure the global worker options.
|
||||
PDFJS.GlobalWorkerOptions.workerSrc = WORKER_SRC;
|
||||
|
||||
PDFJS.pdfBug = true;
|
||||
|
||||
// Set the passed options
|
||||
this.inflight = options.inflight;
|
||||
this.disableScrolling = options.disableScrolling;
|
||||
@ -368,6 +366,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
||||
cMapPacked: CMAP_PACKED,
|
||||
disableRange: task.disableRange,
|
||||
disableAutoFetch: !task.enableAutoFetch,
|
||||
pdfBug: true,
|
||||
}).then((doc) => {
|
||||
task.pdfDoc = doc;
|
||||
this._nextPage(task, failure);
|
||||
|
@ -22,8 +22,8 @@ import {
|
||||
} from './ui_utils';
|
||||
import {
|
||||
build, createBlob, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
||||
InvalidPDFException, LinkTarget, MissingPDFException, OPS, PDFJS, PDFWorker,
|
||||
shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, version
|
||||
InvalidPDFException, LinkTarget, MissingPDFException, OPS, PDFWorker, shadow,
|
||||
UnexpectedResponseException, UNSUPPORTED_FEATURES, version
|
||||
} from 'pdfjs-lib';
|
||||
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
||||
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
||||
@ -306,7 +306,7 @@ let PDFViewerApplication = {
|
||||
}
|
||||
}
|
||||
if ('pdfbug' in hashParams) {
|
||||
PDFJS.pdfBug = true;
|
||||
AppOptions.set('pdfBug', true);
|
||||
let enabled = hashParams['pdfbug'].split(',');
|
||||
waitOn.push(loadAndEnablePDFBug(enabled));
|
||||
}
|
||||
@ -2005,7 +2005,7 @@ function webViewerPageChanging(evt) {
|
||||
PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
|
||||
}
|
||||
|
||||
// we need to update stats
|
||||
// We need to update stats.
|
||||
if (typeof Stats !== 'undefined' && Stats.enabled) {
|
||||
let pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
|
||||
if (pageView && pageView.stats) {
|
||||
|
@ -175,6 +175,11 @@ const defaultOptions = {
|
||||
value: -1,
|
||||
kind: OptionKind.API,
|
||||
},
|
||||
pdfBug: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.API,
|
||||
},
|
||||
postMessageTransfers: {
|
||||
/** @type {boolean} */
|
||||
value: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user