Back to index

wims  3.65+svn20090927
SVGWriter.java
Go to the documentation of this file.
00001 package rene.util.xml;
00002 
00003 import java.io.FileOutputStream;
00004 import java.io.PrintWriter;
00005 
00006 public class SVGWriter extends XmlWriter
00007 {      int W,H;
00008 
00009        public SVGWriter(PrintWriter o, String enc, int w, int h)
00010        {      super(o);
00011               printEncoding(enc);
00012               W=w; H=h;
00013               startTagStart("svg");
00014               printArg("width",""+w);
00015               printArg("height",""+h);
00016               startTagEndNewLine();
00017        }
00018 
00019        public SVGWriter(PrintWriter o)
00020        {      super(o);
00021        }
00022        
00023        public void startSVG (int w, int h)
00024        {      printEncoding("utf-8");
00025               Out.println("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"");
00026               Out.println("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">");
00027               startTagStart("svg");
00028               printArg("xmlns","http://www.w3.org/2000/svg");
00029               printArg("width",""+w);
00030               printArg("height",""+h);
00031               startTagEndNewLine();
00032        }
00033        
00034        public void close ()
00035        {      endTag("svg");
00036               super.close();
00037        }
00038        
00039        public void coord (int x, int y)
00040        {      printArg("x",""+x);
00041               printArg("y",""+y);
00042        }
00043 
00044        public void text (String text, int x, int y)
00045        {      startTagStart("text");
00046               coord(x,y);
00047               startTagEnd();
00048               print(text);
00049               endTagNewLine("text");
00050        }
00051        
00052        public static void main (String args[])
00053               throws Exception
00054        {      SVGWriter out=new SVGWriter(
00055                      new PrintWriter(new FileOutputStream("test.svg")),
00056                      "",300,300);
00057               out.text("Hallo Welt",10,95);
00058               out.startTagStart("path");
00059               out.printArg("d","M 150 150 A 50 50 0 1 0 100 200");
00060               out.printArg("style","fill:none;stroke-width:1;stroke:black");
00061               out.finishTagNewLine();
00062               out.close();
00063        }
00064 }