@@ -72,7 +72,6 @@ import { BaseStream } from "./base_stream.js";
7272import { bidi } from "./bidi.js" ;
7373import { ColorSpace } from "./colorspace.js" ;
7474import { ColorSpaceUtils } from "./colorspace_utils.js" ;
75- import { DecodeStream } from "./decode_stream.js" ;
7675import { getFontSubstitution } from "./font_substitutions.js" ;
7776import { getGlyphsUnicode } from "./glyphlist.js" ;
7877import { getMetrics } from "./metrics.js" ;
@@ -571,7 +570,10 @@ class PartialEvaluator {
571570 localImageCache,
572571 localColorSpaceCache,
573572 } ) {
574- const dict = image . dict ;
573+ const { maxImageSize, ignoreErrors, isOffscreenCanvasSupported } =
574+ this . options ;
575+
576+ const { dict } = image ;
575577 const imageRef = dict . objId ;
576578 const w = dict . get ( "W" , "Width" ) ;
577579 const h = dict . get ( "H" , "Height" ) ;
@@ -580,15 +582,14 @@ class PartialEvaluator {
580582 warn ( "Image dimensions are missing, or not numbers." ) ;
581583 return ;
582584 }
583- const maxImageSize = this . options . maxImageSize ;
584585 if ( maxImageSize !== - 1 && w * h > maxImageSize ) {
585586 const msg = "Image exceeded maximum allowed size and was removed." ;
586587
587- if ( this . options . ignoreErrors ) {
588- warn ( msg ) ;
589- return ;
588+ if ( ! ignoreErrors ) {
589+ throw new Error ( msg ) ;
590590 }
591- throw new Error ( msg ) ;
591+ warn ( msg ) ;
592+ return ;
592593 }
593594
594595 let optionalContent ;
@@ -607,52 +608,10 @@ class PartialEvaluator {
607608 // data can't be done here. Instead of creating a
608609 // complete PDFImage, only read the information needed
609610 // 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-
648611 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 ,
656615 } ) ;
657616
658617 if ( imgData . isSingleOpaquePixel ) {
@@ -677,6 +636,36 @@ class PartialEvaluator {
677636 return ;
678637 }
679638
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+
680669 const objId = `mask_${ this . idFactory . createObjId ( ) } ` ;
681670 operatorList . addDependency ( objId ) ;
682671
@@ -736,7 +725,7 @@ class PartialEvaluator {
736725 } catch ( reason ) {
737726 const msg = `Unable to decode inline image: "${ reason } ".` ;
738727
739- if ( ! this . options . ignoreErrors ) {
728+ if ( ! ignoreErrors ) {
740729 throw new Error ( msg ) ;
741730 }
742731 warn ( msg ) ;
@@ -819,8 +808,7 @@ class PartialEvaluator {
819808 . then ( async imageObj => {
820809 imgData = await imageObj . createImageData (
821810 /* forceRGBA = */ false ,
822- /* isOffscreenCanvasSupported = */ this . options
823- . isOffscreenCanvasSupported
811+ isOffscreenCanvasSupported
824812 ) ;
825813 imgData . dataLen = imgData . bitmap
826814 ? imgData . width * imgData . height * 4
0 commit comments