mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-03 04:47:21 +02:00
Compare commits
10 Commits
91bfe12f38
...
06f44916c8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06f44916c8 | ||
|
|
d9548b1c18 | ||
|
|
604153957a | ||
|
|
2979e23f3c | ||
|
|
5ca57fbd4b | ||
|
|
22cb3080ee | ||
|
|
bd81d390c7 | ||
|
|
b3e16800f5 | ||
|
|
b531720d9c | ||
|
|
122822a750 |
@ -1062,13 +1062,15 @@ class Catalog {
|
|||||||
if (obj instanceof Dict && obj.has("XFAImages")) {
|
if (obj instanceof Dict && obj.has("XFAImages")) {
|
||||||
const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref);
|
const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref);
|
||||||
for (const [key, value] of nameTree.getAll()) {
|
for (const [key, value] of nameTree.getAll()) {
|
||||||
xfaImages ??= new Dict(this.xref);
|
if (value instanceof BaseStream) {
|
||||||
|
xfaImages ??= new Map();
|
||||||
xfaImages.set(
|
xfaImages.set(
|
||||||
stringToPDFString(key, /* keepEscapeSequence = */ true),
|
stringToPDFString(key, /* keepEscapeSequence = */ true),
|
||||||
value
|
value.getBytes()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return shadow(this, "xfaImages", xfaImages);
|
return shadow(this, "xfaImages", xfaImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1237,28 +1237,15 @@ class PDFDocument {
|
|||||||
return this.xfaFactory ? this.xfaFactory.getPages() : null;
|
return this.xfaFactory ? this.xfaFactory.getPages() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadXfaImages() {
|
async #loadXfaImages() {
|
||||||
const xfaImagesDict = await this.pdfManager.ensureCatalog("xfaImages");
|
const xfaImages = await this.pdfManager.ensureCatalog("xfaImages");
|
||||||
if (!xfaImagesDict) {
|
if (!xfaImages) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const keys = xfaImagesDict.getKeys();
|
|
||||||
const objectLoader = new ObjectLoader(xfaImagesDict, keys, this.xref);
|
|
||||||
await objectLoader.load();
|
|
||||||
|
|
||||||
const xfaImages = new Map();
|
|
||||||
for (const key of keys) {
|
|
||||||
const stream = xfaImagesDict.get(key);
|
|
||||||
if (stream instanceof BaseStream) {
|
|
||||||
xfaImages.set(key, stream.getBytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.xfaFactory.setImages(xfaImages);
|
this.xfaFactory.setImages(xfaImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadXfaFonts(handler, task) {
|
async #loadXfaFonts(handler, task) {
|
||||||
const acroForm = await this.pdfManager.ensureCatalog("acroForm");
|
const acroForm = await this.pdfManager.ensureCatalog("acroForm");
|
||||||
if (!acroForm) {
|
if (!acroForm) {
|
||||||
return;
|
return;
|
||||||
@ -1277,18 +1264,19 @@ class PDFDocument {
|
|||||||
|
|
||||||
const options = Object.assign(
|
const options = Object.assign(
|
||||||
Object.create(null),
|
Object.create(null),
|
||||||
this.pdfManager.evaluatorOptions
|
this.pdfManager.evaluatorOptions,
|
||||||
|
{ useSystemFonts: false }
|
||||||
);
|
);
|
||||||
options.useSystemFonts = false;
|
const { builtInCMapCache, fontCache, standardFontDataCache } = this.catalog;
|
||||||
|
|
||||||
const partialEvaluator = new PartialEvaluator({
|
const partialEvaluator = new PartialEvaluator({
|
||||||
xref: this.xref,
|
xref: this.xref,
|
||||||
handler,
|
handler,
|
||||||
pageIndex: -1,
|
pageIndex: -1,
|
||||||
idFactory: this._globalIdFactory,
|
idFactory: this._globalIdFactory,
|
||||||
fontCache: this.catalog.fontCache,
|
fontCache,
|
||||||
builtInCMapCache: this.catalog.builtInCMapCache,
|
builtInCMapCache,
|
||||||
standardFontDataCache: this.catalog.standardFontDataCache,
|
standardFontDataCache,
|
||||||
options,
|
options,
|
||||||
});
|
});
|
||||||
const operatorList = new OperatorList();
|
const operatorList = new OperatorList();
|
||||||
@ -1305,6 +1293,23 @@ class PDFDocument {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseFont = (fontName, fallbackFontDict, cssFontInfo) =>
|
||||||
|
partialEvaluator
|
||||||
|
.handleSetFont(
|
||||||
|
resources,
|
||||||
|
[Name.get(fontName), 1],
|
||||||
|
/* fontRef = */ null,
|
||||||
|
operatorList,
|
||||||
|
task,
|
||||||
|
initialState,
|
||||||
|
fallbackFontDict,
|
||||||
|
cssFontInfo
|
||||||
|
)
|
||||||
|
.catch(reason => {
|
||||||
|
warn(`loadXfaFonts: "${reason}".`);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
for (const [fontName, font] of fontRes) {
|
for (const [fontName, font] of fontRes) {
|
||||||
const descriptor = font.get("FontDescriptor");
|
const descriptor = font.get("FontDescriptor");
|
||||||
@ -1326,21 +1331,7 @@ class PDFDocument {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
promises.push(
|
promises.push(
|
||||||
partialEvaluator
|
parseFont(fontName, /* fallbackFontDict = */ null, cssFontInfo)
|
||||||
.handleSetFont(
|
|
||||||
resources,
|
|
||||||
[Name.get(fontName), 1],
|
|
||||||
/* fontRef = */ null,
|
|
||||||
operatorList,
|
|
||||||
task,
|
|
||||||
initialState,
|
|
||||||
/* fallbackFontDict = */ null,
|
|
||||||
/* cssFontInfo = */ cssFontInfo
|
|
||||||
)
|
|
||||||
.catch(function (reason) {
|
|
||||||
warn(`loadXfaFonts: "${reason}".`);
|
|
||||||
return null;
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1378,27 +1369,12 @@ class PDFDocument {
|
|||||||
{ name: "BoldItalic", fontWeight: 700, italicAngle: 12 },
|
{ name: "BoldItalic", fontWeight: 700, italicAngle: 12 },
|
||||||
]) {
|
]) {
|
||||||
const name = `${missing}-${fontInfo.name}`;
|
const name = `${missing}-${fontInfo.name}`;
|
||||||
const dict = getXfaFontDict(name);
|
|
||||||
|
|
||||||
promises.push(
|
promises.push(
|
||||||
partialEvaluator
|
parseFont(name, getXfaFontDict(name), {
|
||||||
.handleSetFont(
|
|
||||||
resources,
|
|
||||||
[Name.get(name), 1],
|
|
||||||
/* fontRef = */ null,
|
|
||||||
operatorList,
|
|
||||||
task,
|
|
||||||
initialState,
|
|
||||||
/* fallbackFontDict = */ dict,
|
|
||||||
/* cssFontInfo = */ {
|
|
||||||
fontFamily: missing,
|
fontFamily: missing,
|
||||||
fontWeight: fontInfo.fontWeight,
|
fontWeight: fontInfo.fontWeight,
|
||||||
italicAngle: fontInfo.italicAngle,
|
italicAngle: fontInfo.italicAngle,
|
||||||
}
|
|
||||||
)
|
|
||||||
.catch(function (reason) {
|
|
||||||
warn(`loadXfaFonts: "${reason}".`);
|
|
||||||
return null;
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1408,7 +1384,16 @@ class PDFDocument {
|
|||||||
this.xfaFactory.appendFonts(pdfFonts, reallyMissingFonts);
|
this.xfaFactory.appendFonts(pdfFonts, reallyMissingFonts);
|
||||||
}
|
}
|
||||||
|
|
||||||
async serializeXfaData(annotationStorage) {
|
loadXfaResources(handler, task) {
|
||||||
|
return Promise.all([
|
||||||
|
this.#loadXfaFonts(handler, task).catch(() => {
|
||||||
|
// Ignore errors, to allow the document to load.
|
||||||
|
}),
|
||||||
|
this.#loadXfaImages(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
serializeXfaData(annotationStorage) {
|
||||||
return this.xfaFactory
|
return this.xfaFactory
|
||||||
? this.xfaFactory.serializeData(annotationStorage)
|
? this.xfaFactory.serializeData(annotationStorage)
|
||||||
: null;
|
: null;
|
||||||
|
|||||||
@ -95,10 +95,6 @@ class BasePdfManager {
|
|||||||
return this._docBaseUrl;
|
return this._docBaseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
get catalog() {
|
|
||||||
return this.pdfDocument.catalog;
|
|
||||||
}
|
|
||||||
|
|
||||||
ensureDoc(prop, args) {
|
ensureDoc(prop, args) {
|
||||||
return this.ensure(this.pdfDocument, prop, args);
|
return this.ensure(this.pdfDocument, prop, args);
|
||||||
}
|
}
|
||||||
@ -119,18 +115,6 @@ class BasePdfManager {
|
|||||||
return this.pdfDocument.fontFallback(id, handler);
|
return this.pdfDocument.fontFallback(id, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadXfaFonts(handler, task) {
|
|
||||||
return this.pdfDocument.loadXfaFonts(handler, task);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadXfaImages() {
|
|
||||||
return this.pdfDocument.loadXfaImages();
|
|
||||||
}
|
|
||||||
|
|
||||||
serializeXfaData(annotationStorage) {
|
|
||||||
return this.pdfDocument.serializeXfaData(annotationStorage);
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup(manuallyTriggered = false) {
|
cleanup(manuallyTriggered = false) {
|
||||||
return this.pdfDocument.cleanup(manuallyTriggered);
|
return this.pdfDocument.cleanup(manuallyTriggered);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,7 +118,7 @@ class StructTreeRoot {
|
|||||||
pdfManager,
|
pdfManager,
|
||||||
changes,
|
changes,
|
||||||
}) {
|
}) {
|
||||||
const root = pdfManager.catalog.cloneDict();
|
const root = await pdfManager.ensureCatalog("cloneDict");
|
||||||
const cache = new RefSetCache();
|
const cache = new RefSetCache();
|
||||||
cache.put(catalogRef, root);
|
cache.put(catalogRef, root);
|
||||||
|
|
||||||
|
|||||||
@ -170,18 +170,11 @@ class WorkerMessageHandler {
|
|||||||
|
|
||||||
const isPureXfa = await pdfManager.ensureDoc("isPureXfa");
|
const isPureXfa = await pdfManager.ensureDoc("isPureXfa");
|
||||||
if (isPureXfa) {
|
if (isPureXfa) {
|
||||||
const task = new WorkerTask("loadXfaFonts");
|
const task = new WorkerTask("loadXfaResources");
|
||||||
startWorkerTask(task);
|
startWorkerTask(task);
|
||||||
|
|
||||||
await Promise.all([
|
await pdfManager.ensureDoc("loadXfaResources", [handler, task]);
|
||||||
pdfManager
|
finishWorkerTask(task);
|
||||||
.loadXfaFonts(handler, task)
|
|
||||||
.catch(reason => {
|
|
||||||
// Ignore errors, to allow the document to load.
|
|
||||||
})
|
|
||||||
.then(() => finishWorkerTask(task)),
|
|
||||||
pdfManager.loadXfaImages(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const [numPages, fingerprints] = await Promise.all([
|
const [numPages, fingerprints] = await Promise.all([
|
||||||
@ -617,7 +610,9 @@ class WorkerMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isPureXfa) {
|
if (isPureXfa) {
|
||||||
promises.push(pdfManager.serializeXfaData(annotationStorage));
|
promises.push(
|
||||||
|
pdfManager.ensureDoc("serializeXfaData", [annotationStorage])
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
for (let pageIndex = 0; pageIndex < numPages; pageIndex++) {
|
for (let pageIndex = 0; pageIndex < numPages; pageIndex++) {
|
||||||
promises.push(
|
promises.push(
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class XFAFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isValid() {
|
isValid() {
|
||||||
return this.root && this.form;
|
return !!(this.root && this.form);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -3412,8 +3412,7 @@ class Image extends StringObject {
|
|||||||
return HTMLResult.EMPTY;
|
return HTMLResult.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffer =
|
let buffer = this[$globalData].images?.get(this.href);
|
||||||
this[$globalData].images && this[$globalData].images.get(this.href);
|
|
||||||
if (!buffer && (this.href || !this[$content])) {
|
if (!buffer && (this.href || !this[$content])) {
|
||||||
// In general, we don't get remote data and use what we have
|
// In general, we don't get remote data and use what we have
|
||||||
// in the pdf itself, so no picture for non null href.
|
// in the pdf itself, so no picture for non null href.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user