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
|
unreachable, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
|
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer,
|
||||||
RenderingCancelledException, StatTimer
|
RenderingCancelledException, StatTimer
|
||||||
} from './dom_utils';
|
} from './dom_utils';
|
||||||
import { FontFaceObject, FontLoader } from './font_loader';
|
import { FontFaceObject, FontLoader } from './font_loader';
|
||||||
@ -181,6 +181,8 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||||||
* @property {boolean} disableCreateObjectURL - (optional) Disable the use of
|
* @property {boolean} disableCreateObjectURL - (optional) Disable the use of
|
||||||
* `URL.createObjectURL`, for compatibility with older browsers.
|
* `URL.createObjectURL`, for compatibility with older browsers.
|
||||||
* The default value is `false`.
|
* 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.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
|
||||||
params.ignoreErrors = params.stopAtErrors !== true;
|
params.ignoreErrors = params.stopAtErrors !== true;
|
||||||
|
params.pdfBug = params.pdfBug === true;
|
||||||
|
|
||||||
const NativeImageDecoderValues = Object.values(NativeImageDecoding);
|
const NativeImageDecoderValues = Object.values(NativeImageDecoding);
|
||||||
if (params.nativeImageDecoderSupport === undefined ||
|
if (params.nativeImageDecoderSupport === undefined ||
|
||||||
@ -812,12 +815,12 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||||||
* @alias PDFPageProxy
|
* @alias PDFPageProxy
|
||||||
*/
|
*/
|
||||||
var PDFPageProxy = (function PDFPageProxyClosure() {
|
var PDFPageProxy = (function PDFPageProxyClosure() {
|
||||||
function PDFPageProxy(pageIndex, pageInfo, transport) {
|
function PDFPageProxy(pageIndex, pageInfo, transport, pdfBug = false) {
|
||||||
this.pageIndex = pageIndex;
|
this.pageIndex = pageIndex;
|
||||||
this.pageInfo = pageInfo;
|
this.pageInfo = pageInfo;
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
this._stats = (getDefaultSetting('pdfBug') ?
|
this._stats = (pdfBug ? new StatTimer() : DummyStatTimer);
|
||||||
new StatTimer() : DummyStatTimer);
|
this._pdfBug = pdfBug;
|
||||||
this.commonObjs = transport.commonObjs;
|
this.commonObjs = transport.commonObjs;
|
||||||
this.objs = new PDFObjects();
|
this.objs = new PDFObjects();
|
||||||
this.cleanupAfterRender = false;
|
this.cleanupAfterRender = false;
|
||||||
@ -954,7 +957,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
intentState.operatorList,
|
intentState.operatorList,
|
||||||
this.pageNumber,
|
this.pageNumber,
|
||||||
canvasFactory,
|
canvasFactory,
|
||||||
webGLContext);
|
webGLContext,
|
||||||
|
this._pdfBug);
|
||||||
internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
|
internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
|
||||||
if (!intentState.renderTasks) {
|
if (!intentState.renderTasks) {
|
||||||
intentState.renderTasks = [];
|
intentState.renderTasks = [];
|
||||||
@ -1860,8 +1864,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var fontRegistry = null;
|
var fontRegistry = null;
|
||||||
if (getDefaultSetting('pdfBug') && globalScope.FontInspector &&
|
if (params.pdfBug && globalScope.FontInspector &&
|
||||||
globalScope['FontInspector'].enabled) {
|
globalScope.FontInspector.enabled) {
|
||||||
fontRegistry = {
|
fontRegistry = {
|
||||||
registerFont(font, url) {
|
registerFont(font, url) {
|
||||||
globalScope['FontInspector'].fontAdded(font, url);
|
globalScope['FontInspector'].fontAdded(font, url);
|
||||||
@ -2067,7 +2071,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
throw new Error('Transport 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;
|
this.pageCache[pageIndex] = page;
|
||||||
return page;
|
return page;
|
||||||
});
|
});
|
||||||
@ -2327,7 +2332,8 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||||||
let canvasInRendering = new WeakMap();
|
let canvasInRendering = new WeakMap();
|
||||||
|
|
||||||
function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
|
function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
|
||||||
pageNumber, canvasFactory, webGLContext) {
|
pageNumber, canvasFactory, webGLContext,
|
||||||
|
pdfBug = false) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.objs = objs;
|
this.objs = objs;
|
||||||
@ -2337,6 +2343,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||||||
this.pageNumber = pageNumber;
|
this.pageNumber = pageNumber;
|
||||||
this.canvasFactory = canvasFactory;
|
this.canvasFactory = canvasFactory;
|
||||||
this.webGLContext = webGLContext;
|
this.webGLContext = webGLContext;
|
||||||
|
this._pdfBug = pdfBug;
|
||||||
|
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.graphicsReadyCallback = null;
|
this.graphicsReadyCallback = null;
|
||||||
@ -2370,7 +2377,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||||||
if (this.cancelled) {
|
if (this.cancelled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (getDefaultSetting('pdfBug') && globalScope.StepperManager &&
|
if (this._pdfBug && globalScope.StepperManager &&
|
||||||
globalScope.StepperManager.enabled) {
|
globalScope.StepperManager.enabled) {
|
||||||
this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
|
this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
|
||||||
this.stepper.init(this.operatorList);
|
this.stepper.init(this.operatorList);
|
||||||
|
@ -17,7 +17,6 @@ import {
|
|||||||
assert, CMapCompressionType, removeNullCharacters, stringToBytes,
|
assert, CMapCompressionType, removeNullCharacters, stringToBytes,
|
||||||
unreachable, warn
|
unreachable, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import globalScope from '../shared/global_scope';
|
|
||||||
|
|
||||||
const DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
const DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
||||||
const SVG_NS = 'http://www.w3.org/2000/svg';
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
||||||
@ -329,18 +328,6 @@ function getFilenameFromUrl(url) {
|
|||||||
return url.substring(url.lastIndexOf('/', end) + 1, end);
|
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 {
|
class StatTimer {
|
||||||
constructor(enable = true) {
|
constructor(enable = true) {
|
||||||
this.enabled = !!enable;
|
this.enabled = !!enable;
|
||||||
@ -420,7 +407,6 @@ export {
|
|||||||
addLinkAttributes,
|
addLinkAttributes,
|
||||||
getFilenameFromUrl,
|
getFilenameFromUrl,
|
||||||
LinkTarget,
|
LinkTarget,
|
||||||
getDefaultSetting,
|
|
||||||
DEFAULT_LINK_REL,
|
DEFAULT_LINK_REL,
|
||||||
DOMCanvasFactory,
|
DOMCanvasFactory,
|
||||||
DOMCMapReaderFactory,
|
DOMCMapReaderFactory,
|
||||||
|
@ -39,8 +39,6 @@ if (!globalScope.PDFJS) {
|
|||||||
}
|
}
|
||||||
var PDFJS = globalScope.PDFJS;
|
var PDFJS = globalScope.PDFJS;
|
||||||
|
|
||||||
PDFJS.pdfBug = false;
|
|
||||||
|
|
||||||
PDFJS.OPS = OPS;
|
PDFJS.OPS = OPS;
|
||||||
PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
||||||
PDFJS.shadow = shadow;
|
PDFJS.shadow = shadow;
|
||||||
@ -62,12 +60,6 @@ PDFJS.Util = Util;
|
|||||||
PDFJS.PageViewport = PageViewport;
|
PDFJS.PageViewport = PageViewport;
|
||||||
PDFJS.createPromiseCapability = createPromiseCapability;
|
PDFJS.createPromiseCapability = createPromiseCapability;
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables special hooks for debugging PDF.js.
|
|
||||||
* @var {boolean}
|
|
||||||
*/
|
|
||||||
PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
|
|
||||||
|
|
||||||
PDFJS.getDocument = getDocument;
|
PDFJS.getDocument = getDocument;
|
||||||
PDFJS.LoopbackPort = LoopbackPort;
|
PDFJS.LoopbackPort = LoopbackPort;
|
||||||
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { AbortException, createPromiseCapability, Util } from '../shared/util';
|
import { AbortException, createPromiseCapability, Util } from '../shared/util';
|
||||||
import { getDefaultSetting } from './dom_utils';
|
import globalScope from '../shared/global_scope';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text layer render parameters.
|
* Text layer render parameters.
|
||||||
@ -107,11 +107,9 @@ var renderTextLayer = (function renderTextLayerClosure() {
|
|||||||
textDiv.setAttribute('style', textDivProperties.style);
|
textDiv.setAttribute('style', textDivProperties.style);
|
||||||
|
|
||||||
textDiv.textContent = geom.str;
|
textDiv.textContent = geom.str;
|
||||||
// |fontName| is only used by the Font Inspector. This test will succeed
|
// `fontName` is only used by the FontInspector, and we only use `dataset`
|
||||||
// when e.g. the Font Inspector is off but the Stepper is on, but it's
|
// here to make the font name available in the debugger.
|
||||||
// not worth the effort to do a more accurate test. We only use `dataset`
|
if (task._fontInspectorEnabled) {
|
||||||
// here to make the font name available for the debugger.
|
|
||||||
if (getDefaultSetting('pdfBug')) {
|
|
||||||
textDiv.dataset.fontName = geom.fontName;
|
textDiv.dataset.fontName = geom.fontName;
|
||||||
}
|
}
|
||||||
if (angle !== 0) {
|
if (angle !== 0) {
|
||||||
@ -479,6 +477,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
|
|||||||
this._textDivs = textDivs || [];
|
this._textDivs = textDivs || [];
|
||||||
this._textContentItemsStr = textContentItemsStr || [];
|
this._textContentItemsStr = textContentItemsStr || [];
|
||||||
this._enhanceTextSelection = !!enhanceTextSelection;
|
this._enhanceTextSelection = !!enhanceTextSelection;
|
||||||
|
this._fontInspectorEnabled = !!(globalScope.FontInspector &&
|
||||||
|
globalScope.FontInspector.enabled);
|
||||||
|
|
||||||
this._reader = null;
|
this._reader = null;
|
||||||
this._layoutTextLastFontSize = null;
|
this._layoutTextLastFontSize = null;
|
||||||
|
@ -273,8 +273,6 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
|||||||
// Configure the global worker options.
|
// Configure the global worker options.
|
||||||
PDFJS.GlobalWorkerOptions.workerSrc = WORKER_SRC;
|
PDFJS.GlobalWorkerOptions.workerSrc = WORKER_SRC;
|
||||||
|
|
||||||
PDFJS.pdfBug = true;
|
|
||||||
|
|
||||||
// Set the passed options
|
// Set the passed options
|
||||||
this.inflight = options.inflight;
|
this.inflight = options.inflight;
|
||||||
this.disableScrolling = options.disableScrolling;
|
this.disableScrolling = options.disableScrolling;
|
||||||
@ -368,6 +366,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
|||||||
cMapPacked: CMAP_PACKED,
|
cMapPacked: CMAP_PACKED,
|
||||||
disableRange: task.disableRange,
|
disableRange: task.disableRange,
|
||||||
disableAutoFetch: !task.enableAutoFetch,
|
disableAutoFetch: !task.enableAutoFetch,
|
||||||
|
pdfBug: true,
|
||||||
}).then((doc) => {
|
}).then((doc) => {
|
||||||
task.pdfDoc = doc;
|
task.pdfDoc = doc;
|
||||||
this._nextPage(task, failure);
|
this._nextPage(task, failure);
|
||||||
|
@ -22,8 +22,8 @@ import {
|
|||||||
} from './ui_utils';
|
} from './ui_utils';
|
||||||
import {
|
import {
|
||||||
build, createBlob, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
build, createBlob, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
||||||
InvalidPDFException, LinkTarget, MissingPDFException, OPS, PDFJS, PDFWorker,
|
InvalidPDFException, LinkTarget, MissingPDFException, OPS, PDFWorker, shadow,
|
||||||
shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, version
|
UnexpectedResponseException, UNSUPPORTED_FEATURES, version
|
||||||
} from 'pdfjs-lib';
|
} from 'pdfjs-lib';
|
||||||
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
||||||
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
||||||
@ -306,7 +306,7 @@ let PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ('pdfbug' in hashParams) {
|
if ('pdfbug' in hashParams) {
|
||||||
PDFJS.pdfBug = true;
|
AppOptions.set('pdfBug', true);
|
||||||
let enabled = hashParams['pdfbug'].split(',');
|
let enabled = hashParams['pdfbug'].split(',');
|
||||||
waitOn.push(loadAndEnablePDFBug(enabled));
|
waitOn.push(loadAndEnablePDFBug(enabled));
|
||||||
}
|
}
|
||||||
@ -2005,7 +2005,7 @@ function webViewerPageChanging(evt) {
|
|||||||
PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
|
PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to update stats
|
// We need to update stats.
|
||||||
if (typeof Stats !== 'undefined' && Stats.enabled) {
|
if (typeof Stats !== 'undefined' && Stats.enabled) {
|
||||||
let pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
|
let pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
|
||||||
if (pageView && pageView.stats) {
|
if (pageView && pageView.stats) {
|
||||||
|
@ -175,6 +175,11 @@ const defaultOptions = {
|
|||||||
value: -1,
|
value: -1,
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API,
|
||||||
},
|
},
|
||||||
|
pdfBug: {
|
||||||
|
/** @type {boolean} */
|
||||||
|
value: false,
|
||||||
|
kind: OptionKind.API,
|
||||||
|
},
|
||||||
postMessageTransfers: {
|
postMessageTransfers: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: true,
|
value: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user