// SimplePostscript v.09 // Simple Java library for outputting Postscript graphics. // See // http://process.unlekker.net/SimplePostscript/ // // Marius Watz - www.unlekker.net import java.io.*; public class SimplePostscript extends FileWriter { public SimplePostscript(String filename) throws IOException { super(filename); } public static SimplePostscript open(String filename, float x1,float y1, float x2,float y2) { System.out.println("SimplePostscript.open()"); SimplePostscript ps=null; try { ps=new SimplePostscript(filename); ps.println("%!PS-Adobe-3.0 EPSF-3.0\n%%Creator: SimplePostscript\n"); ps.println("%%BoundingBox: "+fmt(x1)+" "+fmt(y1)+" "+fmt(x2)+" "+fmt(y2)); ps.println("%%HiResBoundingBox: "+fmt(x1)+" "+fmt(y1)+" "+fmt(x2)+" "+fmt(y2)); } catch (Exception e) { System.out.println("Exception opening file: "+filename); } return ps; } public void setlinewidth(float w) { println(fmt(w) + " setlinewidth"); } public void setlinejoin(int c) { println(fmt(c) + " setlinejoin"); } public void setlinecap(int c) { println(fmt(c) + " setlinecap"); } public void setdash(String str) { println(str + " setdash"); } public void setgray(float g) { println(fmt(g) + " setgray"); } public void setcmyk(float c,float m,float y,float k) { println(fmt(c) + " " + fmt(m) + " " + fmt(y) + " " + fmt(k) + " setcmykcolor"); } public void setrgb(int r,int g,int b) { println(fmt((float)r/255) + " " + fmt((float)g/255) + " " + fmt((float)b/255) + " setrgbcolor"); } public void setfont(String fontname) { println("/"+fontname+" findfont setfont"); } public void setfont(String fontname,float pt) { println("/"+fontname+" findfont "+fmt(pt)+" scalefont setfont"); } public void moveto(float x,float y) { println(fmt(x)+" "+fmt(y)+" moveto"); } public void lineto(float x,float y) { println(fmt(x)+" "+fmt(y)+" lineto"); } public void rect(float x1,float y1,float x2,float y2) { moveto(x1,y1); lineto(x2,y1); lineto(x2,y2); lineto(x1,y2); lineto(x1,y1); } public void arc(float x,float y,float rad,float deg1,float deg2) { println(fmt(x)+" "+" "+fmt(y)+" "+ fmt(rad)+" "+fmt(deg1)+" "+ fmt(deg2)+" arc"); } public void arcNegative(float x,float y,float rad,float deg1,float deg2) { println(fmt(x)+" "+" "+fmt(y)+" "+ fmt(rad)+" "+fmt(deg1)+" "+ fmt(deg2)+" arcn"); } public void circle(float x,float y,float rad) { moveto(x+rad,y); arc(x,y,rad,0,360); } public void curveto( float x1,float y1, float x2,float y2, float x3,float y3) { println(""+fmt(x1)+" "+fmt(y1)+" "+ fmt(x2)+" "+fmt(y2)+" "+ fmt(x3)+" "+fmt(y3)+" curveto"); } public void fill() { println("fill"); } public void fillclosepath() { println("closepath fill"); } public void stroke() { println("stroke"); } public void strokeclosepath() { println("closepath stroke"); } public void fillstroke() { gsave(); stroke(); grestore(); fill(); } public void fillstrokeclosepath() { gsave(); strokeclosepath(); grestore(); fillclosepath(); } public void rotate(float deg) { println(fmt(deg)+" rotate"); } public void scale(float x,float y) { println(fmt(x)+" "+fmt(y)+" scale"); } public void translate(float x,float y) { println(fmt(x)+" "+fmt(y)+" translate"); } public void gsave() { println("gsave"); } public void grestore() { println("grestore"); } public void text(float x,float y,String s) { if(emptyString(s)) return; moveto(x,y); println("("+formatString(s)+") show"); } public void println(String s) { try {write(s+"\n");} catch(IOException e) {System.out.println("IOException!");} } public void print(String s) { try {write(s);} catch(IOException e) {System.out.println("IOException!");} } private static String fmt(float f) { double m=Math.pow(10,3); f=Math.round(f*m); f/=m; return ""+f; } private String formatString(String str) { String s,dummy; char c; int i; s=""; for(i=0; i