pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1606315 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
Date Sat, 28 Jun 2014 10:53:42 GMT
Author: tilman
Date: Sat Jun 28 10:53:41 2014
New Revision: 1606315

URL: http://svn.apache.org/r1606315
Log:
PDFBOX-1875: use BBox for clipping when rendering a form xobject

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java?rev=1606315&r1=1606314&r2=1606315&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
Sat Jun 28 10:53:41 2014
@@ -17,6 +17,9 @@
 package org.apache.pdfbox.util.operator.pagedrawer;
 
 import java.awt.geom.AffineTransform;
+import java.awt.geom.Area;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Point2D;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.util.List;
@@ -30,6 +33,7 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdfviewer.PageDrawer;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
@@ -129,7 +133,35 @@ public class Invoke extends OperatorProc
                 Matrix xobjectCTM = matrix.multiply( context.getGraphicsState().getCurrentTransformationMatrix());
                 context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
             }
-            getContext().processSubStream( page, pdResources, formContentstream );
+            if (form.getBBox() != null)
+            {
+                PDGraphicsState graphicsState = context.getGraphicsState();
+                PDRectangle bBox = form.getBBox();
+
+                float x1 = bBox.getLowerLeftX();
+                float y1 = bBox.getLowerLeftY();
+                float x2 = bBox.getUpperRightX();
+                float y2 = bBox.getUpperRightY();
+
+                Point2D p0 = drawer.transformedPoint(x1, y1);
+                Point2D p1 = drawer.transformedPoint(x2, y1);
+                Point2D p2 = drawer.transformedPoint(x2, y2);
+                Point2D p3 = drawer.transformedPoint(x1, y2);
+
+                GeneralPath bboxPath = new GeneralPath();
+                bboxPath.moveTo((float) p0.getX(), (float) p0.getY());
+                bboxPath.lineTo((float) p1.getX(), (float) p1.getY());
+                bboxPath.lineTo((float) p2.getX(), (float) p2.getY());
+                bboxPath.lineTo((float) p3.getX(), (float) p3.getY());
+                bboxPath.closePath();
+                
+                Area resultClippingArea = new Area(graphicsState.getCurrentClippingPath());
+                Area newArea = new Area(bboxPath);            
+                resultClippingArea.intersect(newArea);
+
+                graphicsState.setCurrentClippingPath(resultClippingArea);
+            }
+            getContext().processSubStream(page, pdResources, formContentstream);
             
             // restore the graphics state
             context.setGraphicsState( (PDGraphicsState)context.getGraphicsStack().pop() );



Mime
View raw message