Merge pull request #19885 from Snuffleupagus/loadXfaImages-simplify
Simplify the `loadXfaImages` method and related code
This commit is contained in:
commit
5ca57fbd4b
@ -1062,11 +1062,13 @@ 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.set(
|
xfaImages ??= new Map();
|
||||||
stringToPDFString(key, /* keepEscapeSequence = */ true),
|
xfaImages.set(
|
||||||
value
|
stringToPDFString(key, /* keepEscapeSequence = */ true),
|
||||||
);
|
value.getBytes()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shadow(this, "xfaImages", xfaImages);
|
return shadow(this, "xfaImages", xfaImages);
|
||||||
|
|||||||
@ -1238,23 +1238,10 @@ class PDFDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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