Skip to content

Commit e0e59ea

Browse files
committed
Define the global cache-data once in buildPaintImageXObject
Currently we duplicate the same identical code three times, which seems both unnecessary and error prone.
1 parent e8b4ed2 commit e0e59ea

1 file changed

Lines changed: 15 additions & 25 deletions

File tree

src/core/evaluator.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,8 @@ class PartialEvaluator {
742742
// If there is no imageMask, create the PDFImage and a lot
743743
// of image processing can be done here.
744744
let objId = `img_${this.idFactory.createObjId()}`,
745-
cacheGlobally = false;
745+
cacheGlobally = false,
746+
globalCacheData = null;
746747

747748
if (this.parsingType3Font) {
748749
objId = `${this.idFactory.getDocId()}_type3_${objId}`;
@@ -767,15 +768,17 @@ class PartialEvaluator {
767768
operatorList.addImageOps(fn, args, optionalContent, hasMask);
768769

769770
if (cacheGlobally) {
771+
globalCacheData = {
772+
objId,
773+
fn,
774+
args,
775+
optionalContent,
776+
hasMask,
777+
byteSize: 0, // Temporary entry, to avoid `setData` returning early.
778+
};
779+
770780
if (this.globalImageCache.hasDecodeFailed(imageRef)) {
771-
this.globalImageCache.setData(imageRef, {
772-
objId,
773-
fn,
774-
args,
775-
optionalContent,
776-
hasMask,
777-
byteSize: 0, // Data is `null`, since decoding failed previously.
778-
});
781+
this.globalImageCache.setData(imageRef, globalCacheData);
779782

780783
this._sendImgData(objId, /* imgData = */ null, cacheGlobally);
781784
return;
@@ -792,14 +795,7 @@ class PartialEvaluator {
792795
]);
793796

794797
if (localLength) {
795-
this.globalImageCache.setData(imageRef, {
796-
objId,
797-
fn,
798-
args,
799-
optionalContent,
800-
hasMask,
801-
byteSize: 0, // Temporary entry, to avoid `setData` returning early.
802-
});
798+
this.globalImageCache.setData(imageRef, globalCacheData);
803799
this.globalImageCache.addByteSize(imageRef, localLength);
804800
return;
805801
}
@@ -848,14 +844,8 @@ class PartialEvaluator {
848844
this._regionalImageCache.set(/* name = */ null, imageRef, cacheData);
849845

850846
if (cacheGlobally) {
851-
this.globalImageCache.setData(imageRef, {
852-
objId,
853-
fn,
854-
args,
855-
optionalContent,
856-
hasMask,
857-
byteSize: 0, // Temporary entry, note `addByteSize` above.
858-
});
847+
assert(globalCacheData, "The global cache-data must be available.");
848+
this.globalImageCache.setData(imageRef, globalCacheData);
859849
}
860850
}
861851
}

0 commit comments

Comments
 (0)