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

This commit is contained in:
Jonas Jenwald 2018-02-17 22:22:10 +01:00
parent 69d7191034
commit b69abf1111
6 changed files with 19 additions and 16 deletions

View File

@ -26,6 +26,7 @@ import {
RenderingCancelledException, StatTimer RenderingCancelledException, StatTimer
} from './dom_utils'; } from './dom_utils';
import { FontFaceObject, FontLoader } from './font_loader'; import { FontFaceObject, FontLoader } from './font_loader';
import { apiCompatibilityParams } from './api_compatibility';
import { CanvasGraphics } from './canvas'; import { CanvasGraphics } from './canvas';
import globalScope from '../shared/global_scope'; import globalScope from '../shared/global_scope';
import { GlobalWorkerOptions } from './worker_options'; import { GlobalWorkerOptions } from './worker_options';
@ -164,6 +165,10 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
* converted to OpenType fonts and loaded via font face rules. If disabled, * converted to OpenType fonts and loaded via font face rules. If disabled,
* fonts will be rendered using a built-in font renderer that constructs the * fonts will be rendered using a built-in font renderer that constructs the
* glyphs with primitive path commands. The default value is `false`. * glyphs with primitive path commands. The default value is `false`.
* @property {boolean} disableRange - (optional) 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.
* The default value is `false`.
* @property {boolean} disableAutoFetch - (optional) Disable pre-fetching of PDF * @property {boolean} disableAutoFetch - (optional) Disable pre-fetching of PDF
* file data. When range requests are enabled PDF.js will automatically keep * 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. * fetching more data even if it isn't needed to display the current page.
@ -272,6 +277,9 @@ function getDocument(src) {
params.disableFontFace = false; params.disableFontFace = false;
} }
if (typeof params.disableRange !== 'boolean') {
params.disableRange = apiCompatibilityParams.disableRange || false;
}
if (typeof params.disableAutoFetch !== 'boolean') { if (typeof params.disableAutoFetch !== 'boolean') {
params.disableAutoFetch = false; params.disableAutoFetch = false;
} }
@ -342,7 +350,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
let apiVersion = let apiVersion =
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null; typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;
source.disableRange = getDefaultSetting('disableRange');
source.disableStream = getDefaultSetting('disableStream'); source.disableStream = getDefaultSetting('disableStream');
if (pdfDataRangeTransport) { if (pdfDataRangeTransport) {
source.length = pdfDataRangeTransport.length; source.length = pdfDataRangeTransport.length;
@ -2133,6 +2140,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
get loadingParams() { get loadingParams() {
let params = this._params; let params = this._params;
return shadow(this, 'loadingParams', { return shadow(this, 'loadingParams', {
disableRange: params.disableRange,
disableAutoFetch: params.disableAutoFetch, disableAutoFetch: params.disableAutoFetch,
}); });
}, },

View File

@ -338,8 +338,6 @@ function getDefaultSetting(id) {
return globalSettings ? globalSettings.pdfBug : false; return globalSettings ? globalSettings.pdfBug : false;
case 'disableStream': case 'disableStream':
return globalSettings ? globalSettings.disableStream : false; return globalSettings ? globalSettings.disableStream : false;
case 'disableRange':
return globalSettings ? globalSettings.disableRange : false;
case 'disableCreateObjectURL': case 'disableCreateObjectURL':
return globalSettings ? globalSettings.disableCreateObjectURL : false; return globalSettings ? globalSettings.disableCreateObjectURL : false;
default: default:

View File

@ -65,15 +65,6 @@ PDFJS.Util = Util;
PDFJS.PageViewport = PageViewport; PDFJS.PageViewport = PageViewport;
PDFJS.createPromiseCapability = createPromiseCapability; PDFJS.createPromiseCapability = createPromiseCapability;
/**
* 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 * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
* in chunks. This default behavior can be disabled. * in chunks. This default behavior can be disabled.

View File

@ -359,7 +359,6 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
this._log('Loading file "' + task.file + '"\n'); this._log('Loading file "' + task.file + '"\n');
let absoluteUrl = new URL(task.file, window.location).href; let absoluteUrl = new URL(task.file, window.location).href;
PDFJS.disableRange = task.disableRange;
try { try {
PDFJS.getDocument({ PDFJS.getDocument({
url: absoluteUrl, url: absoluteUrl,
@ -367,6 +366,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
nativeImageDecoderSupport: task.nativeImageDecoderSupport, nativeImageDecoderSupport: task.nativeImageDecoderSupport,
cMapUrl: CMAP_URL, cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
disableRange: task.disableRange,
disableAutoFetch: !task.enableAutoFetch, disableAutoFetch: !task.enableAutoFetch,
}).then((doc) => { }).then((doc) => {
task.pdfDoc = doc; task.pdfDoc = doc;

View File

@ -195,10 +195,10 @@ let PDFViewerApplication = {
AppOptions.set('textLayerMode', value); AppOptions.set('textLayerMode', value);
}), }),
preferences.get('disableRange').then(function resolved(value) { preferences.get('disableRange').then(function resolved(value) {
if (PDFJS.disableRange === true) { if (AppOptions.get('disableRange') === true) {
return; return;
} }
PDFJS.disableRange = value; AppOptions.set('disableRange', value);
}), }),
preferences.get('disableStream').then(function resolved(value) { preferences.get('disableStream').then(function resolved(value) {
if (PDFJS.disableStream === true) { if (PDFJS.disableStream === true) {
@ -260,7 +260,7 @@ let PDFViewerApplication = {
waitOn.push(loadFakeWorker()); waitOn.push(loadFakeWorker());
} }
if ('disablerange' in hashParams) { if ('disablerange' in hashParams) {
PDFJS.disableRange = (hashParams['disablerange'] === 'true'); AppOptions.set('disableRange', hashParams['disablerange'] === 'true');
} }
if ('disablestream' in hashParams) { if ('disablestream' in hashParams) {
PDFJS.disableStream = (hashParams['disablestream'] === 'true'); PDFJS.disableStream = (hashParams['disablestream'] === 'true');

View File

@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { apiCompatibilityParams } from 'pdfjs-lib';
import { viewerCompatibilityParams } from './viewer_compatibility'; import { viewerCompatibilityParams } from './viewer_compatibility';
const OptionKind = { const OptionKind = {
@ -149,6 +150,11 @@ const defaultOptions = {
value: false, value: false,
kind: OptionKind.API, kind: OptionKind.API,
}, },
disableRange: {
/** @type {boolean} */
value: apiCompatibilityParams.disableRange || false,
kind: OptionKind.API,
},
isEvalSupported: { isEvalSupported: {
/** @type {boolean} */ /** @type {boolean} */
value: true, value: true,