added some results
[tridge/junkcode.git] / pscript.c
1 /* Here is an implementation of these routines for
2    output to Postscript files */
3
4
5
6 FILE *outfile;
7
8 #define PTS_PER_INCH 72
9 #define P_SCALE_X 0.5
10 #define P_SCALE_Y 0.5
11 #define PAGE_WIDTH 8 /* inches */
12 #define PAGE_HEIGHT 8 /* inches */
13 #define P_MAXX ((int)(PAGE_WIDTH*PTS_PER_INCH/P_SCALE_X))
14 #define P_MAXY ((int)(PAGE_HEIGHT*PTS_PER_INCH/P_SCALE_Y))
15 #define P_ORIGIN_X 0
16 #define P_ORIGIN_Y 100
17 #define P_LINE_WIDTH 1.0
18 #define P_FONT "Courier-Bold"
19 #define P_FONT_SIZE 12
20 #define P_FONT_WIDTH (36.0*P_FONT_SIZE/60)
21 #define P_LINE_CAP 0
22 #define P_MAC1 "/x { moveto } def"
23 #define P_MAC2 "/y { lineto } def"
24 #define P_MAC3 "/z { stroke } def"
25
26
27
28 void start_graphics()
29 {
30 /* Start it going */
31         outfile = stdout;
32         fprintf(outfile,"%c!\ninitgraphics\n",'%');
33 /* Setup scaling etc. */
34         fprintf(outfile,"%-4.2f %-4.2f scale\n",P_SCALE_X,P_SCALE_Y);
35         fprintf(outfile,"%d %d translate\n",P_ORIGIN_X,P_ORIGIN_Y);
36 /* Define some macros */
37         fprintf(outfile,"%s\n%s\n%s\n",P_MAC1,P_MAC2,P_MAC3);
38 /* Default text size etc. */
39         fprintf(outfile,"/%s findfont\n",P_FONT);
40         fprintf(outfile,"%d scalefont\n",(int)(P_FONT_SIZE/P_SCALE_X));
41         fprintf(outfile,"setfont\n");
42 /* Default line width, style etc. */
43         fprintf(outfile,"%-3.1f setlinewidth\n",P_LINE_WIDTH);
44         fprintf(outfile,"%d setlinecap\n",P_LINE_CAP);
45         fprintf(outfile,"[] 0 setdash\n");
46 }
47
48 void end_graphics()
49 {
50 /* display it */
51         fprintf(outfile,"showpage\n");
52 /* close file */
53 /*      fclose(outfile);*/
54 }
55
56 int get_maxx()
57 {
58         return(P_MAXX);
59 }
60
61 int get_maxy()
62 {
63         return(P_MAXY);
64 }
65
66 int new_y(y)
67 int y;
68 /* Flip in Y direction to make origin in bottom left */
69 {
70         return(get_maxy()-y);
71 }
72
73 void draw_line(x1,y1,x2,y2)
74 int x1,y1,x2,y2;
75 {
76         fprintf(outfile,"%d %d x %d %d y z\n",x1,new_y(y1),x2,new_y(y2));
77 }
78
79 int descender()
80 /* Height of descender */
81 {
82         return(char_height()/3);
83 }
84
85 void graph_text(x,y,str)
86 int x,y;
87 char *str;
88 {
89         fprintf(outfile,"%d %d x (%s) show\n",x,new_y(y)+descender(),str);
90 }
91
92 void choose_line_type(type)
93 int type;
94 {
95 char *dashing;
96 double width;
97 int index;
98 index = type % 6;
99 switch (index)
100 {
101         case 0 : dashing="[] 0"; width=1.2; break;
102         case 1 : dashing="[6] 0"; width=1.2; break;
103         case 2 : dashing="[4] 1"; width=1.2; break;
104         case 3 : dashing="[] 0"; width=1.8; break;
105         case 4 : dashing="[6] 0"; width=1.8; break;
106         case 5 : dashing="[4] 1"; width=1.8; break;
107 }
108         fprintf(outfile,"%-3.1f setlinewidth\n",
109                 width*P_LINE_WIDTH);
110         fprintf(outfile,"%s setdash\n",dashing);
111
112 }
113
114 void wait_for_end()
115 {
116 }
117
118 int char_width()
119 {
120         return((int)(P_FONT_WIDTH/P_SCALE_X));
121 }
122
123 int char_height()
124 {
125         return((int)(P_FONT_SIZE/P_SCALE_Y));
126 }
127
128 /* End of PostScript specific routines */
129