public class PSGraphics2D extends AbstractGraphics2D
Originally authored by Keiron Liddle.
Modifier and Type | Field and Description |
---|---|
protected boolean |
clippingDisabled
Disable or enable clipping
|
protected java.awt.Color |
currentColour
the current colour for use in svg
|
protected TextHandler |
customTextHandler
Custom text handler
|
protected TextHandler |
fallbackTextHandler
Fallback text handler
|
protected PSGenerator |
gen
the PostScript generator being created
|
protected PSGraphics2D |
rootG2D
The G2D instance that represents the root instance
(used in context with create()/dispose()).
|
gc, inPossibleRecursion, textAsShapes
Constructor and Description |
---|
PSGraphics2D(boolean textAsShapes)
Create a new Graphics2D that generates PostScript code.
|
PSGraphics2D(boolean textAsShapes,
PSGenerator gen)
Create a new Graphics2D that generates PostScript code.
|
PSGraphics2D(PSGraphics2D g)
Constructor for creating copies
|
Modifier and Type | Method and Description |
---|---|
protected void |
applyPaint(java.awt.Paint paint,
boolean fill)
Applies a new Paint object.
|
protected void |
applyStroke(java.awt.Stroke stroke)
Applies a new Stroke object.
|
static void |
applyStroke(java.awt.Stroke stroke,
PSGenerator gen)
Applies a new Stroke object.
|
java.awt.image.BufferedImage |
buildBufferedImage(java.awt.Dimension size)
Creates a buffered image.
|
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 |
disableClipping(boolean b)
Disable clipping on each draw command.
|
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)
Commits a painting operation.
|
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)
Draws as much of the specified image as has already been scaled
to fit inside the specified rectangle.
|
void |
drawRenderableImage(java.awt.image.renderable.RenderableImage img,
java.awt.geom.AffineTransform xform)
Renders a
RenderableImage ,
applying a transform from image space into user space before drawing. |
void |
drawRenderedImage(java.awt.image.RenderedImage img,
java.awt.geom.AffineTransform xform)
Renders a
RenderedImage ,
applying a transform from image
space into user space before drawing. |
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 |
establishColor(java.awt.Color c)
Establishes the given color in the PostScript interpreter.
|
void |
fill(java.awt.Shape s)
Fills the interior of a
Shape using the settings of the
Graphics2D context. |
TextHandler |
getCustomTextHandler() |
java.awt.GraphicsConfiguration |
getDeviceConfiguration()
Returns the device configuration associated with this
Graphics2D . |
TextHandler |
getFallbackTextHandler() |
java.awt.FontMetrics |
getFontMetrics(java.awt.Font f)
Gets the font metrics for the specified font.
|
PSGenerator |
getPSGenerator() |
void |
handleIOException(java.io.IOException ioe)
Central handler for IOExceptions for this class.
|
void |
preparePainting()
This method is used by AbstractPSDocumentGraphics2D to prepare a new page if
necessary.
|
void |
processPathIterator(java.awt.geom.PathIterator iter)
Processes a path iterator generating the necessary painting operations.
|
int |
processShape(java.awt.Shape s)
Processes a Shape generating the necessary painting operations.
|
void |
setCustomTextHandler(TextHandler handler)
Sets a custom TextHandler implementation that is responsible for painting text.
|
void |
setGraphicContext(GraphicContext c)
Sets the GraphicContext
|
void |
setPSGenerator(PSGenerator gen)
Sets the PostScript generator
|
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.
|
boolean |
shouldBeClipped(java.awt.Shape clip,
java.awt.Shape s)
Determines if a shape interacts with a clipping region.
|
void |
writeClip(java.awt.Shape s)
Establishes a clipping region
|
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 PSGraphics2D rootG2D
protected PSGenerator gen
protected boolean clippingDisabled
protected TextHandler fallbackTextHandler
protected TextHandler customTextHandler
protected java.awt.Color currentColour
public PSGraphics2D(boolean textAsShapes)
textAsShapes
- True if text should be rendered as graphicsAbstractGraphics2D.AbstractGraphics2D(boolean)
public PSGraphics2D(boolean textAsShapes, PSGenerator gen)
textAsShapes
- True if text should be rendered as graphicsgen
- PostScript generator to use for outputAbstractGraphics2D.AbstractGraphics2D(boolean)
public PSGraphics2D(PSGraphics2D g)
g
- parent PostScript Graphics2Dpublic void setPSGenerator(PSGenerator gen)
gen
- the PostScript generatorpublic PSGenerator getPSGenerator()
public void setGraphicContext(GraphicContext c)
c
- GraphicContext to usepublic TextHandler getFallbackTextHandler()
public TextHandler getCustomTextHandler()
public void setCustomTextHandler(TextHandler handler)
handler
- the custom TextHandler implementationpublic void disableClipping(boolean b)
b
- set to true to disable all clipping.public java.awt.Graphics create()
Graphics
object that is
a copy of this Graphics
object.create
in class java.awt.Graphics
public void handleIOException(java.io.IOException ioe)
ioe
- IOException to handlepublic void preparePainting()
public 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 java.awt.image.BufferedImage buildBufferedImage(java.awt.Dimension size)
size
- dimensions of the image to be createdpublic boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
The image is drawn inside the specified rectangle of this graphics context's coordinate space, and is scaled if necessary. Transparent pixels do not affect whatever pixels are already there.
This method returns immediately in all cases, even if the
entire image has not yet been scaled, dithered, and converted
for the current output device.
If the current output representation is not yet complete, then
drawImage
returns false
. As more of
the image becomes available, the process that draws the image notifies
the image observer by calling its imageUpdate
method.
A scaled version of an image will not necessarily be available immediately just because an unscaled version of the image has been constructed for this output device. Each size of the image may be cached separately and generated from the original data in a separate image production sequence.
drawImage
in class java.awt.Graphics
img
- the specified image to be drawn.x
- the x coordinate.y
- the y coordinate.width
- the width of the rectangle.height
- the height of the rectangle.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 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 int processShape(java.awt.Shape s) throws java.io.IOException
s
- Shape to processjava.io.IOException
- In case of an I/O problem.public void processPathIterator(java.awt.geom.PathIterator iter) throws java.io.IOException
iter
- PathIterator to processjava.io.IOException
- In case of an I/O problem.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)
public boolean shouldBeClipped(java.awt.Shape clip, java.awt.Shape s)
clip
- Shape defining the clipping regions
- Shape to be drawnpublic void writeClip(java.awt.Shape s)
s
- Shape defining the clipping regionprotected void applyPaint(java.awt.Paint paint, boolean fill)
paint
- Paint object to usefill
- True if to be applied for fillingprotected void applyStroke(java.awt.Stroke stroke)
stroke
- Stroke object to usepublic static void applyStroke(java.awt.Stroke stroke, PSGenerator gen) throws java.io.IOException
stroke
- the Stroke instancegen
- the PS generatorjava.io.IOException
- if an I/O error occurspublic void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
RenderedImage
,
applying a transform from image
space into user space before drawing.
The transformation from user space into device space is done with
the current Transform
in the Graphics2D
.
The specified transformation is applied to the image before the
transform attribute in the Graphics2D
context is applied.
The rendering attributes applied include the Clip
,
Transform
, and Composite
attributes. Note
that no rendering is done if the specified transform is
noninvertible.drawRenderedImage
in class java.awt.Graphics2D
img
- the image to be renderedxform
- the transformation from image space into user spaceAbstractGraphics2D.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)
public void drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
RenderableImage
,
applying a transform from image space into user space before drawing.
The transformation from user space into device space is done with
the current Transform
in the Graphics2D
.
The specified transformation is applied to the image before the
transform attribute in the Graphics2D
context is applied.
The rendering attributes applied include the Clip
,
Transform
, and Composite
attributes. Note
that no rendering is done if the specified transform is
noninvertible.
Rendering hints set on the Graphics2D
object might
be used in rendering the RenderableImage
.
If explicit control is required over specific hints recognized by a
specific RenderableImage
, or if knowledge of which hints
are used is required, then a RenderedImage
should be
obtained directly from the RenderableImage
and rendered using
drawRenderedImage
.
drawRenderableImage
in class java.awt.Graphics2D
img
- the image to be renderedxform
- the transformation from image space into user spaceAbstractGraphics2D.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)
,
drawRenderedImage(java.awt.image.RenderedImage, java.awt.geom.AffineTransform)
public void establishColor(java.awt.Color c) throws java.io.IOException
c
- the color to setjava.io.IOException
- In case of an I/O problempublic 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 x-coordinate where the String
should be renderedy
- the y-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)
public 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 doDrawing(boolean fill, boolean stroke, boolean nonzero) throws java.io.IOException
fill
- fillingstroke
- strokingnonzero
- true if the non-zero winding rule should be used when fillingjava.io.IOException
- In case of an I/O problempublic 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.