Class MeshGradient.Builder

  • Enclosing class:
    MeshGradient

    public static class MeshGradient.Builder
    extends java.lang.Object
    A Builder used for creating a MeshGradient. See the MeshGradient class API docs for a worked example of using this class.
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder()
      Create a new MeshGradient Builder
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFirst​(java.awt.Shape shape, java.awt.Color c0, java.awt.Color c1, java.awt.Color c2, java.awt.Color c3)
      Add a patch.
      void addNext​(java.awt.Shape shape, java.awt.Color... colors)
      Add a secondary patch which is partially derived from the previous patch(es).
      MeshGradient createMeshGradient()
      Return a new MeshGradient.
      java.awt.Color getColor​(int column, int row, int corner)
      Return the specified color of the specified Patch
      int getNumColumns()
      Return the number of columns in this patch
      int getNumRows()
      Return the number of rows in this patch
      java.lang.String getPath​(int column, int row, int edge)
      Return the specified edge of the specified Patch as an SVG path segment
      java.awt.geom.AffineTransform getTransform()
      Return the AffineTransform set on this mesh
      void nextRow()
      Start the next row of patches in the mesh array.
      void setTransform​(java.awt.geom.AffineTransform transform)
      Set the AffineTransform to use on this mesh
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Builder

        public Builder()
        Create a new MeshGradient Builder
    • Method Detail

      • addFirst

        public void addFirst​(java.awt.Shape shape,
                             java.awt.Color c0,
                             java.awt.Color c1,
                             java.awt.Color c2,
                             java.awt.Color c3)

        Add a patch. A PathIterator will be created from the supplied shape to define the four sides of the patch. As this method is intended for the first patch in the mesh, all four sides and corners must be defined.

        The first patch is typically the top-left corner of the mesh. Its shape must have four segments, drawn clockwise from (typically) the top-left, and there must be four colors describing each corner starting from the start point of the shape.

        Later patches can be added with addNext(java.awt.Shape, java.awt.Color...), or repeated calls to this method can be made if preferred, although care must be taken to ensure the edges are matched.

        All patches should be in the same ColorSpace. If they are not, we'll attempt to resolve this internally, typically falling back to Lab if the colorspaces cannot be reconciled. This may not give the correct results, not least because Lab Coons Patch gradients are poorly supported in PDF viewers (as of 2021).

        Parameters:
        shape - the shape, which should have a PathIterator describing a move followed by 4 line or curve segments
        c0 - the color for the first edge
        c1 - the color for the second edge
        c2 - the color for the third edge
        c3 - the color for the fourth edge
      • addNext

        public void addNext​(java.awt.Shape shape,
                            java.awt.Color... colors)
        Add a secondary patch which is partially derived from the previous patch(es). The number of sides and colors that must be specified depend on where in the mesh this patch is located:
        • Patches on the first row (after the first one) must have three segments which start at the top-left of the patch and describe the top, right and bottom segment. The shape will be translated so the start point matches the patch to the left, and the translated end point must match the corresponding point in that patch. There must be two colors describing the top-right and bottom-right corners
        • The first patch on any row after the first must have three segments which start at the top-right of the patch, and describe the right, bottom and left segment. The shape will be translated so the start point matches the patch on the previous row, and the end point must match the corresponding point on that patch. There must be two colors describing the bottom-right and bottom-left corners
        • Any other patches must have two segments which start at the top-right of the patch and descibe the right and bottom segment. The shape will be translated so the start point matches the patch on the previous row, and the end point must match the patch in the previous column. There must be one color, describing the bottom right corner.

        All patches should be in the same ColorSpace. If they are not, we'll attempt to resolve this internally, typically falling back to Lab if the colorspaces cannot be reconciled. This may not give the correct results, not least because Lab Coons Patch gradients are poorly supported in PDF viewers (as of 2021).

        If the end points of a patch to not align with the correponding points in the previous row and/or column, an IllegalArgumentException is thrown.

        Parameters:
        shape - the shape, which should have a PathIterator describing 1 or 2 line or curve segments
        colors - the list of 1 or 2 colors as described above
        Throws:
        java.lang.IllegalArgumentException - if the points don't match the previous patch
      • nextRow

        public void nextRow()
        Start the next row of patches in the mesh array. The first time this is called, the number of patches added so far determines the number of columns in the patch. Later calls to nextRow must be called so that each row has the same number of columns
      • createMeshGradient

        public MeshGradient createMeshGradient()
        Return a new MeshGradient. A MeshGradient should not be shared across PDF objects; if it is to be reused, a new MeshGradient should be created.
      • setTransform

        public void setTransform​(java.awt.geom.AffineTransform transform)
        Set the AffineTransform to use on this mesh
      • getTransform

        public java.awt.geom.AffineTransform getTransform()
        Return the AffineTransform set on this mesh
      • getNumColumns

        public int getNumColumns()
        Return the number of columns in this patch
      • getNumRows

        public int getNumRows()
        Return the number of rows in this patch
      • getPath

        public java.lang.String getPath​(int column,
                                        int row,
                                        int edge)
        Return the specified edge of the specified Patch as an SVG path segment
        Parameters:
        column - the column number, from 0..getNumColumns()
        row - the row number, from 0..getNumRows()
        edge - the edge, from 0 to 1,2 or 3 inclusive, depending on which patch it is
      • getColor

        public java.awt.Color getColor​(int column,
                                       int row,
                                       int corner)
        Return the specified color of the specified Patch
        Parameters:
        column - the column number, from 0..getNumColumns()
        row - the row number, from 0..getNumRows()
        edge - the corner, from 0 to 1,2 or 3 inclusive, depending on which patch it is
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object