|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Graphics
gnu.jpdf.PDFGraphics
public class PDFGraphics
This class is our implementation of AWT's Graphics class. It provides a Java standard way of rendering into a PDF Document's Page.
PDFGraphics
,
Serialized FormField Summary | |
---|---|
protected java.awt.Rectangle |
clipRectangle
This holds the current clipRectangle |
protected java.awt.Rectangle |
media
This is the media we are working with |
protected int |
trax
This is used to translate coordinates |
protected int |
tray
This is used to translate coordinates |
Constructor Summary | |
---|---|
PDFGraphics()
|
Method Summary | |
---|---|
void |
arc(double axc,
double ayc,
double width,
double height,
double ang1,
double ang2,
boolean clockwise)
This produces an arc by breaking it down into one or more Bezier curves. |
void |
clearRect(int x,
int y,
int w,
int h)
This simply draws a White Rectangle to clear the area |
void |
clipPolygon(java.awt.Polygon p)
This extra method allows PDF users to clip to a Polygon. |
void |
clipRect(int x,
int y,
int w,
int h)
Clips to a set of coordinates |
void |
copyArea(int x,
int y,
int w,
int h,
int dx,
int dy)
This is unsupported - how do you do this with Vector graphics? |
java.awt.Graphics |
create()
This returns a child instance of this Graphics object. |
protected PDFGraphics |
createGraphic(PDFPage page,
java.io.PrintWriter pw)
This method creates a new instance of the class based on the page and a print writer. |
void |
curveto(double x1,
double y1,
double x2,
double y2)
This extension appends a Bezier curve to the path. |
void |
curveto(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
This extension appends a Bezier curve to the path. |
void |
curveto(int x1,
int y1,
int x2,
int y2)
This extension appends a Bezier curve to the path. |
void |
curveto(int x1,
int y1,
int x2,
int y2,
int x3,
int y3)
This extension appends a Bezier curve to the path. |
void |
curveto2(double x1,
double y1,
double x2,
double y2)
This extension appends a Bezier curve to the path. |
void |
curveto2(int x1,
int y1,
int x2,
int y2)
This extension appends a Bezier curve to the path. |
void |
dispose()
This releases any resources used by this Graphics object. |
void |
draw3DRect(int x,
int y,
int width,
int height,
boolean raised)
Not implemented |
void |
drawArc(int x,
int y,
int w,
int h,
int sa,
int aa)
Draws an arc |
void |
drawBytes(byte[] data,
int offset,
int length,
int x,
int y)
Not implemented |
boolean |
drawImage(java.awt.Image img,
int x,
int y,
java.awt.Color bgcolor,
java.awt.image.ImageObserver obs)
Draw's an image onto the page, with a backing colour. |
boolean |
drawImage(java.awt.Image img,
int x,
int y,
java.awt.image.ImageObserver obs)
Draw's an image onto the page |
boolean |
drawImage(java.awt.Image img,
int x,
int y,
int w,
int h,
java.awt.Color bgcolor,
java.awt.image.ImageObserver obs)
Draw's an image onto the page, with a backing colour. |
boolean |
drawImage(java.awt.Image img,
int x,
int y,
int w,
int h,
java.awt.image.ImageObserver obs)
Draws an image onto the page. |
boolean |
drawImage(java.awt.Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
java.awt.Color bgcolor,
java.awt.image.ImageObserver obs)
Draw's an image onto the page, with scaling |
boolean |
drawImage(java.awt.Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
java.awt.image.ImageObserver obs)
Draw's an image onto the page, with scaling |
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line between two coordinates. |
void |
drawOval(int x,
int y,
int w,
int h)
Draws an oval |
void |
drawPolygon(int[] xp,
int[] yp,
int np)
Draws a polygon, linking the first and last coordinates. |
void |
drawPolyline(int[] xp,
int[] yp,
int np)
Draws a polyline. |
void |
drawRect(int x,
int y,
int w,
int h)
We override Graphics.drawRect as it doesn't join the 4 lines. |
void |
drawRoundRect(int x,
int y,
int w,
int h,
int aw,
int ah)
This is not yet implemented |
void |
drawString(java.text.AttributedCharacterIterator aci,
int x,
int y)
Draws a string using a AttributedCharacterIterator. |
void |
drawString(java.lang.String s,
int x,
int y)
This draws a string. |
void |
fill3DRect(int x,
int y,
int width,
int height,
boolean raised)
Not implemented |
void |
fillArc(int x,
int y,
int w,
int h,
int sa,
int aa)
Fills an arc, joining the start and end coordinates |
void |
fillOval(int x,
int y,
int w,
int h)
Draws a filled oval |
void |
fillPolygon(int[] xp,
int[] yp,
int np)
Fills a polygon. |
void |
fillRect(int x,
int y,
int w,
int h)
Fills a rectangle with the current colour |
void |
fillRoundRect(int x,
int y,
int w,
int h,
int aw,
int ah)
This is not yet implemented |
java.awt.Shape |
getClip()
Returns the Shape of the clipping region As my JDK docs say, this may break with Java 2D. |
java.awt.Rectangle |
getClipBounds()
Returns the Rectangle that fits the current clipping region |
java.awt.Color |
getColor()
Returns the current pen Colour |
java.awt.Font |
getFont()
Return's the current font. |
java.awt.FontMetrics |
getFontMetrics(java.awt.Font font)
Returns the FontMetrics for a font. |
PDFPage |
getPage()
Returns the associated PDFPage for this graphic |
java.io.PrintWriter |
getWriter()
Returns the PrintWriter handling the underlying stream |
protected void |
init(PDFPage page)
This is called by PDFPage when creating a Graphcis instance. |
protected void |
init(PDFPage page,
java.io.PrintWriter pw)
This method is used internally by create() and by the PDFJob class |
void |
lineto(double x,
double y)
This adds a line segment to the current path |
void |
lineto(int x,
int y)
This adds a line segment to the current path |
void |
moveto(double x,
double y)
This moves the current drawing point. |
void |
moveto(int x,
int y)
This moves the current drawing point. |
void |
polygon(int[] xp,
int[] yp,
int np)
This is used to add a polygon to the current path. |
void |
setClip(int x,
int y,
int w,
int h)
Clips to a set of coordinates |
void |
setClip(java.awt.Shape s)
As my JDK docs say, this may break with Java 2D. |
void |
setColor(java.awt.Color c)
Sets the colour for drawing |
void |
setDefaultLineWidth()
This extension sets the line width to the default of 1mm which is what Java uses when drawing to a PrintJob. |
void |
setFont(java.awt.Font f)
This sets the font. |
void |
setLineWidth(double w)
This extension allows the width of the drawn line to be set |
void |
setOrientation()
This sets the media Orientation (0=Portrait, 90=Landscape, 180=Inverse, 270=Seascape). |
void |
setPaintMode()
Not implemented, as this is not supported in the PDF specification. |
void |
setXORMode(java.awt.Color c1)
Not implemented, as this is not supported in the PDF specification. |
void |
translate(int x,
int y)
Translate the origin. |
Methods inherited from class java.awt.Graphics |
---|
create, drawChars, drawPolygon, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.awt.Rectangle media
protected int trax
protected int tray
protected java.awt.Rectangle clipRectangle
Constructor Detail |
---|
public PDFGraphics()
Method Detail |
---|
protected PDFGraphics createGraphic(PDFPage page, java.io.PrintWriter pw)
page
- the page to attach topw
- the PrintWriter
to attach to.protected void init(PDFPage page)
page
- The PDFPage to draw onto.protected void init(PDFPage page, java.io.PrintWriter pw)
page
- PDFPage to draw intopw
- PrintWriter to usepublic java.io.PrintWriter getWriter()
public PDFPage getPage()
public java.awt.Graphics create()
This returns a child instance of this Graphics object. As with AWT, the affects of using the parent instance while the child exists, is not determined.
Once complete, the child should be released with it's dispose() method which will restore the graphics state to it's parent.
create
in class java.awt.Graphics
public void dispose()
This releases any resources used by this Graphics object. You must use this method once finished with it. Leaving it open will leave the PDF stream in an inconsistent state, and will produce errors.
If this was created with Graphics.create() then the parent instance can be used again. If not, then this closes the graphics operations for this page when used with PDFJob.
When using PDFPage, you can create another fresh Graphics instance, which will draw over this one.
dispose
in class java.awt.Graphics
public void clearRect(int x, int y, int w, int h)
clearRect
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightpublic void drawRect(int x, int y, int w, int h)
drawRect
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightpublic void draw3DRect(int x, int y, int width, int height, boolean raised)
Not implemented
Draws a 3-D highlighted outline of the specified rectangle. The edges of the rectangle are highlighted so that they appear to be beveled and lit from the upper left corner. The colors used for the highlighting effect are determined based on the current color. The resulting rectangle covers an area that is width + 1 pixels wide by height + 1 pixels tall.
draw3DRect
in class java.awt.Graphics
x
- an int
valuey
- an int
valuewidth
- an int
valueheight
- an int
valueraised
- a boolean
valuepublic void fill3DRect(int x, int y, int width, int height, boolean raised)
Not implemented
fill3DRect
in class java.awt.Graphics
x
- an int
valuey
- an int
valuewidth
- an int
valueheight
- an int
valueraised
- a boolean
valuepublic void fillRect(int x, int y, int w, int h)
fillRect
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightpublic void fillRoundRect(int x, int y, int w, int h, int aw, int ah)
fillRoundRect
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightaw
- a-widthah
- a-heightpublic void drawRoundRect(int x, int y, int w, int h, int aw, int ah)
drawRoundRect
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightaw
- a-widthah
- a-heightpublic void drawOval(int x, int y, int w, int h)
Draws an oval
drawOval
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightpublic void fillOval(int x, int y, int w, int h)
Draws a filled oval
fillOval
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightpublic void drawPolygon(int[] xp, int[] yp, int np)
drawPolygon
in class java.awt.Graphics
xp
- Array of x coordinatesyp
- Array of y coordinatesnp
- number of points in polygonpublic void drawPolyline(int[] xp, int[] yp, int np)
drawPolyline
in class java.awt.Graphics
xp
- Array of x coordinatesyp
- Array of y coordinatesnp
- number of points in polylinepublic void fillPolygon(int[] xp, int[] yp, int np)
fillPolygon
in class java.awt.Graphics
xp
- Array of x coordinatesyp
- Array of y coordinatesnp
- number of points in polygonpublic boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver obs)
drawImage
in class java.awt.Graphics
img
- The java.awt.Imagex
- coordinate on pagey
- coordinate on pageobs
- ImageObserver
public boolean drawImage(java.awt.Image img, int x, int y, int w, int h, java.awt.image.ImageObserver obs)
Draws an image onto the page.
This method is implemented with ASCIIbase85 encoding and the zip stream deflater. It results in a stream that is anywhere from 3 to 10 times as big as the image. This obviusly needs some improvement, but it works well for small images
drawImage
in class java.awt.Graphics
img
- The java.awt.Imagex
- coordinate on pagey
- coordinate on pagew
- Width on pageh
- height on pageobs
- ImageObserver
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver obs)
Draw's an image onto the page, with a backing colour.
drawImage
in class java.awt.Graphics
img
- The java.awt.Imagex
- coordinate on pagey
- coordinate on pagebgcolor
- Background colourobs
- ImageObserver
public boolean drawImage(java.awt.Image img, int x, int y, int w, int h, java.awt.Color bgcolor, java.awt.image.ImageObserver obs)
Draw's an image onto the page, with a backing colour.
drawImage
in class java.awt.Graphics
img
- The java.awt.Imagex
- coordinate on pagey
- coordinate on pagew
- Width on pageh
- height on pagebgcolor
- Background colourobs
- ImageObserver
public boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver obs)
This is not yet supported.
drawImage
in class java.awt.Graphics
img
- The java.awt.Imagedx1
- coordinate on pagedy1
- coordinate on pagedx2
- coordinate on pagedy2
- coordinate on pagesx1
- coordinate on imagesy1
- coordinate on imagesx2
- coordinate on imagesy2
- coordinate on imageobs
- ImageObserver
public boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver obs)
This is not yet supported.
drawImage
in class java.awt.Graphics
img
- The java.awt.Imagedx1
- coordinate on pagedy1
- coordinate on pagedx2
- coordinate on pagedy2
- coordinate on pagesx1
- coordinate on imagesy1
- coordinate on imagesx2
- coordinate on imagesy2
- coordinate on imagebgcolor
- Background colourobs
- ImageObserver
public void clipRect(int x, int y, int w, int h)
clipRect
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightpublic void setClip(int x, int y, int w, int h)
setClip
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightpublic void setClip(java.awt.Shape s)
Sets the clipping region to that of a Shape.
setClip
in class java.awt.Graphics
s
- Shape to clip to.public void clipPolygon(java.awt.Polygon p)
In theory you could use setClip(), except that java.awt.Graphics only supports Rectangle with that method, so we will have an extra method.
p
- Polygon to clip topublic java.awt.Rectangle getClipBounds()
getClipBounds
in class java.awt.Graphics
public java.awt.Color getColor()
getColor
in class java.awt.Graphics
public void setColor(java.awt.Color c)
setColor
in class java.awt.Graphics
c
- Color to usepublic void setPaintMode()
setPaintMode
in class java.awt.Graphics
public void setXORMode(java.awt.Color c1)
setXORMode
in class java.awt.Graphics
c1
- Color to xor withpublic java.awt.FontMetrics getFontMetrics(java.awt.Font font)
This doesn't work correctly. Perhaps having some way of mapping the base 14 fonts to our own FontMetrics implementation?
getFontMetrics
in class java.awt.Graphics
font
- The java.awt.Font to return the metrics for
public java.awt.Font getFont()
getFont
in class java.awt.Graphics
public void setFont(java.awt.Font f)
setFont
in class java.awt.Graphics
f
- java.awt.Font to set to.public void drawString(java.lang.String s, int x, int y)
drawString
in class java.awt.Graphics
s
- String to drawx
- coordy
- coordpublic void drawBytes(byte[] data, int offset, int length, int x, int y)
Not implemented
drawBytes
in class java.awt.Graphics
data
- a byte[]
valueoffset
- an int
valuelength
- an int
valuex
- an int
valuey
- an int
valuepublic void copyArea(int x, int y, int w, int h, int dx, int dy)
copyArea
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightdx
- coorddy
- coordpublic void drawLine(int x1, int y1, int x2, int y2)
drawLine
in class java.awt.Graphics
x1
- coordy1
- coordx2
- coordy2
- coordpublic void translate(int x, int y)
translate
in class java.awt.Graphics
x
- coord offsety
- coord offsetpublic void drawArc(int x, int y, int w, int h, int sa, int aa)
drawArc
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightsa
- Start angleaa
- End anglepublic void fillArc(int x, int y, int w, int h, int sa, int aa)
fillArc
in class java.awt.Graphics
x
- coordy
- coordw
- widthh
- heightsa
- Start angleaa
- End anglepublic void moveto(int x, int y)
x
- coordy
- coordpublic void moveto(double x, double y)
x
- coordy
- coordpublic void lineto(int x, int y)
x
- coordy
- coordpublic void lineto(double x, double y)
x
- coordy
- coordpublic void setLineWidth(double w)
w
- Line width in mmpublic void setDefaultLineWidth()
public void polygon(int[] xp, int[] yp, int np)
xp
- Array of x coordinatesyp
- Array of y coordinatesnp
- number of points in polygondrawPolygon(int[], int[], int)
,
drawPolyline(int[], int[], int)
,
fillPolygon(int[], int[], int)
public void curveto(int x1, int y1, int x2, int y2, int x3, int y3)
The new current point is (x3,y3)
x1
- First control pointy1
- First control pointx2
- Second control pointy2
- Second control pointx3
- Destination pointy3
- Destination pointpublic void curveto(double x1, double y1, double x2, double y2, double x3, double y3)
The new current point is (x3,y3)
x1
- First control pointy1
- First control pointx2
- Second control pointy2
- Second control pointx3
- Destination pointy3
- Destination pointpublic void curveto(int x1, int y1, int x2, int y2)
The new current point is (x2,y2)
x1
- Second control pointy1
- Second control pointx2
- Destination pointy2
- Destination pointpublic void curveto(double x1, double y1, double x2, double y2)
The new current point is (x2,y2)
x1
- Second control pointy1
- Second control pointx2
- Destination pointy2
- Destination pointpublic void curveto2(int x1, int y1, int x2, int y2)
The new current point is (x2,y2)
x1
- Second control pointy1
- Second control pointx2
- Destination pointy2
- Destination pointpublic void curveto2(double x1, double y1, double x2, double y2)
The new current point is (x2,y2)
x1
- Second control pointy1
- Second control pointx2
- Destination pointy2
- Destination pointpublic void arc(double axc, double ayc, double width, double height, double ang1, double ang2, boolean clockwise)
axc
- X coordinate of arc centreayc
- Y coordinate of arc centrewidth
- of bounding rectangleheight
- of bounding rectangleang1
- Start angleang2
- End angleclockwise
- true to draw clockwise, false anti-clockwisepublic void setOrientation()
Normally, this is called when the Graphics instance is created, but if the media is changed, then this must be called, especially when using the PDFJob class to create the file.
public java.awt.Shape getClip()
getClip
in class java.awt.Graphics
public void drawString(java.text.AttributedCharacterIterator aci, int x, int y)
This is not supported yet, as I have no idea what an AttributedCharacterIterator is.
This method is new to the Java2 API.
drawString
in class java.awt.Graphics
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |