@@ -1238,7 +1238,7 @@ else if (scaleX != 0 && scaleY != 0)
12381238 BufferedImage image = pdImage .getStencilImage (getNonStrokingPaint ());
12391239
12401240 // draw the image
1241- drawBufferedImage (image , at );
1241+ drawBufferedImage (pdImage , image , at );
12421242 }
12431243 }
12441244 else
@@ -1247,12 +1247,12 @@ else if (scaleX != 0 && scaleY != 0)
12471247 {
12481248 int subsampling = getSubsampling (pdImage , at );
12491249 // draw the subsampled image
1250- drawBufferedImage (pdImage .getImage (null , subsampling ), at );
1250+ drawBufferedImage (pdImage , pdImage .getImage (null , subsampling ), at );
12511251 }
12521252 else
12531253 {
12541254 // subsampling not allowed, draw the image
1255- drawBufferedImage (pdImage .getImage (), at );
1255+ drawBufferedImage (pdImage , pdImage .getImage (), at );
12561256 }
12571257 }
12581258
@@ -1296,7 +1296,7 @@ protected int getSubsampling(PDImage pdImage, AffineTransform at)
12961296 return subsampling ;
12971297 }
12981298
1299- private void drawBufferedImage (BufferedImage image , AffineTransform at ) throws IOException
1299+ private void drawBufferedImage (PDImage pdImage , BufferedImage image , AffineTransform at ) throws IOException
13001300 {
13011301 AffineTransform originalTransform = graphics .getTransform ();
13021302 AffineTransform imageTransform = new AffineTransform (at );
@@ -1306,7 +1306,15 @@ private void drawBufferedImage(BufferedImage image, AffineTransform at) throws I
13061306 imageTransform .translate (0 , -height );
13071307
13081308 PDSoftMask softMask = getGraphicsState ().getSoftMask ();
1309- if ( softMask != null )
1309+
1310+ // PDFBOX-5307 / PDF.js PR#19269
1311+ // From section 11.6.4.3 Mask Shape and Opacity in the PDF specification:
1312+ // "Either form of mask in the image dictionary shall override the current soft mask
1313+ // in the graphics state"
1314+ boolean hasImageMask = pdImage .getCOSObject ().containsKey (COSName .MASK ) ||
1315+ pdImage .getCOSObject ().containsKey (COSName .SMASK );
1316+
1317+ if (softMask != null && !hasImageMask )
13101318 {
13111319 Rectangle2D rectangle = new Rectangle2D .Float (0 , 0 , width , height );
13121320 Paint awtPaint = new TexturePaint (image , rectangle );
0 commit comments