char *textshift = "\\v'.2m'"; /* move text this far down */
/* scaling stuff defined by s command as X0,Y0 to X1,Y1 */
/* output dimensions set by -l,-w options to 0,0 to hmax, vmax */
/* default output is 6x6 inches */
double xscale;
double yscale;
double hpos = 0; /* current horizontal position in output coordinate system */
double vpos = 0; /* current vertical position; 0 is top of page */
double htrue = 0; /* where we really are */
double vtrue = 0;
double X0, Y0; /* left bottom of input */
double X1, Y1; /* right top of input */
double hmax; /* right end of output */
double vmax; /* top of output (down is positive) */
double xconv(double x) /* convert x from external to internal form */
{
return (x-X0) * xscale;
}
double xsc(double x) /* convert x from external to internal form, scaling only */
{
return (x) * xscale;
}
double yconv(double y) /* convert y from external to internal form */
{
return (Y1-y) * yscale;
}
double ysc(double y) /* convert y from external to internal form, scaling only */
{
return (y) * yscale;
}
void closepl(char *PEline) /* clean up after finished */
{
movehv(0.0, 0.0); /* get back to where we started */
if (strchr(PEline, 'F') == NULL) {
printf(".sp 1+%.3fi\n", yconv(ymin));
}
printf("%s\n", PEline);
printf(".if \\n(00 .fi\n");
}
void move(double x, double y) /* go to position x, y in external coords */
{
hgoto(xconv(x));
vgoto(yconv(y));
}
void movehv(double h, double v) /* go to internal position h, v */
{
hgoto(h);
vgoto(v);
}
void hmot(double n) /* generate n units of horizontal motion */
{
hpos += n;
}
void vmot(double n) /* generate n units of vertical motion */
{
vpos += n;
}
void hgoto(double n)
{
hpos = n;
}
void vgoto(double n)
{
vpos = n;
}
double fabs(double x)
{
return x < 0 ? -x : x;
}
void hvflush(void) /* get to proper point for output */
{
if (fabs(hpos-htrue) >= 0.0005) {
printf("\\h'%.3fi'", hpos - htrue);
htrue = hpos;
}
if (fabs(vpos-vtrue) >= 0.0005) {
printf("\\v'%.3fi'", vpos - vtrue);
vtrue = vpos;
}
}
void flyback(void) /* return to upper left corner (entry point) */
{
printf(".sp -1\n");
htrue = vtrue = 0;
}
void printlf(int n, char *f)
{
if (f)
printf(".lf %d %s\n", n, f);
else
printf(".lf %d\n", n);
}
void troff(char *s) /* output troff right here */
{
printf("%s\n", s);
}
void label(char *s, int t, int nh) /* text s of type t nh half-lines up */
{
int q;
char *p;
if (!s)
return;
hvflush();
dprintf("label: %s %o %d\n", s, t, nh);
printf("%s", textshift); /* shift down and left */
if (t & ABOVE)
nh++;
else if (t & BELOW)
nh--;
if (nh)
printf("\\v'%du*\\n(.vu/2u'", -nh);
/* just in case the text contains a quote: */
q = 0;
for (p = s; *p; p++)
if (*p == '\'') {
q = 1;
break;
}
t &= ~(ABOVE|BELOW);
if (t & LJUST) {
printf("%s", s);
} else if (t & RJUST) {
if (q)
printf("\\h\\(ts-\\w\\(ts%s\\(tsu\\(ts%s", s, s);
else
printf("\\h'-\\w'%s'u'%s", s, s);
} else { /* CENTER */
if (q)
printf("\\h\\(ts-\\w\\(ts%s\\(tsu/2u\\(ts%s", s, s);
else
printf("\\h'-\\w'%s'u/2u'%s", s, s);
}
printf("\n");
flyback();
}
void line(double x0, double y0, double x1, double y1) /* draw line from x0,y0 to x1,y1 */
{
move(x0, y0);
cont(x1, y1);
}
void dot(void) {
hvflush();
/* what character to draw here depends on what's available. */
/* on the 202, l. is good but small. */
/* in general, use a smaller, shifted period and hope */