Move getPage
, on the worker side, from Catalog
and into PDFDocument
instead
Addresses an existing TODO, and avoids having to pass in a `pageFactory` when creating `Catalog` instances.
This commit is contained in:
parent
51b0e60f9b
commit
fbb25ff4e2
@ -355,6 +355,7 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||||||
xref: this.xref,
|
xref: this.xref,
|
||||||
isEvalSupported: evaluatorOptions.isEvalSupported,
|
isEvalSupported: evaluatorOptions.isEvalSupported,
|
||||||
});
|
});
|
||||||
|
this._pagePromises = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function find(stream, needle, limit, backwards) {
|
function find(stream, needle, limit, backwards) {
|
||||||
@ -520,21 +521,7 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||||||
},
|
},
|
||||||
setup: function PDFDocument_setup(recoveryMode) {
|
setup: function PDFDocument_setup(recoveryMode) {
|
||||||
this.xref.parse(recoveryMode);
|
this.xref.parse(recoveryMode);
|
||||||
var pageFactory = {
|
this.catalog = new Catalog(this.pdfManager, this.xref);
|
||||||
createPage: (pageIndex, dict, ref, fontCache, builtInCMapCache) => {
|
|
||||||
return new Page({
|
|
||||||
pdfManager: this.pdfManager,
|
|
||||||
xref: this.xref,
|
|
||||||
pageIndex,
|
|
||||||
pageDict: dict,
|
|
||||||
ref,
|
|
||||||
fontCache,
|
|
||||||
builtInCMapCache,
|
|
||||||
pdfFunctionFactory: this.pdfFunctionFactory,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
|
|
||||||
},
|
},
|
||||||
get numPages() {
|
get numPages() {
|
||||||
var linearization = this.linearization;
|
var linearization = this.linearization;
|
||||||
@ -599,8 +586,25 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||||||
return shadow(this, 'fingerprint', fileID);
|
return shadow(this, 'fingerprint', fileID);
|
||||||
},
|
},
|
||||||
|
|
||||||
getPage: function PDFDocument_getPage(pageIndex) {
|
getPage(pageIndex) {
|
||||||
return this.catalog.getPage(pageIndex);
|
if (this._pagePromises[pageIndex] !== undefined) {
|
||||||
|
return this._pagePromises[pageIndex];
|
||||||
|
}
|
||||||
|
const catalog = this.catalog;
|
||||||
|
|
||||||
|
return this._pagePromises[pageIndex] =
|
||||||
|
catalog.getPageDict(pageIndex).then(([pageDict, ref]) => {
|
||||||
|
return new Page({
|
||||||
|
pdfManager: this.pdfManager,
|
||||||
|
xref: this.xref,
|
||||||
|
pageIndex,
|
||||||
|
pageDict,
|
||||||
|
ref,
|
||||||
|
fontCache: catalog.fontCache,
|
||||||
|
builtInCMapCache: catalog.builtInCMapCache,
|
||||||
|
pdfFunctionFactory: this.pdfFunctionFactory,
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
cleanup: function PDFDocument_cleanup() {
|
cleanup: function PDFDocument_cleanup() {
|
||||||
|
@ -29,7 +29,7 @@ import { CipherTransformFactory } from './crypto';
|
|||||||
import { ColorSpace } from './colorspace';
|
import { ColorSpace } from './colorspace';
|
||||||
|
|
||||||
var Catalog = (function CatalogClosure() {
|
var Catalog = (function CatalogClosure() {
|
||||||
function Catalog(pdfManager, xref, pageFactory) {
|
function Catalog(pdfManager, xref) {
|
||||||
this.pdfManager = pdfManager;
|
this.pdfManager = pdfManager;
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
this.catDict = xref.getCatalogObj();
|
this.catDict = xref.getCatalogObj();
|
||||||
@ -40,9 +40,6 @@ var Catalog = (function CatalogClosure() {
|
|||||||
this.fontCache = new RefSetCache();
|
this.fontCache = new RefSetCache();
|
||||||
this.builtInCMapCache = Object.create(null);
|
this.builtInCMapCache = Object.create(null);
|
||||||
this.pageKidsCountCache = new RefSetCache();
|
this.pageKidsCountCache = new RefSetCache();
|
||||||
// TODO refactor to move getPage() to the PDFDocument.
|
|
||||||
this.pageFactory = pageFactory;
|
|
||||||
this.pagePromises = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Catalog.prototype = {
|
Catalog.prototype = {
|
||||||
@ -453,18 +450,6 @@ var Catalog = (function CatalogClosure() {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getPage: function Catalog_getPage(pageIndex) {
|
|
||||||
if (!(pageIndex in this.pagePromises)) {
|
|
||||||
this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
|
|
||||||
([dict, ref]) => {
|
|
||||||
return this.pageFactory.createPage(pageIndex, dict, ref,
|
|
||||||
this.fontCache,
|
|
||||||
this.builtInCMapCache);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this.pagePromises[pageIndex];
|
|
||||||
},
|
|
||||||
|
|
||||||
getPageDict: function Catalog_getPageDict(pageIndex) {
|
getPageDict: function Catalog_getPageDict(pageIndex) {
|
||||||
var capability = createPromiseCapability();
|
var capability = createPromiseCapability();
|
||||||
var nodesToVisit = [this.catDict.getRaw('Pages')];
|
var nodesToVisit = [this.catDict.getRaw('Pages')];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user