Replace a number of semi-private fields with actual private ones in src/core/document.js
These are fields that can be moved out of their class constructors, and be initialized directly.
This commit is contained in:
parent
39803a9f25
commit
92b065c87e
@ -79,6 +79,8 @@ import { XRef } from "./xref.js";
|
|||||||
const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
||||||
|
|
||||||
class Page {
|
class Page {
|
||||||
|
#resourcesPromise = null;
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
pdfManager,
|
pdfManager,
|
||||||
xref,
|
xref,
|
||||||
@ -108,7 +110,6 @@ class Page {
|
|||||||
this.systemFontCache = systemFontCache;
|
this.systemFontCache = systemFontCache;
|
||||||
this.nonBlendModesSet = nonBlendModesSet;
|
this.nonBlendModesSet = nonBlendModesSet;
|
||||||
this.evaluatorOptions = pdfManager.evaluatorOptions;
|
this.evaluatorOptions = pdfManager.evaluatorOptions;
|
||||||
this.resourcesPromise = null;
|
|
||||||
this.xfaFactory = xfaFactory;
|
this.xfaFactory = xfaFactory;
|
||||||
|
|
||||||
const idCounters = {
|
const idCounters = {
|
||||||
@ -400,7 +401,10 @@ class Page {
|
|||||||
|
|
||||||
async loadResources(keys) {
|
async loadResources(keys) {
|
||||||
// TODO: add async `#getInheritableProperty` and remove this.
|
// TODO: add async `#getInheritableProperty` and remove this.
|
||||||
await (this.resourcesPromise ??= this.pdfManager.ensure(this, "resources"));
|
await (this.#resourcesPromise ??= this.pdfManager.ensure(
|
||||||
|
this,
|
||||||
|
"resources"
|
||||||
|
));
|
||||||
|
|
||||||
await ObjectLoader.load(this.resources, keys, this.xref);
|
await ObjectLoader.load(this.resources, keys, this.xref);
|
||||||
}
|
}
|
||||||
@ -876,6 +880,10 @@ function find(stream, signature, limit = 1024, backwards = false) {
|
|||||||
* The `PDFDocument` class holds all the (worker-thread) data of the PDF file.
|
* The `PDFDocument` class holds all the (worker-thread) data of the PDF file.
|
||||||
*/
|
*/
|
||||||
class PDFDocument {
|
class PDFDocument {
|
||||||
|
#pagePromises = new Map();
|
||||||
|
|
||||||
|
#version = null;
|
||||||
|
|
||||||
constructor(pdfManager, stream) {
|
constructor(pdfManager, stream) {
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
assert(
|
assert(
|
||||||
@ -892,8 +900,6 @@ class PDFDocument {
|
|||||||
this.pdfManager = pdfManager;
|
this.pdfManager = pdfManager;
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.xref = new XRef(stream, pdfManager);
|
this.xref = new XRef(stream, pdfManager);
|
||||||
this._pagePromises = new Map();
|
|
||||||
this._version = null;
|
|
||||||
|
|
||||||
const idCounters = {
|
const idCounters = {
|
||||||
font: 0,
|
font: 0,
|
||||||
@ -1014,7 +1020,7 @@ class PDFDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (PDF_VERSION_REGEXP.test(version)) {
|
if (PDF_VERSION_REGEXP.test(version)) {
|
||||||
this._version = version;
|
this.#version = version;
|
||||||
} else {
|
} else {
|
||||||
warn(`Invalid PDF header version: ${version}`);
|
warn(`Invalid PDF header version: ${version}`);
|
||||||
}
|
}
|
||||||
@ -1347,7 +1353,7 @@ class PDFDocument {
|
|||||||
* the catalog, if present, should overwrite the version from the header.
|
* the catalog, if present, should overwrite the version from the header.
|
||||||
*/
|
*/
|
||||||
get version() {
|
get version() {
|
||||||
return this.catalog.version || this._version;
|
return this.catalog.version || this.#version;
|
||||||
}
|
}
|
||||||
|
|
||||||
get formInfo() {
|
get formInfo() {
|
||||||
@ -1554,7 +1560,7 @@ class PDFDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPage(pageIndex) {
|
getPage(pageIndex) {
|
||||||
const cachedPromise = this._pagePromises.get(pageIndex);
|
const cachedPromise = this.#pagePromises.get(pageIndex);
|
||||||
if (cachedPromise) {
|
if (cachedPromise) {
|
||||||
return cachedPromise;
|
return cachedPromise;
|
||||||
}
|
}
|
||||||
@ -1588,7 +1594,7 @@ class PDFDocument {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._pagePromises.set(pageIndex, promise);
|
this.#pagePromises.set(pageIndex, promise);
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1603,7 +1609,7 @@ class PDFDocument {
|
|||||||
// Clear out the various caches to ensure that we haven't stored any
|
// Clear out the various caches to ensure that we haven't stored any
|
||||||
// inconsistent and/or incorrect state, since that could easily break
|
// inconsistent and/or incorrect state, since that could easily break
|
||||||
// subsequent `this.getPage` calls.
|
// subsequent `this.getPage` calls.
|
||||||
this._pagePromises.delete(0);
|
this.#pagePromises.delete(0);
|
||||||
await this.cleanup();
|
await this.cleanup();
|
||||||
|
|
||||||
throw new XRefParseException();
|
throw new XRefParseException();
|
||||||
@ -1642,7 +1648,7 @@ class PDFDocument {
|
|||||||
// Clear out the various caches to ensure that we haven't stored any
|
// Clear out the various caches to ensure that we haven't stored any
|
||||||
// inconsistent and/or incorrect state, since that could easily break
|
// inconsistent and/or incorrect state, since that could easily break
|
||||||
// subsequent `this.getPage` calls.
|
// subsequent `this.getPage` calls.
|
||||||
this._pagePromises.delete(numPages - 1);
|
this.#pagePromises.delete(numPages - 1);
|
||||||
await this.cleanup();
|
await this.cleanup();
|
||||||
|
|
||||||
if (reason instanceof XRefEntryException && !recoveryMode) {
|
if (reason instanceof XRefEntryException && !recoveryMode) {
|
||||||
@ -1689,7 +1695,7 @@ class PDFDocument {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._pagePromises.set(pageIndex, promise);
|
this.#pagePromises.set(pageIndex, promise);
|
||||||
}
|
}
|
||||||
catalog.setActualNumPages(pagesTree.size);
|
catalog.setActualNumPages(pagesTree.size);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user