pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1617131 [3/3] - in /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox: pdfviewer/ pdmodel/graphics/pattern/ pdmodel/graphics/shading/
Date Sun, 10 Aug 2014 16:34:18 GMT
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java?rev=1617131&r1=1617130&r2=1617131&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingContext.java Sun Aug 10 16:34:17 2014
@@ -16,99 +16,62 @@
 package org.apache.pdfbox.pdmodel.graphics.shading;
 
 import java.awt.PaintContext;
-import java.awt.Transparency;
-import java.awt.color.ColorSpace;
+import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.NoninvertibleTransformException;
 import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
 import java.io.IOException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.pdmodel.common.function.PDFunction;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
-import org.apache.pdfbox.pdmodel.graphics.color.PDSeparation;
 import org.apache.pdfbox.util.Matrix;
 
 /**
- * This represents the Paint of a type 1 (Function based) shading context.
+ * AWT PaintContext for function-based (Type 1) shading.
  *
- * @author lehmi
- * @author Tilman Hausherr <tilman@snafu.de>
+ * @author Andreas Lehmkühler
+ * @author Tilman Hausherr
  */
-class Type1ShadingContext implements PaintContext
+class Type1ShadingContext extends ShadingContext implements PaintContext
 {
     private static final Log LOG = LogFactory.getLog(Type1ShadingContext.class);
 
-    private ColorModel outputColorModel;
-    private ColorSpace shadingColorSpace;
-    private PDFunction shadingTinttransform;
-    private PDShadingType1 shadingType;
+    private PDShadingType1 type1ShadingType;
     private AffineTransform rat;
-    private float[] domain;
+    private final float[] domain;
     private Matrix matrix;
     private float[] background;
 
     /**
      * Constructor creates an instance to be used for fill operations.
      *
-     * @param shadingType1 the shading type to be used
-     * @param colorModelValue the color model to be used
+     * @param shading the shading type to be used
+     * @param colorModel the color model to be used
      * @param xform transformation for user to device space
      * @param ctm current transformation matrix
      * @param pageHeight height of the current page
-     *
+     * @param dBounds device bounds
      */
-    public Type1ShadingContext(PDShadingType1 shadingType1, ColorModel colorModelValue, 
-            AffineTransform xform, Matrix currentTransformationMatrix, int pageHeight)
+    public Type1ShadingContext(PDShadingType1 shading, ColorModel colorModel, AffineTransform xform,
+            Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
-        shadingType = shadingType1;
-        
+        super(shading, colorModel, xform, ctm, pageHeight, dBounds);
+        this.type1ShadingType = shading;
+
         // PDFBOX-1966 flip the AffineTransform in 1.8 branch
         //TODO find out why AffineTransform passed in 1.8 branch is flipped         
         xform.scale(1,-1);
         xform.translate(0, -pageHeight);
 
-        // colorSpace 
-        try
-        {
-            PDColorSpace cs = shadingType.getColorSpace();
-            if (!(cs instanceof PDDeviceRGB))
-            {
-                // we have to create an instance of the shading colorspace if it isn't RGB
-                shadingColorSpace = cs.getJavaColorSpace();
-                if (cs instanceof PDDeviceN)
-                {
-                    shadingTinttransform = ((PDDeviceN) cs).getTintTransform();
-                }
-                else if (cs instanceof PDSeparation)
-                {
-                    shadingTinttransform = ((PDSeparation) cs).getTintTransform();
-                }
-            }
-        }
-        catch (IOException exception)
-        {
-            LOG.error("error while creating colorSpace", exception);
-        }
-        // create the output colormodel using RGB+alpha as colorspace
-        ColorSpace outputCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
-        outputColorModel = new ComponentColorModel(outputCS, true, false, Transparency.TRANSLUCENT,
-                DataBuffer.TYPE_BYTE);
-        
         // spec p.308
         // (Optional) An array of four numbers [ xmin xmax ymin ymax ] 
         // specifying the rectangular domain of coordinates over which the 
         // color function(s) are defined. Default value: [ 0.0 1.0 0.0 1.0 ].
-        if (shadingType.getDomain() != null)
+        if (shading.getDomain() != null)
         {
-            domain = shadingType.getDomain().toFloatArray();
+            domain = shading.getDomain().toFloatArray();
         }
         else
         {
@@ -118,7 +81,7 @@ class Type1ShadingContext implements Pai
             };
         }
 
-        matrix = shadingType.getMatrix();
+        matrix = shading.getMatrix();
         if (matrix == null)
         {
             matrix = new Matrix();
@@ -130,16 +93,16 @@ class Type1ShadingContext implements Pai
             // shading matrix and current user / device space 
             // when handling actual pixels in getRaster()
             rat = matrix.createAffineTransform().createInverse();
-            rat.concatenate(currentTransformationMatrix.createAffineTransform().createInverse());
+            rat.concatenate(ctm.createAffineTransform().createInverse());
             rat.concatenate(xform.createInverse());
         }
         catch (NoninvertibleTransformException ex)
         {
-            LOG.error(ex,ex);
+            LOG.error(ex, ex);
         }
 
         // get background values if available
-        COSArray bg = shadingType1.getBackground();
+        COSArray bg = shading.getBackground();
         if (bg != null)
         {
             background = bg.toFloatArray();
@@ -154,7 +117,7 @@ class Type1ShadingContext implements Pai
         outputColorModel = null;
         shadingColorSpace = null;
         shadingTinttransform = null;
-        shadingType = null;
+        type1ShadingType = null;
     }
 
     /**
@@ -170,14 +133,28 @@ class Type1ShadingContext implements Pai
      */
     public Raster getRaster(int x, int y, int w, int h)
     {
-        // create writable raster
-        
         WritableRaster raster = getColorModel().createCompatibleWritableRaster(w, h);
         int[] data = new int[w * h * 4];
         for (int j = 0; j < h; j++)
         {
+            int currentY = y + j;
+            if (bboxRect != null)
+            {
+                if (currentY < minBBoxY || currentY > maxBBoxY)
+                {
+                    continue;
+                }
+            }
             for (int i = 0; i < w; i++)
             {
+                int currentX = x + i;
+                if (bboxRect != null)
+                {
+                    if (currentX < minBBoxX || currentX > maxBBoxX)
+                    {
+                        continue;
+                    }
+                }
                 int index = (j * w + i) * 4;
                 boolean useBackground = false;
                 float[] values = new float[]
@@ -205,7 +182,7 @@ class Type1ShadingContext implements Pai
                     }
                     else
                     {
-                        values = shadingType.evalFunction(values);
+                        values = type1ShadingType.evalFunction(values);
                     }
                     // convert color values from shading colorspace to RGB 
                     if (shadingColorSpace != null)
@@ -235,9 +212,4 @@ class Type1ShadingContext implements Pai
     {
         return domain;
     }
-
-    public PDFunction getShadingTintTransform()
-    {
-        return shadingTinttransform;
-    }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingPaint.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingPaint.java?rev=1617131&r1=1617130&r2=1617131&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingPaint.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type1ShadingPaint.java Sun Aug 10 16:34:17 2014
@@ -23,31 +23,35 @@ import java.awt.RenderingHints;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.ColorModel;
+import java.io.IOException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.util.Matrix;
 
 /**
- * This represents the Paint of an type1 shading.
- *
+ * AWT PaintContext for function-based (Type 1) shading.
  */
 public class Type1ShadingPaint implements Paint
 {
+    private static final Log LOG = LogFactory.getLog(Type1ShadingPaint.class);
+
     private PDShadingType1 shading;
-    private Matrix currentTransformationMatrix;
+    private Matrix ctm;
     private int pageHeight;
 
     /**
      * Constructor.
      *
-     * @param shadingType1 the shading resources
+     * @param shading the shading resources
      * @param ctm current transformation matrix
-     * @param pageHeightValue the height of the page
+     * @param pageHeight the height of the page
      */
-    public Type1ShadingPaint(PDShadingType1 shadingType1, Matrix ctm, int pageHeightValue)
+    public Type1ShadingPaint(PDShadingType1 shading, Matrix ctm, int pageHeight)
     {
-        shading = shadingType1;
-        currentTransformationMatrix = ctm;
-        pageHeight = pageHeightValue;
+        this.shading = shading;
+        this.ctm = ctm;
+        this.pageHeight = pageHeight;
     }
 
     /**
@@ -64,6 +68,14 @@ public class Type1ShadingPaint implement
     public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
             Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
     {
-        return new Type1ShadingContext(shading, cm, xform, currentTransformationMatrix, pageHeight);
+        try
+        {
+            return new Type1ShadingContext(shading, cm, xform, ctm, pageHeight, deviceBounds);
+        }
+        catch (IOException ex)
+        {
+            LOG.error(ex);
+            return null;
+        }
     }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java?rev=1617131&r1=1617130&r2=1617131&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingContext.java Sun Aug 10 16:34:17 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.shading;
 
+import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.awt.image.ColorModel;
@@ -26,114 +27,154 @@ import javax.imageio.stream.ImageInputSt
 import javax.imageio.stream.MemoryCacheImageInputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.common.PDRange;
 import org.apache.pdfbox.util.Matrix;
 
 /**
- * This represents the Paint of a type 4 (Gouraud triangle mesh) shading
- * context.
+ * AWT PaintContext for Gouraud Triangle Mesh (Type 4) shading.
  *
  * @author Tilman Hausherr
+ * @author Shaola Ren
  */
 class Type4ShadingContext extends GouraudShadingContext
 {
     private static final Log LOG = LogFactory.getLog(Type4ShadingContext.class);
-
-    private int bitsPerFlag;
+    private final int bitsPerFlag;
 
     /**
      * Constructor creates an instance to be used for fill operations.
      *
-     * @param shadingType4 the shading type to be used
-     * @param colorModelValue the color model to be used
+     * @param shading the shading type to be used
+     * @param cm the color model to be used
      * @param xform transformation for user to device space
      * @param ctm current transformation matrix
      * @param pageHeight height of the current page
-     *
      */
-    public Type4ShadingContext(PDShadingType4 shadingType4, ColorModel colorModelValue,
-            AffineTransform xform, Matrix ctm, int pageHeight) throws IOException
+    public Type4ShadingContext(PDShadingType4 shading, ColorModel cm, AffineTransform xform,
+            Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
-        super(shadingType4, colorModelValue, xform, ctm, pageHeight);
+        super(shading, cm, xform, ctm, pageHeight, dBounds);
+        LOG.debug("Type4ShadingContext");
 
-        ArrayList<Vertex> vertexList = new ArrayList<Vertex>();
+        bitsPerFlag = shading.getBitsPerFlag();
+        LOG.debug("bitsPerFlag: " + bitsPerFlag); //TODO handle cases where bitperflag isn't 8
+        
+        // PDFBOX-1966 flip the AffineTransform in 1.8 branch
+        xform.scale(1,-1);
+        xform.translate(0, -pageHeight);        
 
-        LOG.debug("Type4ShadingContext");
+        triangleList = getTriangleList(xform, ctm);
+        pixelTable = calcPixelTable();
+    }
 
-        bitsPerColorComponent = shadingType4.getBitsPerComponent();
-        LOG.debug("bitsPerColorComponent: " + bitsPerColorComponent);
-        bitsPerCoordinate = shadingType4.getBitsPerCoordinate();
-        LOG.debug(Math.pow(2, bitsPerCoordinate) - 1);
+    private ArrayList<ShadedTriangle> getTriangleList(AffineTransform xform, Matrix ctm) throws IOException
+    {
+        PDShadingType4 freeTriangleShadingType = (PDShadingType4) shading;
+        COSDictionary cosDictionary = freeTriangleShadingType.getCOSDictionary();
+        PDRange rangeX = freeTriangleShadingType.getDecodeForParameter(0);
+        PDRange rangeY = freeTriangleShadingType.getDecodeForParameter(1);
+        PDRange[] colRange = new PDRange[numberOfColorComponents];
+        for (int i = 0; i < numberOfColorComponents; ++i)
+        {
+            colRange[i] = freeTriangleShadingType.getDecodeForParameter(2 + i);
+        }
+        ArrayList<ShadedTriangle> list = new ArrayList<ShadedTriangle>();
         long maxSrcCoord = (long) Math.pow(2, bitsPerCoordinate) - 1;
         long maxSrcColor = (long) Math.pow(2, bitsPerColorComponent) - 1;
-        LOG.debug("maxSrcCoord: " + maxSrcCoord);
-        LOG.debug("maxSrcColor: " + maxSrcColor);
-
-        COSDictionary cosDictionary = shadingType4.getCOSDictionary();
         COSStream cosStream = (COSStream) cosDictionary;
 
-        //The Decode key specifies how
-        //to decode coordinate and color component data into the ranges of values
-        //appropriate for each. The ranges are specified as [xmin xmax ymin ymax c1,min,
-        //c1,max,..., cn, min, cn,max].
-        //
-        // see p344
-        COSArray decode = (COSArray) cosDictionary.getDictionaryObject(COSName.DECODE);
-        LOG.debug("decode: " + decode);
-        PDRange rangeX = shadingType4.getDecodeForParameter(0);
-        PDRange rangeY = shadingType4.getDecodeForParameter(1);
-        LOG.debug("rangeX: " + rangeX.getMin() + ", " + rangeX.getMax());
-        LOG.debug("rangeY: " + rangeY.getMin() + ", " + rangeY.getMax());
+        ImageInputStream mciis = new MemoryCacheImageInputStream(cosStream.getUnfilteredStream());
+        byte flag = (byte) 0;
 
-        PDRange[] colRangeTab = new PDRange[numberOfColorComponents];
-        for (int i = 0; i < numberOfColorComponents; ++i)
+        try
         {
-            colRangeTab[i] = shadingType4.getDecodeForParameter(2 + i);
+            flag = (byte) (mciis.readBits(bitsPerFlag) & 3);
         }
-
-        LOG.debug("bitsPerCoordinate: " + bitsPerCoordinate);
-        bitsPerFlag = shadingType4.getBitsPerFlag();
-        LOG.debug("bitsPerFlag: " + bitsPerFlag); //TODO handle cases where bitperflag isn't 8
-        LOG.debug("Stream size: " + cosStream.getInt(COSName.LENGTH));
-
-        // get background values if available
-        COSArray bg = shadingType4.getBackground();
-        if (bg != null)
+        catch (EOFException ex)
         {
-            background = bg.toFloatArray();
+            LOG.error(ex);
         }
 
-        //TODO missing: BBox, AntiAlias (p. 305 in 1.7 spec)
-        // p318:
-        //  reading in sequence from higher-order to lower-order bit positions
-        ImageInputStream mciis = new MemoryCacheImageInputStream(cosStream.getUnfilteredStream());
         while (true)
         {
+            Vertex p0, p1, p2;
+            Point2D[] ps;
+            float[][] cs;
+            int lastIndex;
             try
             {
-                byte flag = (byte) (mciis.readBits(bitsPerFlag) & 3);
-                LOG.debug("flag: " + flag);
                 switch (flag)
                 {
                     case 0:
-                        Vertex v1 = readVertex(mciis, flag, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRangeTab);
-                        Vertex v2 = readVertex(mciis, (byte) mciis.readBits(bitsPerFlag), maxSrcCoord, maxSrcColor,
-                                rangeX, rangeY, colRangeTab);
-                        Vertex v3 = readVertex(mciis, (byte) mciis.readBits(bitsPerFlag), maxSrcCoord, maxSrcColor,
-                                rangeX, rangeY, colRangeTab);
-
-                        // add them after they're read, so that they are never added if there is a premature EOF
-                        vertexList.add(v1);
-                        vertexList.add(v2);
-                        vertexList.add(v3);
+                        p0 = readVertex(mciis, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRange, ctm, xform);
+                        flag = (byte) (mciis.readBits(bitsPerFlag) & 3);
+                        if (flag != 0)
+                        {
+                            LOG.error("bad triangle: " + flag);
+                        }
+                        p1 = readVertex(mciis, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRange, ctm, xform);
+                        mciis.readBits(bitsPerFlag);
+                        if (flag != 0)
+                        {
+                            LOG.error("bad triangle: " + flag);
+                        }
+                        p2 = readVertex(mciis, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRange, ctm, xform);
+                        ps = new Point2D[]
+                        {
+                            p0.point, p1.point, p2.point
+                        };
+                        cs = new float[][]
+                        {
+                            p0.color, p1.color, p2.color
+                        };
+                        list.add(new ShadedTriangle(ps, cs));
+                        flag = (byte) (mciis.readBits(bitsPerFlag) & 3);
                         break;
                     case 1:
+                        lastIndex = list.size() - 1;
+                        if (lastIndex < 0)
+                        {
+                            LOG.error("broken data stream: " + list.size());
+                        }
+                        else
+                        {
+                            ShadedTriangle preTri = list.get(lastIndex);
+                            p2 = readVertex(mciis, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRange, ctm, xform);
+                            ps = new Point2D[]
+                            {
+                                preTri.corner[1], preTri.corner[2], p2.point
+                            };
+                            cs = new float[][]
+                            {
+                                preTri.color[1], preTri.color[2], p2.color
+                            };
+                            list.add(new ShadedTriangle(ps, cs));
+                            flag = (byte) (mciis.readBits(bitsPerFlag) & 3);
+                        }
+                        break;
                     case 2:
-                        vertexList.add(readVertex(mciis, flag, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRangeTab));
+                        lastIndex = list.size() - 1;
+                        if (lastIndex < 0)
+                        {
+                            LOG.error("broken data stream: " + list.size());
+                        }
+                        else
+                        {
+                            ShadedTriangle preTri = list.get(lastIndex);
+                            p2 = readVertex(mciis, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRange, ctm, xform);
+                            ps = new Point2D[]
+                            {
+                                preTri.corner[0], preTri.corner[2], p2.point
+                            };
+                            cs = new float[][]
+                            {
+                                preTri.color[0], preTri.color[2], p2.color
+                            };
+                            list.add(new ShadedTriangle(ps, cs));
+                            flag = (byte) (mciis.readBits(bitsPerFlag) & 3);
+                        }
                         break;
                     default:
                         LOG.warn("bad flag: " + flag);
@@ -142,121 +183,11 @@ class Type4ShadingContext extends Gourau
             }
             catch (EOFException ex)
             {
-                LOG.debug("EOF");
-                if (vertexList.size() < 3)
-                {
-                    LOG.warn("Incomplete mesh is ignored");
-                    vertexList.clear();
-                }
-                else if (vertexList.size() > 1 && vertexList.get(0).flag != 0)
-                {
-                    LOG.warn("Mesh with incorrect start flag " + vertexList.get(0).flag + " is ignored");
-                    vertexList.clear();
-                }
-                // check that there are 3 entries if there is a 0 flag
-                int vi = 0;
-                while (vi < vertexList.size())
-                {
-                    if (vertexList.get(vi).flag == 0)
-                    {
-                        if (vi + 2 >= vertexList.size())
-                        {
-                            LOG.warn("Mesh with incomplete triangle");
-                            // remove rest
-                            while (vertexList.size() >= vi + 1)
-                            {
-                                vertexList.remove(vi);
-                            }
-                            break;
-                        }
-                        vi += 3;
-                    }
-                    else
-                    {
-                        ++vi;
-                    }
-                }
                 break;
             }
         }
         mciis.close();
-        transformVertices(vertexList, ctm, xform, pageHeight);
-        createTriangleList(vertexList);
+        return list;
     }
 
-    /**
-     * Create GouraudTriangle list from vertices, see p.316 of pdf spec 1.7.
-     *
-     * @param vertexList list of vertices
-     */
-    private void createTriangleList(ArrayList<Vertex> vertexList)
-    {
-        Point2D a = null, b = null, c = null;
-        float[] aColor = null, bColor = null, cColor = null;
-        int vi = 0;
-        while (vi < vertexList.size())
-        {
-            Vertex v = vertexList.get(vi);
-            switch (v.flag)
-            {
-                case 0:
-                    a = v.point;
-                    aColor = v.color;
-                    ++vi;
-
-                    v = vertexList.get(vi);
-                    b = v.point;
-                    bColor = v.color;
-                    ++vi;
-
-                    v = vertexList.get(vi);
-                    c = v.point;
-                    cColor = v.color;
-                    break;
-
-                case 1:
-                    a = b;
-                    aColor = bColor;
-
-                    b = c;
-                    bColor = cColor;
-
-                    v = vertexList.get(vi);
-                    c = v.point;
-                    cColor = v.color;
-                    break;
-
-                case 2:
-                    b = c;
-                    bColor = cColor;
-
-                    v = vertexList.get(vi);
-                    c = v.point;
-                    cColor = v.color;
-                    break;
-
-                default:
-                    break;
-            }
-            ++vi;
-            GouraudTriangle g = new GouraudTriangle(a, aColor, b, bColor, c, cColor);
-            if (!g.isEmpty())
-            {
-                triangleList.add(g);
-            }
-            else
-            {
-                LOG.debug("triangle is empty!");
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void dispose()
-    {
-        super.dispose();
-    }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingPaint.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingPaint.java?rev=1617131&r1=1617130&r2=1617131&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingPaint.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type4ShadingPaint.java Sun Aug 10 16:34:17 2014
@@ -24,56 +24,51 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.ColorModel;
 import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.util.Matrix;
 
 /**
- * This represents the Paint of an type4 shading.
- *
+ * AWT PaintContext for Gouraud Triangle Mesh (Type 4) shading.
  */
 public class Type4ShadingPaint implements Paint
 {
+    private static final Log LOG = LogFactory.getLog(Type4ShadingPaint.class);
+
     private PDShadingType4 shading;
-    private Matrix currentTransformationMatrix;
+    private Matrix ctm;
     private int pageHeight;
 
     /**
      * Constructor.
      *
-     * @param shadingType4 the shading resources
+     * @param shading the shading resources
      * @param ctm current transformation matrix
-     * @param pageHeightValue the height of the page
+     * @param pageHeight the height of the page
      */
-    public Type4ShadingPaint(PDShadingType4 shadingType4, Matrix ctm, int pageHeightValue)
+    public Type4ShadingPaint(PDShadingType4 shading, Matrix ctm, int pageHeight)
     {
-        shading = shadingType4;
-        currentTransformationMatrix = ctm;
-        pageHeight = pageHeightValue;
+        this.shading = shading;
+        this.ctm = ctm;
+        this.pageHeight = pageHeight;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public int getTransparency()
     {
         return 0;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
-            Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
+    public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds,
+            AffineTransform xform, RenderingHints hints)
     {
         try
         {
-            return new Type4ShadingContext(shading, cm, xform, currentTransformationMatrix, pageHeight);
+            return new Type4ShadingContext(shading, cm, xform, ctm, pageHeight, deviceBounds);
         }
         catch (IOException ex)
         {
-            Logger.getLogger(Type4ShadingPaint.class.getName()).log(Level.SEVERE, null, ex);
+            LOG.error(ex);
             return null;
         }
     }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java?rev=1617131&r1=1617130&r2=1617131&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingContext.java Sun Aug 10 16:34:17 2014
@@ -16,7 +16,9 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.shading;
 
+import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
 import java.awt.image.ColorModel;
 import java.io.EOFException;
 import java.io.IOException;
@@ -25,156 +27,117 @@ import javax.imageio.stream.ImageInputSt
 import javax.imageio.stream.MemoryCacheImageInputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.common.PDRange;
 import org.apache.pdfbox.util.Matrix;
 
 /**
- *
- * This represents the Paint of a type 5 (Gouraud triangle lattice) shading
- * context.
+ * AWT PaintContext for Gouraud Triangle Lattice (Type 5) shading.
  *
  * @author Tilman Hausherr
+ * @author Shaola Ren
  */
-public class Type5ShadingContext extends GouraudShadingContext
+class Type5ShadingContext extends GouraudShadingContext
 {
     private static final Log LOG = LogFactory.getLog(Type5ShadingContext.class);
 
     /**
      * Constructor creates an instance to be used for fill operations.
      *
-     * @param shadingType5 the shading type to be used
-     * @param colorModelValue the color model to be used
+     * @param shading the shading type to be used
+     * @param cm the color model to be used
      * @param xform transformation for user to device space
      * @param ctm current transformation matrix
      * @param pageHeight height of the current page
-     *
      * @throws IOException if something went wrong
      */
-    public Type5ShadingContext(PDShadingType5 shadingType5, ColorModel colorModelValue,
-            AffineTransform xform, Matrix ctm, int pageHeight) throws IOException
+    public Type5ShadingContext(PDShadingType5 shading, ColorModel cm, AffineTransform xform,
+            Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
     {
-        super(shadingType5, colorModelValue, xform, ctm, pageHeight);
+        super(shading, cm, xform, ctm, pageHeight, dBounds);
 
         LOG.debug("Type5ShadingContext");
+        
+        // PDFBOX-1966 flip the AffineTransform in 1.8 branch
+        xform.scale(1,-1);
+        xform.translate(0, -pageHeight);        
+
+        triangleList = getTriangleList(xform, ctm);
+        pixelTable = calcPixelTable();
+    }
 
-        bitsPerColorComponent = shadingType5.getBitsPerComponent();
-        LOG.debug("bitsPerColorComponent: " + bitsPerColorComponent);
-        bitsPerCoordinate = shadingType5.getBitsPerCoordinate();
-        LOG.debug(Math.pow(2, bitsPerCoordinate) - 1);
+    private ArrayList<ShadedTriangle> getTriangleList(AffineTransform xform, Matrix ctm) throws IOException
+    {
+        ArrayList<ShadedTriangle> list = new ArrayList<ShadedTriangle>();
+        PDShadingType5 latticeTriangleShadingType = (PDShadingType5) shading;
+        COSDictionary cosDictionary = latticeTriangleShadingType.getCOSDictionary();
+        PDRange rangeX = latticeTriangleShadingType.getDecodeForParameter(0);
+        PDRange rangeY = latticeTriangleShadingType.getDecodeForParameter(1);
+        int numPerRow = latticeTriangleShadingType.getVerticesPerRow();
+        PDRange[] colRange = new PDRange[numberOfColorComponents];
+        for (int i = 0; i < numberOfColorComponents; ++i)
+        {
+            colRange[i] = latticeTriangleShadingType.getDecodeForParameter(2 + i);
+        }
+        ArrayList<Vertex> vlist = new ArrayList<Vertex>();
         long maxSrcCoord = (long) Math.pow(2, bitsPerCoordinate) - 1;
         long maxSrcColor = (long) Math.pow(2, bitsPerColorComponent) - 1;
-        LOG.debug("maxSrcCoord: " + maxSrcCoord);
-        LOG.debug("maxSrcColor: " + maxSrcColor);
-
-        COSDictionary cosDictionary = shadingType5.getCOSDictionary();
         COSStream cosStream = (COSStream) cosDictionary;
 
-        //The Decode key specifies how
-        //to decode coordinate and color component data into the ranges of values
-        //appropriate for each. The ranges are specified as [xmin xmax ymin ymax c1,min,
-        //c1,max,..., cn, min, cn,max].
-        //
-        // see p344
-        COSArray decode = (COSArray) cosDictionary.getDictionaryObject(COSName.DECODE);
-        LOG.debug("decode: " + decode);
-        PDRange rangeX = shadingType5.getDecodeForParameter(0);
-        PDRange rangeY = shadingType5.getDecodeForParameter(1);
-        LOG.debug("rangeX: " + rangeX.getMin() + ", " + rangeX.getMax());
-        LOG.debug("rangeY: " + rangeY.getMin() + ", " + rangeY.getMax());
-
-        PDRange[] colRangeTab = new PDRange[numberOfColorComponents];
-        for (int i = 0; i < numberOfColorComponents; ++i)
+        ImageInputStream mciis = new MemoryCacheImageInputStream(cosStream.getUnfilteredStream());
+        while (true)
         {
-            colRangeTab[i] = shadingType5.getDecodeForParameter(2 + i);
+            Vertex p;
+            try
+            {
+                p = readVertex(mciis, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRange, ctm, xform);
+                vlist.add(p);
+            }
+            catch (EOFException ex)
+            {
+                break;
+            }
         }
-
-        LOG.debug("bitsPerCoordinate: " + bitsPerCoordinate);
-
-        // get background values if available
-        COSArray bg = shadingType5.getBackground();
-        if (bg != null)
+        int sz = vlist.size(), rowNum = sz / numPerRow;
+        Vertex[][] latticeArray = new Vertex[rowNum][numPerRow];
+        if (rowNum < 2)
         {
-            background = bg.toFloatArray();
+            return triangleList;
+        }
+        for (int i = 0; i < rowNum; i++)
+        {
+            for (int j = 0; j < numPerRow; j++)
+            {
+                latticeArray[i][j] = vlist.get(i * numPerRow + j);
+            }
         }
 
-        //TODO missing: BBox, AntiAlias (p. 305 in 1.7 spec)
-        
-        // p318:
-        //  reading in sequence from higher-order to lower-order bit positions
-        ImageInputStream mciis = new MemoryCacheImageInputStream(cosStream.getUnfilteredStream());
-
-        int verticesPerRow = shadingType5.getVerticesPerRow(); //TODO check >=2
-        LOG.debug("verticesPerRow" + verticesPerRow);
-
-        try
+        for (int i = 0; i < rowNum - 1; i++)
         {
-            ArrayList<Vertex> prevVertexRow = new ArrayList<Vertex>();
-            while (true)
+            for (int j = 0; j < numPerRow - 1; j++)
             {
-                // read a vertex row
-                ArrayList<Vertex> vertexList = new ArrayList<Vertex>();
-                for (int row = 0; row < verticesPerRow; ++row)
+                Point2D[] ps = new Point2D[]
                 {
-                    vertexList.add(readVertex(mciis, (byte) 0, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRangeTab));
-                }
-                transformVertices(vertexList, ctm, xform, pageHeight);
-
-                // create the triangles from two rows
-                if (!prevVertexRow.isEmpty())
+                    latticeArray[i][j].point, latticeArray[i][j + 1].point, latticeArray[i + 1][j].point
+                };
+                float[][] cs = new float[][]
+                {
+                    latticeArray[i][j].color, latticeArray[i][j + 1].color, latticeArray[i + 1][j].color
+                };
+                list.add(new ShadedTriangle(ps, cs));
+                ps = new Point2D[]
                 {
-                    for (int vj = 0; vj < vertexList.size() - 1; ++vj)
-                    {
-                        // p.192,194 pdf spec 1.7
-                        Vertex vij = prevVertexRow.get(vj); // v i,j
-                        Vertex vijplus1 = prevVertexRow.get(vj + 1); // v i,j+1
-                        Vertex viplus1j = vertexList.get(vj); // v i+1,j
-                        Vertex viplus1jplus1 = vertexList.get(vj + 1); // v i+1,j+1
-                        GouraudTriangle g = new GouraudTriangle(vij.point, vij.color,
-                                vijplus1.point, vijplus1.color,
-                                viplus1j.point, viplus1j.color);
-                        if (!g.isEmpty())
-                        {
-                            triangleList.add(g);
-                        }
-                        else
-                        {
-                            LOG.debug("triangle is empty!");
-                        }
-                        g = new GouraudTriangle(vijplus1.point, vijplus1.color,
-                                viplus1j.point, viplus1j.color,
-                                viplus1jplus1.point, viplus1jplus1.color);
-                        if (!g.isEmpty())
-                        {
-                            triangleList.add(g);
-                        }
-                        else
-                        {
-                            LOG.debug("triangle is empty!");
-                        }
-                    }
-                }
-                prevVertexRow = vertexList;
+                    latticeArray[i][j + 1].point, latticeArray[i + 1][j].point, latticeArray[i + 1][j + 1].point
+                };
+                cs = new float[][]
+                {
+                    latticeArray[i][j + 1].color, latticeArray[i + 1][j].color, latticeArray[i + 1][j + 1].color
+                };
+                list.add(new ShadedTriangle(ps, cs));
             }
         }
-        catch (EOFException ex)
-        {
-            LOG.debug("EOF");
-        }
-
-        mciis.close();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void dispose()
-    {
-        super.dispose();
+        return list;
     }
 
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingPaint.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingPaint.java?rev=1617131&r1=1617130&r2=1617131&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingPaint.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type5ShadingPaint.java Sun Aug 10 16:34:17 2014
@@ -24,34 +24,34 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.ColorModel;
 import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.util.Matrix;
 
 /**
- * This represents the Paint of an type5 shading.
- *
- *
+ * AWT Paint for Gouraud Triangle Lattice (Type 5) shading.
  */
 public class Type5ShadingPaint implements Paint
 {
+    private static final Log LOG = LogFactory.getLog(Type5ShadingPaint.class);
+
     private PDShadingType5 shading;
-    private Matrix currentTransformationMatrix;
+    private Matrix ctm;
     private int pageHeight;
 
     /**
      * Constructor.
      *
-     * @param shadingType5 the shading resources
+     * @param shading the shading resources
      * @param ctm current transformation matrix
-     * @param pageHeightValue
+     * @param pageHeight the height of the page
      */
-    public Type5ShadingPaint(PDShadingType5 shadingType5, Matrix ctm, int pageHeightValue)
+    public Type5ShadingPaint(PDShadingType5 shading, Matrix ctm, int pageHeight)
     {
-        shading = shadingType5;
-        currentTransformationMatrix = ctm;
-        pageHeight = pageHeightValue;
+        this.shading = shading;
+        this.ctm = ctm;
+        this.pageHeight = pageHeight;
     }
 
     /**
@@ -70,11 +70,11 @@ public class Type5ShadingPaint implement
     {
         try
         {
-            return new Type5ShadingContext(shading, cm, xform, currentTransformationMatrix, pageHeight);
+            return new Type5ShadingContext(shading, cm, xform, ctm, pageHeight, deviceBounds);
         }
         catch (IOException ex)
         {
-            Logger.getLogger(Type5ShadingPaint.class.getName()).log(Level.SEVERE, null, ex);
+            LOG.error(ex);
             return null;
         }
     }

Added: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java?rev=1617131&view=auto
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java (added)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java Sun Aug 10 16:34:17 2014
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.image.ColorModel;
+import java.io.IOException;
+import java.util.ArrayList;
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.PDRange;
+import org.apache.pdfbox.util.Matrix;
+
+/**
+ * AWT PaintContext for coons patch meshes (type 6) shading. This was done as
+ * part of GSoC2014, Tilman Hausherr is the mentor.
+ *
+ * @author Shaola Ren
+ */
+class Type6ShadingContext extends PatchMeshesShadingContext
+{
+
+    /**
+     * Constructor creates an instance to be used for fill operations.
+     *
+     * @param shading the shading type to be used
+     * @param colorModel the color model to be used
+     * @param xform transformation for user to device space
+     * @param ctm current transformation matrix
+     * @param pageHeight height of the current page
+     * @param dBounds device bounds
+     * @throws IOException if something went wrong
+     */
+    public Type6ShadingContext(PDShadingType6 shading, ColorModel colorModel, AffineTransform xform,
+            Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
+    {
+        super(shading, colorModel, xform, ctm, pageHeight, dBounds);
+
+        // PDFBOX-1966 flip the AffineTransform in 1.8 branch
+        xform.scale(1,-1);
+        xform.translate(0, -pageHeight);        
+
+        patchList = getCoonsPatchList(xform, ctm);
+        pixelTable = calcPixelTable();
+    }
+
+    // get the patch list which forms the type 6 shading image from data stream
+    private ArrayList<Patch> getCoonsPatchList(AffineTransform xform, Matrix ctm) throws IOException
+    {
+        PDShadingType6 coonsShadingType = (PDShadingType6) patchMeshesShadingType;
+        COSDictionary cosDictionary = coonsShadingType.getCOSDictionary();
+        PDRange rangeX = coonsShadingType.getDecodeForParameter(0);
+        PDRange rangeY = coonsShadingType.getDecodeForParameter(1);
+        
+        PDRange[] colRange = new PDRange[numberOfColorComponents];
+        for (int i = 0; i < numberOfColorComponents; ++i)
+        {
+            colRange[i] = coonsShadingType.getDecodeForParameter(2 + i);
+        }
+        return getPatchList(xform, ctm, cosDictionary, rangeX, rangeY, colRange, 12);
+    }
+
+    @Override
+    protected Patch generatePatch(Point2D[] points, float[][] color)
+    {
+        return new CoonsPatch(points, color);
+    }
+
+}

Propchange: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingPaint.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingPaint.java?rev=1617131&view=auto
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingPaint.java (added)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingPaint.java Sun Aug 10 16:34:17 2014
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+import java.awt.Paint;
+import java.awt.PaintContext;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.ColorModel;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.util.Matrix;
+
+/**
+ * AWT Paint for coons patch meshes (Type 6) shading. This was done as part of
+ * GSoC2014, Tilman Hausherr is the mentor.
+ *
+ * @author Shaola Ren
+ */
+public class Type6ShadingPaint implements Paint
+{
+    private static final Log LOG = LogFactory.getLog(Type6ShadingPaint.class);
+
+    private final PDShadingType6 shading;
+    private final Matrix ctm;
+    private final int pageHeight;
+
+    /**
+     * Constructor.
+     *
+     * @param shading the shading resources
+     * @param ctm current transformation matrix
+     * @param pageHeight the height of the page
+     */
+    public Type6ShadingPaint(PDShadingType6 shading, Matrix ctm, int pageHeight)
+    {
+        this.shading = shading;
+        this.ctm = ctm;
+        this.pageHeight = pageHeight;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getTransparency()
+    {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds,
+            AffineTransform xform, RenderingHints hints)
+    {
+        try
+        {
+            return new Type6ShadingContext(shading, cm, xform, ctm, pageHeight, deviceBounds);
+        }
+        catch (IOException ex)
+        {
+            LOG.error(ex);
+            return null;
+        }
+    }
+}

Propchange: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type6ShadingPaint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java?rev=1617131&view=auto
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java (added)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java Sun Aug 10 16:34:17 2014
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.image.ColorModel;
+import java.io.IOException;
+import java.util.ArrayList;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.PDRange;
+import org.apache.pdfbox.util.Matrix;
+
+/**
+ * AWT PaintContext for tensor-product patch meshes (type 7) shading. This was
+ * done as part of GSoC2014, Tilman Hausherr is the mentor.
+ *
+ * @author Shaola Ren
+ */
+class Type7ShadingContext extends PatchMeshesShadingContext
+{
+
+    /**
+     * Constructor creates an instance to be used for fill operations.
+     *
+     * @param shading the shading type to be used
+     * @param colorModel the color model to be used
+     * @param xform transformation for user to device space
+     * @param ctm current transformation matrix
+     * @param pageHeight height of the current page
+     * @param dBounds device bounds
+     * @throws IOException if something went wrong
+     */
+    public Type7ShadingContext(PDShadingType7 shading, ColorModel colorModel, AffineTransform xform,
+            Matrix ctm, int pageHeight, Rectangle dBounds) throws IOException
+    {
+        super(shading, colorModel, xform, ctm, pageHeight, dBounds);
+
+        // PDFBOX-1966 flip the AffineTransform in 1.8 branch
+        xform.scale(1,-1);
+        xform.translate(0, -pageHeight);        
+        
+        patchList = getTensorPatchList(xform, ctm);
+        pixelTable = calcPixelTable();
+    }
+
+    // get the patch list which forms the type 7 shading image from data stream
+    private ArrayList<Patch> getTensorPatchList(AffineTransform xform, Matrix ctm) throws IOException
+    {
+        PDShadingType7 tensorShadingType = (PDShadingType7) patchMeshesShadingType;
+        COSDictionary cosDictionary = tensorShadingType.getCOSDictionary();
+        PDRange rangeX = tensorShadingType.getDecodeForParameter(0);
+        PDRange rangeY = tensorShadingType.getDecodeForParameter(1);
+        PDRange[] colRange = new PDRange[numberOfColorComponents];
+        for (int i = 0; i < numberOfColorComponents; ++i)
+        {
+            colRange[i] = tensorShadingType.getDecodeForParameter(2 + i);
+        }
+        return getPatchList(xform, ctm, cosDictionary, rangeX, rangeY, colRange, 16);
+    }
+
+    @Override
+    protected Patch generatePatch(Point2D[] points, float[][] color)
+    {
+        return new TensorPatch(points, color);
+    }
+
+}

Propchange: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingPaint.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingPaint.java?rev=1617131&view=auto
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingPaint.java (added)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingPaint.java Sun Aug 10 16:34:17 2014
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+import java.awt.Paint;
+import java.awt.PaintContext;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.ColorModel;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.util.Matrix;
+
+/**
+ * AWT Paint for tensor-product patch meshes (Type 7) shading. This was done as
+ * part of GSoC2014, Tilman Hausherr is the mentor.
+ *
+ * @author Shaola Ren
+ */
+public class Type7ShadingPaint implements Paint
+{
+    private static final Log LOG = LogFactory.getLog(Type7ShadingPaint.class);
+
+    private final PDShadingType7 shading;
+    private final Matrix ctm;
+    private final int pageHeight;
+
+    /**
+     * Constructor.
+     *
+     * @param shading the shading resources
+     * @param ctm current transformation matrix
+     * @param pageHeight the height of the page
+     */
+    public Type7ShadingPaint(PDShadingType7 shading, Matrix ctm, int pageHeight)
+    {
+        this.shading = shading;
+        this.ctm = ctm;
+        this.pageHeight = pageHeight;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getTransparency()
+    {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds,
+            AffineTransform xform, RenderingHints hints)
+    {
+        try
+        {
+            return new Type7ShadingContext(shading, cm, xform, ctm, pageHeight, deviceBounds);
+        }
+        catch (IOException ex)
+        {
+            LOG.error(ex);
+            return null;
+        }
+    }
+}

Propchange: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Type7ShadingPaint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Vertex.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Vertex.java?rev=1617131&r1=1617130&r2=1617131&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Vertex.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/Vertex.java Sun Aug 10 16:34:17 2014
@@ -14,28 +14,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.pdfbox.pdmodel.graphics.shading;
 
 import java.awt.geom.Point2D;
 
 /**
- * 
- * Helper class to deal with Vertices for type 4 and 5 shading.
+ * Vertex for Type 4 and Type 5 shadings.
  *
  * @author Tilman Hausherr
  */
 class Vertex
 {
-    public byte flag; // used only with type 4 shading
     public Point2D point;
     public float[] color;
 
-    public Vertex(byte flag, Point2D point, float[] color)
+    public Vertex(Point2D p, float[] c)
     {
-        this.flag = flag;
-        this.point = point;
-        this.color = color.clone();
+        point = p;
+        color = c.clone();
     }
 
     @Override
@@ -44,13 +40,12 @@ class Vertex
         String colorStr = "";
         for (float f : color)
         {
-            if (colorStr.length() > 0)
+            if (!colorStr.isEmpty())
             {
                 colorStr += " ";
             }
             colorStr += String.format("%3.2f", f);
         }
-        return "Vertex{" + flag + ": " + point + ", colors=[" + colorStr + "] }";
+        return "Vertex{" + " " + point + ", colors=[" + colorStr + "] }";
     }
-
 }



Mime
View raw message