// draw_post.java calls to generate a .ps postscript file // draw_post1 first call for setup output file // draw_post99 last call to finish output file // draw_post2 to draw line // draw_post3 to draw arc or circle // draw_post4 to draw text import java.io.*; import java.util.*; import java.text.*; public strictfp class draw_post { PrintWriter file_out; String filename; public void draw_post1(String filename) { // open for write System.out.println("drawpost writing "+filename); try { this.filename = filename; FileWriter fout = new FileWriter(filename); BufferedWriter b_fout = new BufferedWriter(fout); file_out = new PrintWriter(b_fout); file_out.print("%%!PS-Adobe-1.0\n"); file_out.print("/bdef {bind def} bind def \n"); file_out.print("/ldef {load def} bdef \n"); file_out.print("/n /newpath ldef \n"); file_out.print("/c /closepath ldef \n"); file_out.print("/l /lineto ldef \n"); file_out.print("/m /moveto ldef \n"); file_out.print("/s /setgray ldef \n"); file_out.print("/f /fill ldef \n"); file_out.print("/st /stroke ldef \n"); file_out.print("/sw /setlinewidth ldef \n"); file_out.print("newpath\n"); file_out.print("/Courier findfont\n"); file_out.print("12 scalefont setfont\n"); file_out.print(" 50 750 moveto (from "+filename+") show\n"); file_out.print("stroke\n"); } catch(FileNotFoundException exception) { System.out.println(filename+" not found"); } catch(Exception exception) // catches all exceptions { System.out.println("draw_post exception"); } } // end draw_post1 // draw line, thick=0.5 for thin, =1.0 for normal, =2.0 for thick public void draw_post2(Double x1, Double y1, Double x2, Double y2, Double thick) { file_out.print(thick+" setlinewidth\n"); file_out.print("newpath\n"); file_out.print(x1+" "+y1+" moveto\n"); file_out.print(x2+" "+y2+" lineto\n"); file_out.print("stroke\n"); // fprintf(PSU,"%4.2f sw n %6.2f %6.2f m %6.2f %6.2f l st\n", // thick, x1, y1, x2, y2); } // end draw_post2 // draw arc center x1,y1 from x2,y2 public void draw_post3(Double x1, Double y1, Double x2, Double y2, Double radius, Double ang1, Double ang2, Double thick) { // 1.00 setlinewidth // newpath // 98.00 636.00 moveto // 90.00 636.00 7.00 0 360 arc // stroke file_out.print(thick+" setlinewidth\n"); file_out.print("newpath\n"); file_out.print(x1+" "+y1+" moveto\n"); file_out.print(x2+" "+y2+" "+radius+" "+ang1+" "+ang2+" arc\n"); file_out.print("stroke\n"); } // end draw_post3 // draw text from x1,y1 string font_size public void draw_post4(Double x1, Double y1, String txt, Double fsize) { // newpath // /Courier findfont // 12.00 scalefont setfont // 178.00 331.00 moveto (equal6) show file_out.print("newpath\n"); file_out.print("/Courier findfont\n"); file_out.print(fsize+" scalefont setfont\n"); file_out.print(x1+" "+y1+" moveto ("+txt+") show\n"); file_out.print("stroke\n"); } // end draw_post4 // finish out file plotout.ps */ public void draw_post99() { file_out.print("showpage\n"); file_out.close(); System.out.println("finished writing "+filename); } /* end draw_post99 */ } // end draw_post.java