|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Graphics | +--java.awt.Graphics2D | +--org.apache.batik.ext.awt.g2d.AbstractGraphics2D | +--org.apache.batik.svggen.SVGGraphics2D
This implementation of the java.awt.Graphics2D abstract class allows users to generate SVG (Scalable Vector Graphics) content from Java code. SVGGraphics2D generates a DOM tree whose root is obtained through the getRoot method. Refer to the DOMTreeManager and DOMGroupManager documentation for details on the structure of the generated DOM tree. The SVGGraphics2D class can produce a DOM tree using any implementation that conforms to the W3C DOM 1.0 specification (see http://www.w3.org). At construction time, the SVGGraphics2D must be given a org.w3.dom.Document instance that is used as a factory to create the various nodes in the DOM tree it generates. The various graphic context attributes (e.g., AffineTransform, Paint) are managed by a GraphicContext object.
GraphicContext
,
DOMTreeManager
,
DOMGroupManager
,
ImageHandler
,
ExtensionHandler
,
Document
Field Summary | |
static int |
DEFAULT_MAX_GC_OVERRIDES
Controls the policy for grouping nodes. |
static java.lang.String |
DEFAULT_XML_ENCODING
|
Fields inherited from class org.apache.batik.ext.awt.g2d.AbstractGraphics2D |
gc, textAsShapes |
Constructor Summary | |
SVGGraphics2D(Document domFactory)
|
|
SVGGraphics2D(Document domFactory,
ImageHandler imageHandler,
ExtensionHandler extensionHandler,
boolean textAsShapes)
|
|
SVGGraphics2D(SVGGeneratorContext generatorCtx,
boolean textAsShapes)
|
|
SVGGraphics2D(SVGGraphics2D g)
This private constructor is used in create |
Method Summary | |
static SVGGeneratorContext |
buildSVGGeneratorContext(Document domFactory,
ImageHandler imageHandler,
ExtensionHandler extensionHandler)
Helper method to create an SVGGeneratorContext from the constructor parameters. |
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. |
void |
draw(java.awt.Shape s)
Strokes the outline of a Shape using the settings of the
current Graphics2D context. |
void |
drawImage(java.awt.image.BufferedImage img,
java.awt.image.BufferedImageOp op,
int x,
int y)
Renders a BufferedImage that is
filtered with a
BufferedImageOp .
|
boolean |
drawImage(java.awt.Image img,
java.awt.geom.AffineTransform xform,
java.awt.image.ImageObserver obs)
Renders an image, applying a transform from image space into user space before drawing. |
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 trans2)
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 trans2)
Renders a RenderedImage ,
applying a transform from image
space into user space before drawing.
|
void |
drawString(java.text.AttributedCharacterIterator iterator,
float x,
float y)
Renders the text of the specified iterator, using the Graphics2D context's current Paint . |
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. |
java.util.List |
getDefinitionSet()
Invoking this method will return a set of definition element that contain all the definitions referenced by the attributes generated by the various converters. |
java.awt.GraphicsConfiguration |
getDeviceConfiguration()
Returns the device configuration associated with this Graphics2D . |
Document |
getDOMFactory()
|
DOMTreeManager |
getDOMTreeManager()
|
ExtensionHandler |
getExtensionHandler()
|
java.awt.FontMetrics |
getFontMetrics(java.awt.Font f)
Gets the font metrics for the specified font. |
SVGGeneratorContext |
getGeneratorContext()
|
GenericImageHandler |
getGenericImageHandler()
|
ImageHandler |
getImageHandler()
|
Element |
getRoot()
|
java.awt.Dimension |
getSVGCanvasSize()
|
Element |
getTopLevelGroup()
Invoking this method will return a reference to the topLevelGroup Element managed by this object. |
Element |
getTopLevelGroup(boolean includeDefinitionSet)
Invoking this method will return a reference to the topLevelGroup Element managed by this object. |
void |
setExtensionHandler(ExtensionHandler extensionHandler)
|
void |
setSVGCanvasSize(java.awt.Dimension svgCanvasSize)
|
void |
setTopLevelGroup(Element topLevelGroup)
Sets the topLevelGroup to the input element. |
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. |
void |
stream(Element svgRoot,
java.io.Writer writer)
|
void |
stream(Element svgRoot,
java.io.Writer writer,
boolean useCss)
|
void |
stream(java.lang.String svgFileName)
|
void |
stream(java.lang.String svgFileName,
boolean useCss)
|
void |
stream(java.io.Writer writer)
|
void |
stream(java.io.Writer writer,
boolean useCss)
|
Methods inherited from class org.apache.batik.ext.awt.g2d.AbstractGraphics2D |
addRenderingHints, clearRect, clip, clipRect, drawArc, drawGlyphVector, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, getBackground, getClip, getClipBounds, getColor, getComposite, getFont, getFontRenderContext, 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 |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String DEFAULT_XML_ENCODING
public static final int DEFAULT_MAX_GC_OVERRIDES
DOMTreeManager
Constructor Detail |
public SVGGraphics2D(Document domFactory)
domFactory
- Factory which will produce Elements for the DOM tree
this Graphics2D generates.SVGGraphics2DRuntimeException
- if domFactory is null.public SVGGraphics2D(Document domFactory, ImageHandler imageHandler, ExtensionHandler extensionHandler, boolean textAsShapes)
domFactory
- Factory which will produce Elements for the DOM tree
this Graphics2D generates.imageHandler
- defines how images are referenced in the
generated SVG fragmentextensionHandler
- defines how Java 2D API extensions map
to SVG Nodes.textAsShapes
- if true, all text is turned into SVG shapes in the
convertion. No SVG text is output.SVGGraphics2DRuntimeException
- if domFactory is null.public SVGGraphics2D(SVGGeneratorContext generatorCtx, boolean textAsShapes)
generatorContext
- the SVGGeneratorContext
instance
that will provide all useful information to the generator.textAsShapes
- if true, all text is turned into SVG shapes in the
convertion. No SVG text is output.SVGGraphics2DRuntimeException
- if generatorContext is null.public SVGGraphics2D(SVGGraphics2D g)
create()
Method Detail |
public final java.awt.Dimension getSVGCanvasSize()
public final void setSVGCanvasSize(java.awt.Dimension svgCanvasSize)
SVG
- Canvas size. May be null (equivalent to 100%, 100%)public final SVGGeneratorContext getGeneratorContext()
public final DOMTreeManager getDOMTreeManager()
public final Document getDOMFactory()
public final ImageHandler getImageHandler()
public final GenericImageHandler getGenericImageHandler()
public final ExtensionHandler getExtensionHandler()
public final void setExtensionHandler(ExtensionHandler extensionHandler)
new
- extension handler this SVGGraphics2D should usepublic static SVGGeneratorContext buildSVGGeneratorContext(Document domFactory, ImageHandler imageHandler, ExtensionHandler extensionHandler)
public void stream(java.lang.String svgFileName) throws SVGGraphics2DIOException
svgFileName
- name of the file where SVG content
should be writtenpublic void stream(java.lang.String svgFileName, boolean useCss) throws SVGGraphics2DIOException
svgFileName
- name of the file where SVG content
should be writtenuseCss
- defines whether the output SVG should use CSS style
properties as opposed to plain attributes.public void stream(java.io.Writer writer) throws SVGGraphics2DIOException
writer
- used to writer out the SVG contentpublic void stream(java.io.Writer writer, boolean useCss) throws SVGGraphics2DIOException
writer
- used to writer out the SVG contentuseCss
- defines whether the output SVG should use CSS
style properties as opposed to plain attributes.public void stream(Element svgRoot, java.io.Writer writer) throws SVGGraphics2DIOException
svgRoot
- root element to stream outpublic void stream(Element svgRoot, java.io.Writer writer, boolean useCss) throws SVGGraphics2DIOException
svgRoot
- root element to stream outwriter
- outputuseCss
- defines whether the output SVG should use CSS style
properties as opposed to plain attributes.public java.util.List getDefinitionSet()
public Element getTopLevelGroup()
public Element getTopLevelGroup(boolean includeDefinitionSet)
includeDefinitionSet
- if true, the definition set is included and
the converters are reset (i.e., they start with an empty set
of definitions).public void setTopLevelGroup(Element topLevelGroup)
public Element getRoot()
public java.awt.Graphics create()
Graphics
object that is
a copy of this Graphics
object.create
in class java.awt.Graphics
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 java.awt.FontMetrics getFontMetrics(java.awt.Font f)
getFontMetrics
in class java.awt.Graphics
f
- the specified fontGraphics.getFont()
,
FontMetrics
,
Graphics.getFontMetrics()
public 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.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 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 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 drawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)
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.drawImage
in class AbstractGraphics2D
img
- the Image
to be renderedxform
- the transformation from image space into user spaceobs
- the ImageObserver
to be notified as more of the Image
is convertedtrue
if the Image
is
fully loaded and completely rendered;
false
if the Image
is still being loaded.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)
public void drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)
BufferedImage
that is
filtered with a
BufferedImageOp
.
The rendering attributes applied include the Clip
,
Transform
and Composite
attributes. This is equivalent to:
img1 = op.filter(img, null); drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
drawImage
in class AbstractGraphics2D
op
- the filter to be applied to the image before renderingimg
- the BufferedImage
to be renderedx, y
- the location in user space where the upper left
corner of the
image is renderedAbstractGraphics2D.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 drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform trans2)
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 trans2)
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(RenderedImage, AffineTransform)
.
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 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, y
- the coordinates 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 drawString(java.text.AttributedCharacterIterator iterator, float x, float y)
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.drawString
in class java.awt.Graphics2D
iterator
- the iterator whose text is to be renderedx, y
- the coordinates where the iterator's text is to be
renderedAbstractGraphics2D.setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
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)
public java.awt.GraphicsConfiguration getDeviceConfiguration()
Graphics2D
.getDeviceConfiguration
in class java.awt.Graphics2D
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |