You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2021/05/08 05:48:09 UTC
svn commit: r1889657 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java
Author: tilman
Date: Sat May 8 05:48:09 2021
New Revision: 1889657
URL: http://svn.apache.org/viewvc?rev=1889657&view=rev
Log:
PDFBOX-4892: avoid NPE as suggested by valerybokov
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java?rev=1889657&r1=1889656&r2=1889657&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java Sat May 8 05:48:09 2021
@@ -169,9 +169,9 @@ class TilingPaint implements Paint
Math.abs(patternMatrix.getScalingFactorY()));
// move origin to (0,0)
+ PDRectangle bbox = pattern.getBBox();
newPatternMatrix.concatenate(
- Matrix.getTranslateInstance(-pattern.getBBox().getLowerLeftX(),
- -pattern.getBBox().getLowerLeftY()));
+ Matrix.getTranslateInstance(-bbox.getLowerLeftX(), -bbox.getLowerLeftY()));
// render using PageDrawer
drawer.drawTilingPattern(graphics, pattern, colorSpace, color, newPatternMatrix);
@@ -200,20 +200,25 @@ class TilingPaint implements Paint
/**
* Returns the anchor rectangle, which includes the XStep/YStep and scaling.
*/
- private Rectangle2D getAnchorRect(PDTilingPattern pattern)
+ private Rectangle2D getAnchorRect(PDTilingPattern pattern) throws IOException
{
+ PDRectangle bbox = pattern.getBBox();
+ if (bbox == null)
+ {
+ throw new IOException("Pattern /BBox is missing");
+ }
float xStep = pattern.getXStep();
if (xStep == 0)
{
LOG.warn("/XStep is 0, using pattern /BBox width");
- xStep = pattern.getBBox().getWidth();
+ xStep = bbox.getWidth();
}
float yStep = pattern.getYStep();
if (yStep == 0)
{
LOG.warn("/YStep is 0, using pattern /BBox height");
- yStep = pattern.getBBox().getHeight();
+ yStep = bbox.getHeight();
}
float xScale = patternMatrix.getScalingFactorX();
@@ -227,7 +232,7 @@ class TilingPaint implements Paint
LOG.info("Pattern surface is too large, will be clipped");
LOG.info("width: " + width + ", height: " + height);
LOG.info("XStep: " + xStep + ", YStep: " + yStep);
- LOG.info("bbox: " + pattern.getBBox());
+ LOG.info("bbox: " + bbox);
LOG.info("pattern matrix: " + pattern.getMatrix());
LOG.info("concatenated matrix: " + patternMatrix);
width = Math.min(MAXEDGE, Math.abs(width)) * Math.signum(width);
@@ -236,9 +241,8 @@ class TilingPaint implements Paint
}
// returns the anchor rect with scaling applied
- PDRectangle anchor = pattern.getBBox();
- return new Rectangle2D.Float(anchor.getLowerLeftX() * xScale,
- anchor.getLowerLeftY() * yScale,
+ return new Rectangle2D.Float(bbox.getLowerLeftX() * xScale,
+ bbox.getLowerLeftY() * yScale,
width, height);
}
}