cwi.SVGGraphics
Class SVGGraphics

java.lang.Object
  extended by java.awt.Graphics
      extended by java.awt.Graphics2D
          extended by cwi.SVGGraphics.SVGGraphics

public class SVGGraphics
extends java.awt.Graphics2D

SVG generator for Java.

Using this class makes it easy(er) to generate SVG files from Java. The intention is to use SVG as a kind of "screen dump", using possibly the same user methods as for the generation of the screen content. This is the reason why the object is defined as an extension of Graphics2D: various methods which can use any Graphics2D instances can be used in conjunction with this class. The approach is similar to the printing facilities in Java. Here is a typical usage of the class:

      SVGGraphics svg = SVGGraphics.create(yourCanvas);
      if( svg == null ) return;
      yourCanvas.yourDrawMethod(svg);
      svg.close();
 
Note the usage of the close method, which is necessary to properly close the SVG file.

Most of the graphics calls in Graphics2D translate into SVG easily. There are some differences, difficulties, or not-yet-implemented features, though, check the comments on the individual methods themselves. The generated SVG file includes a number of groups: one for each different transformation and/or stroke settings. Gradient colours of Java are separated into a distinct set of definitions.

Coordinates in the generated SVG file are simply passed on from Java, and the transformation matrices in the groups take care of the proper positioning. The only exception are the coordinates in the linear gradients in the definitions, where the coordinates are transformed before being stored in the file.

As mentioned before most of the Java calls can be translated into SVG easily. The only major exception is the handling of images. In Java, images are pixels (by the time the methods in Graphics are called) whereas SVG refers to URL-s. I did not see any obvious ways to store pixel information in SVG and, even if it was possible, it would be a waste of bandwidth. The solution chosen in SVGGraphics is to accept only those Image objects, whose property with a key "url" has been set. This url is then used as a reference in the SVG file. The only problem with using "url" key for an image that it is not immediately obvious how one would set a property on an image. For reasons which I do not completely understand, although there is a public getProperty method for an Image object, there is no public setProperty method. The only way I found was to use a special image consumer filter to generate a new Image instance with the property set. To make life easier for the users of SVGGraphics, a separate class, called SVGImageFilter, is available. See the description of that class for further details on how to use it. Note that the same restriction applies for the texture paint: the buffered image which is used in a texture paint has to include the "url" property. If it is there, a separate pattern specification (in SVG terms) is generated into the output.

The user might also want to look at the class STest which I used for testing SVGGraphics.

Version:
1.1
Author:
Ivan Herman
See Also:
SVGImageFilter

Constructor Summary
protected SVGGraphics()
          Create a new object.
protected SVGGraphics(java.io.PrintStream o, java.awt.Component origin)
          Create a new object.
 
Method Summary
 void addRenderingHints(java.util.Map hints)
          Sets the values of an arbitrary number of preferences for the rendering algorithms.
 void clearRect(int x, int y, int width, int height)
          Clears the specified rectangle by filling it with the background color of the current drawing surface.
 void clip(java.awt.Shape s)
          Intersects the current Clip with the interior of the specified Shape and sets the Clip to the resulting intersection.
 void clipRect(int x, int y, int width, int height)
          Intersects the current clip with the specified rectangle.
 void close()
          Close the object.
 void close(boolean closeFile)
          Close the object.
 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.
static SVGGraphics create(java.awt.Component origin)
          Create a new SVGGraphics object through a file picker widget.
static SVGGraphics create(java.io.PrintStream o, java.awt.Component origin)
          Create a new SVGGraphics object.
 void dispose()
          This method is inherited from the superclass.
 void draw(java.awt.Shape s)
          Strokes the outline of a Shape using the settings of the current Graphics2D context.
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draws the outline of a circular or elliptical arc covering the specified rectangle.
 void drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)
          Renders the text of the specified GlyphVector using the Graphics2D context's rendering attributes.
 void drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)
          Renders a BufferedImage.
 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.Color bgcolor, java.awt.image.ImageObserver obs)
          Draws as much of the specified image as is currently available.
 boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver obs)
          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.Color bgcolor, java.awt.image.ImageObserver obs)
          Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
 boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver obs)
          Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
 boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
          Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
 boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
          Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line.
 void drawOval(int x, int y, int width, int height)
          Draws the outline of an oval.
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draws a closed polygon defined by arrays of x and y coordinates.
 void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
          Draws a sequence of connected lines defined by arrays of x and y coordinates.
 void drawRect(int x, int y, int width, int height)
          Draws the specified rectangle.
 void drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
          Draws a renderable image
 void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
          Draws a rendered image
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws an outlined round-cornered rectangle using this graphics context's current color.
 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.text.AttributedCharacterIterator iterator, int x, int 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 drawString(java.lang.String s, int x, int y)
          Renders the text of 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.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Fills a circular or elliptical arc covering the specified rectangle.
 void fillOval(int x, int y, int width, int height)
          Fills an oval bounded by the specified rectangle with the current color.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Fills a closed polygon defined by arrays of x and y coordinates.
 void fillRect(int x, int y, int width, int height)
          Fills the specified rectangle.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Fills the specified rounded corner rectangle with the current color.
 java.awt.Color getBackground()
          Returns the background colour used for clearing a region.
 java.awt.Shape getClip()
          Gets the current clipping area.
 java.awt.Rectangle getClipBounds()
          Returns the bounding rectangle of the current clipping area.
 java.awt.Color getColor()
          Gets this graphics context's current color.
 java.awt.Composite getComposite()
          Returns the current Composite in the Graphics2D context.
 java.awt.GraphicsConfiguration getDeviceConfiguration()
          Returns the device configuration associated with this Graphics2D.
 java.awt.Font getFont()
          Gets the current font.
 java.awt.FontMetrics getFontMetrics(java.awt.Font f)
          Gets the font metrics for the specified font.
 java.awt.font.FontRenderContext getFontRenderContext()
          Get the rendering context of the Font within this Graphics2D context.
 java.awt.Paint getPaint()
          Returns the current Paint of the Graphics2D context.
 java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
          Returns the value of a single preference for the rendering algorithms.
 java.awt.RenderingHints getRenderingHints()
          Gets the preferences for the rendering algorithms.
 java.awt.Stroke getStroke()
          Returns the current Stroke.
 java.awt.geom.AffineTransform getTransform()
          Returns a copy of the current Transform in the Graphics2D context.
 boolean hit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)
          Checks whether or not the specified Shape intersects the specified Rectangle, which is in device space.
 void println(java.lang.String arg)
          Print a line to the output.
 void println(java.lang.String[] arg)
          Print a sequence of lines to the output.
 void printlnDef(java.lang.String arg)
          Print a line to the defintion section.
 void rotate(double theta)
          Concatenates the current Graphics2D Transform with a rotation transform.
 void rotate(double theta, double x, double y)
          Concatenates the current Graphics2D Transform with a translated rotation transform.
 void scale(double sx, double sy)
          Concatenates the current Graphics2D Transform with a scaling transformation.
 void setBackground(java.awt.Color colour)
          Sets the background colour for the Graphics2D context.
 void setClip(int x, int y, int width, int height)
          Sets the current clip to the rectangle specified by the given coordinates.
 void setClip(java.awt.Shape clip)
          Sets the current clipping area to an arbitrary clip shape.
 void setColor(java.awt.Color c)
          Store the current colour.
 void setComposite(java.awt.Composite comp)
          Sets the current composite instance.
 void setFont(java.awt.Font font)
          Sets the current font.
 void setPaint(java.awt.Paint paint)
          Sets the Paint attribute for the Graphics2D context.
 void setPaintMode()
          Only plain paint mode is implemented for SVG.
 void setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)
          Sets the value of a single preference for the rendering algorithms.
 void setRenderingHints(java.util.Map hints)
          Replaces the values of all preferences for the rendering algorithms with the specified hints.
 void setStroke(java.awt.Stroke s)
          Sets the Stroke for the Graphics2D context.
 void setTransform(java.awt.geom.AffineTransform Tx)
          Sets the Transform in the Graphics2D context.
 void setXORMode(java.awt.Color c1)
          Setting XOR mode.
 void shear(double shx, double shy)
          Concatenates the current Graphics2D Transform with a shearing transform.
 void transform(java.awt.geom.AffineTransform Tx)
          Composes an AffineTransform object with the Transform in this Graphics2D according to the rule last-specified-first-applied.
 void translate(double tx, double ty)
          Concatenates the current Graphics2D Transform with a translation transform.
 void translate(int x, int y)
          Concatenates the current Graphics2D Transform.
 
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
 

Constructor Detail

SVGGraphics

protected SVGGraphics()
Create a new object. In fact, this version is not used, it does not initialize anything; it is there for compatibility only with the superclasses.


SVGGraphics

protected SVGGraphics(java.io.PrintStream o,
                      java.awt.Component origin)
Create a new object. This is the constructor which is really used by this class: it receives the output stream, and the size of the picture, which should be put into the header. The SVG statements are printed through the print stream. Because the constructor is protected, it cannot be called directly from outside. Users should call the create calls instead.

Parameters:
o - output stream for the svg content
origin - the "parent" component. Its bounds will be used to determine the svg width and height parameters. If null, the values 400 and 400 will be used.
See Also:
create(java.io.PrintStream, java.awt.Component)
Method Detail

println

public void println(java.lang.String[] arg)
Print a sequence of lines to the output. Users can use this method to put svg statements directly into the output stream. Note, however, that no semantic check is done on the string, so user have to know what they are doing!

Parameters:
arg - texts to be put appende to the output stream

println

public void println(java.lang.String arg)
Print a line to the output. Users can use this method to put SVG statements directly into the output stream. Note, however, that no semantic check is done on the string, so user have to know what they are doing!

Parameters:
arg - text to be put appende to the output stream

printlnDef

public void printlnDef(java.lang.String arg)
Print a line to the defintion section.

Parameters:
arg - text to be put append to the output stream

create

public static SVGGraphics create(java.io.PrintStream o,
                                 java.awt.Component origin)
Create a new SVGGraphics object.

Parameters:
o - output stream for the svg content
origin - the "parent" component. Its bounds will be used to determine the svg width and height parameters. If null, the values 400 and 400 will be used.
Returns:
the new SVGGraphics object.

create

public static SVGGraphics create(java.awt.Component origin)
Create a new SVGGraphics object through a file picker widget. The user can select a file through the widget, which will be used for output.

Parameters:
origin - the "parent" component. Its bounds will be used to determine the svg width and height parameters. If null, the values 400 and 400 will be used.
Returns:
the new SVGGraphics object. If the file choice was unsuccessful (e.g., the user cancelled the choice), the returned value is null.

close

public void close(boolean closeFile)
Close the object. This will flush the buffers for the SVG file properly. It is imperative for the user to issue this call before closing the object, otherwise the SVG file will not be generated!

Parameters:
closeFile - if true, a 'close' command will also be issued on the PrintStream, too.

close

public void close()
Close the object. This will close the SVG file properly and flush the buffers. It is imperative for the user to issue this call before closing the object, otherwise the SVG file will not be generated! The PrintStream object will also be closed.


dispose

public void dispose()
This method is inherited from the superclass. On its own the method issues simple close. In this sense, using this method is an alternative to the close method.

Specified by:
dispose in class java.awt.Graphics
See Also:
close(boolean)

create

public java.awt.Graphics create()
Creates a new Graphics object that is a copy of this Graphics object. This method is mandated by the superclass but, for the case of SVG, it does not really make sense, because the internal buffers are not be copied. The call is here to make the java compiler happy...

Specified by:
create in class java.awt.Graphics
Returns:
a new graphics context that is a copy of this graphics context.

translate

public void translate(double tx,
                      double ty)
Concatenates the current Graphics2D Transform with a translation transform. A new group will be created in SVG.

Specified by:
translate in class java.awt.Graphics2D
Parameters:
tx - the distance to translate along the x-axis
ty - the distance to translate along the y-axis

translate

public void translate(int x,
                      int y)
Concatenates the current Graphics2D Transform. A new group will be created in SVG.

Specified by:
translate in class java.awt.Graphics2D
Parameters:
x - the x coordinate.
y - the y coordinate.

rotate

public void rotate(double theta)
Concatenates the current Graphics2D Transform with a rotation transform. A new group will be created in SVG. x axis toward the positive y axis.

Specified by:
rotate in class java.awt.Graphics2D
Parameters:
theta - the angle of rotation in radians

rotate

public void rotate(double theta,
                   double x,
                   double y)
Concatenates the current Graphics2D Transform with a translated rotation transform. A new group will be created in SVG.

Specified by:
rotate in class java.awt.Graphics2D
Parameters:
theta - the angle of rotation in radians
x, y - coordinates of the origin of the rotation

scale

public void scale(double sx,
                  double sy)
Concatenates the current Graphics2D Transform with a scaling transformation. A new group will be created in SVG.

Specified by:
scale in class java.awt.Graphics2D
Parameters:
sx - the amount by which X coordinates in subsequent rendering operations are multiplied relative to previous rendering operations.
sy - the amount by which Y coordinates in subsequent rendering operations are multiplied relative to previous rendering operations.

shear

public void shear(double shx,
                  double shy)
Concatenates the current Graphics2D Transform with a shearing transform. A new group will be created in SVG.

Specified by:
shear in class java.awt.Graphics2D
Parameters:
shx - the multiplier by which coordinates are shifted in the positive X axis direction as a function of their Y coordinate
shy - the multiplier by which coordinates are shifted in the positive Y axis direction as a function of their X coordinate

transform

public void transform(java.awt.geom.AffineTransform Tx)
Composes an AffineTransform object with the Transform in this Graphics2D according to the rule last-specified-first-applied. A new group will be created in SVG.

Specified by:
transform in class java.awt.Graphics2D
Parameters:
Tx - the AffineTransform object to be composed with the current Transform
See Also:
setTransform(java.awt.geom.AffineTransform), AffineTransform

setTransform

public void setTransform(java.awt.geom.AffineTransform Tx)
Sets the Transform in the Graphics2D context. A new group will be created in SVG.

Specified by:
setTransform in class java.awt.Graphics2D
Parameters:
Tx - the AffineTransform object to be used in the rendering process

getTransform

public java.awt.geom.AffineTransform getTransform()
Returns a copy of the current Transform in the Graphics2D context.

Specified by:
getTransform in class java.awt.Graphics2D
Returns:
the current AffineTransform in the Graphics2D context.

getColor

public java.awt.Color getColor()
Gets this graphics context's current color.

Specified by:
getColor in class java.awt.Graphics
Returns:
this graphics context's current color.

setColor

public void setColor(java.awt.Color c)
Store the current colour. This will be the current 'paint' too, because Color also implements the Paint interface.

Specified by:
setColor in class java.awt.Graphics
Parameters:
c - new colour object

setPaint

public void setPaint(java.awt.Paint paint)
Sets the Paint attribute for the Graphics2D context.

The TexturePaint requires that the image would should have the "url" property!

Specified by:
setPaint in class java.awt.Graphics2D
Parameters:
paint - new paint object

getPaint

public java.awt.Paint getPaint()
Returns the current Paint of the Graphics2D context.

Specified by:
getPaint in class java.awt.Graphics2D
Returns:
the current Graphics2D Paint, which defines a color or pattern.

setBackground

public void setBackground(java.awt.Color colour)
Sets the background colour for the Graphics2D context.

Specified by:
setBackground in class java.awt.Graphics2D
Parameters:
colour - the background colour that is used in subsequent calls to clearRect

getBackground

public java.awt.Color getBackground()
Returns the background colour used for clearing a region.

Specified by:
getBackground in class java.awt.Graphics2D
Returns:
the current Color, which defines the background color.
See Also:
setBackground(java.awt.Color)

setPaintMode

public void setPaintMode()
Only plain paint mode is implemented for SVG.

Specified by:
setPaintMode in class java.awt.Graphics

setXORMode

public void setXORMode(java.awt.Color c1)
Setting XOR mode.

XOR mode is not implemented!

Specified by:
setXORMode in class java.awt.Graphics

setStroke

public void setStroke(java.awt.Stroke s)
Sets the Stroke for the Graphics2D context. A new group will be created in SVG.

The only implementing class of this interface in Java 1.2 is BasicStroke, and this assumption is used in the code (to retrieve linewidth, dash array, etc.). If users add their own Stroke implementations, or if new ones appear in later releases of Java, this has to be extended.

Specified by:
setStroke in class java.awt.Graphics2D
Parameters:
s - the Stroke object to be used to stroke a Shape during the rendering process

getStroke

public java.awt.Stroke getStroke()
Returns the current Stroke.

Specified by:
getStroke in class java.awt.Graphics2D
See Also:
setStroke(java.awt.Stroke)

setComposite

public void setComposite(java.awt.Composite comp)
Sets the current composite instance.

The only implementing class of this interface in Java 1.2 is AlphaComposite, and this assumption is used in the code (to retrieve alpha values). If users add their own Composite implementations, or if new ones appear in later releases of Java, this has to be extended.

The only used attribute of the composite class is the alpha value (through the getAlpha()) which is used to set the opacity. I would not know, at this moment, how to translate the complicated composition rules of Java into SVG statements.

Specified by:
setComposite in class java.awt.Graphics2D
Parameters:
comp - the Composite object to be used for rendering.

getComposite

public java.awt.Composite getComposite()
Returns the current Composite in the Graphics2D context.

Specified by:
getComposite in class java.awt.Graphics2D
Returns:
the current Graphics2D Composite, which defines a compositing style.
See Also:
setComposite(java.awt.Composite)

getFont

public java.awt.Font getFont()
Gets the current font.

Specified by:
getFont in class java.awt.Graphics
Returns:
current font.

setFont

public void setFont(java.awt.Font font)
Sets the current font.

There are some small problems in implementing this method. Indeed, a java user can also set a "logical" font, ie, using a "logical" name for the font instead of the exact family. Of course, the set of available logical names in Java (Dialog, DialogInput, Monospaces, Serif, SansSerif, and Symbol) is not identical with SVG (more exactly, CSS). It is not clear in Java what Dialog and DialogInput mean and there is no such symbolic font name in CSS either. On a Windows NT environment Dialog seems to be mapped onto sans serif, and DialogInput seems to be mapped to monospaced, so this is what is used.

If "real" font family name is used, it is used without any change for SVG.

Specified by:
setFont in class java.awt.Graphics
Parameters:
font - the new font

getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
Gets the font metrics for the specified font.

This is only partially implemented. There is no real way of inquiring about font data in SVG, so this method is only approximative. As a help for the user, if the "parent" component has been set, then the font metrics generated by that component is returned.

Specified by:
getFontMetrics in class java.awt.Graphics
Parameters:
f - the specified font
Returns:
the font metrics for the specified font.

drawString

public void drawString(java.lang.String s,
                       int x,
                       int y)
Renders the text of the specified String, using the current Font and Paint attributes in the Graphics2D context.

Specified by:
drawString in class java.awt.Graphics2D
Parameters:
s - the string to be dislplayed
x - x coordinate for the start of the string
y - y coordinate for the start of the string

drawString

public 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.

Specified by:
drawString in class java.awt.Graphics2D
Parameters:
str - the string to be dislplayed
x - x coordinate for the start of the string
y - y coordinate for the start of the string

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       int x,
                       int y)
Renders the text of the specified iterator, using the Graphics2D context's current Paint.

This method is not yet implemented.

Specified by:
drawString in class java.awt.Graphics2D
Parameters:
iterator - character iterator
x - x coordinate for the start of the string
y - y coordinate for the start of the string

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       float x,
                       float y)
Renders the text of the specified iterator, using the Graphics2D context's current Paint.

This method is not yet implemented.

Specified by:
drawString in class java.awt.Graphics2D
Parameters:
iterator - character iterator
x - x coordinate for the start of the string
y - y coordinate for the start of the string

drawGlyphVector

public void drawGlyphVector(java.awt.font.GlyphVector g,
                            float x,
                            float y)
Renders the text of the specified GlyphVector using the Graphics2D context's rendering attributes.

This method is not yet implemented.

Specified by:
drawGlyphVector in class java.awt.Graphics2D
Parameters:
g - glyph vector
x - x coordinate for the start of the string
y - y coordinate for the start of the string

getClipBounds

public java.awt.Rectangle getClipBounds()
Returns the bounding rectangle of the current clipping area. This method refers to the user clip, which is independent of the clipping associated with device bounds and window visibility. If no clip has previously been set, or if the clip has been cleared using setClip(null), this method returns null.

Specified by:
getClipBounds in class java.awt.Graphics
Returns:
the bounding rectangle of the current clipping area, or null if no clip is set.

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)
Intersects the current clip with the specified rectangle. The resulting clipping area is the intersection of the current clipping area and the specified rectangle. If there is no current clipping area, either because the clip has never been set, or the clip has been cleared using setClip(null), the specified rectangle becomes the new clip.

The intersection of clips with existing shapes is not implemented yet. In other words, this method is void, unless the current clip shape is not yet set, in which case it is equivalent to a setClip call.

Specified by:
clipRect in class java.awt.Graphics
Parameters:
x - upper left hand corner x coordinate
y - upper left hand corner y coordinate
width - width of the rectangle
height - height of the rectangle

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Sets the current clip to the rectangle specified by the given coordinates. This method sets the user clip, which is independent of the clipping associated with device bounds and window visibility. In SVG, a clipPath is generated.

Specified by:
setClip in class java.awt.Graphics
Parameters:
x - upper left hand corner x coordinate
y - upper left hand corner y coordinate
width - width of the rectangle
height - height of the rectangle

getClip

public java.awt.Shape getClip()
Gets the current clipping area.

Specified by:
getClip in class java.awt.Graphics

setClip

public void setClip(java.awt.Shape clip)
Sets the current clipping area to an arbitrary clip shape.

In SVG, a clipPath is generated.

Specified by:
setClip in class java.awt.Graphics
Parameters:
clip - the clip shape

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.

This method is not yet implemented.

Specified by:
copyArea in class java.awt.Graphics
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.

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line.

Specified by:
drawLine in class java.awt.Graphics
Parameters:
x1 - the first point's x coordinate.
y1 - the first point's y coordinate.
x2 - the second point's x coordinate.
y2 - the second point's y coordinate.

draw

public void draw(java.awt.Shape s)
Strokes the outline of a Shape using the settings of the current Graphics2D context.

Specified by:
draw in class java.awt.Graphics2D
Parameters:
s - the Shape to be rendered

fill

public void fill(java.awt.Shape s)
Fills the interior of a Shape using the settings of the Graphics2D context. .

Specified by:
fill in class java.awt.Graphics2D
Parameters:
s - the Shape to be filled

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Draws the specified rectangle.

Overrides:
drawRect in class java.awt.Graphics
Parameters:
x - the x coordinate of the rectangle to be filled.
y - the y coordinate of the rectangle to be filled.
width - the width of the rectangle to be filled.
height - the height of the rectangle to be filled.

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Fills the specified rectangle.

Specified by:
fillRect in class java.awt.Graphics
Parameters:
x - the x coordinate of the rectangle to be filled.
y - the y coordinate of the rectangle to be filled.
width - the width of the rectangle to be filled.
height - the height of the rectangle to be filled.

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Clears the specified rectangle by filling it with the background color of the current drawing surface.

Specified by:
clearRect in class java.awt.Graphics
Parameters:
x - the x coordinate of the rectangle to clear.
y - the y coordinate of the rectangle to clear.
width - the width of the rectangle to clear.
height - the height of the rectangle to clear.

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draws an outlined round-cornered rectangle using this graphics context's current color.

At present, the rounded rectangle is replaced by a plain rectangle. (SVG does not have the notion of rounded rectangle, and an appropriate path should be calculated instead, which has not been done.)

Specified by:
drawRoundRect in class java.awt.Graphics
Parameters:
x - the x coordinate of the rectangle to be drawn.
y - the y coordinate of the rectangle to be drawn.
width - the width of the rectangle to be drawn.
height - the height of the rectangle to be drawn.
arcWidth - the horizontal diameter of the arc at the four corners.
arcHeight - the vertical diameter of the arc at the four corners.

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Fills the specified rounded corner rectangle with the current color.

At present, the rounded rectangle is replaced by a plain rectangle. (SVG does not have the notion of rounded rectangle, and an appropriate path should be calculated instead, which has not been done.)

Specified by:
fillRoundRect in class java.awt.Graphics
Parameters:
x - the x coordinate of the rectangle to be filled.
y - the y coordinate of the rectangle to be filled.
width - the width of the rectangle to be filled.
height - the height of the rectangle to be filled.
arcWidth - the horizontal diameter of the arc at the four corners.
arcHeight - the vertical diameter of the arc at the four corners.

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Draws the outline of an oval.

An ellipse statement is generated in SVG.

Specified by:
drawOval in class java.awt.Graphics
Parameters:
x - the x coordinate of the upper left corner of the oval to be drawn.
y - the y coordinate of the upper left corner of the oval to be drawn.
width - the width of the oval to be drawn.
height - the height of the oval to be drawn.

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Fills an oval bounded by the specified rectangle with the current color.

An ellipse statement is generated in SVG.

Specified by:
fillOval in class java.awt.Graphics
Parameters:
x - the x coordinate of the upper left corner of the oval to be filled.
y - the y coordinate of the upper left corner of the oval to be filled.
width - the width of the oval to be filled.
height - the height of the oval to be filled.

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Draws the outline of a circular or elliptical arc covering the specified rectangle.

Specified by:
drawArc in class java.awt.Graphics
Parameters:
x - the x coordinate of the upper-left corner of the arc to be drawn.
y - the y coordinate of the upper-left corner of the arc to be drawn.
width - the width of the arc to be drawn.
height - the height of the arc to be drawn.
startAngle - the beginning angle.
arcAngle - the angular extent of the arc, relative to the start angle.

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Fills a circular or elliptical arc covering the specified rectangle.

Specified by:
fillArc in class java.awt.Graphics
Parameters:
x - the x coordinate of the upper-left corner of the arc to be filled.
y - the y coordinate of the upper-left corner of the arc to be filled.
width - the width of the arc to be filled.
height - the height of the arc to be filled.
startAngle - the beginning angle.
arcAngle - the angular extent of the arc, relative to the start angle.
See Also:
Graphics.drawArc(int, int, int, int, int, int)

drawPolyline

public void drawPolyline(int[] xPoints,
                         int[] yPoints,
                         int nPoints)
Draws a sequence of connected lines defined by arrays of x and y coordinates.

Specified by:
drawPolyline in class java.awt.Graphics
Parameters:
xPoints - an array of x points
yPoints - an array of y points
nPoints - the total number of points
See Also:
Graphics.drawPolygon(int[], int[], int)

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Draws a closed polygon defined by arrays of x and y coordinates. Each pair of (xy) coordinates defines a point.

Specified by:
drawPolygon in class java.awt.Graphics
Parameters:
xPoints - a an array of x coordinates.
yPoints - a an array of y coordinates.
nPoints - a the total number of points.

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Fills a closed polygon defined by arrays of x and y coordinates.

Specified by:
fillPolygon in class java.awt.Graphics
Parameters:
xPoints - a an array of x coordinates.
yPoints - a an array of y coordinates.
nPoints - a the total number of points.
See Also:
Graphics.drawPolygon(int[], int[], int)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         java.awt.image.ImageObserver obs)
Draws as much of the specified image as is currently available.

The image has to have the property "url". See comments on the class level for further details.

Specified by:
drawImage in class java.awt.Graphics
Parameters:
img - the specified image to be drawn.
x - the x coordinate.
y - the y coordinate.
obs - object to be notified as more of the image is converted.

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.image.ImageObserver obs)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

The image has to have the property "url". See comments on the class level for further details.

Specified by:
drawImage in class java.awt.Graphics
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.

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver obs)
Draws as much of the specified image as is currently available.

The image has to have the property "url". See comments on the class level for further details.

Specified by:
drawImage in class java.awt.Graphics
Parameters:
img - the specified image to be drawn.
x - the x coordinate.
y - the y coordinate.
bgcolor - the background color to paint under the non-opaque portions of the image.
observer - object to be notified as more of the image is converted.

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver obs)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

The image has to have the property "url". See comments on the class level for further details.

Specified by:
drawImage in class java.awt.Graphics
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.
bgcolor - the background color to paint under the non-opaque portions of the image.
observer - object to be notified as more of the image is converted.

drawImage

public boolean drawImage(java.awt.Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         java.awt.image.ImageObserver observer)
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. Transparent pixels do not affect whatever pixels are already there.

Cutting part of the image is not yet implemented. (It would probably require to use some of the image filters defined in SVG, but this has not been checked.)

Specified by:
drawImage in class java.awt.Graphics
Parameters:
img - the specified image to be drawn
dx1 - the x coordinate of the first corner of the destination rectangle.
dy1 - the y coordinate of the first corner of the destination rectangle.
dx2 - the x coordinate of the second corner of the destination rectangle.
dy2 - the y coordinate of the second corner of the destination rectangle.
sx1 - the x coordinate of the first corner of the source rectangle.
sy1 - the y coordinate of the first corner of the source rectangle.
sx2 - the x coordinate of the second corner of the source rectangle.
sy2 - the y coordinate of the second corner of the source rectangle.
observer - object to be notified as more of the image is scaled and converted.

drawImage

public boolean drawImage(java.awt.Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.

Cutting part of the image is not yet implemented. (It would probably require to use some of the image filters defined in SVG, but this has not been checked.)

Specified by:
drawImage in class java.awt.Graphics
Parameters:
img - the specified image to be drawn
dx1 - the x coordinate of the first corner of the destination rectangle.
dy1 - the y coordinate of the first corner of the destination rectangle.
dx2 - the x coordinate of the second corner of the destination rectangle.
dy2 - the y coordinate of the second corner of the destination rectangle.
sx1 - the x coordinate of the first corner of the source rectangle.
sy1 - the y coordinate of the first corner of the source rectangle.
sx2 - the x coordinate of the second corner of the source rectangle.
sy2 - the y coordinate of the second corner of the source rectangle.
bgcolor - the background color to paint under the non-opaque portions of the image.
observer - object to be notified as more of the image is scaled and converted.

drawImage

public 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.

The method is implemented by enclosing a usual image call into a group with the right transformation.

The image has to have the property "url". See comments on the class level for further details.

Specified by:
drawImage in class java.awt.Graphics2D
Parameters:
img - the Image to be rendered
xform - the transformation from image space into user space
obs - the ImageObserver to be notified as more of the Image is converted
Returns:
true if the image could be displayed, and false otherwise.

drawImage

public void drawImage(java.awt.image.BufferedImage img,
                      java.awt.image.BufferedImageOp op,
                      int x,
                      int y)
Renders a BufferedImage.

Handling of Buffered Images is not implemented.

Specified by:
drawImage in class java.awt.Graphics2D
Parameters:
op - the filter to be applied to the image before rendering
img - the BufferedImage to be rendered
x, y - the location in user space where the upper left corner of the image is rendered
See Also:
transform(java.awt.geom.AffineTransform), setTransform(java.awt.geom.AffineTransform), setComposite(java.awt.Composite), clip(java.awt.Shape), setClip(int, int, int, int)

drawRenderedImage

public void drawRenderedImage(java.awt.image.RenderedImage img,
                              java.awt.geom.AffineTransform xform)
Draws a rendered image

Handling of rendered images is not implemented.

Specified by:
drawRenderedImage in class java.awt.Graphics2D
Parameters:
img - the image to be rendered
xform - the transformation from image space into user space
See Also:
transform(java.awt.geom.AffineTransform), setTransform(java.awt.geom.AffineTransform), setComposite(java.awt.Composite), clip(java.awt.Shape), setClip(int, int, int, int)

drawRenderableImage

public void drawRenderableImage(java.awt.image.renderable.RenderableImage img,
                                java.awt.geom.AffineTransform xform)
Draws a renderable image

Handling of renderable images is not implemented.

Specified by:
drawRenderableImage in class java.awt.Graphics2D
Parameters:
img - the image to be rendered
xform - the transformation from image space into user space
See Also:
transform(java.awt.geom.AffineTransform), setTransform(java.awt.geom.AffineTransform), setComposite(java.awt.Composite), clip(java.awt.Shape), setClip(int, int, int, int), drawRenderedImage(java.awt.image.RenderedImage, java.awt.geom.AffineTransform)

hit

public boolean hit(java.awt.Rectangle rect,
                   java.awt.Shape s,
                   boolean onStroke)
Checks whether or not the specified Shape intersects the specified Rectangle, which is in device space.

Specified by:
hit in class java.awt.Graphics2D
Returns:
true if there is a hit; false otherwise.

setRenderingHint

public void setRenderingHint(java.awt.RenderingHints.Key hintKey,
                             java.lang.Object hintValue)
Sets the value of a single preference for the rendering algorithms.

This method has no effect in SVG.

Specified by:
setRenderingHint in class java.awt.Graphics2D
Parameters:
hintKey - the key of the hint to be set.
hintValue - the value indicating preferences for the specified hint category.
See Also:
RenderingHints

getRenderingHint

public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
Returns the value of a single preference for the rendering algorithms.

The returned values are constants and, in a sense, meaningless. The rendering quality depends on the quality of the SVG browser, and not the SVG file itself, so the assumption is that the browser is of the highest quality.

Specified by:
getRenderingHint in class java.awt.Graphics2D
Parameters:
hintKey - the key corresponding to the hint to get.
Returns:
an object representing the value for the specified hint key. Some of the keys and their associated values are defined in the RenderingHints class.
See Also:
RenderingHints

setRenderingHints

public void setRenderingHints(java.util.Map hints)
Replaces the values of all preferences for the rendering algorithms with the specified hints.

The method is void and, in a sense, meaningless. The rendering quality depends on the quality of the SVG browser, and not the SVG file itself, so the assumption is that the browser is of the highest quality.

Specified by:
setRenderingHints in class java.awt.Graphics2D
Parameters:
hints - the rendering hints to be set
See Also:
RenderingHints

addRenderingHints

public void addRenderingHints(java.util.Map hints)
Sets the values of an arbitrary number of preferences for the rendering algorithms.

The method is void and, in a sense, meaningless. The rendering quality depends on the quality of the SVG browser, and not the SVG file itself, so the assumption is that the browser is of the highest quality.

Specified by:
addRenderingHints in class java.awt.Graphics2D
Parameters:
hints - the rendering hints to be set
See Also:
RenderingHints

getRenderingHints

public java.awt.RenderingHints getRenderingHints()
Gets the preferences for the rendering algorithms.

The returned values are constants and, in a sense, meaningless. The rendering quality depends on the quality of the SVG browser, and not the SVG file itself, so the assumption is that the browser is of the highest quality.

Specified by:
getRenderingHints in class java.awt.Graphics2D
Returns:
a reference to an instance of RenderingHints that contains the current preferences.
See Also:
RenderingHints

clip

public void clip(java.awt.Shape s)
Intersects the current Clip with the interior of the specified Shape and sets the Clip to the resulting intersection.

This method has not been implemented yet.

Specified by:
clip in class java.awt.Graphics2D
Parameters:
s - the Shape to be intersected with the current Clip. If s is null, this method clears the current Clip.

getFontRenderContext

public java.awt.font.FontRenderContext getFontRenderContext()
Get the rendering context of the Font within this Graphics2D context.

There is no real counterpart in SVG for this. As a help to the user, if the parent component has been set and there is a current font, the rendering context for that environment is returned. This might help in having an idea on how big the chain of character will be, for example.

Specified by:
getFontRenderContext in class java.awt.Graphics2D
Returns:
a reference to an instance of FontRenderContext.

getDeviceConfiguration

public java.awt.GraphicsConfiguration getDeviceConfiguration()
Returns the device configuration associated with this Graphics2D.

The implementation is fake. Just to give an indication to the user, it returns the graphics configuration of the "parent" (i.e., "real") component, although this might be meaningless for the display of the SVG file.

Specified by:
getDeviceConfiguration in class java.awt.Graphics2D
Returns:
the graphics configuration of the "parent" component, if set, and null otherwise.