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 patternswidth
is the width of the pattern before it repeats, as a floatheight
is the height of the pattern before it repeats, as a floataction
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
Constructors Constructor Description PDFPattern(String pattern, float x1, float y1, float x2, float y2, Color fg, Color bg)
Create a PDFPattern from a known, named duotone pattern.PDFPattern(PDFCanvas canvas, float x1, float y1, float x2, float y2)
Create a pattern from the specifiedPDFCanvas
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PDFPattern
brightnessClone(float delta, float min, float max)
PaintContext
createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
Required as part of thePaint
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 thePaint
contract.void
setTransform(AffineTransform transform)
Set the transform to use for this pattern.String
toString()
-
-
-
Constructor Detail
-
PDFPattern
public PDFPattern(PDFCanvas canvas, float x1, float y1, float x2, float y2)
Create a pattern from the specifiedPDFCanvas
. 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 patternx1
- the left edge of the patterns reference tile on the pagey1
- the bottom edge of the patterns reference tile on the pagex2
- the left edge of the patterns reference tile on the pagey2
- 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, oftenx1
andy1
are 0, andx2
andy2
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 aPropertyResourceBundle
to load.x1
- the left edge of the patterns reference tile on the pagey1
- the bottom edge of the patterns reference tile on the pagex2
- the right edge of the patterns reference tile on the pagey2
- the top edge of the patterns reference tile on the pagefg
- the foreground color to usebg
- the background color to use- Throws:
MissingResourceException
- if the specified pattern cannot be found.
-
-
Method Detail
-
getTransparency
public int getTransparency()
Required as part of thePaint
contract. ReturnsTransparency.OPAQUE
.- Specified by:
getTransparency
in interfaceTransparency
-
createContext
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
Required as part of thePaint
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 interfacePaint
-
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)
-
-