Skip to content

Commit

Permalink
PDFBOX-5307: for images that include SMask/Mask entries, ignore an SM…
Browse files Browse the repository at this point in the history
…ask defined in the current graphics state, as done by SehoAhn and Jonas Jenwald in PDF.js PR 19269

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922800 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 31, 2024
1 parent af4c174 commit 8f8ece5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ else if (scaleX != 0 && scaleY != 0)
BufferedImage image = pdImage.getStencilImage(getNonStrokingPaint());

// draw the image
drawBufferedImage(image, at);
drawBufferedImage(pdImage, image, at);
}
}
else
Expand All @@ -1247,12 +1247,12 @@ else if (scaleX != 0 && scaleY != 0)
{
int subsampling = getSubsampling(pdImage, at);
// draw the subsampled image
drawBufferedImage(pdImage.getImage(null, subsampling), at);
drawBufferedImage(pdImage, pdImage.getImage(null, subsampling), at);
}
else
{
// subsampling not allowed, draw the image
drawBufferedImage(pdImage.getImage(), at);
drawBufferedImage(pdImage, pdImage.getImage(), at);
}
}

Expand Down Expand Up @@ -1296,7 +1296,7 @@ protected int getSubsampling(PDImage pdImage, AffineTransform at)
return subsampling;
}

private void drawBufferedImage(BufferedImage image, AffineTransform at) throws IOException
private void drawBufferedImage(PDImage pdImage, BufferedImage image, AffineTransform at) throws IOException
{
AffineTransform originalTransform = graphics.getTransform();
AffineTransform imageTransform = new AffineTransform(at);
Expand All @@ -1306,7 +1306,15 @@ private void drawBufferedImage(BufferedImage image, AffineTransform at) throws I
imageTransform.translate(0, -height);

PDSoftMask softMask = getGraphicsState().getSoftMask();
if( softMask != null )

// PDFBOX-5307 / PDF.js PR#19269
// From section 11.6.4.3 Mask Shape and Opacity in the PDF specification:
// "Either form of mask in the image dictionary shall override the current soft mask
// in the graphics state"
boolean hasImageMask = pdImage.getCOSObject().containsKey(COSName.MASK) ||
pdImage.getCOSObject().containsKey(COSName.SMASK);

if (softMask != null && !hasImageMask)
{
Rectangle2D rectangle = new Rectangle2D.Float(0, 0, width, height);
Paint awtPaint = new TexturePaint(image, rectangle);
Expand Down

0 comments on commit 8f8ece5

Please sign in to comment.