public class SVGUtil extends Object
Mainly to keep the footprint small only a very limited set of SVG functionality is supported. In case more features are required have a look at Batik - Java SVG Toolkit.
Example
String s = doc(svg( 160, 200, rect(0, 0, 160, 200, "fill:red;") + svg(10, 10, 100, 100, rect(0, 0, 100, 100, "fill:orange; stroke:rgb(0,0,0);")) + line(20, 20, 100, 100, "stroke:black; stroke-width:2px;") + line(20, 100, 100, 20, "stroke:black; stroke-width:2px;") + text(10, 140, "font-family:verdana; font-size:20px; font-weight:bold;", "Hello world"))); File file = new File("demo.svg"); FileWriter w = null; try { w = new FileWriter(file); w.write(s); } finally { if (w != null) { w.close(); } }(see
main(String[])
)
Constructor and Description |
---|
SVGUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
doc(String content) |
static String |
line(Number x1,
Number y1,
Number x2,
Number y2,
String style) |
static String |
line(String x1,
String y1,
String x2,
String y2,
String style) |
static void |
main(String[] args)
Creates a sample SVG file "demo.svg"
|
static String |
rect(Number x,
Number y,
Number width,
Number height,
String style) |
static String |
rect(Number x,
Number y,
Number width,
Number height,
String style,
String extraAttributes) |
static String |
rect(String x,
String y,
String width,
String height,
String style) |
static String |
rect(String x,
String y,
String width,
String height,
String style,
String extraAttributes) |
static String |
svg(Number x,
Number y,
Number width,
Number height,
String content) |
static String |
svg(Number width,
Number height,
String content) |
static String |
svg(String width,
String height,
String content) |
static String |
svg(String x,
String y,
String width,
String height,
String content) |
static String |
text(Number x,
Number y,
String style,
String text) |
static String |
text(String x,
String y,
String style,
String text) |
public static String rect(String x, String y, String width, String height, String style, String extraAttributes)
x
- y
- width
- height
- style
- extraAttributes
- [default:""]public static String rect(Number x, Number y, Number width, Number height, String style, String extraAttributes)
x
- y
- width
- height
- style
- extraAttributes
- [default:""]public static void main(String[] args) throws IOException
args
- option '-view': view the just created file
(may not be supported on all platforms)IOException
- Copyright © 2019. All Rights Reserved.