Package org.apache.fop.svg
Class SVGUtilities
- java.lang.Object
-
- org.apache.fop.svg.SVGUtilities
-
public final class SVGUtilities extends java.lang.Object
Some utilities for creating svg DOM documents and elements.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.w3c.dom.Element
createClip(org.w3c.dom.Document doc, org.w3c.dom.Element els, java.lang.String id)
Create an SVG Clip.static org.w3c.dom.Element
createEllipse(org.w3c.dom.Document doc, float cx, float cy, float rx, float ry)
Create an SVG Ellipsestatic org.w3c.dom.Element
createG(org.w3c.dom.Document doc)
Create an SVG G.static org.w3c.dom.Element
createImage(org.w3c.dom.Document doc, java.lang.String ref, float width, float height)
Create and svg image element.static org.w3c.dom.Element
createLine(org.w3c.dom.Document doc, float x, float y, float x2, float y2)
Create an SVG Linestatic org.w3c.dom.Element
createPath(org.w3c.dom.Document doc, java.lang.String str)
Create an SVG Path.static org.w3c.dom.Element
createRect(org.w3c.dom.Document doc, float x, float y, float width, float height)
Create an SVG Rectangle.static org.w3c.dom.Document
createSVGDocument(float width, float height)
Create a new svg document with batik.static org.w3c.dom.Element
createText(org.w3c.dom.Document doc, float x, float y, java.lang.String str)
Create an SVG Text object.static java.awt.geom.Rectangle2D
getStringBounds(java.lang.String str, java.awt.Font font)
Get the string bounds for a particular string given the font.static float
getStringHeight(java.lang.String str, java.awt.Font font)
Get the string height for a particular string given the font.static float
getStringWidth(java.lang.String str, java.awt.Font font)
Get the string width for a particular string given the font.static org.w3c.dom.Element
wrapText(org.w3c.dom.Document doc, java.lang.String str, java.awt.Font font, float width)
Create some SVG text that is wrapped into a specified width.
-
-
-
Method Detail
-
createSVGDocument
public static org.w3c.dom.Document createSVGDocument(float width, float height)
Create a new svg document with batik.- Parameters:
width
- the width of the root svg elementheight
- the height of the root svg element- Returns:
- a new SVG Document
-
getStringWidth
public static float getStringWidth(java.lang.String str, java.awt.Font font)
Get the string width for a particular string given the font.- Parameters:
str
- the stringfont
- the font- Returns:
- the width of the string in the given font
-
getStringHeight
public static float getStringHeight(java.lang.String str, java.awt.Font font)
Get the string height for a particular string given the font.- Parameters:
str
- the stringfont
- the font- Returns:
- the height of the string in the given font
-
getStringBounds
public static java.awt.geom.Rectangle2D getStringBounds(java.lang.String str, java.awt.Font font)
Get the string bounds for a particular string given the font.- Parameters:
str
- the stringfont
- the font- Returns:
- the bounds of the string
-
createLine
public static org.w3c.dom.Element createLine(org.w3c.dom.Document doc, float x, float y, float x2, float y2)
Create an SVG Line- Parameters:
doc
- the document to create the elementx
- the start x positiony
- the start y positionx2
- the end x positiony2
- the end y position- Returns:
- the new line element
-
createEllipse
public static org.w3c.dom.Element createEllipse(org.w3c.dom.Document doc, float cx, float cy, float rx, float ry)
Create an SVG Ellipse- Parameters:
doc
- the document to create the elementcx
- the centre x positioncy
- the centre y positionrx
- the x axis radiusry
- the y axis radius- Returns:
- the new ellipse element
-
createPath
public static org.w3c.dom.Element createPath(org.w3c.dom.Document doc, java.lang.String str)
Create an SVG Path.- Parameters:
doc
- the document to create the elementstr
- the string for the d attribute on the path- Returns:
- the new path element
-
createText
public static org.w3c.dom.Element createText(org.w3c.dom.Document doc, float x, float y, java.lang.String str)
Create an SVG Text object.- Parameters:
doc
- the document to create the elementx
- the start x positiony
- the start y positionstr
- the string- Returns:
- the new text element
-
createRect
public static org.w3c.dom.Element createRect(org.w3c.dom.Document doc, float x, float y, float width, float height)
Create an SVG Rectangle.- Parameters:
doc
- the document to create the elementx
- the start x positiony
- the start y positionwidth
- the width of the rectangleheight
- the height of the rectangle- Returns:
- the new rectangle element
-
createG
public static org.w3c.dom.Element createG(org.w3c.dom.Document doc)
Create an SVG G.- Parameters:
doc
- the document to create the element- Returns:
- the new g element
-
createClip
public static org.w3c.dom.Element createClip(org.w3c.dom.Document doc, org.w3c.dom.Element els, java.lang.String id)
Create an SVG Clip.- Parameters:
doc
- the document to create the elementels
- the child elements that make the clipid
- the id of the clipping path- Returns:
- the new clip element
-
createImage
public static org.w3c.dom.Element createImage(org.w3c.dom.Document doc, java.lang.String ref, float width, float height)
Create and svg image element.- Parameters:
doc
- the document to create the elementref
- the href link to the imagewidth
- the width to set on the imageheight
- the height to set on the image- Returns:
- a new image element
-
wrapText
public static org.w3c.dom.Element wrapText(org.w3c.dom.Document doc, java.lang.String str, java.awt.Font font, float width)
Create some SVG text that is wrapped into a specified width.- Parameters:
doc
- the document to create the elementsstr
- the string to wrapfont
- the fontwidth
- the width to wrap- Returns:
- the new element containing the wrapped text
-
-