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/04/11 13:44:23 UTC
svn commit: r1888628 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
Author: tilman
Date: Sun Apr 11 13:44:23 2021
New Revision: 1888628
URL: http://svn.apache.org/viewvc?rev=1888628&view=rev
Log:
PDFBOX-4892: performance improvements, as suggested by valerybokov
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java?rev=1888628&r1=1888627&r2=1888628&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java Sun Apr 11 13:44:23 2021
@@ -205,20 +205,21 @@ public abstract class PDFStreamEngine
Deque<PDGraphicsState> savedStack = saveGraphicsStack();
Matrix parentMatrix = initialMatrix;
+ PDGraphicsState graphicsState = getGraphicsState();
// the stream's initial matrix includes the parent CTM, e.g. this allows a scaled form
- initialMatrix = getGraphicsState().getCurrentTransformationMatrix().clone();
+ initialMatrix = graphicsState.getCurrentTransformationMatrix().clone();
// transform the CTM using the stream's matrix
- getGraphicsState().getCurrentTransformationMatrix().concatenate(group.getMatrix());
+ graphicsState.getCurrentTransformationMatrix().concatenate(group.getMatrix());
// Before execution of the transparency group XObjectâs content stream,
// the current blend mode in the graphics state shall be initialized to Normal,
// the current stroking and nonstroking alpha constants to 1.0, and the current soft mask to None.
- getGraphicsState().setBlendMode(BlendMode.NORMAL);
- getGraphicsState().setAlphaConstant(1);
- getGraphicsState().setNonStrokeAlphaConstant(1);
- getGraphicsState().setSoftMask(null);
+ graphicsState.setBlendMode(BlendMode.NORMAL);
+ graphicsState.setAlphaConstant(1);
+ graphicsState.setNonStrokeAlphaConstant(1);
+ graphicsState.setSoftMask(null);
// clip to bounding box
clipToRect(group.getBBox());
@@ -289,12 +290,13 @@ public abstract class PDFStreamEngine
PDRectangle bbox = appearance.getBBox();
PDRectangle rect = annotation.getRectangle();
- Matrix matrix = appearance.getMatrix();
// zero-sized rectangles are not valid
if (rect != null && rect.getWidth() > 0 && rect.getHeight() > 0 &&
bbox != null && bbox.getWidth() > 0 && bbox.getHeight() > 0)
{
+ Matrix matrix = appearance.getMatrix();
+
// transformed appearance box fixme: may be an arbitrary shape
Rectangle2D transformedBox = bbox.transform(matrix).getBounds2D();
@@ -369,19 +371,20 @@ public abstract class PDFStreamEngine
PDRectangle rect = new PDRectangle((float)bbox.getX(), (float)bbox.getY(),
(float)bbox.getWidth(), (float)bbox.getHeight());
graphicsStack.push(new PDGraphicsState(rect));
+ PDGraphicsState graphicsState = getGraphicsState();
// non-colored patterns have to be given a color
if (colorSpace != null)
{
color = new PDColor(color.getComponents(), colorSpace);
- getGraphicsState().setNonStrokingColorSpace(colorSpace);
- getGraphicsState().setNonStrokingColor(color);
- getGraphicsState().setStrokingColorSpace(colorSpace);
- getGraphicsState().setStrokingColor(color);
+ graphicsState.setNonStrokingColorSpace(colorSpace);
+ graphicsState.setNonStrokingColor(color);
+ graphicsState.setStrokingColorSpace(colorSpace);
+ graphicsState.setStrokingColor(color);
}
// transform the CTM using the stream's matrix
- getGraphicsState().getCurrentTransformationMatrix().concatenate(patternMatrix);
+ graphicsState.getCurrentTransformationMatrix().concatenate(patternMatrix);
// clip to bounding box
clipToRect(tilingPattern.getBBox());
@@ -455,12 +458,13 @@ public abstract class PDFStreamEngine
PDResources parent = pushResources(contentStream);
Deque<PDGraphicsState> savedStack = saveGraphicsStack();
Matrix parentMatrix = initialMatrix;
+ PDGraphicsState graphicsState = getGraphicsState();
// transform the CTM using the stream's matrix
- getGraphicsState().getCurrentTransformationMatrix().concatenate(contentStream.getMatrix());
+ graphicsState.getCurrentTransformationMatrix().concatenate(contentStream.getMatrix());
// the stream's initial matrix includes the parent CTM, e.g. this allows a scaled form
- initialMatrix = getGraphicsState().getCurrentTransformationMatrix().clone();
+ initialMatrix = graphicsState.getCurrentTransformationMatrix().clone();
// clip to bounding box
PDRectangle bbox = contentStream.getBBox();