public class PDFGraphics2D extends org.apache.xmlgraphics.java2d.AbstractGraphics2D implements NativeImageHandler
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.
This work was authored by Keiron Liddle (keiron@aftexsw.com).
AbstractGraphics2D
Modifier and Type | Field and Description |
---|---|
protected int |
baseLevel
The PDF graphics state level that this svg is being drawn into.
|
protected PDFColorHandler |
colorHandler
the PDF color handler
|
protected java.lang.String |
currentFontName
the current (internal) font name
|
protected float |
currentFontSize
the current font size in millipoints
|
protected java.io.StringWriter |
currentStream
the current stream to add PDF commands to
|
protected FontInfo |
fontInfo
The current font information.
|
protected int |
nativeCount
The count of natively handled images added to document so they receive
unique keys.
|
protected java.io.OutputStream |
outputStream
The output stream for the pdf document.
|
protected Font |
ovFontState
The override font state used when drawing text and the font cannot be
set using java fonts.
|
protected java.lang.String |
pageRef
The PDF reference of the current page.
|
protected PDFPaintingState |
paintingState
The PDF painting state
|
protected PDFDocument |
pdfDoc
the PDF Document being created
|
protected PDFResourceContext |
resourceContext
The current resource context for adding fonts, patterns etc.
|
Modifier | Constructor and Description |
---|---|
protected |
PDFGraphics2D(boolean textAsShapes)
Create a new PDFGraphics2D.
|
|
PDFGraphics2D(boolean textAsShapes,
FontInfo fi,
PDFDocument doc,
PDFResourceContext page,
java.lang.String pref,
java.lang.String font,
float size)
Create a new PDFGraphics2D with the given pdf document info.
|
|
PDFGraphics2D(PDFGraphics2D g)
This constructor supports the create method.
|
Modifier and Type | Method and Description |
---|---|
void |
addLink(java.awt.geom.Rectangle2D bounds,
java.awt.geom.AffineTransform trans,
java.lang.String dest,
int linkType)
This is a pdf specific method used to add a link to the
pdf document.
|
void |
addNativeImage(org.apache.xmlgraphics.image.loader.Image image,
float x,
float y,
float width,
float height)
Add a natively handled image directly to the PDF document.
|
protected void |
applyAlpha(int fillAlpha,
int strokeAlpha)
Applies the given alpha values for filling and stroking.
|
protected void |
applyColor(java.awt.Color col,
boolean fill)
Apply the java Color to PDF.
|
protected boolean |
applyPaint(java.awt.Paint paint,
boolean fill)
Apply the java paint to the PDF.
|
protected void |
applyStroke(java.awt.Stroke stroke)
Apply the stroke to the PDF.
|
protected boolean |
applyUnknownPaint(java.awt.Paint paint,
java.awt.Shape shape) |
protected void |
checkTransparencyAllowed()
Checks whether the use of transparency is allowed.
|
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 . |
java.awt.Graphics |
create()
Creates a new
Graphics object that is
a copy of this Graphics object. |
void |
dispose()
Disposes of this graphics context and releases
any system resources that it is using.
|
protected void |
doDrawing(boolean fill,
boolean stroke,
boolean nonzero)
Do the PDF drawing command.
|
void |
draw(java.awt.Shape s)
Strokes the outline of a
Shape using the settings of the
current Graphics2D context. |
boolean |
drawImage(java.awt.Image img,
int x,
int y,
java.awt.image.ImageObserver observer)
Draws as much of the specified image as is currently available.
|
boolean |
drawImage(java.awt.Image img,
int x,
int y,
int width,
int height,
java.awt.image.ImageObserver observer) |
void |
drawInnerRenderedImage(java.lang.String key,
java.awt.image.RenderedImage img,
java.awt.geom.AffineTransform xform) |
void |
drawRenderableImage(java.awt.image.renderable.RenderableImage img,
java.awt.geom.AffineTransform xform) |
void |
drawRenderedImage(java.awt.image.RenderedImage img,
java.awt.geom.AffineTransform xform) |
void |
drawString(java.lang.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. |
void |
fill(java.awt.Shape s)
Fills the interior of a
Shape using the settings of the
Graphics2D context. |
protected java.awt.geom.AffineTransform |
getBaseTransform()
This is mainly used for shading patterns which use the document-global coordinate system
instead of the local one.
|
java.lang.StringBuffer |
getBuffer()
Get the string buffer from the currentStream, containing all
the commands written into this Graphics so far.
|
java.awt.GraphicsConfiguration |
getDeviceConfiguration()
Returns the device configuration associated with this
Graphics2D . |
java.awt.FontMetrics |
getFontMetrics(java.awt.Font f)
Gets the font metrics for the specified font.
|
protected Font |
getInternalFontForAWTFont(java.awt.Font awtFont)
Deprecated.
use FontInfo.getFontInstanceForAWTFont(java.awt.Font awtFont) instead
|
java.lang.String |
getPageReference()
Gets the PDF reference of the current page.
|
java.lang.String |
getString()
Get the string containing all the commands written into this
Graphics.
|
protected void |
handleIOException(java.io.IOException ioe)
Central handler for IOExceptions for this class.
|
protected boolean |
isMultiByteFont(java.lang.String name)
Determines whether the font with the given name is a multi-byte font.
|
protected void |
preparePainting()
This method is used by PDFDocumentGraphics2D to prepare a new page if
necessary.
|
void |
processPathIterator(java.awt.geom.PathIterator iter)
Processes a path iterator generating the necessary painting operations.
|
void |
setGraphicContext(org.apache.xmlgraphics.java2d.GraphicContext c)
Set the Graphics context.
|
void |
setOutputStream(java.io.OutputStream os)
Set the output stream that this PDF document is
being drawn to.
|
void |
setOverrideFontState(Font infont)
Set the override font state for drawing text.
|
void |
setPaintingState(PDFPaintingState state)
Set the PDF state to use when starting to draw
into the PDF graphics.
|
void |
setXORMode(java.awt.Color c1)
Sets the paint mode of this graphics context to alternate between
this graphics context's current color and the new specified color.
|
protected void |
updateCurrentFont(Font font)
Updates the currently selected font.
|
protected void |
writeClip(java.awt.Shape s)
Set the clipping shape for future PDF drawing in the current graphics state.
|
addRenderingHints, clearRect, clip, clipRect, drawArc, drawGlyphVector, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, drawString, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, getBackground, getClip, getClipBounds, getColor, getComposite, getFont, getFontRenderContext, getGraphicContext, getPaint, getRenderingHint, getRenderingHints, getStroke, getTransform, hit, rotate, rotate, scale, setBackground, setClip, setClip, setColor, setComposite, setFont, setPaint, setPaintMode, setRenderingHint, setRenderingHints, setStroke, setTransform, shear, transform, translate, translate
protected PDFDocument pdfDoc
protected PDFResourceContext resourceContext
protected java.lang.String pageRef
protected PDFPaintingState paintingState
protected PDFColorHandler colorHandler
protected int baseLevel
protected int nativeCount
protected FontInfo fontInfo
protected Font ovFontState
protected java.io.StringWriter currentStream
protected java.lang.String currentFontName
protected float currentFontSize
protected java.io.OutputStream outputStream
public PDFGraphics2D(boolean textAsShapes, FontInfo fi, PDFDocument doc, PDFResourceContext page, java.lang.String pref, java.lang.String font, float size)
textAsShapes
- if true then draw text as shapesfi
- the current font informationdoc
- the pdf document for creating pdf objectspage
- the current resource context or pagepref
- the PDF reference of the current pagefont
- the current font namesize
- the current font sizeprotected PDFGraphics2D(boolean textAsShapes)
textAsShapes
- true if drawing text as shapespublic PDFGraphics2D(PDFGraphics2D g)
g
- the PDF graphics to make a copy ofpublic java.awt.Graphics create()
Graphics
object that is
a copy of this Graphics
object.create
in class java.awt.Graphics
protected void handleIOException(java.io.IOException ioe)
ioe
- IOException to handleprotected void preparePainting()
public void setPaintingState(PDFPaintingState state)
state
- the PDF statepublic void setOutputStream(java.io.OutputStream os)
os
- the output stream that is being used for the PDF documentpublic java.lang.String getString()
public java.lang.StringBuffer getBuffer()
public java.lang.String getPageReference()
public void setGraphicContext(org.apache.xmlgraphics.java2d.GraphicContext c)
c
- the graphics context to usepublic void setOverrideFontState(Font infont)
infont
- the font state to useprotected java.awt.geom.AffineTransform getBaseTransform()
public void addLink(java.awt.geom.Rectangle2D bounds, java.awt.geom.AffineTransform trans, java.lang.String dest, int linkType)
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 externalpublic void addNativeImage(org.apache.xmlgraphics.image.loader.Image image, float x, float y, float width, float height)
addNativeImage
in interface NativeImageHandler
image
- the image to drawx
- the x positiony
- the y positionwidth
- the width to draw the imageheight
- the height to draw the imagepublic boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
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.
drawImage
in class java.awt.Graphics
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.Image
,
ImageObserver
,
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
public boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
drawImage
in class java.awt.Graphics
public void dispose()
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.
dispose
in class java.awt.Graphics
Graphics.finalize()
,
Component.paint(java.awt.Graphics)
,
Component.update(java.awt.Graphics)
,
Component.getGraphics()
,
Graphics.create()
public void draw(java.awt.Shape s)
Shape
using the settings of the
current Graphics2D
context. The rendering attributes
applied include the Clip
, Transform
,
Paint
, Composite
and
Stroke
attributes.draw
in class java.awt.Graphics2D
s
- the Shape
to be renderedAbstractGraphics2D.setStroke(java.awt.Stroke)
,
AbstractGraphics2D.setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
AbstractGraphics2D.transform(java.awt.geom.AffineTransform)
,
AbstractGraphics2D.setTransform(java.awt.geom.AffineTransform)
,
AbstractGraphics2D.clip(java.awt.Shape)
,
AbstractGraphics2D.setClip(int, int, int, int)
,
AbstractGraphics2D.setComposite(java.awt.Composite)
protected void writeClip(java.awt.Shape s)
s
- the clipping shapeprotected void applyColor(java.awt.Color col, boolean fill)
col
- the java colourfill
- true if the colour will be used for fillingprotected boolean applyPaint(java.awt.Paint paint, boolean fill)
paint
- the paint to convert to PDFfill
- true if the paint should be set for fillingprotected boolean applyUnknownPaint(java.awt.Paint paint, java.awt.Shape shape)
paint
- some paintshape
- a shapeprotected void applyStroke(java.awt.Stroke stroke)
stroke
- the java strokepublic void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
drawRenderedImage
in class java.awt.Graphics2D
public void drawInnerRenderedImage(java.lang.String key, java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
key
- a keyimg
- an imagexform
- a transformpublic void drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
drawRenderableImage
in class java.awt.Graphics2D
public void drawString(java.lang.String s, float x, float y)
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.drawString
in class java.awt.Graphics2D
s
- the String
to be renderedx
- the coordinate where the String
should be renderedy
- the coordinate where the String
should be renderedAbstractGraphics2D.setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
Graphics.setFont(java.awt.Font)
,
AbstractGraphics2D.setTransform(java.awt.geom.AffineTransform)
,
AbstractGraphics2D.setComposite(java.awt.Composite)
,
AbstractGraphics2D.setClip(int, int, int, int)
protected void applyAlpha(int fillAlpha, int strokeAlpha)
fillAlpha
- A value between 0 and 255 (=OPAQUE) for fillingstrokeAlpha
- A value between 0 and 255 (=OPAQUE) for strokingprotected void updateCurrentFont(Font font)
font
- the new font to use@Deprecated protected Font getInternalFontForAWTFont(java.awt.Font awtFont)
awtFont
- the AWT fontprotected boolean isMultiByteFont(java.lang.String name)
name
- the name of the fontpublic void fill(java.awt.Shape s)
Shape
using the settings of the
Graphics2D
context. The rendering attributes applied
include the Clip
, Transform
,
Paint
, and Composite
.fill
in class java.awt.Graphics2D
s
- the Shape
to be filledAbstractGraphics2D.setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
AbstractGraphics2D.transform(java.awt.geom.AffineTransform)
,
AbstractGraphics2D.setTransform(java.awt.geom.AffineTransform)
,
AbstractGraphics2D.setComposite(java.awt.Composite)
,
AbstractGraphics2D.clip(java.awt.Shape)
,
AbstractGraphics2D.setClip(int, int, int, int)
protected void checkTransparencyAllowed()
public void processPathIterator(java.awt.geom.PathIterator iter)
iter
- PathIterator to processprotected void doDrawing(boolean fill, boolean stroke, boolean nonzero)
fill
- true if filling the pathstroke
- true if stroking the pathnonzero
- true if using the non-zero winding rulepublic java.awt.GraphicsConfiguration getDeviceConfiguration()
Graphics2D
.getDeviceConfiguration
in class java.awt.Graphics2D
public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
getFontMetrics
in class java.awt.Graphics
f
- the specified fontGraphics.getFont()
,
FontMetrics
,
Graphics.getFontMetrics()
public void setXORMode(java.awt.Color c1)
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.
setXORMode
in class java.awt.Graphics
c1
- the XOR alternation colorpublic void copyArea(int x, int y, int width, int height, int dx, int dy)
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.copyArea
in class java.awt.Graphics
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.Copyright 1999-2012 The Apache Software Foundation. All Rights Reserved.