mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Re-factor the idFactory
functionality, used in the core/
-code, and move the fontID
generation into it
Note how the `getFontID`-method in `src/core/fonts.js` is *completely* global, rather than properly tied to the current document. This means that if you repeatedly open and parse/render, and then close, even the *same* PDF document the `fontID`s will still be incremented continuously. For comparison the `createObjId` method, on `idFactory`, will always create a *consistent* id, assuming of course that the document and its pages are parsed/rendered in the same order. In order to address this inconsistency, it thus seems reasonable to add a new `createFontId` method on the `idFactory` and use that when obtaining `fontID`s. (When the current `getFontID` method was added the `idFactory` didn't actually exist yet, which explains why the code looks the way it does.) *Please note:* Since the document id is (still) part of the `loadedName`, it's thus not possible for different documents to have identical font names.
This commit is contained in:
parent
cf8daaf78b
commit
4cc6797f17
5 changed files with 56 additions and 30 deletions
|
@ -28,6 +28,7 @@ import {
|
|||
shadow,
|
||||
stringToBytes,
|
||||
stringToPDFString,
|
||||
unreachable,
|
||||
Util,
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
|
@ -71,6 +72,7 @@ class Page {
|
|||
pageIndex,
|
||||
pageDict,
|
||||
ref,
|
||||
globalIdFactory,
|
||||
fontCache,
|
||||
builtInCMapCache,
|
||||
globalImageCache,
|
||||
|
@ -89,13 +91,10 @@ class Page {
|
|||
const idCounters = {
|
||||
obj: 0,
|
||||
};
|
||||
this.idFactory = {
|
||||
createObjId() {
|
||||
this._localIdFactory = class extends globalIdFactory {
|
||||
static createObjId() {
|
||||
return `p${pageIndex}_${++idCounters.obj}`;
|
||||
},
|
||||
getDocId() {
|
||||
return `g_${pdfManager.docId}`;
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -257,7 +256,7 @@ class Page {
|
|||
xref: this.xref,
|
||||
handler,
|
||||
pageIndex: this.pageIndex,
|
||||
idFactory: this.idFactory,
|
||||
idFactory: this._localIdFactory,
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
|
@ -350,7 +349,7 @@ class Page {
|
|||
xref: this.xref,
|
||||
handler,
|
||||
pageIndex: this.pageIndex,
|
||||
idFactory: this.idFactory,
|
||||
idFactory: this._localIdFactory,
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
|
@ -399,7 +398,7 @@ class Page {
|
|||
this.xref,
|
||||
annotationRef,
|
||||
this.pdfManager,
|
||||
this.idFactory
|
||||
this._localIdFactory
|
||||
).catch(function (reason) {
|
||||
warn(`_parsedAnnotations: "${reason}".`);
|
||||
return null;
|
||||
|
@ -504,6 +503,23 @@ class PDFDocument {
|
|||
this.stream = stream;
|
||||
this.xref = new XRef(stream, pdfManager);
|
||||
this._pagePromises = [];
|
||||
|
||||
const idCounters = {
|
||||
font: 0,
|
||||
};
|
||||
this._globalIdFactory = class {
|
||||
static getDocId() {
|
||||
return `g_${pdfManager.docId}`;
|
||||
}
|
||||
|
||||
static createFontId() {
|
||||
return `f${++idCounters.font}`;
|
||||
}
|
||||
|
||||
static createObjId() {
|
||||
unreachable("Abstract method `createObjId` called.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
parse(recoveryMode) {
|
||||
|
@ -808,6 +824,7 @@ class PDFDocument {
|
|||
pageIndex,
|
||||
pageDict,
|
||||
ref,
|
||||
globalIdFactory: this._globalIdFactory,
|
||||
fontCache: catalog.fontCache,
|
||||
builtInCMapCache: catalog.builtInCMapCache,
|
||||
globalImageCache: catalog.globalImageCache,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue