@@ -73,6 +73,7 @@ import {
73
73
getSymbolsFonts ,
74
74
} from "./standard_fonts.js" ;
75
75
import { getTilingPatternIR , Pattern } from "./pattern.js" ;
76
+ import { GlobalImageCacheKind , NativeImageDecoder } from "./image_utils.js" ;
76
77
import { Lexer , Parser } from "./parser.js" ;
77
78
import { bidi } from "./bidi.js" ;
78
79
import { ColorSpace } from "./colorspace.js" ;
@@ -82,7 +83,6 @@ import { getMetrics } from "./metrics.js";
82
83
import { isPDFFunction } from "./function.js" ;
83
84
import { JpegStream } from "./jpeg_stream.js" ;
84
85
import { MurmurHash3_64 } from "./murmurhash3.js" ;
85
- import { NativeImageDecoder } from "./image_utils.js" ;
86
86
import { OperatorList } from "./operator_list.js" ;
87
87
import { PDFImage } from "./image.js" ;
88
88
@@ -105,6 +105,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
105
105
idFactory,
106
106
fontCache,
107
107
builtInCMapCache,
108
+ globalImageCache,
108
109
options = null ,
109
110
pdfFunctionFactory,
110
111
} ) {
@@ -114,6 +115,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
114
115
this . idFactory = idFactory ;
115
116
this . fontCache = fontCache ;
116
117
this . builtInCMapCache = builtInCMapCache ;
118
+ this . globalImageCache = globalImageCache ;
117
119
this . options = options || DefaultPartialEvaluatorOptions ;
118
120
this . pdfFunctionFactory = pdfFunctionFactory ;
119
121
this . parsingType3Font = false ;
@@ -446,11 +448,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
446
448
image,
447
449
isInline = false ,
448
450
operatorList,
451
+ task,
449
452
cacheKey,
450
453
imageCache,
454
+ cacheGlobally = false ,
451
455
forceDisableNativeImageDecoder = false ,
452
456
} ) {
453
457
var dict = image . dict ;
458
+ const imageRef = dict . objId ;
454
459
var w = dict . get ( "Width" , "W" ) ;
455
460
var h = dict . get ( "Height" , "H" ) ;
456
461
@@ -528,7 +533,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
528
533
return undefined ;
529
534
}
530
535
531
- const nativeImageDecoderSupport = forceDisableNativeImageDecoder
536
+ let nativeImageDecoderSupport = forceDisableNativeImageDecoder
532
537
? NativeImageDecoding . NONE
533
538
: this . options . nativeImageDecoderSupport ;
534
539
// If there is no imageMask, create the PDFImage and a lot
@@ -542,6 +547,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
542
547
) ;
543
548
544
549
objId = `${ this . idFactory . getDocId ( ) } _type3res_${ objId } ` ;
550
+ } else if ( cacheGlobally ) {
551
+ nativeImageDecoderSupport = NativeImageDecoding . NONE ;
552
+
553
+ objId = `${ this . idFactory . getDocId ( ) } _${ objId } ` ;
545
554
}
546
555
547
556
if (
@@ -566,7 +575,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
566
575
image . getIR ( this . options . forceDataSchema ) ,
567
576
] )
568
577
. then (
569
- function ( ) {
578
+ ( ) => {
570
579
// Only add the dependency once we know that the native JPEG
571
580
// decoding succeeded, to ensure that rendering will always
572
581
// complete.
@@ -579,6 +588,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
579
588
fn : OPS . paintJpegXObject ,
580
589
args,
581
590
} ;
591
+
592
+ if ( imageRef ) {
593
+ this . globalImageCache . set ( {
594
+ ref : imageRef ,
595
+ task,
596
+ objId,
597
+ fn : OPS . paintJpegXObject ,
598
+ args,
599
+ } ) ;
600
+ }
582
601
}
583
602
} ,
584
603
reason => {
@@ -639,6 +658,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
639
658
[ objId , "FontType3Res" , imgData ] ,
640
659
[ imgData . data . buffer ]
641
660
) ;
661
+ } else if ( cacheGlobally ) {
662
+ this . handler . send (
663
+ "commonobj" ,
664
+ [ objId , "Image" , imgData ] ,
665
+ [ imgData . data . buffer ]
666
+ ) ;
667
+ return undefined ;
642
668
}
643
669
this . handler . send (
644
670
"obj" ,
@@ -656,6 +682,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
656
682
"FontType3Res" ,
657
683
null ,
658
684
] ) ;
685
+ } else if ( cacheGlobally ) {
686
+ this . handler . send ( "commonobj" , [ objId , "Image" , null ] ) ;
687
+ return undefined ;
659
688
}
660
689
this . handler . send ( "obj" , [ objId , this . pageIndex , "Image" , null ] ) ;
661
690
return undefined ;
@@ -674,6 +703,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
674
703
fn : OPS . paintImageXObject ,
675
704
args,
676
705
} ;
706
+
707
+ if ( imageRef ) {
708
+ this . globalImageCache . set ( {
709
+ ref : imageRef ,
710
+ task,
711
+ objId,
712
+ fn : OPS . paintImageXObject ,
713
+ args,
714
+ } ) ;
715
+ }
677
716
}
678
717
return undefined ;
679
718
} ,
@@ -1322,7 +1361,35 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
1322
1361
) ;
1323
1362
}
1324
1363
1325
- const xobj = xobjs . get ( name ) ;
1364
+ let xobj = xobjs . getRaw ( name ) ,
1365
+ cacheGlobally = false ;
1366
+ if ( xobj instanceof Ref ) {
1367
+ const cacheKind = self . globalImageCache . kind ( {
1368
+ ref : xobj ,
1369
+ task,
1370
+ } ) ;
1371
+
1372
+ switch ( cacheKind ) {
1373
+ case GlobalImageCacheKind . IS_CACHED :
1374
+ const globalImage = self . globalImageCache . get ( {
1375
+ ref : xobj ,
1376
+ } ) ;
1377
+
1378
+ if ( globalImage ) {
1379
+ operatorList . addDependency ( globalImage . objId ) ;
1380
+ operatorList . addOp ( globalImage . fn , globalImage . args ) ;
1381
+
1382
+ resolveXObject ( ) ;
1383
+ return ;
1384
+ }
1385
+ break ;
1386
+ case GlobalImageCacheKind . SHOULD_CACHE :
1387
+ cacheGlobally = true ;
1388
+ break ;
1389
+ }
1390
+ xobj = xref . fetch ( xobj ) ;
1391
+ }
1392
+
1326
1393
if ( ! xobj ) {
1327
1394
operatorList . addOp ( fn , args ) ;
1328
1395
resolveXObject ( ) ;
@@ -1359,8 +1426,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
1359
1426
resources,
1360
1427
image : xobj ,
1361
1428
operatorList,
1429
+ task,
1362
1430
cacheKey : name ,
1363
1431
imageCache,
1432
+ cacheGlobally,
1364
1433
} )
1365
1434
. then ( resolveXObject , rejectXObject ) ;
1366
1435
return ;
0 commit comments