pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1605864 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
Date Thu, 26 Jun 2014 18:03:07 GMT
Author: tilman
Date: Thu Jun 26 18:03:07 2014
New Revision: 1605864

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

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java?rev=1605864&r1=1605863&r2=1605864&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
Thu Jun 26 18:03:07 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,11 +33,13 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.filter.MissingImageReaderException;
 import org.apache.pdfbox.rendering.PageDrawer;
 import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
 import org.apache.pdfbox.pdmodel.graphics.PDXObject;
+import org.apache.pdfbox.pdmodel.graphics.state.PDGraphicsState;
 import org.apache.pdfbox.util.Matrix;
 import org.apache.pdfbox.util.operator.PDFOperator;
 import org.apache.pdfbox.util.operator.OperatorProcessor;
@@ -118,6 +123,34 @@ public final class Invoke extends Operat
                                     context.getGraphicsState().getCurrentTransformationMatrix());
                     context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
                 }
+                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(pdResources, formContentStream);
 
                 // restore the graphics state



Mime
View raw message