Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.faceless.pdf2
Class PDFPattern

    java.lang.Object
      org.faceless.pdf2.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

Brick | A "brick-wall" pattern
Check | A chequered-square pattern
Grid | A grid pattern
Spot | A spot pattern, like the half-toning pattern used in newspapers
Star | A 5-pointed star pattern
Stripexxx | A 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

Field Summary

Fields inherited from interface java.awt.Transparency
`BITMASK, OPAQUE, TRANSLUCENT`

Constructor Summary
`PDFPattern(PDFCanvas canvas, float x1, float y1, float x2, float y2)` Create a pattern from the specified `PDFCanvas`.
`PDFPattern(String pattern, float x1, float y1, float x2, float y2, Color fg, Color bg)` Create a PDFPattern from a known, named duotone pattern.

Method Summary
`PDFPattern` | `brightnessClone(float delta, float min, float max)`
`PaintContext` | `createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)` Required as part of the `Paint` contract.
`Paint` | `getShaded(float delta, float min, float max)` This method is required when painting patterns using the graph library.
`int` | `getTransparency()` Required as part of the `Paint` contract.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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

### getTransparency

    public int getTransparency()

  Required as part of the `Paint` contract. Returns `Transparency.OPAQUE`.

  Specified by:
    `getTransparency` in interface `Transparency`

### createContext

    public PaintContext createContext(ColorModel cm,
                                      Rectangle deviceBounds,
                                      Rectangle2D userBounds,
                                      AffineTransform xform,
                                      RenderingHints hints)

  Required as part of the `Paint` contract. This method is only needed when drawing a Paint to an AWT canvas, so it's not implemented and throws an error if called.

  Specified by:
    `createContext` in interface `Paint`

### 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)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2012 Big Faceless Organization