org.foray.render.svg
Class SVGUtilities

java.lang.Object
  extended by org.foray.render.svg.SVGUtilities

public final class SVGUtilities
extends Object

Some utilities for creating svg DOM documents and elements.


Method Summary
static Element createClip(Document doc, Element els, String id)
          Create an SVG Clip.
static Element createEllipse(Document doc, float cx, float cy, float rx, float ry)
          Create an SVG Ellipse.
static Element createG(Document doc)
          Create an SVG G (group) element.
static Element createImage(Document doc, String ref, float width, float height)
          Create an SVG Image.
static Element createLine(Document doc, float x, float y, float x2, float y2)
          Create an SVG Line.
static Element createPath(Document doc, String str)
          Create an SVG Path.
static Element createRect(Document doc, float x, float y, float width, float height)
          Create an SVG Rectangle.
static Element createText(Document doc, float x, float y, String str)
          Create an SVG Text object.
static Rectangle2D getStringBounds(String str, Font font)
          Get the bounds for a particular string, given the font.
static float getStringHeight(String str, Font font)
          Get the height of a particular string for a given font.
static float getStringWidth(String str, Font font)
          Get the width of a particular string for a given font.
static Element wrapText(Document doc, String str, Font font, float width)
          Create some SVG text that is wrapped into a specified width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStringWidth

public static float getStringWidth(String str,
                                   Font font)
Get the width of a particular string for a given font.

Parameters:
str - The String whose width is needed.
font - The AWT Font which should be used to compute the width.
Returns:
The width of the String, in points (??).

getStringHeight

public static float getStringHeight(String str,
                                    Font font)
Get the height of a particular string for a given font.

Parameters:
str - The String whose width is needed.
font - The AWT Font which should be used to compute the height.
Returns:
The height of the String, in points (??).

getStringBounds

public static Rectangle2D getStringBounds(String str,
                                          Font font)
Get the bounds for a particular string, given the font.

Parameters:
str - The String whose bounds are needed.
font - The AWT Font which should be used to compute the bounds.
Returns:
The rectangle marking the bounds of the String, in points (??).

createLine

public static Element createLine(Document doc,
                                 float x,
                                 float y,
                                 float x2,
                                 float y2)
Create an SVG Line.

Parameters:
doc - The parent DOM.
x - The x coordinate of the start of the line, in points (??).
y - The y coordinate of the start of the line, in points (??).
x2 - The x coordinate of the end of the line, in points (??).
y2 - The y coordinate of the end of the line, in points (??).
Returns:
The DOM Element representing the line in SVG.

createEllipse

public static Element createEllipse(Document doc,
                                    float cx,
                                    float cy,
                                    float rx,
                                    float ry)
Create an SVG Ellipse.

Parameters:
doc - The parent DOM.
cx - The x coordinate of the center of the ellipse, in points (??).
cy - The y coordinate of the center of the ellipse, in points (??).
rx - The x radius of the ellipse, in points (??).
ry - The y radius of the ellipse, in points (??).
Returns:
The DOM Element representing the line in SVG.

createPath

public static Element createPath(Document doc,
                                 String str)
Create an SVG Path.

Parameters:
doc - The parent DOM.
str - The String containing the attributes of the path.
Returns:
The DOM Element representing the path in SVG.

createText

public static Element createText(Document doc,
                                 float x,
                                 float y,
                                 String str)
Create an SVG Text object.

Parameters:
doc - The parent DOM.
x - The x coordinate of the start of the text, in points (??).
y - The y coordinate of the start of the text, in points (??).
str - The text to be written.
Returns:
The DOM Element representing the text in SVG.

createRect

public static Element createRect(Document doc,
                                 float x,
                                 float y,
                                 float width,
                                 float height)
Create an SVG Rectangle.

Parameters:
doc - The parent DOM.
x - The x coordinate of the start of the rectangle, in points (??).
y - The y coordinate of the start of the rectangle, in points (??).
width - The width of the rectangle, in points (??).
height - The height of the rectangle, in points (??).
Returns:
The DOM Element representing the rectangle in SVG.

createG

public static Element createG(Document doc)
Create an SVG G (group) element.

Parameters:
doc - The parent DOM.
Returns:
The DOM Element representing the group in SVG.

createClip

public static Element createClip(Document doc,
                                 Element els,
                                 String id)
Create an SVG Clip.

Parameters:
doc - The parent DOM.
els - The elements to be clipped (??).
id - The "id" attribute for the clip.
Returns:
The DOM Element representing the clip in SVG.

createImage

public static Element createImage(Document doc,
                                  String ref,
                                  float width,
                                  float height)
Create an SVG Image.

Parameters:
doc - The parent DOM.
ref - The URL to the image.
width - The width, in pixels (??), of the image.
height - The height, in pixels (??), of the image.
Returns:
The DOM Element representing the image in SVG.

wrapText

public static Element wrapText(Document doc,
                               String str,
                               Font font,
                               float width)
Create some SVG text that is wrapped into a specified width.

Parameters:
doc - The parent DOM.
str - The text to be written.
font - The AWT font which should be used to write the text.
width - The constraining width into which the text should be made to fit.
Returns:
The DOM Element representing the text in SVG.


Copyright © 2017. All rights reserved.