Skip to content

Commit 40923fa

Browse files
committed
PDFBOX-5660: optimize, as suggested by Valery Bokov, closes #364
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/branches/3.0@1930396 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5238b6f commit 40923fa

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,8 @@ public void drawImage(PDImage pdImage) throws IOException
10851085
{
10861086
return;
10871087
}
1088-
Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
1088+
PDGraphicsState graphicsState = getGraphicsState();
1089+
Matrix ctm = graphicsState.getCurrentTransformationMatrix();
10891090
AffineTransform at = ctm.createAffineTransform();
10901091

10911092
if (!pdImage.getInterpolate())
@@ -1114,12 +1115,12 @@ public void drawImage(PDImage pdImage) throws IOException
11141115
}
11151116
}
11161117

1117-
graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
1118+
graphics.setComposite(graphicsState.getNonStrokingJavaComposite());
11181119
setClip();
11191120

11201121
if (pdImage.isStencil())
11211122
{
1122-
if (getGraphicsState().getNonStrokingColor().getColorSpace() instanceof PDPattern)
1123+
if (graphicsState.getNonStrokingColor().getColorSpace() instanceof PDPattern)
11231124
{
11241125
// The earlier code for stencils (see "else") doesn't work with patterns because the
11251126
// CTM is not taken into consideration.
@@ -1498,9 +1499,10 @@ public void shadingFill(COSName shadingName) throws IOException
14981499
LOG.error("shading " + shadingName + " does not exist in resources dictionary");
14991500
return;
15001501
}
1501-
Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
1502+
PDGraphicsState graphicsState = getGraphicsState();
1503+
Matrix ctm = graphicsState.getCurrentTransformationMatrix();
15021504

1503-
graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
1505+
graphics.setComposite(graphicsState.getNonStrokingJavaComposite());
15041506
Shape savedClip = graphics.getClip();
15051507
graphics.setClip(null);
15061508
lastClips = null;
@@ -1509,10 +1511,11 @@ public void shadingFill(COSName shadingName) throws IOException
15091511
// need to do it here and not in shading getRaster() because it may have been rotated
15101512
PDRectangle bbox = shading.getBBox();
15111513
Area area;
1514+
Area currentClippingPath = graphicsState.getCurrentClippingPath();
15121515
if (bbox != null)
15131516
{
15141517
area = new Area(bbox.transform(ctm));
1515-
area.intersect(getGraphicsState().getCurrentClippingPath());
1518+
area.intersect(currentClippingPath);
15161519
}
15171520
else
15181521
{
@@ -1524,18 +1527,18 @@ public void shadingFill(COSName shadingName) throws IOException
15241527
bounds.add(new Point2D.Double(Math.ceil(bounds.getMaxX() + 1),
15251528
Math.ceil(bounds.getMaxY() + 1)));
15261529
area = new Area(bounds);
1527-
area.intersect(getGraphicsState().getCurrentClippingPath());
1530+
area.intersect(currentClippingPath);
15281531
}
15291532
else
15301533
{
1531-
area = getGraphicsState().getCurrentClippingPath();
1534+
area = currentClippingPath;
15321535
}
15331536
}
15341537
if (!area.isEmpty())
15351538
{
15361539
// creating Paint is sometimes a costly operation, so avoid if possible
15371540
Paint paint = shading.toPaint(ctm);
1538-
paint = applySoftMaskToPaint(paint, getGraphicsState().getSoftMask());
1541+
paint = applySoftMaskToPaint(paint, graphicsState.getSoftMask());
15391542
graphics.setPaint(paint);
15401543
graphics.fill(area);
15411544
}

0 commit comments

Comments
 (0)