1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Define the global cache-data once in buildPaintImageXObject

Currently we duplicate the same identical code three times, which seems both unnecessary and error prone.
This commit is contained in:
Jonas Jenwald 2025-03-31 10:29:29 +02:00
parent e8b4ed2fde
commit e0e59eaf01

View file

@ -742,7 +742,8 @@ class PartialEvaluator {
// If there is no imageMask, create the PDFImage and a lot
// of image processing can be done here.
let objId = `img_${this.idFactory.createObjId()}`,
cacheGlobally = false;
cacheGlobally = false,
globalCacheData = null;
if (this.parsingType3Font) {
objId = `${this.idFactory.getDocId()}_type3_${objId}`;
@ -767,15 +768,17 @@ class PartialEvaluator {
operatorList.addImageOps(fn, args, optionalContent, hasMask);
if (cacheGlobally) {
globalCacheData = {
objId,
fn,
args,
optionalContent,
hasMask,
byteSize: 0, // Temporary entry, to avoid `setData` returning early.
};
if (this.globalImageCache.hasDecodeFailed(imageRef)) {
this.globalImageCache.setData(imageRef, {
objId,
fn,
args,
optionalContent,
hasMask,
byteSize: 0, // Data is `null`, since decoding failed previously.
});
this.globalImageCache.setData(imageRef, globalCacheData);
this._sendImgData(objId, /* imgData = */ null, cacheGlobally);
return;
@ -792,14 +795,7 @@ class PartialEvaluator {
]);
if (localLength) {
this.globalImageCache.setData(imageRef, {
objId,
fn,
args,
optionalContent,
hasMask,
byteSize: 0, // Temporary entry, to avoid `setData` returning early.
});
this.globalImageCache.setData(imageRef, globalCacheData);
this.globalImageCache.addByteSize(imageRef, localLength);
return;
}
@ -848,14 +844,8 @@ class PartialEvaluator {
this._regionalImageCache.set(/* name = */ null, imageRef, cacheData);
if (cacheGlobally) {
this.globalImageCache.setData(imageRef, {
objId,
fn,
args,
optionalContent,
hasMask,
byteSize: 0, // Temporary entry, note `addByteSize` above.
});
assert(globalCacheData, "The global cache-data must be available.");
this.globalImageCache.setData(imageRef, globalCacheData);
}
}
}