Annotation of researchv9/jtools/src/Jpic/pltroff.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *     jerq driver
                      3:  */
                      4: 
                      5: #include <stdio.h>
                      6: #include <math.h>
                      7: #include "y.tab.h"
                      8: #include "pic.h"
                      9: 
                     10: 
                     11: #define        abs(n)  (n >= 0 ? n : -(n))
                     12: #define        PI      3.141592654
                     13: #define        PI2     PI/2
                     14: 
                     15: extern int     res;
                     16: extern int     DX;     /* step size in x */
                     17: extern int     DY;     /* step size in y */
                     18: 
                     19: extern float   hshift; /* how much to move left by for text */
                     20: extern float   vshift; /* how much down */
                     21: 
                     22: /* scaling stuff, specific to typesetter */
                     23: /* defined by s command as X0,Y0 to X1,Y1 */
                     24: /* output dimensions set by -l,-w options to 0,0 to hmax, vmax */
                     25: /* default output is 6x6 inches */
                     26: 
                     27: float  xscale;
                     28: float  yscale;
                     29: 
                     30: int    hpos    = 0;    /* current horizontal position in output coordinate system */
                     31: int    vpos    = 0;    /* current vertical position; 0 is top of page */
                     32: 
                     33: int    X0, Y0;         /* left bottom of input */
                     34: int    X1, Y1;         /* right top of input */
                     35: #define        CX      0       /* center of jerq screen */
                     36: #define        CY      0
                     37: #define        JERQRES 81
                     38: 
                     39: int    hmax;           /* right end of output */
                     40: int    vmax;           /* top of output (down is positive) */
                     41: 
                     42: extern float   deltx;
                     43: extern float   delty;
                     44: extern int     xmin, ymin, xmax, ymax, sxmin, symin, sxmax, symax;
                     45: extern int     crop;
                     46: 
                     47: openpl(s)      /* initialize device */
                     48: char *s;       /* residue of .PS invocation line */
                     49: {
                     50:        hpos = vpos = 0;
                     51:        res = JERQRES;
                     52:        if (delty == 0)
                     53:                delty = deltx;  /* -w alone implies -s */
                     54:        hmax = vmax = 8 * res;  /* default = 8 x 8 */
                     55:        if (deltx > 0 && delty > 0) {   /* have to change default size */
                     56:                if (deltx < 9)  /* assume inches were specified */
                     57:                        hmax = res * deltx;
                     58:                else
                     59:                        hmax = res * 9;
                     60:                if (deltx < 9)  /* assume inches were specified */
                     61:                        vmax = res * delty;
                     62:                else
                     63:                        vmax = res * 9;
                     64:        }
                     65:        if (crop) {
                     66:                if (xmax == xmin)
                     67:                        space(xmin, ymin, xmin + ymax-ymin, ymax);
                     68:                else
                     69:                        space(xmin, ymin, xmax, ymin + xmax-xmin);      /* assumes 1:1 aspect ratio */
                     70:        }
                     71:        else
                     72:                space(sxmin, symin, sxmax, symax);
                     73:        printf("... %d %d %d %d %d %d %d %d\n",
                     74:                (xmin), (ymin), (xmax), (ymax),
                     75:                (sxmin), (symin), (sxmax), (symax));
                     76:        printf("... %du %du %du %du %du %du %du %du\n",
                     77:                xconv(xmin), yconv(ymin), xconv(xmax), yconv(ymax),
                     78:                xconv(sxmin), yconv(symin), xconv(sxmax), yconv(symax));
                     79:        printf(".PS %d %d %s", yconv(ymin), xconv(xmax), s);
                     80:                /* assumes \n comes as part of s */
                     81:        erase();
                     82: }
                     83: 
                     84: closepl(type)  /* clean up after finished */
                     85: {
                     86:        printf("S\n");
                     87: }
                     88: 
                     89: move(x, y)     /* go to position x, y in external coords */
                     90: int x, y;
                     91: {
                     92:        hgoto(xconv(x));
                     93:        vgoto(yconv(y));
                     94: }
                     95: 
                     96: movehv(h, v)   /* go to internal position h, v */
                     97: int h, v;
                     98: {
                     99:        hgoto(h);
                    100:        vgoto(v);
                    101: }
                    102: 
                    103: hmot(n)        /* generate n units of horizontal motion */
                    104: int n;
                    105: {
                    106:        hpos += n;
                    107: }
                    108: 
                    109: vmot(n)        /* generate n units of vertical motion */
                    110: int n;
                    111: {
                    112:        vpos += n;
                    113: }
                    114: 
                    115: hgoto(n)
                    116: {
                    117:        hpos = n;
                    118: }
                    119: 
                    120: vgoto(n)
                    121: {
                    122:        vpos = n;
                    123: }
                    124: 
                    125: hvflush()      /* get to proper point for output */
                    126: {
                    127:        printf("m %d %d\n", hpos, vpos);
                    128: }
                    129: 
                    130: troff(s)       /* output troff right here */
                    131: char *s;
                    132: {
                    133:        printf("%s\n", s);
                    134: }
                    135: 
                    136: label(s, t, nh)        /* text s of type t nh half-lines up */
                    137: char *s;
                    138: int t, nh;
                    139: {
                    140:        int x0, y0, x1, y1;
                    141:        int q;
                    142:        char *p;
                    143: 
                    144:        if (t == 'A')
                    145:                nh++;
                    146:        else if (t == 'B')
                    147:                nh--;
                    148:        vpos += nh * 10;        /* approx 1/2 line */
                    149:        switch (t) {
                    150:        default:
                    151:                t = ' ';
                    152:                /* FALL THROUGH */
                    153:        case 'L':
                    154:        case 'A':
                    155:        case 'B':
                    156:        case 'C':
                    157:        case 'R':
                    158:                printf("t %d %d %c%s\n", hpos, vpos, t, s);
                    159:                break;
                    160:        }
                    161: }
                    162: 
                    163: /* line(x0, y0, x1, y1)        /* draw line from x0,y0 to x1,y1 */
                    164: /* int x0, y0, x1, y1;
                    165: /* {
                    166: /*     printf("l %d %d %d %d\n", xconv(x0), yconv(y0), xconv(x1), yconv(y1));
                    167: /* }
                    168: */
                    169: 
                    170: arrow(x0, y0, x1, y1, w, h)    /* draw arrow (without line), head wid w & len h */
                    171: {
                    172:        double alpha, rot, hyp;
                    173:        int dx, dy;
                    174:        extern int dbg;
                    175: 
                    176:        rot = atan2( ((double) w) / 2, (double) h );
                    177:        hyp = sqrt( (float) (w/2 * w/2 + h * h) );
                    178:        alpha = atan2((float)(y1-y0), (float)(x1-x0));
                    179:        if (dbg)
                    180:                printf("rot=%f, hyp=%f, alpha=%f\n", rot, hyp, alpha);
                    181:        dx = hyp * cos(alpha + PI + rot) + 0.5;
                    182:        dy = hyp * sin(alpha + PI + rot) + 0.5;
                    183:        if (dbg) printf("dx,dy = %d,%d\n", dx, dy);
                    184:        /* line(x1+dx, y1+dy, x1, y1); */
                    185:        printf("l 2 %d %d %d %d\n",
                    186:                xconv(x1+dx), yconv(y1+dy), xconv(x1), yconv(y1));
                    187:        dx = hyp * cos(alpha + PI - rot) + 0.5;
                    188:        dy = hyp * sin(alpha + PI - rot) + 0.5;
                    189:        if (dbg) printf("dx,dy = %d,%d\n", dx, dy);
                    190:        /* line(x1+dx, y1+dy, x1, y1); */
                    191:        printf("l 2 %d %d %d %d\n",
                    192:                xconv(x1+dx), yconv(y1+dy), xconv(x1), yconv(y1));
                    193: }
                    194: 
                    195: box(x0, y0, x1, y1, dotdash, ddval)
                    196: {
                    197:        printf("b");
                    198:        if (dotdash == DOT)
                    199:                printf(". %d", xsc(ddval));
                    200:        else if (dotdash == DASH)
                    201:                printf("- %d", xsc(ddval));
                    202:        printf(" %d %d %d %d\n", xconv(x0), yconv(y0), xconv(x1), yconv(y1));
                    203: }
                    204: 
                    205: circle(x, y, r)
                    206: {
                    207:        printf("c %d %d %d\n", hpos = xconv(x), vpos = yconv(y), xsc(r));
                    208: }
                    209: 
                    210: spline(x, y, n, p, head)
                    211:        int x, y, n, *p, head;
                    212: {
                    213:        int i, j, dx, dy;
                    214: 
                    215:        printf("~ ");
                    216:        if (head & HEAD1)
                    217:                printf("<");
                    218:        if (head & HEAD2)
                    219:                printf(">");
                    220:        printf(" %d %d %d", n+1, hpos = xconv(x), vpos = yconv(y));
                    221:        for (i = 0; i < 2 * n; i += 2) {
                    222:                x += p[i];
                    223:                y += p[i+1];
                    224:                printf(" %d %d", xconv(x), yconv(y));
                    225:        }
                    226:        printf("\n");
                    227: }
                    228: 
                    229: line(x, y, n, p, head, dotdash, ddval)
                    230:        int x, y, n, *p, head;
                    231:        int dotdash, ddval;
                    232: {
                    233:        int i, j, dx, dy;
                    234: 
                    235:        printf("l ");   /* a line */
                    236:        if (head & HEAD1)
                    237:                printf("<");
                    238:        if (head & HEAD2)
                    239:                printf(">");
                    240:        if (dotdash == DOT)
                    241:                printf(". %d", xsc(ddval));
                    242:        else if (dotdash == DASH)
                    243:                printf("- %d", xsc(ddval));
                    244:        printf(" %d %d %d", n+1, hpos = xconv(x), vpos = yconv(y));
                    245:        for (i = 0; i < 2 * n; i += 2) {
                    246:                x += p[i];
                    247:                y += p[i+1];
                    248:                printf(" %d %d", xconv(x), yconv(y));
                    249:        }
                    250:        printf("\n");
                    251: }
                    252: 
                    253: 
                    254: ellipse(x, y, r1, r2)
                    255: {
                    256:        r1 = xsc(r1);
                    257:        r2 = ysc(r2);
                    258:        printf("e %d %d %d %d\n", xconv(x), yconv(y), abs(r1), abs(r2));
                    259: }
                    260: 
                    261: arc(x, y, x0, y0, x1, y1)      /* draw arc with center x,y */
                    262: {
                    263:        float r;
                    264:        float dx2, dy2, phi, ht, d;
                    265:        int cx, cy;
                    266: 
                    267:        r = sqrt( (float) (x0-x) * (x0-x) + (float) (y0-y) * (y0-y) );
                    268:        /* decide which radius is really needed: */
                    269:        dx2 = (float)(x1 - x0) / 2;
                    270:        dy2 = (float)(y1 - y0) / 2;
                    271:        phi = atan2(dy2, dx2) + PI2;
                    272:        ht = sqrt(r*r - (dx2*dx2 + dy2*dy2));
                    273:        cx = x0 + dx2 + ht * cos(phi) + 0.5;
                    274:        cy = y0 + dy2 + ht * sin(phi) + 0.5;
                    275:        if (abs(cx-x) >= 5 || abs(cy-y) >= 5)
                    276:                r = -r; /* wrong center was picked */
                    277:        printf("a %d %d %d %d %d %d\n", xconv(x), yconv(y),
                    278:                xconv(x0), yconv(y0), xconv(x1), yconv(y1));
                    279: }
                    280: 
                    281: erase()        /* get to bottom of frame */
                    282: {
                    283:        printf("E\n");
                    284:        fflush(stdout);
                    285: }
                    286: 
                    287: point(x, y)    /* put point at x,y */
                    288: int x, y;
                    289: {
                    290:        static char *temp = ".";
                    291: 
                    292:        move(x, y);
                    293:        label(temp, 'L');
                    294: }
                    295: 
                    296: space(x0, y0, x1, y1)  /* set limits of page */
                    297: int x0, y0, x1, y1;
                    298: {
                    299:        if (x0 == x1)
                    300:                x1 = x0 + 1;
                    301:        if (y0 == y1)
                    302:                y1 = y0 - 1;    /* kludge */
                    303:        X0 = x0;
                    304:        Y0 = y0;
                    305:        X1 = x1;
                    306:        Y1 = y1;
                    307:        xscale = (float) hmax / (float) (X1-X0);
                    308:        yscale = (float) vmax / (float) (Y0-Y1);
                    309: }
                    310: 
                    311: xconv(x)       /* convert x from external to internal form */
                    312: int x;
                    313: {
                    314:        int v;
                    315: 
                    316:        v = (x-X0) * xscale + 0.5;
                    317:        return v + CX;
                    318: }
                    319: 
                    320: xsc(x) /* convert x from external to internal form, scaling only */
                    321: int x;
                    322: {
                    323:        int v;
                    324: 
                    325:        v = (x) * xscale + 0.5;
                    326:        return v;
                    327: }
                    328: 
                    329: yconv(y)       /* convert y from external to internal form */
                    330: int y;
                    331: {
                    332:        int v;
                    333: 
                    334:        y += Y1 - ymax;
                    335:        v = (y-Y1) * yscale + 0.5;
                    336:        return v + CY;
                    337: }
                    338: 
                    339: ysc(y) /* convert y from external to internal form, scaling only */
                    340: int y;
                    341: {
                    342:        int v;
                    343: 
                    344:        v = (y) * yscale + 0.5;
                    345:        return v;
                    346: }
                    347: 
                    348: linemod(s)
                    349: char *s;
                    350: {
                    351: }
                    352: 
                    353: dot() {
                    354:        hvflush();
                    355:        printf("tc.\n");
                    356: }

unix.superglobalmegacorp.com

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