pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1635011 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: contentstream/PDFStreamEngine.java pdmodel/graphics/state/PDExternalGraphicsState.java pdmodel/graphics/state/PDGraphicsState.java rendering/PageDrawer.java
Date Wed, 29 Oct 2014 00:08:56 GMT
Author: jahewson
Date: Wed Oct 29 00:08:55 2014
New Revision: 1635011

URL: http://svn.apache.org/r1635011
Log:
PDFBOX-2423: Fix transparency group rendering

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.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=1635011&r1=1635010&r2=1635011&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
Wed Oct 29 00:08:55 2014
@@ -43,6 +43,7 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.pdmodel.font.PDFontFactory;
 import org.apache.pdfbox.pdmodel.font.PDType3CharProc;
 import org.apache.pdfbox.pdmodel.font.PDType3Font;
+import org.apache.pdfbox.pdmodel.graphics.blend.BlendMode;
 import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
 import org.apache.pdfbox.pdmodel.graphics.state.PDGraphicsState;
@@ -173,7 +174,7 @@ public class PDFStreamEngine
      */
     public void showTransparencyGroup(PDFormXObject form) throws IOException
     {
-        showForm(form);
+        processTransparencyGroup(form);
     }
 
     /**
@@ -204,6 +205,40 @@ public class PDFStreamEngine
     }
 
     /**
+     * Processes a transparency group stream.
+     */
+    protected void processTransparencyGroup(PDFormXObject group)
+            throws IOException
+    {
+        if (currentPage == null)
+        {
+            throw new IllegalStateException("No current page, call " +
+                    "#processChildStream(PDContentStream, PDPage) instead");
+        }
+
+        PDResources parent = pushResources(group);
+        saveGraphicsState();
+
+        // transform the CTM using the stream's matrix (this is the FontMatrix)
+        getGraphicsState().getCurrentTransformationMatrix().concatenate(group.getMatrix());
+
+        // clip to bounding box
+        clipToRect(group.getBBox());
+
+        // render into a normal opaque buffer
+        PDGraphicsState state = getGraphicsState();
+        state.setBlendMode(BlendMode.NORMAL);
+        state.setAlphaConstant(1.0);
+        state.setNonStrokeAlphaConstants(1.0);
+        state.setSoftMask(null);
+
+        processStreamOperators(group);
+
+        restoreGraphicsState();
+        popResources(parent);
+    }
+
+    /**
      * Processes a Type 3 character stream.
      *
      * @param charProc Type 3 character procedure
@@ -330,17 +365,10 @@ public class PDFStreamEngine
         }
         clipToRect(bbox);
 
-        // fixme: stream matrix
-        Matrix oldSubStreamMatrix = subStreamMatrix;
-        subStreamMatrix = getGraphicsState().getCurrentTransformationMatrix();
-
         processStreamOperators(contentStream);
 
         restoreGraphicsState();
         popResources(parent);
-
-        // fixme: stream matrix
-        subStreamMatrix = oldSubStreamMatrix;
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java?rev=1635011&r1=1635010&r2=1635011&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java
Wed Oct 29 00:08:55 2014
@@ -119,7 +119,7 @@ public class PDExternalGraphicsState imp
             }
             else if( key.equals( COSName.CA ) )
             {
-                gs.setAlphaConstants( getStrokingAlphaConstant() );
+                gs.setAlphaConstant(getStrokingAlphaConstant());
             }
             else if( key.equals( COSName.CA_NS ) )
             {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java?rev=1635011&r1=1635010&r2=1635011&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
Wed Oct 29 00:08:55 2014
@@ -18,7 +18,6 @@ package org.apache.pdfbox.pdmodel.graphi
 
 import java.awt.BasicStroke;
 import java.awt.Composite;
-import java.awt.Rectangle;
 import java.awt.geom.Area;
 import java.awt.geom.GeneralPath;
 
@@ -55,8 +54,8 @@ public class PDGraphicsState implements 
     private boolean strokeAdjustment = false;
     private BlendMode blendMode = BlendMode.COMPATIBLE;
     private PDSoftMask softMask;
-    private double alphaConstants = 1.0;
-    private double nonStrokingAlphaConstants = 1.0;
+    private double alphaConstant = 1.0;
+    private double nonStrokingAlphaConstant = 1.0;
     private boolean alphaSource = false;
 
     // DEVICE-DEPENDENT parameters
@@ -203,9 +202,9 @@ public class PDGraphicsState implements 
      *
      * @return The value of the stroke alpha constants parameter.
      */
-    public double getAlphaConstants()
+    public double getAlphaConstant()
     {
-        return alphaConstants;
+        return alphaConstant;
     }
 
     /**
@@ -213,9 +212,9 @@ public class PDGraphicsState implements 
      *
      * @param value The value of the stroke alpha constants parameter.
      */
-    public void setAlphaConstants(double value)
+    public void setAlphaConstant(double value)
     {
-        alphaConstants = value;
+        alphaConstant = value;
     }
 
     /**
@@ -225,7 +224,7 @@ public class PDGraphicsState implements 
      */
     public double getNonStrokeAlphaConstants()
     {
-        return nonStrokingAlphaConstants;
+        return nonStrokingAlphaConstant;
     }
 
     /**
@@ -235,7 +234,7 @@ public class PDGraphicsState implements 
      */
     public void setNonStrokeAlphaConstants(double value)
     {
-        nonStrokingAlphaConstants = value;
+        nonStrokingAlphaConstant = value;
     }
 
     /**
@@ -583,11 +582,11 @@ public class PDGraphicsState implements 
 
     public Composite getStrokingJavaComposite()
     {
-        return BlendComposite.getInstance(blendMode, (float) alphaConstants);
+        return BlendComposite.getInstance(blendMode, (float) alphaConstant);
     }
 
     public Composite getNonStrokingJavaComposite()
     {
-        return BlendComposite.getInstance(blendMode, (float) nonStrokingAlphaConstants);
+        return BlendComposite.getInstance(blendMode, (float) nonStrokingAlphaConstant);
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1635011&r1=1635010&r2=1635011&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java Wed Oct
29 00:08:55 2014
@@ -58,7 +58,6 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
 import org.apache.pdfbox.pdmodel.font.PDType3Font;
 import org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern;
-import org.apache.pdfbox.pdmodel.graphics.blend.BlendMode;
 import org.apache.pdfbox.pdmodel.graphics.state.PDSoftMask;
 import org.apache.pdfbox.pdmodel.graphics.blend.SoftMaskPaint;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
@@ -420,7 +419,7 @@ public class PageDrawer extends PDFGraph
      */
     private Raster createSoftMaskRaster(PDSoftMask softMask) throws IOException
     {
-        TransparencyGroup transparencyGroup = createTransparencyGroup(softMask.getGroup());
+        TransparencyGroup transparencyGroup = new TransparencyGroup(softMask.getGroup());
         COSName subtype = softMask.getSubType();
         if (COSName.ALPHA.equals(subtype))
         {
@@ -506,8 +505,7 @@ public class PageDrawer extends PDFGraph
     public void strokePath() throws IOException
     {
         graphics.setComposite(getGraphicsState().getStrokingJavaComposite());
-        Paint strokingPaint = getStrokingPaint();
-        graphics.setPaint(strokingPaint);
+        graphics.setPaint(getStrokingPaint());
         graphics.setStroke(getStroke());
         setClip();
         graphics.draw(linePath);
@@ -518,8 +516,7 @@ public class PageDrawer extends PDFGraph
     public void fillPath(int windingRule) throws IOException
     {
         graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
-        Paint nonStrokingPaint = getNonStrokingPaint();
-        graphics.setPaint(nonStrokingPaint);
+        graphics.setPaint(getNonStrokingPaint());
         setClip();
         linePath.setWindingRule(windingRule);
 
@@ -760,18 +757,13 @@ public class PageDrawer extends PDFGraph
         super.showAnnotation(annotation);
     }
 
-    //@Override
+    @Override
     public void showTransparencyGroup(PDFormXObject form) throws IOException
     {
-        TransparencyGroup group = createTransparencyGroup(form);
+        TransparencyGroup group = new TransparencyGroup(form);
         group.draw();
     }
 
-    private TransparencyGroup createTransparencyGroup(PDFormXObject form) throws IOException
-    {
-        return new TransparencyGroup(form);
-    }
-
     /**
      * Transparency group.
      **/
@@ -833,15 +825,10 @@ public class PageDrawer extends PDFGraph
             }
             matrix = matrix1;
 
-            PDGraphicsState state = getGraphicsState();
-            state.setBlendMode(BlendMode.NORMAL);
-            state.setAlphaConstants(1.0);
-            state.setNonStrokeAlphaConstants(1.0);
-            state.setSoftMask(null);
             graphics = g;
             try
             {
-                processChildStream(form);
+                processTransparencyGroup(form);
             }
             finally 
             {



Mime
View raw message