Annotation of researchv10no/cmd/map/plotPS.c, revision 1.1.1.1

1.1       root        1: /* Map-plotting functions for PostScript */
                      2: #include "plot.h"
                      3: 
                      4: static double _a,_b,_c,_d, _ox, _oy; 
                      5: static int anystroke = 0;
                      6: static char *fontname = "/Times-Roman";
                      7: static int fontsize = 10;
                      8: 
                      9: #define xs(_x) (_ox = _a*(_x)+_b)
                     10: #define ys(_y) (_oy = _c*(_y)+_d)
                     11: 
                     12: void
                     13: space(int xmin, int ymin, int xmax, int ymax)
                     14: {
                     15:        _a = 6.5*72/(xmax-xmin);
                     16:        _b = -_a*xmin + 1.0*72;
                     17:        _c = 6.5*72/(ymax-ymin);
                     18:        _d = -_c*ymin + 3.5*72;
                     19: }
                     20: 
                     21: 
                     22: /* open the plotting output */
                     23: void
                     24: erase(void)
                     25: {
                     26:        printf("%%!PS\n"
                     27:                "%%Creator: map\n"
                     28:                "%%BoundingBox: 72 252 540 720\n"
                     29:                "%%EndComments\n"
                     30:                "/m /moveto load def\n"
                     31:                "/s /stroke load def\n"
                     32:                "/t {moveto show} bind def\n"
                     33:                "/v /lineto load def\n"
                     34:                "%%EndProlog\n"
                     35:                "gsave\n"
                     36:                "/Helvetica findfont 10 scalefont setfont\n"
                     37:                "1 setlinecap\n"
                     38:                "1 setlinejoin\n"
                     39:                ".5 setlinewidth\n");
                     40:        printf("%s findfont\n"
                     41:                "/scale %d def\n"
                     42:                "scale scalefont\n"
                     43:                "setfont\n", fontname, fontsize);
                     44:        printf("newpath\n"
                     45:                "72 72 m\n");
                     46:        anystroke = 1;
                     47: }
                     48: 
                     49: /* close the plotting output */
                     50: void
                     51: closepl(void)
                     52: {
                     53:        printf("showpage\ngrestore\n");
                     54: }
                     55: 
                     56: /* make sure the page or screen is clear */
                     57: void
                     58: openpl(void)
                     59: {
                     60:        anystroke = 0;
                     61: }
                     62: 
                     63: /* plot a point at _x,_y, which becomes current */
                     64: void
                     65: point(int _x, int _y)
                     66: {
                     67:        move(_x, _y);
                     68:        cont(_x, _y);
                     69: }
                     70: 
                     71: /* place text, first letter at current point, which does not change */
                     72: void
                     73: label(char *_s)
                     74: {
                     75:        if(anystroke)
                     76:                printf("s\n");
                     77:        printf("(%s) %.1f %.1f scale .3 mul sub t\n",_s,_ox,_oy);
                     78:        anystroke = 0;
                     79: }
                     80: 
                     81: /* draw line from current point to _x,_y, which becomes current */
                     82: void
                     83: cont(int _x, int _y)
                     84: {
                     85:        printf("%.1f %.1f v\n", xs(_x),ys(_y));
                     86:        anystroke = 1;
                     87: }
                     88: 
                     89: /* _x,_y becomes current point */
                     90: void
                     91: move(int _x, int _y)
                     92: {
                     93:        if(anystroke)
                     94:                printf("s\n");
                     95:        printf("%.1f %.1f m\n", xs(_x), ys(_y));
                     96:        anystroke = 1;
                     97: }
                     98: 
                     99: struct dashpat {
                    100:        char *name;
                    101:        char *pat;
                    102:        double width;
                    103: } pattern[] = {
                    104:        "solid", "[] 0", 0.5,
                    105:        "dotted", "[3 6] 0", 0,
                    106:        "dotdash", "[18 6 3 6] 0", .5,
                    107: };
                    108: 
                    109: /* specify style for drawing lines: "dotted", "solid", "dotdash" */
                    110: void
                    111: linemod(char *s)
                    112: {
                    113:        int i;
                    114:        for(i=0; i<sizeof(pattern)/sizeof(*pattern); i++)
                    115:                if(strcmp(s,pattern[i].name) == 0)
                    116:                        break;
                    117:        if(i >= sizeof(pattern)/sizeof(*pattern))
                    118:                i = 0;
                    119:        if(anystroke)
                    120:                printf("s\n");
                    121:        printf("%f setlinewidth\n%s setdash\n",
                    122:                pattern[i].width, pattern[i].pat);
                    123:        anystroke = 0;
                    124: }
                    125: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.