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 2022/01/22 03:58:08 UTC
svn commit: r1897314 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
Author: tilman
Date: Sat Jan 22 03:58:07 2022
New Revision: 1897314
URL: http://svn.apache.org/viewvc?rev=1897314&view=rev
Log:
PDFBOX-5366: clean up after processing operators
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=1897314&r1=1897313&r2=1897314&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 Sat Jan 22 03:58:07 2022
@@ -240,12 +240,17 @@ public abstract class PDFStreamEngine
// clip to bounding box
clipToRect(group.getBBox());
- processStreamOperators(group);
-
- initialMatrix = parentMatrix;
+ try
+ {
+ processStreamOperators(group);
+ }
+ finally
+ {
+ initialMatrix = parentMatrix;
- restoreGraphicsStack(savedStack);
- popResources(parent);
+ restoreGraphicsStack(savedStack);
+ popResources(parent);
+ }
}
/**
@@ -281,14 +286,19 @@ public abstract class PDFStreamEngine
Matrix textLineMatrixOld = textLineMatrix;
textLineMatrix = new Matrix();
- processStreamOperators(charProc);
-
- // restore text matrices
- textMatrix = textMatrixOld;
- textLineMatrix = textLineMatrixOld;
+ try
+ {
+ processStreamOperators(charProc);
+ }
+ finally
+ {
+ // restore text matrices
+ textMatrix = textMatrixOld;
+ textLineMatrix = textLineMatrixOld;
- restoreGraphicsStack(savedStack);
- popResources(parent);
+ restoreGraphicsStack(savedStack);
+ popResources(parent);
+ }
}
/**
@@ -301,9 +311,6 @@ public abstract class PDFStreamEngine
protected void processAnnotation(PDAnnotation annotation, PDAppearanceStream appearance)
throws IOException
{
- PDResources parent = pushResources(appearance);
- Deque<PDGraphicsState> savedStack = saveGraphicsStack();
-
PDRectangle bbox = appearance.getBBox();
PDRectangle rect = annotation.getRectangle();
@@ -311,6 +318,9 @@ public abstract class PDFStreamEngine
if (rect != null && rect.getWidth() > 0 && rect.getHeight() > 0 &&
bbox != null && bbox.getWidth() > 0 && bbox.getHeight() > 0)
{
+ PDResources parent = pushResources(appearance);
+ Deque<PDGraphicsState> savedStack = saveGraphicsStack();
+
Matrix matrix = appearance.getMatrix();
// transformed appearance box fixme: may be an arbitrary shape
@@ -339,11 +349,16 @@ public abstract class PDFStreamEngine
// needed for patterns in appearance streams, e.g. PDFBOX-2182
initialMatrix = aa.clone();
- processStreamOperators(appearance);
+ try
+ {
+ processStreamOperators(appearance);
+ }
+ finally
+ {
+ restoreGraphicsStack(savedStack);
+ popResources(parent);
+ }
}
-
- restoreGraphicsStack(savedStack);
- popResources(parent);
}
/**
@@ -383,7 +398,8 @@ public abstract class PDFStreamEngine
Deque<PDGraphicsState> savedStack = saveGraphicsStack();
// save a clean state (new clipping path, line path, etc.)
- Rectangle2D bbox = tilingPattern.getBBox().transform(patternMatrix).getBounds2D();
+ PDRectangle tilingBBox = tilingPattern.getBBox();
+ Rectangle2D bbox = tilingBBox.transform(patternMatrix).getBounds2D();
PDRectangle rect = new PDRectangle((float)bbox.getX(), (float)bbox.getY(),
(float)bbox.getWidth(), (float)bbox.getHeight());
graphicsStack.push(new PDGraphicsState(rect));
@@ -403,18 +419,24 @@ public abstract class PDFStreamEngine
graphicsState.getCurrentTransformationMatrix().concatenate(patternMatrix);
// clip to bounding box
- clipToRect(tilingPattern.getBBox());
+ clipToRect(tilingBBox);
// save text matrices (pattern stream may contain BT/ET, see PDFBOX-4896)
Matrix textMatrixSave = textMatrix;
Matrix textLineMatrixSave = textLineMatrix;
- processStreamOperators(tilingPattern);
- textMatrix = textMatrixSave;
- textLineMatrix = textLineMatrixSave;
-
- initialMatrix = parentMatrix;
- restoreGraphicsStack(savedStack);
- popResources(parent);
+
+ try
+ {
+ processStreamOperators(tilingPattern);
+ }
+ finally
+ {
+ textMatrix = textMatrixSave;
+ textLineMatrix = textLineMatrixSave;
+ initialMatrix = parentMatrix;
+ restoreGraphicsStack(savedStack);
+ popResources(parent);
+ }
}
/**
@@ -486,11 +508,16 @@ public abstract class PDFStreamEngine
PDRectangle bbox = contentStream.getBBox();
clipToRect(bbox);
- processStreamOperators(contentStream);
-
- initialMatrix = parentMatrix;
- restoreGraphicsStack(savedStack);
- popResources(parent);
+ try
+ {
+ processStreamOperators(contentStream);
+ }
+ finally
+ {
+ initialMatrix = parentMatrix;
+ restoreGraphicsStack(savedStack);
+ popResources(parent);
+ }
}
/**