Author: tilman
Date: Tue Dec 9 18:47:07 2025
New Revision: 1930398
Log:
PDFBOX-5660: optimize, as suggested by Valery Bokov, closes #364
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
==============================================================================
---
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Tue Dec 9 18:47:02 2025 (r1930397)
+++
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Tue Dec 9 18:47:07 2025 (r1930398)
@@ -1084,7 +1084,8 @@ public class PageDrawer extends PDFGraph
{
return;
}
- Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
+ PDGraphicsState graphicsState = getGraphicsState();
+ Matrix ctm = graphicsState.getCurrentTransformationMatrix();
AffineTransform at = ctm.createAffineTransform();
if (!pdImage.getInterpolate())
@@ -1113,12 +1114,12 @@ public class PageDrawer extends PDFGraph
}
}
-
graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
+ graphics.setComposite(graphicsState.getNonStrokingJavaComposite());
setClip();
if (pdImage.isStencil())
{
- if (getGraphicsState().getNonStrokingColor().getColorSpace()
instanceof PDPattern)
+ if (graphicsState.getNonStrokingColor().getColorSpace() instanceof
PDPattern)
{
// The earlier code for stencils (see "else") doesn't work
with patterns because the
// CTM is not taken into consideration.
@@ -1497,9 +1498,10 @@ public class PageDrawer extends PDFGraph
LOG.error("shading {} does not exist in resources dictionary",
shadingName);
return;
}
- Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
+ PDGraphicsState graphicsState = getGraphicsState();
+ Matrix ctm = graphicsState.getCurrentTransformationMatrix();
-
graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
+ graphics.setComposite(graphicsState.getNonStrokingJavaComposite());
Shape savedClip = graphics.getClip();
graphics.setClip(null);
lastClips = null;
@@ -1507,11 +1509,12 @@ public class PageDrawer extends PDFGraph
// get the transformed BBox and intersect with current clipping path
// need to do it here and not in shading getRaster() because it may
have been rotated
PDRectangle bbox = shading.getBBox();
+ Area currentClippingPath = graphicsState.getCurrentClippingPath();
Area area;
if (bbox != null)
{
area = new Area(bbox.transform(ctm));
- area.intersect(getGraphicsState().getCurrentClippingPath());
+ area.intersect(currentClippingPath);
}
else
{
@@ -1523,18 +1526,18 @@ public class PageDrawer extends PDFGraph
bounds.add(new Point2D.Double(Math.ceil(bounds.getMaxX() + 1),
Math.ceil(bounds.getMaxY() + 1)));
area = new Area(bounds);
- area.intersect(getGraphicsState().getCurrentClippingPath());
+ area.intersect(currentClippingPath);
}
else
{
- area = getGraphicsState().getCurrentClippingPath();
+ area = currentClippingPath;
}
}
if (!area.isEmpty())
{
// creating Paint is sometimes a costly operation, so avoid if
possible
Paint paint = shading.toPaint(ctm);
- paint = applySoftMaskToPaint(paint,
getGraphicsState().getSoftMask());
+ paint = applySoftMaskToPaint(paint, graphicsState.getSoftMask());
graphics.setPaint(paint);
graphics.fill(area);
}