Skip to content

Commit 97bf09b

Browse files
Merge pull request #19739 from Snuffleupagus/buildPaintImageXObject-fn-OPS
Reduce duplication when specifying the fn-operations in `buildPaintImageXObject`
2 parents cb818ce + 8e3a338 commit 97bf09b

File tree

1 file changed

+19
-49
lines changed

1 file changed

+19
-49
lines changed

src/core/evaluator.js

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ class PartialEvaluator {
595595
}
596596

597597
const imageMask = dict.get("IM", "ImageMask") || false;
598-
let imgData, args;
598+
let imgData, fn, args;
599599
if (imageMask) {
600600
// This depends on a tmpCanvas being filled with the
601601
// current fillStyle, such that processing the pixel
@@ -618,20 +618,13 @@ class PartialEvaluator {
618618
});
619619

620620
imgData.cached = !!cacheKey;
621-
args = [imgData];
622621

623-
operatorList.addImageOps(
624-
OPS.paintImageMaskXObject,
625-
args,
626-
optionalContent
627-
);
622+
fn = OPS.paintImageMaskXObject;
623+
args = [imgData];
624+
operatorList.addImageOps(fn, args, optionalContent);
628625

629626
if (cacheKey) {
630-
const cacheData = {
631-
fn: OPS.paintImageMaskXObject,
632-
args,
633-
optionalContent,
634-
};
627+
const cacheData = { fn, args, optionalContent };
635628
localImageCache.set(cacheKey, imageRef, cacheData);
636629

637630
if (imageRef) {
@@ -658,18 +651,12 @@ class PartialEvaluator {
658651
if (imgData.isSingleOpaquePixel) {
659652
// Handles special case of mainly LaTeX documents which use image
660653
// masks to draw lines with the current fill style.
661-
operatorList.addImageOps(
662-
OPS.paintSolidColorImageMask,
663-
[],
664-
optionalContent
665-
);
654+
fn = OPS.paintSolidColorImageMask;
655+
args = [];
656+
operatorList.addImageOps(fn, args, optionalContent);
666657

667658
if (cacheKey) {
668-
const cacheData = {
669-
fn: OPS.paintSolidColorImageMask,
670-
args: [],
671-
optionalContent,
672-
};
659+
const cacheData = { fn, args, optionalContent };
673660
localImageCache.set(cacheKey, imageRef, cacheData);
674661

675662
if (imageRef) {
@@ -691,6 +678,7 @@ class PartialEvaluator {
691678
: imgData.data.length;
692679
this._sendImgData(objId, imgData);
693680

681+
fn = OPS.paintImageMaskXObject;
694682
args = [
695683
{
696684
data: objId,
@@ -700,19 +688,10 @@ class PartialEvaluator {
700688
count: 1,
701689
},
702690
];
703-
operatorList.addImageOps(
704-
OPS.paintImageMaskXObject,
705-
args,
706-
optionalContent
707-
);
691+
operatorList.addImageOps(fn, args, optionalContent);
708692

709693
if (cacheKey) {
710-
const cacheData = {
711-
objId,
712-
fn: OPS.paintImageMaskXObject,
713-
args,
714-
optionalContent,
715-
};
694+
const cacheData = { objId, fn, args, optionalContent };
716695
localImageCache.set(cacheKey, imageRef, cacheData);
717696

718697
if (imageRef) {
@@ -782,19 +761,16 @@ class PartialEvaluator {
782761

783762
// Ensure that the dependency is added before the image is decoded.
784763
operatorList.addDependency(objId);
764+
765+
fn = OPS.paintImageXObject;
785766
args = [objId, w, h];
786-
operatorList.addImageOps(
787-
OPS.paintImageXObject,
788-
args,
789-
optionalContent,
790-
hasMask
791-
);
767+
operatorList.addImageOps(fn, args, optionalContent, hasMask);
792768

793769
if (cacheGlobally) {
794770
if (this.globalImageCache.hasDecodeFailed(imageRef)) {
795771
this.globalImageCache.setData(imageRef, {
796772
objId,
797-
fn: OPS.paintImageXObject,
773+
fn,
798774
args,
799775
optionalContent,
800776
hasMask,
@@ -818,7 +794,7 @@ class PartialEvaluator {
818794
if (localLength) {
819795
this.globalImageCache.setData(imageRef, {
820796
objId,
821-
fn: OPS.paintImageXObject,
797+
fn,
822798
args,
823799
optionalContent,
824800
hasMask,
@@ -865,13 +841,7 @@ class PartialEvaluator {
865841
});
866842

867843
if (cacheKey) {
868-
const cacheData = {
869-
objId,
870-
fn: OPS.paintImageXObject,
871-
args,
872-
optionalContent,
873-
hasMask,
874-
};
844+
const cacheData = { objId, fn, args, optionalContent, hasMask };
875845
localImageCache.set(cacheKey, imageRef, cacheData);
876846

877847
if (imageRef) {
@@ -880,7 +850,7 @@ class PartialEvaluator {
880850
if (cacheGlobally) {
881851
this.globalImageCache.setData(imageRef, {
882852
objId,
883-
fn: OPS.paintImageXObject,
853+
fn,
884854
args,
885855
optionalContent,
886856
hasMask,

0 commit comments

Comments
 (0)