Author: tilman
Date: Tue Dec 9 18:46:57 2025
New Revision: 1930396
Log:
PDFBOX-5660: optimize, as suggested by Valery Bokov, closes #364
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
==============================================================================
---
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Tue Dec 9 18:38:14 2025 (r1930395)
+++
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Tue Dec 9 18:46:57 2025 (r1930396)
@@ -1085,7 +1085,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())
@@ -1114,12 +1115,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.
@@ -1498,9 +1499,10 @@ public class PageDrawer extends PDFGraph
LOG.error("shading " + shadingName + " does not exist in resources
dictionary");
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;
@@ -1509,10 +1511,11 @@ public class PageDrawer extends PDFGraph
// need to do it here and not in shading getRaster() because it may
have been rotated
PDRectangle bbox = shading.getBBox();
Area area;
+ Area currentClippingPath = graphicsState.getCurrentClippingPath();
if (bbox != null)
{
area = new Area(bbox.transform(ctm));
- area.intersect(getGraphicsState().getCurrentClippingPath());
+ area.intersect(currentClippingPath);
}
else
{
@@ -1524,18 +1527,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);
}