mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Move the disableAutoFetch
option from the global PDFJS
object and into getDocument
instead
One additional complication with removing this option from the global `PDFJS` object, is that the viewer currently needs to check `disableAutoFetch` in a couple of places. To address this I'm thus proposing adding a getter in `PDFDocumentProxy`, to allow checking the *actually* used values for a particular `getDocument` invocation.
This commit is contained in:
parent
c7c583583b
commit
69d7191034
7 changed files with 38 additions and 22 deletions
|
@ -18,7 +18,7 @@ import {
|
|||
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
||||
isArrayBuffer, isNum, isSameOrigin, MessageHandler, MissingPDFException,
|
||||
NativeImageDecoding, PageViewport, PasswordException, setVerbosityLevel,
|
||||
stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
||||
shadow, stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
||||
unreachable, Util, warn
|
||||
} from '../shared/util';
|
||||
import {
|
||||
|
@ -164,6 +164,12 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||
* 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
|
||||
* glyphs with primitive path commands. The default value is `false`.
|
||||
* @property {boolean} disableAutoFetch - (optional) Disable pre-fetching of PDF
|
||||
* 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.
|
||||
* The default value is `false`.
|
||||
* NOTE: It is also necessary to disable streaming, see above,
|
||||
* in order for disabling of pre-fetching to work correctly.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -266,6 +272,10 @@ function getDocument(src) {
|
|||
params.disableFontFace = false;
|
||||
}
|
||||
|
||||
if (typeof params.disableAutoFetch !== 'boolean') {
|
||||
params.disableAutoFetch = false;
|
||||
}
|
||||
|
||||
// Set the main-thread verbosity level.
|
||||
setVerbosityLevel(params.verbosity);
|
||||
|
||||
|
@ -333,7 +343,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;
|
||||
|
||||
source.disableRange = getDefaultSetting('disableRange');
|
||||
source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
|
||||
source.disableStream = getDefaultSetting('disableStream');
|
||||
if (pdfDataRangeTransport) {
|
||||
source.length = pdfDataRangeTransport.length;
|
||||
|
@ -683,6 +692,10 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||
destroy: function PDFDocumentProxy_destroy() {
|
||||
return this.loadingTask.destroy();
|
||||
},
|
||||
|
||||
get loadingParams() {
|
||||
return this.transport.loadingParams;
|
||||
},
|
||||
};
|
||||
return PDFDocumentProxy;
|
||||
})();
|
||||
|
@ -2116,6 +2129,13 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
this.fontLoader.clear();
|
||||
});
|
||||
},
|
||||
|
||||
get loadingParams() {
|
||||
let params = this._params;
|
||||
return shadow(this, 'loadingParams', {
|
||||
disableAutoFetch: params.disableAutoFetch,
|
||||
});
|
||||
},
|
||||
};
|
||||
return WorkerTransport;
|
||||
|
||||
|
|
|
@ -336,8 +336,6 @@ function getDefaultSetting(id) {
|
|||
switch (id) {
|
||||
case 'pdfBug':
|
||||
return globalSettings ? globalSettings.pdfBug : false;
|
||||
case 'disableAutoFetch':
|
||||
return globalSettings ? globalSettings.disableAutoFetch : false;
|
||||
case 'disableStream':
|
||||
return globalSettings ? globalSettings.disableStream : false;
|
||||
case 'disableRange':
|
||||
|
|
|
@ -82,18 +82,6 @@ PDFJS.disableRange = (PDFJS.disableRange === undefined ?
|
|||
PDFJS.disableStream = (PDFJS.disableStream === undefined ?
|
||||
false : PDFJS.disableStream);
|
||||
|
||||
/**
|
||||
* Disable pre-fetching of PDF 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. This default behavior can be disabled.
|
||||
*
|
||||
* NOTE: It is also necessary to disable streaming, see above,
|
||||
* in order for disabling of pre-fetching to work correctly.
|
||||
* @var {boolean}
|
||||
*/
|
||||
PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
|
||||
false : PDFJS.disableAutoFetch);
|
||||
|
||||
/**
|
||||
* Enables special hooks for debugging PDF.js.
|
||||
* @var {boolean}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue