Class PSGraphics2D
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
AbstractPSDocumentGraphics2D
- Version:
- $Id$
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Disable or enable clippingprotected Color
the current colour for use in svgprotected TextHandler
Custom text handlerprotected TextHandler
Fallback text handlerprotected PSGenerator
the PostScript generator being createdprotected PSGraphics2D
The G2D instance that represents the root instance (used in context with create()/dispose()).protected boolean
Fields inherited from class org.apache.xmlgraphics.java2d.AbstractGraphics2D
gc, inPossibleRecursion, textAsShapes
-
Constructor Summary
ConstructorsConstructorDescriptionPSGraphics2D
(boolean textAsShapes) Create a new Graphics2D that generates PostScript code.PSGraphics2D
(boolean textAsShapes, PSGenerator gen) Create a new Graphics2D that generates PostScript code.Constructor for creating copies -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyPaint
(Paint paint, boolean fill) Applies a new Paint object.protected void
applyStroke
(Stroke stroke) Applies a new Stroke object.static void
applyStroke
(Stroke stroke, PSGenerator gen) Applies a new Stroke object.buildBufferedImage
(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 bydx
anddy
.create()
Creates a newGraphics
object that is a copy of thisGraphics
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
Strokes the outline of aShape
using the settings of the currentGraphics2D
context.boolean
drawImage
(Image img, int x, int y, int width, int height, ImageObserver observer) Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.boolean
drawImage
(Image img, int x, int y, ImageObserver observer) Draws as much of the specified image as is currently available.boolean
drawImage
(Image img, int x, int y, ImageObserver observer, Color mask) boolean
drawImage
(Image img, int x, int y, ImageObserver observer, Color mask, RenderedImage imageMask) void
drawRenderableImage
(RenderableImage img, AffineTransform xform) Renders aRenderableImage
, applying a transform from image space into user space before drawing.void
drawRenderedImage
(RenderedImage img, AffineTransform xform) Renders aRenderedImage
, applying a transform from image space into user space before drawing.void
drawString
(String s, float x, float y) Renders the text specified by the specifiedString
, using the currentFont
andPaint
attributes in theGraphics2D
context.void
Establishes the given color in the PostScript interpreter.void
Fills the interior of aShape
using the settings of theGraphics2D
context.Returns the device configuration associated with thisGraphics2D
.Gets the font metrics for the specified font.void
Central handler for IOExceptions for this class.void
This method is used by AbstractPSDocumentGraphics2D to prepare a new page if necessary.void
Processes a path iterator generating the nexessary painting operations.protected void
protected String
int
processShape
(Shape s, boolean cached) Processes a Shape generating the necessary painting operations.void
setCustomTextHandler
(TextHandler handler) Sets a custom TextHandler implementation that is responsible for painting text.void
Sets the GraphicContextvoid
Sets the PostScript generatorvoid
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.boolean
shouldBeClipped
(Shape clip, Shape s) Determines if a shape interacts with a clipping region.void
Establishes a clipping regionMethods inherited from class org.apache.xmlgraphics.java2d.AbstractGraphics2D
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
Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
Methods inherited from class java.awt.Graphics
create, drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
-
Field Details
-
pathHashCache
-
startCache
protected boolean startCache -
rootG2D
The G2D instance that represents the root instance (used in context with create()/dispose()). Null if this instance is the root instance. -
gen
the PostScript generator being created -
clippingDisabled
protected boolean clippingDisabledDisable or enable clipping -
fallbackTextHandler
Fallback text handler -
customTextHandler
Custom text handler -
currentColour
the current colour for use in svg
-
-
Constructor Details
-
PSGraphics2D
public PSGraphics2D(boolean textAsShapes) Create a new Graphics2D that generates PostScript code.- Parameters:
textAsShapes
- True if text should be rendered as graphics- See Also:
-
PSGraphics2D
Create a new Graphics2D that generates PostScript code.- Parameters:
textAsShapes
- True if text should be rendered as graphicsgen
- PostScript generator to use for output- See Also:
-
PSGraphics2D
Constructor for creating copies- Parameters:
g
- parent PostScript Graphics2D
-
-
Method Details
-
setPSGenerator
Sets the PostScript generator- Parameters:
gen
- the PostScript generator
-
getPSGenerator
- Returns:
- the PostScript generator used by this instance.
-
setGraphicContext
Sets the GraphicContext- Parameters:
c
- GraphicContext to use
-
getFallbackTextHandler
- Returns:
- the fallback TextHandler implementation
-
getCustomTextHandler
- Returns:
- the custom TextHandler implementation
-
setCustomTextHandler
Sets a custom TextHandler implementation that is responsible for painting text. The default TextHandler paints all text as shapes. A custom implementation can implement text painting using text painting operators.- Parameters:
handler
- the custom TextHandler implementation
-
disableClipping
public void disableClipping(boolean b) Disable clipping on each draw command.- Parameters:
b
- set to true to disable all clipping.
-
create
Creates a newGraphics
object that is a copy of thisGraphics
object. -
handleIOException
Central handler for IOExceptions for this class.- Parameters:
ioe
- IOException to handle
-
preparePainting
public void preparePainting()This method is used by AbstractPSDocumentGraphics2D to prepare a new page if necessary. -
drawImage
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
returnsfalse
. As more of the image becomes available, the process that draws the image notifies the specified image observer. -
drawImage
-
drawImage
public boolean drawImage(Image img, int x, int y, ImageObserver observer, Color mask, RenderedImage imageMask) -
buildBufferedImage
Creates a buffered image.- Parameters:
size
- dimensions of the image to be created- Returns:
- the buffered image
-
drawImage
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.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
returnsfalse
. As more of the image becomes available, the process that draws the image notifies the image observer by calling itsimageUpdate
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.
- Specified by:
drawImage
in classGraphics
- Parameters:
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.- Returns:
- True if the image has been fully loaded/drawn
- See Also:
-
dispose
public void dispose()Disposes of this graphics context and releases any system resources that it is using. AGraphics
object cannot be used afterdispose
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
andupdate
methods of components are automatically released by the system when those methods return. For efficiency, programmers should calldispose
when finished using aGraphics
object only if it was created directly from a component or anotherGraphics
object. -
processShape
Processes a Shape generating the necessary painting operations.- Parameters:
s
- Shape to process- Returns:
- the winding rule of the path defining the shape
- Throws:
IOException
- In case of an I/O problem.
-
processPathIteratorToString
- Throws:
IOException
-
processPathIteratorCached
- Throws:
IOException
-
processPathIterator
Processes a path iterator generating the nexessary painting operations.- Parameters:
iter
- PathIterator to process- Throws:
IOException
- In case of an I/O problem.
-
draw
Strokes the outline of aShape
using the settings of the currentGraphics2D
context. The rendering attributes applied include theClip
,Transform
,Paint
,Composite
andStroke
attributes.- Specified by:
draw
in classGraphics2D
- Parameters:
s
- theShape
to be rendered- See Also:
-
shouldBeClipped
Determines if a shape interacts with a clipping region.- Parameters:
clip
- Shape defining the clipping regions
- Shape to be drawn- Returns:
- true if code for a clipping region needs to be generated.
-
writeClip
Establishes a clipping region- Parameters:
s
- Shape defining the clipping region
-
applyPaint
Applies a new Paint object.- Parameters:
paint
- Paint object to usefill
- True if to be applied for filling
-
applyStroke
Applies a new Stroke object.- Parameters:
stroke
- Stroke object to use
-
applyStroke
Applies a new Stroke object.- Parameters:
stroke
- the Stroke instancegen
- the PS generator- Throws:
IOException
- if an I/O error occurs
-
drawRenderedImage
Renders aRenderedImage
, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the currentTransform
in theGraphics2D
. The specified transformation is applied to the image before the transform attribute in theGraphics2D
context is applied. The rendering attributes applied include theClip
,Transform
, andComposite
attributes. Note that no rendering is done if the specified transform is noninvertible.- Specified by:
drawRenderedImage
in classGraphics2D
- Parameters:
img
- the image to be renderedxform
- the transformation from image space into user space- See Also:
-
drawRenderableImage
Renders aRenderableImage
, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the currentTransform
in theGraphics2D
. The specified transformation is applied to the image before the transform attribute in theGraphics2D
context is applied. The rendering attributes applied include theClip
,Transform
, andComposite
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 theRenderableImage
. If explicit control is required over specific hints recognized by a specificRenderableImage
, or if knowledge of which hints are used is required, then aRenderedImage
should be obtained directly from theRenderableImage
and rendered usingdrawRenderedImage
.- Specified by:
drawRenderableImage
in classGraphics2D
- Parameters:
img
- the image to be renderedxform
- the transformation from image space into user space- See Also:
-
establishColor
Establishes the given color in the PostScript interpreter.- Parameters:
c
- the color to set- Throws:
IOException
- In case of an I/O problem
-
drawString
Renders the text specified by the specifiedString
, using the currentFont
andPaint
attributes in theGraphics2D
context. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include theClip
,Transform
,Paint
,Font
andComposite
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.- Specified by:
drawString
in classGraphics2D
- Parameters:
s
- theString
to be renderedx
- the x-coordinate where theString
should be renderedy
- the y-coordinate where theString
should be rendered- See Also:
-
fill
Fills the interior of aShape
using the settings of theGraphics2D
context. The rendering attributes applied include theClip
,Transform
,Paint
, andComposite
.- Specified by:
fill
in classGraphics2D
- Parameters:
s
- theShape
to be filled- See Also:
-
doDrawing
Commits a painting operation.- Parameters:
fill
- fillingstroke
- strokingnonzero
- true if the non-zero winding rule should be used when filling- Throws:
IOException
- In case of an I/O problem
-
getDeviceConfiguration
Returns the device configuration associated with thisGraphics2D
.- Specified by:
getDeviceConfiguration
in classGraphics2D
- Returns:
- the device configuration
-
getFontMetrics
Gets the font metrics for the specified font.- Specified by:
getFontMetrics
in classGraphics
- Parameters:
f
- the specified font- Returns:
- the font metrics for the specified font.
- See Also:
-
setXORMode
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.
- Specified by:
setXORMode
in classGraphics
- Parameters:
c1
- the XOR alternation color
-
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 bydx
anddy
. From the point specified byx
andy
, this method copies downwards and to the right. To copy an area of the component to the left or upwards, specify a negative value fordx
ordy
. 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'spaint
method.- Specified by:
copyArea
in classGraphics
- Parameters:
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.
-