FreeHEP API
Version current

org.freehep.graphicsio.svg
Class SVGGraphics2D

java.lang.Object
  extended byjava.awt.Graphics
      extended byjava.awt.Graphics2D
          extended byorg.freehep.graphics2d.VectorGraphics
              extended byorg.freehep.graphics2d.AbstractVectorGraphics
                  extended byorg.freehep.graphicsio.VectorGraphicsIO
                      extended byorg.freehep.graphicsio.AbstractVectorGraphicsIO
                          extended byorg.freehep.graphicsio.svg.SVGGraphics2D
All Implemented Interfaces:
VectorGraphicsConstants

public class SVGGraphics2D
extends AbstractVectorGraphicsIO

This class implements the Scalable Vector Graphics output. SVG specifications can be found at http://www.w3c.org/Graphics/SVG/ The current implementation is based on REC-SVG-20010904 but can generate also files for the older specs CR-SVG-20000802, WD-SVG-20000303

Version:
$Id: SVGGraphics2D.java,v 1.22 2005/01/05 20:44:40 duns Exp $
Author:
Mark Donszelmann
Source Code:
SVGGraphics2D.java

Field Summary
static String BACKGROUND
           
static String BACKGROUND_COLOR
           
static String COMPRESS
           
static String EXPORT_IMAGES
           
static String EXPORT_SUFFIX
           
static String FOR
           
static String IMAGE_SIZE
           
static String STYLABLE
           
static String TITLE
           
static String TRANSPARENT
           
static String version
           
static String VERSION
           
static String VERSION_1_0
           
static String VERSION_1_1
           
static String WRITE_IMAGES_AS
           
 
Fields inherited from class org.freehep.graphicsio.AbstractVectorGraphicsIO
EMIT_ERRORS, EMIT_WARNINGS
 
Fields inherited from interface org.freehep.graphics2d.VectorGraphicsConstants
NUMBER_OF_HORIZ_ALIGNMENTS, NUMBER_OF_SYMBOLS, NUMBER_OF_VERTICAL_ALIGNMENTS, SYMBOL_BOX, SYMBOL_CIRCLE, SYMBOL_CROSS, SYMBOL_DIAMOND, SYMBOL_DN_TRIANGLE, SYMBOL_HLINE, SYMBOL_PLUS, SYMBOL_STAR, SYMBOL_UP_TRIANGLE, SYMBOL_VLINE, TEXT_BASELINE, TEXT_BOTTOM, TEXT_CENTER, TEXT_LEFT, TEXT_RIGHT, TEXT_TOP
 
Constructor Summary
  SVGGraphics2D(File file, Component component)
           
  SVGGraphics2D(File file, Dimension size)
           
  SVGGraphics2D(OutputStream os, Component component)
           
  SVGGraphics2D(OutputStream os, Dimension size)
           
protected SVGGraphics2D(SVGGraphics2D graphics, boolean doRestoreOnDispose)
           
 
Method Summary
 void closeStream()
          Called to close the stream you are writing to.
 void copyArea(int x, int y, int width, int height, int dx, int dy)
           
 Graphics create()
           
 Graphics create(double x, double y, double width, double height)
           
 void draw(Shape shape)
           
 void drawArc(double x, double y, double width, double height, double startAngle, double arcAngle)
          Draws an arc.
 void drawLine(double x1, double y1, double x2, double y2)
          Draws a straight line.
 void drawOval(double x, double y, double width, double height)
          Draws an oval.
 void drawPolygon(double[] xPoints, double[] yPoints, int nPoints)
          Draws a polygon.
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
           
 void drawPolygon(Polygon p)
           
 void drawPolyline(double[] xPoints, double[] yPoints, int nPoints)
          Draws a polyline.
 void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
           
 void drawRect(double x, double y, double width, double height)
          Draws a rectangle.
 void drawRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
          Draws a rounded rectangle.
 void drawString(String str, double x, double y, int horizontal, int vertical, boolean framed, Color frameColor, double frameWidth, boolean banner, Color bannerColor)
          Draws a string with a lot of parameters.
 void drawString(TagString str, double x, double y, int horizontal, int vertical, boolean framed, Color frameColor, double frameWidth, boolean banner, Color bannerColor)
          Draws a TagString with a lot of parameters.
 void fill(Shape shape)
           
 void fillAndDraw(Shape shape, Color fillColor)
           
 void fillArc(double x, double y, double width, double height, double startAngle, double arcAngle)
          Fills an arc.
 void fillOval(double x, double y, double width, double height)
          Fills an oval.
 void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
          Fills a polygon.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
           
 void fillPolygon(Polygon p)
           
 void fillRect(double x, double y, double width, double height)
          Fills a rectangle.
 void fillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
          Fills a rounded rectangle.
static String fixedPrecision(double d)
           
static Properties getDefaultProperties()
           
 GraphicsConfiguration getDeviceConfiguration()
           
 boolean hit(Rectangle rect, Shape s, boolean onStroke)
           
 void setBoundingBox()
          Get the bounding box for this image.
static void setDefaultProperties(Properties newProperties)
           
 void setFont(Font font)
          Method sets the current font.
 void setPaintMode()
           
 void setXORMode(Color c1)
           
 String toString()
           
 void writeBackground()
           
protected  void writeCap(int cap)
          Writes out the cap of the stroke.
protected  void writeClip(Rectangle2D r2d)
          Write out Rectangle2D clip.
protected  void writeClip(Shape s)
          Write out Shape clip.
 void writeComment(String s)
          Called to Write out a comment.
protected  void writeDash(double[] dash, double phase)
          Writes out the dash of the stroke.
protected  void writeGraphicsRestore()
          Writes out the restore of a graphics context.
protected  void writeGraphicsSave()
          Writes out the save of a graphics context for a later restore.
 void writeHeader()
          Write out the header of this SVG file.
protected  void writeImage(RenderedImage image, AffineTransform xform, Color bkg)
           
protected  void writeJoin(int join)
          Writes out the join of the stroke.
protected  void writeMiterLimit(float limit)
          Writes out the miter limit of the stroke.
protected  void writePaint(Color c)
          Writes out paint as the given color.
protected  void writePaint(GradientPaint paint)
          Writes out paint as the given gradient.
protected  void writePaint(Paint p)
          Writes out paint.
protected  void writePaint(TexturePaint paint)
          Writes out paint as the given texture.
protected  void writeString(String str, double x, double y)
           
 void writeTrailer()
          Called to write the trailing part of the output.
protected  void writeTransform(AffineTransform transform)
          Writes out the transform as it needs to be concatenated to the internal transform of the output format.
protected  void writeWidth(float width)
          Writes out the width of the stroke.
 
Methods inherited from class org.freehep.graphicsio.AbstractVectorGraphicsIO
addRenderingHints, clearRect, clip, clipRect, clipRect, createShape, dispose, drawGlyphVector, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawRenderableImage, drawRenderedImage, drawString, drawString, endExport, getClip, getClipBounds, getClipBounds, getComponent, getComposite, getFontMetrics, getFontRenderContext, getRenderingHint, getRenderingHints, getSize, getStroke, getTransform, handleException, printComment, resetClip, rotate, scale, setClip, setClip, setClip, setColor, setComposite, setPaint, setRenderingHint, setRenderingHints, setStroke, setTransform, shear, startExport, transform, translate, writeClip, writeError, writeGraphicsState, writeSetClip, writeStroke, writeWarning, writeWarning
 
Methods inherited from class org.freehep.graphicsio.VectorGraphicsIO
copyResourceTo, copyResourceTo
 
Methods inherited from class org.freehep.graphics2d.AbstractVectorGraphics
clearRect, createShape, drawArc, drawLine, drawOval, drawRect, drawRoundRect, drawString, drawString, drawString, drawString, drawString, drawString, drawSymbol, drawSymbol, drawSymbol, fillAndDrawSymbol, fillAndDrawSymbol, fillArc, fillOval, fillRect, fillRoundRect, fillSymbol, fillSymbol, fillSymbol, getBackground, getColor, getColorMode, getCreator, getFont, getPaint, getPrintColor, getProperties, getProperty, getPropertyColor, getPropertyDimension, getPropertyDouble, getPropertyInsets, getPropertyInt, getPropertyRectangle, initProperties, isDeviceIndependent, isProperty, rotate, setBackground, setColorMode, setCreator, setDeviceIndependent, setLineWidth, setLineWidth, setProperties, translate
 
Methods inherited from class org.freehep.graphics2d.VectorGraphics
create, create, getSymbol, getTextAlignment, getXalignment, getYalignment
 
Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
 
Methods inherited from class java.awt.Graphics
drawBytes, drawChars, finalize, getClipRect, getFontMetrics, hitClip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION_1_0

public static final String VERSION_1_0
See Also:
Constant Field Values

VERSION_1_1

public static final String VERSION_1_1
See Also:
Constant Field Values

TRANSPARENT

public static final String TRANSPARENT

BACKGROUND

public static final String BACKGROUND

BACKGROUND_COLOR

public static final String BACKGROUND_COLOR

VERSION

public static final String VERSION

COMPRESS

public static final String COMPRESS

STYLABLE

public static final String STYLABLE

IMAGE_SIZE

public static final String IMAGE_SIZE

EXPORT_IMAGES

public static final String EXPORT_IMAGES

EXPORT_SUFFIX

public static final String EXPORT_SUFFIX

WRITE_IMAGES_AS

public static final String WRITE_IMAGES_AS

FOR

public static final String FOR

TITLE

public static final String TITLE

version

public static final String version
See Also:
Constant Field Values
Constructor Detail

SVGGraphics2D

public SVGGraphics2D(File file,
                     Dimension size)
              throws IOException

SVGGraphics2D

public SVGGraphics2D(File file,
                     Component component)
              throws IOException

SVGGraphics2D

public SVGGraphics2D(OutputStream os,
                     Dimension size)

SVGGraphics2D

public SVGGraphics2D(OutputStream os,
                     Component component)

SVGGraphics2D

protected SVGGraphics2D(SVGGraphics2D graphics,
                        boolean doRestoreOnDispose)
Method Detail

getDefaultProperties

public static Properties getDefaultProperties()

setDefaultProperties

public static void setDefaultProperties(Properties newProperties)

setBoundingBox

public void setBoundingBox()
Get the bounding box for this image.


writeHeader

public void writeHeader()
                 throws IOException
Write out the header of this SVG file.

Specified by:
writeHeader in class AbstractVectorGraphicsIO
Throws:
IOException

writeBackground

public void writeBackground()
                     throws IOException
Specified by:
writeBackground in class AbstractVectorGraphicsIO
Throws:
IOException

writeTrailer

public void writeTrailer()
                  throws IOException
Description copied from class: AbstractVectorGraphicsIO
Called to write the trailing part of the output.

Specified by:
writeTrailer in class AbstractVectorGraphicsIO
Throws:
IOException

closeStream

public void closeStream()
                 throws IOException
Description copied from class: AbstractVectorGraphicsIO
Called to close the stream you are writing to.

Specified by:
closeStream in class AbstractVectorGraphicsIO
Throws:
IOException

create

public Graphics create()
Specified by:
create in class VectorGraphics

create

public Graphics create(double x,
                       double y,
                       double width,
                       double height)
Specified by:
create in class VectorGraphics

writeGraphicsSave

protected void writeGraphicsSave()
                          throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out the save of a graphics context for a later restore. Some implementations keep track of this by hand if the output format does not support it.

Specified by:
writeGraphicsSave in class AbstractVectorGraphicsIO
Throws:
IOException

writeGraphicsRestore

protected void writeGraphicsRestore()
                             throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out the restore of a graphics context. Some implementations keep track of this by hand if the output format does not support it.

Specified by:
writeGraphicsRestore in class AbstractVectorGraphicsIO
Throws:
IOException

drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2)
Description copied from class: VectorGraphics
Draws a straight line. Uses Line2D to call draw(Shape).

Overrides:
drawLine in class AbstractVectorGraphics

drawRect

public void drawRect(double x,
                     double y,
                     double width,
                     double height)
Description copied from class: VectorGraphics
Draws a rectangle. Uses Rectangle2D to call draw(Shape).

Overrides:
drawRect in class AbstractVectorGraphics

fillRect

public void fillRect(double x,
                     double y,
                     double width,
                     double height)
Description copied from class: VectorGraphics
Fills a rectangle. Uses Rectangle2D to call fill(Shape).

Overrides:
fillRect in class AbstractVectorGraphics

drawRoundRect

public void drawRoundRect(double x,
                          double y,
                          double width,
                          double height,
                          double arcWidth,
                          double arcHeight)
Description copied from class: VectorGraphics
Draws a rounded rectangle. Uses RoundRectangle2D to call draw(Shape).

Overrides:
drawRoundRect in class AbstractVectorGraphics

fillRoundRect

public void fillRoundRect(double x,
                          double y,
                          double width,
                          double height,
                          double arcWidth,
                          double arcHeight)
Description copied from class: VectorGraphics
Fills a rounded rectangle. Uses RoundRectangle2D to call fill(Shape).

Overrides:
fillRoundRect in class AbstractVectorGraphics

drawPolyline

public void drawPolyline(int[] xPoints,
                         int[] yPoints,
                         int nPoints)
Overrides:
drawPolyline in class AbstractVectorGraphics

drawPolyline

public void drawPolyline(double[] xPoints,
                         double[] yPoints,
                         int nPoints)
Description copied from class: VectorGraphics
Draws a polyline. Uses createShape(...) to call draw(Shape).

Overrides:
drawPolyline in class AbstractVectorGraphics

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Overrides:
drawPolygon in class AbstractVectorGraphics

drawPolygon

public void drawPolygon(double[] xPoints,
                        double[] yPoints,
                        int nPoints)
Description copied from class: VectorGraphics
Draws a polygon. Uses createShape(...) to call draw(Shape).

Overrides:
drawPolygon in class AbstractVectorGraphics

drawPolygon

public void drawPolygon(Polygon p)

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Overrides:
fillPolygon in class AbstractVectorGraphics

fillPolygon

public void fillPolygon(double[] xPoints,
                        double[] yPoints,
                        int nPoints)
Description copied from class: VectorGraphics
Fills a polygon. Uses createShape(...) to call fill(Shape).

Overrides:
fillPolygon in class AbstractVectorGraphics

fillPolygon

public void fillPolygon(Polygon p)

drawArc

public void drawArc(double x,
                    double y,
                    double width,
                    double height,
                    double startAngle,
                    double arcAngle)
Description copied from class: VectorGraphics
Draws an arc. Uses Arc2D to call draw(Shape).

Overrides:
drawArc in class AbstractVectorGraphics

fillArc

public void fillArc(double x,
                    double y,
                    double width,
                    double height,
                    double startAngle,
                    double arcAngle)
Description copied from class: VectorGraphics
Fills an arc. Uses Arc2D to call fill(Shape).

Overrides:
fillArc in class AbstractVectorGraphics

drawOval

public void drawOval(double x,
                     double y,
                     double width,
                     double height)
Description copied from class: VectorGraphics
Draws an oval. Uses Ellipse2D to call draw(Shape).

Overrides:
drawOval in class AbstractVectorGraphics

fillOval

public void fillOval(double x,
                     double y,
                     double width,
                     double height)
Description copied from class: VectorGraphics
Fills an oval. Uses Ellipse2D to call fill(Shape).

Overrides:
fillOval in class AbstractVectorGraphics

draw

public void draw(Shape shape)
Specified by:
draw in class VectorGraphics

fill

public void fill(Shape shape)
Specified by:
fill in class VectorGraphics

fillAndDraw

public void fillAndDraw(Shape shape,
                        Color fillColor)
Overrides:
fillAndDraw in class AbstractVectorGraphics

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)
Specified by:
copyArea in class VectorGraphics

writeImage

protected void writeImage(RenderedImage image,
                          AffineTransform xform,
                          Color bkg)
                   throws IOException
Specified by:
writeImage in class AbstractVectorGraphicsIO
Throws:
IOException

writeString

protected void writeString(String str,
                           double x,
                           double y)
                    throws IOException
Specified by:
writeString in class AbstractVectorGraphicsIO
Throws:
IOException

drawString

public void drawString(String str,
                       double x,
                       double y,
                       int horizontal,
                       int vertical,
                       boolean framed,
                       Color frameColor,
                       double frameWidth,
                       boolean banner,
                       Color bannerColor)
Description copied from class: VectorGraphics
Draws a string with a lot of parameters.

Overrides:
drawString in class AbstractVectorGraphicsIO

drawString

public void drawString(TagString str,
                       double x,
                       double y,
                       int horizontal,
                       int vertical,
                       boolean framed,
                       Color frameColor,
                       double frameWidth,
                       boolean banner,
                       Color bannerColor)
Description copied from class: VectorGraphics
Draws a TagString with a lot of parameters.

Overrides:
drawString in class AbstractVectorGraphicsIO

writeTransform

protected void writeTransform(AffineTransform transform)
                       throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out the transform as it needs to be concatenated to the internal transform of the output format. If there is no implementation of an internal transform, then this method needs to do nothing, BUT all coordinates need to be transformed by the currentTransform before being written out.

Specified by:
writeTransform in class AbstractVectorGraphicsIO
Parameters:
transform - to be written
Throws:
IOException

writeClip

protected void writeClip(Rectangle2D r2d)
                  throws IOException
Description copied from class: AbstractVectorGraphicsIO
Write out Rectangle2D clip.

Specified by:
writeClip in class AbstractVectorGraphicsIO
Parameters:
r2d - to be used for clipping
Throws:
IOException

writeClip

protected void writeClip(Shape s)
                  throws IOException
Description copied from class: AbstractVectorGraphicsIO
Write out Shape clip.

Specified by:
writeClip in class AbstractVectorGraphicsIO
Parameters:
s - to be used for clipping
Throws:
IOException

writeWidth

protected void writeWidth(float width)
                   throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out the width of the stroke.

Overrides:
writeWidth in class AbstractVectorGraphicsIO
Parameters:
width - of the stroke
Throws:
IOException

writeCap

protected void writeCap(int cap)
                 throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out the cap of the stroke.

Overrides:
writeCap in class AbstractVectorGraphicsIO
Parameters:
cap - of the stroke
Throws:
IOException

writeJoin

protected void writeJoin(int join)
                  throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out the join of the stroke.

Overrides:
writeJoin in class AbstractVectorGraphicsIO
Parameters:
join - of the stroke
Throws:
IOException

writeMiterLimit

protected void writeMiterLimit(float limit)
                        throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out the miter limit of the stroke.

Overrides:
writeMiterLimit in class AbstractVectorGraphicsIO
Parameters:
limit - miter limit of the stroke
Throws:
IOException

writeDash

protected void writeDash(double[] dash,
                         double phase)
                  throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out the dash of the stroke.

Overrides:
writeDash in class AbstractVectorGraphicsIO
Parameters:
dash - dash pattern, empty array is solid line
phase - of the dash pattern
Throws:
IOException

setPaintMode

public void setPaintMode()
Specified by:
setPaintMode in class VectorGraphics

setXORMode

public void setXORMode(Color c1)
Specified by:
setXORMode in class VectorGraphics

writePaint

protected void writePaint(Color c)
                   throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out paint as the given color.

Specified by:
writePaint in class AbstractVectorGraphicsIO
Parameters:
c - to be written
Throws:
IOException

writePaint

protected void writePaint(GradientPaint paint)
                   throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out paint as the given gradient.

Specified by:
writePaint in class AbstractVectorGraphicsIO
Parameters:
paint - to be written
Throws:
IOException

writePaint

protected void writePaint(TexturePaint paint)
                   throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out paint as the given texture.

Specified by:
writePaint in class AbstractVectorGraphicsIO
Parameters:
paint - to be written
Throws:
IOException

writePaint

protected void writePaint(Paint p)
                   throws IOException
Description copied from class: AbstractVectorGraphicsIO
Writes out paint.

Specified by:
writePaint in class AbstractVectorGraphicsIO
Parameters:
p - to be written
Throws:
IOException

setFont

public void setFont(Font font)
Method sets the current font. This method makes a reasonable guess for the desired SVG font since the names of the actual SVG fonts is implementation dependent. Currently, this tries to identify Helvetica, Times, Courier, Symbol, and ZapfDingbats fonts. If all else fails, Helvetica is used.

Overrides:
setFont in class AbstractVectorGraphics
Parameters:
font - to be set

getDeviceConfiguration

public GraphicsConfiguration getDeviceConfiguration()
Specified by:
getDeviceConfiguration in class VectorGraphics

hit

public boolean hit(Rectangle rect,
                   Shape s,
                   boolean onStroke)
Specified by:
hit in class VectorGraphics

writeComment

public void writeComment(String s)
                  throws IOException
Description copied from class: AbstractVectorGraphicsIO
Called to Write out a comment.

Specified by:
writeComment in class AbstractVectorGraphicsIO
Parameters:
s - to be written
Throws:
IOException

toString

public String toString()
Specified by:
toString in class VectorGraphics

fixedPrecision

public static String fixedPrecision(double d)

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.