# #----------------------------to_ps.awk-------------------------------------- # # usage: # awk -f to_ps.awk dvi_file > ps_file # # where dvi_file consists of Taylor's device-independent commands # for line graphics. (With a further command `d' for dot.) # # Then ps_file will be valid PostScript code. # # This is designed to work like my to_ps.c; I have not gone to the # trouble of giving all the error messages of to_ps.c. This code # is very similar to that --- in fact I made it by fiddling with # that code --- but in some ways it is more compact and readable. # Therefore, some students may find it useful as a model for making # translators. Could be applied, for example, to make a Bezier curve # plotter. # # An interesting way to `improve' this would be to add ps defs of # the frequently encountered strings. # BEGIN{ ok_to_draw_line=0 # initialize window coordinates: LL_x = 0.0; LL_y = 0.0; UR_x = 1.0; UR_y = 1.0; # begin output with %!, as required for # PostScript printers: printf("%%!\n") } {q_x=p_x; q_y=p_y} #save old p-values /^%/ #print any line beginning with % # # From now on, commands depend on the # first character of a line: # /^t/{fontsize = 8} /^x/{fontsize = 10} /^T/{fontsize = 14} /^t/||/^x/||/^T/ { printf "/Times-Roman findfont %d scalefont setfont\n" , fontsize printf "(" printf "%s", substr($0,2,length-1) printf ") show\n" } /^r/ {r_x=$2 ; r_y=$3 ; s_x=$4; s_y=$5 r_x = (r_x-LL_x) / (UR_x-LL_x); r_y = (r_y-LL_y) / (UR_y-LL_y); s_x = (s_x-LL_x) / (UR_x-LL_x); s_y = (s_y-LL_y) / (UR_y-LL_y);} /^w/ {LL_x=$2 ; LL_y=$3 ; UR_x=$4; UR_y=$5 } /^m/ { p_x=$2 ; p_y=$3 ; p_x = (p_x-LL_x) / (UR_x-LL_x); p_y = (p_y-LL_y) / (UR_y-LL_y); ok_to_draw_line = 1; i = (p_x * 72)*8.5; j = ((p_y * 8.5) + 2.5) *72; if (i>0.0 && j>0.0 && i<612.0 && j<792.0) { printf "%4.1f %4.1f moveto\n" ,i,j }} /^l/ { p_x=$2 ; p_y=$3 ; p_x = (p_x-LL_x) / (UR_x-LL_x); p_y = (p_y-LL_y) / (UR_y-LL_y); i = (p_x * 72)*8.5; j = ((p_y * 8.5) + 2.5) *72; ii = (q_x * 72)*8.5; jj = ((q_y * 8.5) + 2.5) *72; if (i>0.0 && j>0.0 && i<612.0 && j<792.0) { printf "newpath\n" printf "%4.1f %4.1f moveto\n" ,ii,jj printf "%4.1f %4.1f lineto\n" ,i,j printf "stroke\n" }} /^W/ { x = ($2)*(72.0/300.0); printf "%3.1f setlinewidth\n",x } /^d/ { p_x=$2 ; p_y=$3 ; p_x = (p_x-LL_x) / (UR_x-LL_x); p_y = (p_y-LL_y) / (UR_y-LL_y); i = (p_x * 72)*8.5; j = ((p_y * 8.5) + 2.5) *72; k = (($4 * 8.5)+0.0)*72; printf("newpath\n"); printf("%4.1f %4.1f moveto ",i,j,k); printf("%4.1f %4.1f %4.1f 0 360 arc fill stroke\n",i,j,k); } END{ printf "showpage\n" }