Class PDFPattern

  • All Implemented Interfaces:
    Paint, Transparency

    public final class PDFPattern
    extends Object
    implements Paint

    Create a new "pattern" fill to paint with. A PDFPattern can be passed into the PDFStyle.setFillColor(java.awt.Paint) method to cause any shapes or text painted with that style to be filled with the specified pattern.

    Patterns can either be created by passing in a PDFCanvas, or by loading a named duotone or color pattern from a file (duotone patterns require a background and foreground color to be specified, whereas color patterns already include this information).

    Several patterns are supplied with the default distribution. They include

    BrickA "brick-wall" pattern
    CheckA chequered-square pattern
    GridA grid pattern
    SpotA spot pattern, like the half-toning pattern used in newspapers
    StarA 5-pointed star pattern
    StripexxxA stripe pattern. xxx is the angle of the strripes - eg. "000" for vertical stripes, "045" or "060" for diagonal and so on

    Users may create their own patterns and store them in a file for use by the library. The file is a standard PropertyResourceBundle file, with the following attributes (all mandatory):

    • type must be the word "color" for color patterns or "duotone" for duotone patterns
    • width is the width of the pattern before it repeats, as a float
    • height is the height of the pattern before it repeats, as a float
    • action is the raw PDF graphics state instructions to write to the stream. So, for example, "1 1 1 rg 0 0 300 200 re f 1 0 0 rg 0 100 300 200 re f" would draw the Indonesian flag (it's a simple example). Duotone patterns should not include any color commands, whereas color patterns must set the fill and/or line colors before they're used.

    This file should then be stored as part of a package, eg "com/yourcompany/yourpattern.properties". The resource name can then be passed into the PDFPattern constructor, eg.

       PDFPattern pattern = new PDFPattern("com.yourcompany.yourpattern", 0, 0, 300, 200);
     
    Since:
    2.0
    • Constructor Detail

      • PDFPattern

        public PDFPattern​(PDFCanvas canvas,
                          float x1,
                          float y1,
                          float x2,
                          float y2)
        Create a pattern from the specified PDFCanvas. The two parameters specify where on the page to start tiling the canvas from.
        Parameters:
        canvas - the PDFCanvas to use as the source of the pattern
        x1 - the left edge of the patterns reference tile on the page
        y1 - the bottom edge of the patterns reference tile on the page
        x2 - the left edge of the patterns reference tile on the page
        y2 - the bottom edge of the patterns reference tile on the page
      • PDFPattern

        public PDFPattern​(String pattern,
                          float x1,
                          float y1,
                          float x2,
                          float y2,
                          Color fg,
                          Color bg)
                   throws MissingResourceException

        Create a PDFPattern from a known, named duotone pattern. The pattern will be resized so that the rectangle (x1, y1, x2, y2) on the page will contain one complete copy of the pattern - drawing it outside this rectangle will tile it appropriately. For simpler patterns that don't have to be positioned exactly, often x1 and y1 are 0, and x2 and y2 specify your choice for the width and height of the pattern.

        Patterns created with this constructor are two-color or "duotone" patterns. A background and foreground color must be supplied, which may be translucent

        Parameters:
        pattern - the name of the pattern to load - either one of the predefined patterns (see above), or the fully-qualified name of a PropertyResourceBundle to load.
        x1 - the left edge of the patterns reference tile on the page
        y1 - the bottom edge of the patterns reference tile on the page
        x2 - the right edge of the patterns reference tile on the page
        y2 - the top edge of the patterns reference tile on the page
        fg - the foreground color to use
        bg - the background color to use
        Throws:
        MissingResourceException - if the specified pattern cannot be found.
    • Method Detail

      • setTransform

        public void setTransform​(AffineTransform transform)
        Set the transform to use for this pattern.
        Parameters:
        transform - the transform to apply when painting this pattern
        Since:
        2.23.3
      • getShaded

        public Paint getShaded​(float delta,
                               float min,
                               float max)
        This method is required when painting patterns using the graph library. It should not be called by the user
      • brightnessClone

        public PDFPattern brightnessClone​(float delta,
                                          float min,
                                          float max)