@@ -72,7 +72,6 @@ import { BaseStream } from "./base_stream.js";
72
72
import { bidi } from "./bidi.js" ;
73
73
import { ColorSpace } from "./colorspace.js" ;
74
74
import { ColorSpaceUtils } from "./colorspace_utils.js" ;
75
- import { DecodeStream } from "./decode_stream.js" ;
76
75
import { getFontSubstitution } from "./font_substitutions.js" ;
77
76
import { getGlyphsUnicode } from "./glyphlist.js" ;
78
77
import { getMetrics } from "./metrics.js" ;
@@ -571,7 +570,10 @@ class PartialEvaluator {
571
570
localImageCache,
572
571
localColorSpaceCache,
573
572
} ) {
574
- const dict = image . dict ;
573
+ const { maxImageSize, ignoreErrors, isOffscreenCanvasSupported } =
574
+ this . options ;
575
+
576
+ const { dict } = image ;
575
577
const imageRef = dict . objId ;
576
578
const w = dict . get ( "W" , "Width" ) ;
577
579
const h = dict . get ( "H" , "Height" ) ;
@@ -580,15 +582,14 @@ class PartialEvaluator {
580
582
warn ( "Image dimensions are missing, or not numbers." ) ;
581
583
return ;
582
584
}
583
- const maxImageSize = this . options . maxImageSize ;
584
585
if ( maxImageSize !== - 1 && w * h > maxImageSize ) {
585
586
const msg = "Image exceeded maximum allowed size and was removed." ;
586
587
587
- if ( this . options . ignoreErrors ) {
588
- warn ( msg ) ;
589
- return ;
588
+ if ( ! ignoreErrors ) {
589
+ throw new Error ( msg ) ;
590
590
}
591
- throw new Error ( msg ) ;
591
+ warn ( msg ) ;
592
+ return ;
592
593
}
593
594
594
595
let optionalContent ;
@@ -607,52 +608,10 @@ class PartialEvaluator {
607
608
// data can't be done here. Instead of creating a
608
609
// complete PDFImage, only read the information needed
609
610
// for later.
610
- const interpolate = dict . get ( "I" , "Interpolate" ) ;
611
- const bitStrideLength = ( w + 7 ) >> 3 ;
612
- const imgArray = image . getBytes ( bitStrideLength * h ) ;
613
- const decode = dict . getArray ( "D" , "Decode" ) ;
614
-
615
- if ( this . parsingType3Font ) {
616
- // NOTE: Compared to other image resources we don't bother caching
617
- // Type3-glyph image masks, since we've not come across any cases
618
- // where that actually helps.
619
- // In Type3-glyphs image masks are "always" inline resources,
620
- // they're usually fairly small and aren't being re-used either.
621
-
622
- imgData = PDFImage . createRawMask ( {
623
- imgArray,
624
- width : w ,
625
- height : h ,
626
- imageIsFromDecodeStream : image instanceof DecodeStream ,
627
- inverseDecode : decode ?. [ 0 ] > 0 ,
628
- interpolate,
629
- } ) ;
630
- args = compileType3Glyph ( imgData ) ;
631
-
632
- if ( args ) {
633
- operatorList . addImageOps ( OPS . constructPath , args , optionalContent ) ;
634
- return ;
635
- }
636
- warn ( "Cannot compile Type3 glyph." ) ;
637
-
638
- // If compilation failed, or was disabled, fallback to using an inline
639
- // image mask; this case should be extremely rare.
640
- operatorList . addImageOps (
641
- OPS . paintImageMaskXObject ,
642
- [ imgData ] ,
643
- optionalContent
644
- ) ;
645
- return ;
646
- }
647
-
648
611
imgData = await PDFImage . createMask ( {
649
- imgArray,
650
- width : w ,
651
- height : h ,
652
- imageIsFromDecodeStream : image instanceof DecodeStream ,
653
- inverseDecode : decode ?. [ 0 ] > 0 ,
654
- interpolate,
655
- isOffscreenCanvasSupported : this . options . isOffscreenCanvasSupported ,
612
+ image,
613
+ isOffscreenCanvasSupported :
614
+ isOffscreenCanvasSupported && ! this . parsingType3Font ,
656
615
} ) ;
657
616
658
617
if ( imgData . isSingleOpaquePixel ) {
@@ -677,6 +636,36 @@ class PartialEvaluator {
677
636
return ;
678
637
}
679
638
639
+ if ( this . parsingType3Font ) {
640
+ // NOTE: Compared to other image resources we don't bother caching
641
+ // Type3-glyph image masks, since we've not come across any cases
642
+ // where that actually helps.
643
+ // In Type3-glyphs image masks are "always" inline resources,
644
+ // they're usually fairly small and aren't being re-used either.
645
+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) {
646
+ assert (
647
+ imgData . data instanceof Uint8Array ,
648
+ "Type3 glyph image mask must be a TypedArray."
649
+ ) ;
650
+ }
651
+ args = compileType3Glyph ( imgData ) ;
652
+
653
+ if ( args ) {
654
+ operatorList . addImageOps ( OPS . constructPath , args , optionalContent ) ;
655
+ return ;
656
+ }
657
+ warn ( "Cannot compile Type3 glyph." ) ;
658
+
659
+ // If compilation failed, or was disabled, fallback to using an inline
660
+ // image mask; this case should be extremely rare.
661
+ operatorList . addImageOps (
662
+ OPS . paintImageMaskXObject ,
663
+ [ imgData ] ,
664
+ optionalContent
665
+ ) ;
666
+ return ;
667
+ }
668
+
680
669
const objId = `mask_${ this . idFactory . createObjId ( ) } ` ;
681
670
operatorList . addDependency ( objId ) ;
682
671
@@ -736,7 +725,7 @@ class PartialEvaluator {
736
725
} catch ( reason ) {
737
726
const msg = `Unable to decode inline image: "${ reason } ".` ;
738
727
739
- if ( ! this . options . ignoreErrors ) {
728
+ if ( ! ignoreErrors ) {
740
729
throw new Error ( msg ) ;
741
730
}
742
731
warn ( msg ) ;
@@ -819,8 +808,7 @@ class PartialEvaluator {
819
808
. then ( async imageObj => {
820
809
imgData = await imageObj . createImageData (
821
810
/* forceRGBA = */ false ,
822
- /* isOffscreenCanvasSupported = */ this . options
823
- . isOffscreenCanvasSupported
811
+ isOffscreenCanvasSupported
824
812
) ;
825
813
imgData . dataLen = imgData . bitmap
826
814
? imgData . width * imgData . height * 4
0 commit comments