Class SemanticSVGGraphics2D

java.lang.Object
java.awt.Graphics
java.awt.Graphics2D
org.freehep.graphics2d.VectorGraphics
org.freehep.graphics2d.AbstractVectorGraphics
org.freehep.graphicsio.VectorGraphicsIO
org.freehep.graphicsio.AbstractVectorGraphicsIO
de.cau.cs.kieler.klighd.piccolo.freehep.SemanticSVGGraphics2D
All Implemented Interfaces:
org.freehep.graphics2d.VectorGraphicsConstants

public class SemanticSVGGraphics2D extends org.freehep.graphicsio.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-SVG11-20030114
Version:
$Id: freehep-graphicsio-svg/src/main/java/org/freehep/graphicsio/svg/SVGGraphics2D.java 4c4708a97391 2007/06/12 22:32:31 duns $ - Added capabilities to add semantic information to the svg, ie key/value pairs within the 'klighd' namespace. - Allow comments to be switched off. - Corrected direction of color gradients. - Added support for multi-line text and proper font sizing.
Author:
Mark Donszelmann, uru
  • Field Details

    • VERSION_1_1

      public static final String VERSION_1_1
      See Also:
    • 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
      use style="font-size:20" instaed of font-size="20" see style(java.util.Properties) for details
    • 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
    • EMBED_FONTS

      public static final String EMBED_FONTS
    • DESCRIPTION

      public static final String DESCRIPTION
    • ADDITIONAL_ROOT_DATA

      public static final String ADDITIONAL_ROOT_DATA
    • CSS

      public static final String CSS
    • version

      public static final String version
      See Also:
  • Constructor Details

  • Method Details

    • getDefaultProperties

      public static Properties getDefaultProperties()
    • setDefaultProperties

      public static void setDefaultProperties(Properties newProperties)
    • getAdjustedFontHeight

      protected float getAdjustedFontHeight()
    • dispose

      public void dispose()
      Overrides:
      dispose in class org.freehep.graphicsio.AbstractVectorGraphicsIO
    • setBoundingBox

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

      public void setWriteComments(boolean writeComments)
      Parameters:
      writeComments - the writeComments to set
    • writeHeader

      public void writeHeader() throws IOException
      Write out the header of this SVG file.
      Specified by:
      writeHeader in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeBackground

      public void writeBackground() throws IOException
      Specified by:
      writeBackground in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeTrailer

      public void writeTrailer() throws IOException
      Writes the font definitions and calls writeGraphicsRestore() to close all open XML Tags
      Specified by:
      writeTrailer in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • closeStream

      public void closeStream() throws IOException
      Specified by:
      closeStream in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • create

      public Graphics create()
      Specified by:
      create in class org.freehep.graphics2d.VectorGraphics
    • create

      public Graphics create(double x, double y, double width, double height)
      Specified by:
      create in class org.freehep.graphics2d.VectorGraphics
    • writeGraphicsSave

      protected void writeGraphicsSave() throws IOException
      Specified by:
      writeGraphicsSave in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeGraphicsRestore

      protected void writeGraphicsRestore() throws IOException
      Specified by:
      writeGraphicsRestore in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • draw

      public void draw(Shape shape)
      Draws the shape using the current paint as border
      Specified by:
      draw in class org.freehep.graphics2d.VectorGraphics
      Parameters:
      shape - Shape to draw
    • fill

      public void fill(Shape shape)
      Fills the shape without a border using the current paint
      Specified by:
      fill in class org.freehep.graphics2d.VectorGraphics
      Parameters:
      shape - Shape to be filled with the current paint
    • copyArea

      public void copyArea(int x, int y, int width, int height, int dx, int dy)
      Specified by:
      copyArea in class org.freehep.graphics2d.VectorGraphics
    • writeImage

      protected void writeImage(RenderedImage image, AffineTransform xform, Color bkg) throws IOException
      Specified by:
      writeImage in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • setNextTextLength

      public void setNextTextLength(double textLength)
    • drawString

      public void drawString(String string, double x, double y)
      Copied from AbstractVectorGraphicsIO to change the handling of text as shapes. Draws the string at (x, y). If TEXT_AS_SHAPES is set AbstractVectorGraphicsIO.drawGlyphVector(java.awt.font.GlyphVector, float, float) is used, otherwise writeString(String, double, double) for a more direct output of the string.
      Overrides:
      drawString in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Parameters:
      string -
      x -
      y -
    • writeString

      protected void writeString(String str, double x, double y) throws IOException
      Specified by:
      writeString in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • getAdjustedFontHeight

      protected float getAdjustedFontHeight(int height, int ascent, int descent, boolean firstLine)
    • textLength

      protected String textLength(Double nextLength)
    • getFontMetrics

      public FontMetrics getFontMetrics()
      KLighD uses SWT to estimate font sizes, hence we do the same when exporting svgs.
      Overrides:
      getFontMetrics in class Graphics
    • getFontHeight

      public float getFontHeight()
      Gets the height of the current font.
      Returns:
      The current font height.
    • writeTransform

      protected void writeTransform(AffineTransform transform) throws IOException
      Specified by:
      writeTransform in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeSetTransform

      protected void writeSetTransform(AffineTransform transform) throws IOException
      Overrides:
      writeSetTransform in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeClip

      protected void writeClip(Shape s) throws IOException
      Specified by:
      writeClip in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeSetClip

      protected void writeSetClip(Shape s) throws IOException
      Specified by:
      writeSetClip in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeWidth

      protected void writeWidth(float width) throws IOException
      Overrides:
      writeWidth in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeCap

      protected void writeCap(int cap) throws IOException
      Overrides:
      writeCap in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeJoin

      protected void writeJoin(int join) throws IOException
      Overrides:
      writeJoin in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeMiterLimit

      protected void writeMiterLimit(float limit) throws IOException
      Overrides:
      writeMiterLimit in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeDash

      protected void writeDash(float[] dash, float phase) throws IOException
      Overrides:
      writeDash in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • setPaintMode

      public void setPaintMode()
      Specified by:
      setPaintMode in class org.freehep.graphics2d.VectorGraphics
    • setXORMode

      public void setXORMode(Color c1)
      Specified by:
      setXORMode in class org.freehep.graphics2d.VectorGraphics
    • writePaint

      protected void writePaint(Color c) throws IOException
      Specified by:
      writePaint in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writePaint

      protected void writePaint(GradientPaint paint) throws IOException
      Specified by:
      writePaint in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writePaint

      protected void writePaint(TexturePaint paint) throws IOException
      Specified by:
      writePaint in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writePaint

      protected void writePaint(Paint p) throws IOException
      Specified by:
      writePaint in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • writeFont

      protected void writeFont(Font font) throws IOException
      Specified by:
      writeFont in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • getDeviceConfiguration

      public GraphicsConfiguration getDeviceConfiguration()
      Specified by:
      getDeviceConfiguration in class org.freehep.graphics2d.VectorGraphics
    • writeComment

      public void writeComment(String s) throws IOException
      Specified by:
      writeComment in class org.freehep.graphicsio.AbstractVectorGraphicsIO
      Throws:
      IOException
    • pushComment

      public void pushComment(Stack<String> stack, String s)
    • toString

      public String toString()
      Specified by:
      toString in class org.freehep.graphics2d.VectorGraphics
    • getPathContent

      protected static String getPathContent(PathIterator path)
    • getPath

      protected String getPath(PathIterator path)
    • addSemanticData

      public void addSemanticData(KlighdSemanticDiagramData nextSemanticData)
    • startGroup

      public void startGroup(KlighdSemanticDiagramData nextSemanticData)
    • endGroup

      public void endGroup()
    • createAWTPath

      public static Path2D createAWTPath(org.eclipse.swt.graphics.PathData pathData)
      Builds up a AWT Path2D according to a given SWT Geometry PathData.
      Parameters:
      pathData - provides the segments the new path shall contain. the device to create the path on
      Returns:
      the desired Path2D object.
    • getFontData

      protected org.eclipse.swt.graphics.FontData getFontData(Font font)
    • fixedPrecision

      public static String fixedPrecision(double d)
      converts the double value to a representing string
      Parameters:
      d - double value to convert
      Returns:
      same as string
    • getOutputStream

      protected PrintWriter getOutputStream()