pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1619223 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
Date Wed, 20 Aug 2014 20:46:07 GMT
Author: tilman
Date: Wed Aug 20 20:46:06 2014
New Revision: 1619223

URL: http://svn.apache.org/r1619223
Log:
PDFBOX-2277: apply BBox clipping to appearance stream

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java?rev=1619223&r1=1619222&r2=1619223&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java Wed
Aug 20 20:46:06 2014
@@ -48,11 +48,15 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType3;
 import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType4;
 import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType5;
+import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType6;
+import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType7;
 import org.apache.pdfbox.pdmodel.graphics.shading.Type1ShadingPaint;
 import org.apache.pdfbox.pdmodel.graphics.shading.AxialShadingPaint;
 import org.apache.pdfbox.pdmodel.graphics.shading.RadialShadingPaint;
 import org.apache.pdfbox.pdmodel.graphics.shading.Type4ShadingPaint;
 import org.apache.pdfbox.pdmodel.graphics.shading.Type5ShadingPaint;
+import org.apache.pdfbox.pdmodel.graphics.shading.Type6ShadingPaint;
+import org.apache.pdfbox.pdmodel.graphics.shading.Type7ShadingPaint;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
@@ -62,10 +66,6 @@ import org.apache.pdfbox.util.PDFStreamE
 import org.apache.pdfbox.util.ResourceLoader;
 import org.apache.pdfbox.util.TextPosition;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType6;
-import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingType7;
-import org.apache.pdfbox.pdmodel.graphics.shading.Type6ShadingPaint;
-import org.apache.pdfbox.pdmodel.graphics.shading.Type7ShadingPaint;
 
 
 /**
@@ -156,8 +156,39 @@ public class PageDrawer extends PDFStrea
                 { 
                     PDAppearanceStream appearance = 
                         (PDAppearanceStream)appearanceMap.get( appearanceName ); 
-                    if( appearance != null ) 
-                    { 
+                    if (appearance != null)
+                    {
+                        // save the graphics state
+                        getGraphicsStack().push((PDGraphicsState) getGraphicsState().clone());
+                        if (appearance.getBoundingBox() != null)
+                        {
+                            PDGraphicsState graphicsState = getGraphicsState();
+                            PDRectangle bBox = appearance.getBoundingBox();
+
+                            float x1 = bBox.getLowerLeftX();
+                            float y1 = bBox.getLowerLeftY();
+                            float x2 = bBox.getUpperRightX();
+                            float y2 = bBox.getUpperRightY();
+
+                            Point2D p0 = transformedPoint(x1, y1);
+                            Point2D p1 = transformedPoint(x2, y1);
+                            Point2D p2 = transformedPoint(x2, y2);
+                            Point2D p3 = 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);
+                        }
+
                         Point2D point = new Point2D.Float(rect.getLowerLeftX(), rect.getLowerLeftY());
                         Matrix matrix = appearance.getMatrix();
                         if (matrix != null) 
@@ -169,6 +200,9 @@ public class PageDrawer extends PDFStrea
                         g.translate( (int)point.getX(), -(int)point.getY() );
                         processSubStream( page, appearance.getResources(), appearance.getStream()
); 
                         g.translate( -(int)point.getX(), (int)point.getY() ); 
+
+                        // restore the graphics state
+                        setGraphicsState((PDGraphicsState) getGraphicsStack().pop());
                     }
                 }
             }



Mime
View raw message