PDF Graphics 2D.
Used for drawing into a pdf document as if it is a graphics object.
This takes a pdf document and draws into it.
baseLevel
protected int baseLevel
The PDF graphics state level that this svg is being drawn into.
currentFontName
protected String currentFontName
the current (internal) font name
currentFontSize
protected float currentFontSize
the current font size in millipoints
currentStream
protected StringWriter currentStream
the current stream to add PDF commands to
fontInfo
protected FontInfo fontInfo
The current font information.
graphicsState
protected PDFState graphicsState
the current state of the pdf graphics
nativeCount
protected int nativeCount
The count of natively handled images added to document so they receive
unique keys.
outputStream
protected OutputStream outputStream
The output stream for the pdf document.
If this is set then it can progressively output
the pdf document objects to reduce memory.
Especially with images.
ovFontState
protected Font ovFontState
The override font state used when drawing text and the font cannot be
set using java fonts.
pageRef
protected String pageRef
The PDF reference of the current page.
pdfDoc
protected PDFDocument pdfDoc
the PDF Document being created
resourceContext
protected PDFResourceContext resourceContext
The current resource context for adding fonts, patterns etc.
addLink
public void addLink(Rectangle2D bounds,
AffineTransform trans,
String dest,
int linkType)
This is a pdf specific method used to add a link to the
pdf document.
bounds
- the bounds of the link in user coordinatestrans
- the transform of the current drawing positiondest
- the PDF destinationlinkType
- the type of link, internal or external
applyAlpha
protected void applyAlpha(int fillAlpha,
int strokeAlpha)
Applies the given alpha values for filling and stroking.
fillAlpha
- A value between 0 and 255 (=OPAQUE) for fillingstrokeAlpha
- A value between 0 and 255 (=OPAQUE) for stroking
applyColor
protected void applyColor(Color col,
boolean fill)
Apply the java Color to PDF.
This converts the java colour to a PDF colour and
sets it for the next drawing.
col
- the java colourfill
- true if the colour will be used for filling
applyPaint
protected boolean applyPaint(Paint paint,
boolean fill)
Apply the java paint to the PDF.
This takes the java paint sets up the appropraite PDF commands
for the drawing with that paint.
Currently this supports the gradients and patterns from batik.
paint
- the paint to convert to PDFfill
- true if the paint should be set for filling
- true if the paint is handled natively, false if the paint should be rasterized
applyStroke
protected void applyStroke(Stroke stroke)
Apply the stroke to the PDF.
This takes the java stroke and outputs the appropriate settings
to the PDF so that the stroke attributes are handled.
applyUnknownPaint
protected boolean applyUnknownPaint(Paint paint,
Shape shape)
checkTransparencyAllowed
protected void checkTransparencyAllowed()
Checks whether the use of transparency is allowed.
copyArea
public void copyArea(int x,
int y,
int width,
int height,
int dx,
int dy)
Copies an area of the component by a distance specified by
dx
and dy
. From the point specified
by x
and y
, this method
copies downwards and to the right. To copy an area of the
component to the left or upwards, specify a negative value for
dx
or dy
.
If a portion of the source rectangle lies outside the bounds
of the component, or is obscured by another window or component,
copyArea
will be unable to copy the associated
pixels. The area that is omitted can be refreshed by calling
the component's paint
method.
x
- the x coordinate of the source rectangle.y
- the y coordinate of the source rectangle.width
- the width of the source rectangle.height
- the height of the source rectangle.dx
- the horizontal distance to copy the pixels.dy
- the vertical distance to copy the pixels.
create
public Graphics create()
Creates a new Graphics
object that is
a copy of this Graphics
object.
- a new graphics context that is a copy of
this graphics context.
dispose
public void dispose()
Disposes of this graphics context and releases
any system resources that it is using.
A
Graphics
object cannot be used after
dispose
has been called.
When a Java program runs, a large number of
Graphics
objects can be created within a short time frame.
Although the finalization process of the garbage collector
also disposes of the same system resources, it is preferable
to manually free the associated resources by calling this
method rather than to rely on a finalization process which
may not run to completion for a long period of time.
Graphics objects which are provided as arguments to the
paint
and
update
methods
of components are automatically released by the system when
those methods return. For efficiency, programmers should
call
dispose
when finished using
a
Graphics
object only if it was created
directly from a component or another
Graphics
object.
java.awt.Graphics.finalize
, java.awt.Component.paint
, java.awt.Component.update
, java.awt.Component.getGraphics
, java.awt.Graphics.create
doDrawing
protected void doDrawing(boolean fill,
boolean stroke,
boolean nonzero)
Do the PDF drawing command.
This does the PDF drawing command according to fill
stroke and winding rule.
fill
- true if filling the pathstroke
- true if stroking the pathnonzero
- true if using the non-zero winding rule
draw
public void draw(Shape s)
Strokes the outline of a Shape
using the settings of the
current Graphics2D
context. The rendering attributes
applied include the Clip
, Transform
,
Paint
, Composite
and
Stroke
attributes.
s
- the Shape
to be rendered
PDFGraphics2D
, PDFGraphics2D
, java.awt.Graphics.setColor
, PDFGraphics2D
, PDFGraphics2D
, PDFGraphics2D
, PDFGraphics2D
, PDFGraphics2D
drawImage
public boolean drawImage(Image img,
int x,
int y,
ImageObserver observer)
Draws as much of the specified image as is currently available.
The image is drawn with its top-left corner at
(
x,
y) in this graphics context's coordinate
space. Transparent pixels in the image do not affect whatever
pixels are already there.
This method returns immediately in all cases, even if the
complete image has not yet been loaded, and it has not been dithered
and converted for the current output device.
If the image has not yet been completely loaded, then
drawImage
returns
false
. As more of
the image becomes available, the process that draws the image notifies
the specified image observer.
img
- the specified image to be drawn.x
- the x coordinate.y
- the y coordinate.observer
- object to be notified as more of
the image is converted.
- true if the image was drawn
java.awt.Image
, java.awt.image.ImageObserver
, java.awt.image.ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
drawImage
public boolean drawImage(Image img,
int x,
int y,
int width,
int height,
ImageObserver observer)
drawInnerRenderedImage
public void drawInnerRenderedImage(String key,
RenderedImage img,
AffineTransform xform)
drawRenderableImage
public void drawRenderableImage(RenderableImage img,
AffineTransform xform)
drawRenderedImage
public void drawRenderedImage(RenderedImage img,
AffineTransform xform)
drawString
public void drawString(AttributedCharacterIterator iterator,
float x,
float y)
Renders the text of the specified iterator, using the
Graphics2D
context's current Paint
. The
iterator must specify a font
for each character. The baseline of the
first character is at position (x, y) in the
User Space.
The rendering attributes applied include the Clip
,
Transform
, Paint
, and
Composite
attributes.
For characters in script systems such as Hebrew and Arabic,
the glyphs can be rendered from right to left, in which case the
coordinate supplied is the location of the leftmost character
on the baseline.
iterator
- the iterator whose text is to be renderedx
- the coordinate where the iterator's text is to be
renderedy
- the coordinate where the iterator's text is to be
rendered
PDFGraphics2D
, java.awt.Graphics.setColor
, PDFGraphics2D
, PDFGraphics2D
, PDFGraphics2D
drawString
public void drawString(String s,
float x,
float y)
Renders the text specified by the specified String
,
using the current Font
and Paint
attributes
in the Graphics2D
context.
The baseline of the first character is at position
(x, y) in the User Space.
The rendering attributes applied include the Clip
,
Transform
, Paint
, Font
and
Composite
attributes. For characters in script systems
such as Hebrew and Arabic, the glyphs can be rendered from right to
left, in which case the coordinate supplied is the location of the
leftmost character on the baseline.
s
- the String
to be renderedx
- the coordinate where the String
should be renderedy
- the coordinate where the String
should be rendered
PDFGraphics2D
, java.awt.Graphics.setColor
, java.awt.Graphics.setFont
, PDFGraphics2D
, PDFGraphics2D
, PDFGraphics2D
fill
public void fill(Shape s)
Fills the interior of a Shape
using the settings of the
Graphics2D
context. The rendering attributes applied
include the Clip
, Transform
,
Paint
, and Composite
.
s
- the Shape
to be filled
PDFGraphics2D
, java.awt.Graphics.setColor
, PDFGraphics2D
, PDFGraphics2D
, PDFGraphics2D
, PDFGraphics2D
, PDFGraphics2D
getBaseTransform
protected AffineTransform getBaseTransform()
This is mainly used for shading patterns which use the document-global coordinate system
instead of the local one.
- the transformation matrix that established the basic user space for this document
getBuffer
public StringBuffer getBuffer()
Get the string buffer from the currentStream, containing all
the commands written into this Grpahics so far.
- the StringBuffer containing the PDF markup
getDeviceConfiguration
public GraphicsConfiguration getDeviceConfiguration()
Returns the device configuration associated with this
Graphics2D
.
- the PDF graphics configuration
getFontMetrics
public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
Gets the font metrics for the specified font.
- the font metrics for the specified font.
java.awt.Graphics.getFont
, java.awt.FontMetrics
, java.awt.Graphics.getFontMetrics()
getInternalFontForAWTFont
protected Font getInternalFontForAWTFont(java.awt.Font awtFont)
Returns a suitable internal font given an AWT Font instance.
getString
public String getString()
Get the string containing all the commands written into this
Grpahics.
- the string containing the PDF markup
handleIOException
protected void handleIOException(IOException ioe)
Central handler for IOExceptions for this class.
ioe
- IOException to handle
isMultiByteFont
protected boolean isMultiByteFont(String name)
Determines whether the font with the given name is a multi-byte font.
name
- the name of the font
- true if it's a multi-byte font
preparePainting
protected void preparePainting()
This method is used by PDFDocumentGraphics2D to prepare a new page if
necessary.
processPathIterator
public void processPathIterator(PathIterator iter)
Processes a path iterator generating the necessary painting operations.
iter
- PathIterator to process
setGraphicContext
public void setGraphicContext(GraphicContext c)
Set the Grpahics context.
c
- the graphics context to use
setOutputStream
public void setOutputStream(OutputStream os)
Set the output stream that this PDF document is
being drawn to. This is so that it can progressively
use the PDF document to output data such as images.
This results in a significant saving on memory.
os
- the output stream that is being used for the PDF document
setOverrideFontState
public void setOverrideFontState(Font infont)
Set the override font state for drawing text.
This is used by the PDF text painter so that it can temporarily
set the font state when a java font cannot be used.
The next drawString will use this font state.
infont
- the font state to use
setPDFState
public void setPDFState(PDFState state)
Set the PDF state to use when starting to draw
into the PDF graphics.
setXORMode
public void setXORMode(Color c1)
Sets the paint mode of this graphics context to alternate between
this graphics context's current color and the new specified color.
This specifies that logical pixel operations are performed in the
XOR mode, which alternates pixels between the current color and
a specified XOR color.
When drawing operations are performed, pixels which are the
current color are changed to the specified color, and vice versa.
Pixels that are of colors other than those two colors are changed
in an unpredictable but reversible manner; if the same figure is
drawn twice, then all pixels are restored to their original values.
c1
- the XOR alternation color
updateCurrentFont
protected void updateCurrentFont(Font font)
Updates the currently selected font.
font
- the new font to use
writeClip
protected void writeClip(Shape s)
Set the clipping shape for future PDF drawing in the current graphics state.
This sets creates and writes a clipping shape that will apply
to future drawings in the current graphics state.