@@ -689,7 +689,7 @@ export default function (doc, svg, x, y, options) {
689689 doc . page . xobjects [ group . name ] = group . xobj ;
690690 doc . addContent ( '/' + group . name + ' Do' ) ;
691691 }
692- function docApplyMask ( group ) {
692+ function docApplyAlphaMask ( group ) {
693693 let name = 'M' + ( doc . _maskCount = ( doc . _maskCount || 0 ) + 1 ) ;
694694 let gstate = doc . ref ( {
695695 Type : 'ExtGState' ,
@@ -706,6 +706,22 @@ export default function (doc, svg, x, y, options) {
706706 doc . page . ext_gstates [ name ] = gstate ;
707707 doc . addContent ( '/' + name + ' gs' ) ;
708708 }
709+ function docApplyMask ( group ) {
710+ let name = 'M' + ( doc . _maskCount = ( doc . _maskCount || 0 ) + 1 ) ;
711+ let gstate = doc . ref ( {
712+ Type : 'ExtGState' ,
713+ CA : 1 ,
714+ ca : 1 ,
715+ BM : 'Normal' ,
716+ SMask : {
717+ S : 'Luminosity' ,
718+ G : group . xobj ,
719+ } ,
720+ } ) ;
721+ gstate . end ( ) ;
722+ doc . page . ext_gstates [ name ] = gstate ;
723+ doc . addContent ( '/' + name + ' gs' ) ;
724+ }
709725 function applyBlendMode ( group , blendMode ) {
710726 // map svg blendMode to pdf
711727 const key = String ( blendMode || '' ) . toLowerCase ( ) ;
@@ -3297,7 +3313,7 @@ export default function (doc, svg, x, y, options) {
32973313 this . drawChildren ( true , false ) ;
32983314 doc . restore ( ) ;
32993315 docEndGroup ( group ) ;
3300- docApplyMask ( group ) ;
3316+ docApplyAlphaMask ( group ) ;
33013317 } ;
33023318 } ;
33033319
@@ -3321,11 +3337,16 @@ export default function (doc, svg, x, y, options) {
33213337 if ( this . attr ( 'maskContentUnits' ) === 'objectBoundingBox' ) {
33223338 doc . transform ( bBox [ 2 ] - bBox [ 0 ] , 0 , 0 , bBox [ 3 ] - bBox [ 1 ] , bBox [ 0 ] , bBox [ 1 ] ) ;
33233339 }
3340+ const maskType = this . attr ( 'mask-type' ) ?? 'luminance' ;
33243341 this . clip ( ) ;
33253342 this . drawChildren ( false , true ) ;
33263343 doc . restore ( ) ;
33273344 docEndGroup ( group ) ;
3328- docApplyMask ( group ) ;
3345+ if ( maskType === 'alpha' ) {
3346+ docApplyAlphaMask ( group ) ;
3347+ } else {
3348+ docApplyMask ( group ) ;
3349+ }
33293350 } ;
33303351 } ;
33313352
0 commit comments