123890Sjaap #ifndef lint
2*64044Sbostic /*
338595Sjaap static char sccsid[] = "@(#)t10.c	2.4 (CWI) 89/08/14";
4*64044Sbostic */
5*64044Sbostic static char sccsid[] = "@(#)t10.c	2.5 (Berkeley) 07/27/93";
623890Sjaap #endif lint
723890Sjaap #include "tdef.h"
823911Sjaap #include <sgtty.h>
923911Sjaap #include <ctype.h>
1023911Sjaap #include "ext.h"
1123890Sjaap /*
1223911Sjaap  * troff10.c
1323911Sjaap  *
1423911Sjaap  * typesetter interface
1523911Sjaap  */
1623890Sjaap 
1723890Sjaap int	vpos	 = 0;	/* absolute vertical position on page */
1823890Sjaap int	hpos	 = 0;	/* ditto horizontal */
1923890Sjaap 
2023890Sjaap short	*chtab;
2123890Sjaap char	*chname;
2223890Sjaap char	*fontab[NFONT+1];
2323890Sjaap char	*kerntab[NFONT+1];
2423890Sjaap char	*fitab[NFONT+1];
2523911Sjaap char	*codetab[NFONT+1];
2623890Sjaap 
2723890Sjaap int	Inch;
2823890Sjaap int	Hor;
2923890Sjaap int	Vert;
3023890Sjaap int	Unitwidth;
3123890Sjaap int	nfonts;
3223890Sjaap int	nsizes;
3323890Sjaap int	nchtab;
3438595Sjaap int	nstips;
3538595Sjaap tchar	*stiplab;
3623890Sjaap 
3723890Sjaap /* these characters are used as various signals or values
3823890Sjaap /* in miscellaneous places.
3923890Sjaap /* values are set in specnames in t10.c
4023890Sjaap */
4123890Sjaap 
4223890Sjaap int	c_hyphen;
4323890Sjaap int	c_emdash;
4423890Sjaap int	c_rule;
4523890Sjaap int	c_minus;
4623890Sjaap int	c_fi;
4723890Sjaap int	c_fl;
4823890Sjaap int	c_ff;
4923890Sjaap int	c_ffi;
5023890Sjaap int	c_ffl;
5123890Sjaap int	c_acute;
5223890Sjaap int	c_grave;
5323890Sjaap int	c_under;
5423890Sjaap int	c_rooten;
5523890Sjaap int	c_boxrule;
5623890Sjaap int	c_lefthand;
5723911Sjaap int	c_dagger;
5823890Sjaap 
5923890Sjaap #include "dev.h"
6023890Sjaap struct dev dev;
6123911Sjaap struct Font *fontbase[NFONT+1];
6223890Sjaap 
6323890Sjaap 
ptinit()6423890Sjaap ptinit()
6523890Sjaap {
6623890Sjaap 	int	i, fin, nw;
67*64044Sbostic 	char	*filebase, *p;
6823890Sjaap 
6923890Sjaap 	/* open table for device,
7023890Sjaap 	/* read in resolution, size info, font info, etc.
7123890Sjaap 	/* and set params
7223890Sjaap 	*/
7323890Sjaap 	strcat(termtab, "/dev");
7423890Sjaap 	strcat(termtab, devname);
7523890Sjaap 	strcat(termtab, "/DESC.out");	/* makes "..../devXXX/DESC.out" */
7623890Sjaap 	if ((fin = open(termtab, 0)) < 0) {
7723911Sjaap 		errprint("can't open tables for %s", termtab);
7823890Sjaap 		done3(1);
7923890Sjaap 	}
8023911Sjaap 	read(fin, (char *) &dev, sizeof(struct dev ));
8123890Sjaap 	Inch = dev.res;
8223890Sjaap 	Hor = dev.hor;
8323890Sjaap 	Vert = dev.vert;
8423890Sjaap 	Unitwidth = dev.unitwidth;
8523890Sjaap 	nfonts = dev.nfonts;
8623890Sjaap 	nsizes = dev.nsizes;
8723890Sjaap 	nchtab = dev.nchtab;
8838595Sjaap 	nstips = dev.spare1;
89*64044Sbostic 	stiplab = (tchar *) malloc((nstips + 1) * sizeof(tchar));
90*64044Sbostic 	filebase = malloc(dev.filesize + 2 * EXTRAFONT);
9123890Sjaap 	read(fin, filebase, dev.filesize);	/* all at once */
9223890Sjaap 	pstab = (short *) filebase;
9323890Sjaap 	chtab = pstab + nsizes + 1;
9423890Sjaap 	chname = (char *) (chtab + dev.nchtab);
9523890Sjaap 	p = chname + dev.lchname;
9623890Sjaap 	for (i = 1; i <= nfonts; i++) {
9723911Sjaap 		fontbase[i] = (struct Font *) p;
9823911Sjaap 		nw = *p & BYTEMASK;	/* 1st thing is width count */
9923890Sjaap 		fontlab[i] = PAIR(fontbase[i]->namefont[0], fontbase[i]->namefont[1]);
10023890Sjaap 		/* for now, still 2 char names */
10123890Sjaap 		if (smnt == 0 && fontbase[i]->specfont == 1)
10223890Sjaap 			smnt = i;	/* first special font */
10323911Sjaap 		p += sizeof(struct Font);	/* that's what's on the beginning */
10423890Sjaap 		fontab[i] = p;
10523890Sjaap 		kerntab[i] = p + nw;
10623911Sjaap 		codetab[i] = p + 2 * nw;
10723890Sjaap 		fitab[i] = p + 3 * nw;	/* skip width, kern, code */
10823890Sjaap 		p += 3 * nw + dev.nchtab + 128 - 32;
10923890Sjaap 	}
11038595Sjaap 	for (i = 1; i <= nstips; i++) {		/* make stipple names tchars */
11138595Sjaap 		stiplab[i] = PAIR(*p, *(p+1));
11238595Sjaap 		while (*(p++));
11338595Sjaap 	}
11423911Sjaap 	fontbase[0] = (struct Font *) p;	/* the last shall be first */
11523890Sjaap 	fontbase[0]->nwfont = MAXCHARS;
11623911Sjaap 	fontab[0] = p + sizeof (struct Font);
11723890Sjaap 	close(fin);
11823890Sjaap 	/* there are a lot of things that used to be constant
11923890Sjaap 	/* that now require code to be executed.
12023890Sjaap 	*/
12123890Sjaap 	sps = SPS;
12223890Sjaap 	ics = ICS;
12323890Sjaap 	for (i = 0; i < 16; i++)
12423890Sjaap 		tabtab[i] = DTAB * (i + 1);
12523890Sjaap 	pl = 11 * INCH;
12623890Sjaap 	po = PO;
12723890Sjaap 	spacesz = SS;
12823890Sjaap 	lss = lss1 = VS;
12923890Sjaap 	ll = ll1 = lt = lt1 = LL;
13023890Sjaap 	specnames();	/* install names like "hyphen", etc. */
13123890Sjaap 	if (ascii)
13223890Sjaap 		return;
13323911Sjaap 	fdprintf(ptid, "x T %s\n", devname);
13423911Sjaap 	fdprintf(ptid, "x res %d %d %d\n", Inch, Hor, Vert);
13523911Sjaap 	fdprintf(ptid, "x init\n");	/* do initialization for particular device */
136*64044Sbostic #ifdef notdef
13723890Sjaap 	for (i = 1; i <= nfonts; i++)
13823911Sjaap 		fdprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont);
13923911Sjaap 	fdprintf(ptid, "x xxx fonts=%d sizes=%d unit=%d\n", nfonts, nsizes, Unitwidth);
14023911Sjaap 	fdprintf(ptid, "x xxx nchtab=%d lchname=%d nfitab=%d\n",
14123890Sjaap 		dev.nchtab, dev.lchname, dev.nchtab+128-32);
14223911Sjaap 	fdprintf(ptid, "x xxx sizes:\nx xxx ");
14323890Sjaap 	for (i = 0; i < nsizes; i++)
14423911Sjaap 		fdprintf(ptid, " %d", pstab[i]);
14523911Sjaap 	fdprintf(ptid, "\nx xxx chars:\nx xxx ");
14623890Sjaap 	for (i = 0; i < dev.nchtab; i++)
14723911Sjaap 		fdprintf(ptid, " %s", &chname[chtab[i]]);
14823911Sjaap 	fdprintf(ptid, "\nx xxx\n");
149*64044Sbostic #endif
15023890Sjaap }
15123890Sjaap 
specnames()15223890Sjaap specnames()
15323890Sjaap {
15423890Sjaap 	static struct {
15523890Sjaap 		int	*n;
15623890Sjaap 		char	*v;
15723890Sjaap 	} spnames[] = {
15823890Sjaap 		&c_hyphen, "hy",
15923890Sjaap 		&c_emdash, "em",
16023890Sjaap 		&c_rule, "ru",
16123890Sjaap 		&c_minus, "\\-",
16223890Sjaap 		&c_fi, "fi",
16323890Sjaap 		&c_fl, "fl",
16423890Sjaap 		&c_ff, "ff",
16523890Sjaap 		&c_ffi, "Fi",
16623890Sjaap 		&c_ffl, "Fl",
16723890Sjaap 		&c_acute, "aa",
16823890Sjaap 		&c_grave, "ga",
16923890Sjaap 		&c_under, "ul",
17023890Sjaap 		&c_rooten, "rn",
17123890Sjaap 		&c_boxrule, "br",
17223890Sjaap 		&c_lefthand, "lh",
17323911Sjaap 		&c_dagger, "dg",
17423890Sjaap 		0, 0
17523890Sjaap 	};
17623890Sjaap 	int	i;
17723890Sjaap 
17823890Sjaap 	for (i = 0; spnames[i].n; i++)
17923890Sjaap 		*spnames[i].n = findch(spnames[i].v);
18023890Sjaap }
18123890Sjaap 
findch(s)18223890Sjaap findch(s)	/* find char s in chname */
18323890Sjaap register char	*s;
18423890Sjaap {
18523890Sjaap 	register int	i;
18623890Sjaap 
18723890Sjaap 	for (i = 0; i < nchtab; i++)
18823890Sjaap 		if (strcmp(s, &chname[chtab[i]]) == 0)
18923890Sjaap 			return(i + 128);
19023890Sjaap 	return(0);
19123890Sjaap }
19223890Sjaap 
ptout(i)19323890Sjaap ptout(i)
19423911Sjaap register tchar	i;
19523890Sjaap {
19623911Sjaap 	register dv;
19723890Sjaap 	register tchar	*k;
19823911Sjaap 	int temp, a, b;
19923890Sjaap 
20023890Sjaap 	if (cbits(i) != '\n') {
20123890Sjaap 		*olinep++ = i;
20223890Sjaap 		return;
20323890Sjaap 	}
20423890Sjaap 	if (olinep == oline) {
20523890Sjaap 		lead += lss;
20623890Sjaap 		return;
20723890Sjaap 	}
20823890Sjaap 
20923890Sjaap 	hpos = po;	/* ??? */
21023890Sjaap 	esc = 0;	/* ??? */
21123890Sjaap 	ptesc();	/* the problem is to get back to the left end of the line */
21223890Sjaap 	dv = 0;
21323890Sjaap 	for (k = oline; k < olinep; k++) {
21423890Sjaap 		if (ismot(*k) && isvmot(*k)) {
21523890Sjaap 			temp = absmot(*k);
21623890Sjaap 			if (isnmot(*k))
21723890Sjaap 				temp = -temp;
21823890Sjaap 			dv += temp;
21923890Sjaap 		}
22023890Sjaap 	}
22123890Sjaap 	if (dv) {
22223890Sjaap 		vflag++;
22323890Sjaap 		*olinep++ = makem(-dv);
22423890Sjaap 		vflag = 0;
22523890Sjaap 	}
22623890Sjaap 
22723890Sjaap 	b = dip->blss + lss;
22823890Sjaap 	lead += dip->blss + lss;
22923890Sjaap 	dip->blss = 0;
23023890Sjaap 	for (k = oline; k < olinep; )
23123890Sjaap 		k += ptout0(k);	/* now passing a pointer! */
23223890Sjaap 	olinep = oline;
23323890Sjaap 	lead += dip->alss;
23423890Sjaap 	a = dip->alss;
23523890Sjaap 	dip->alss = 0;
23623890Sjaap 	/*
23723911Sjaap 	fdprintf(ptid, "x xxx end of line: hpos=%d, vpos=%d\n", hpos, vpos);
23823890Sjaap */
23923911Sjaap 	fdprintf(ptid, "n%d %d\n", b, a);	/* be nice to chuck */
24023890Sjaap }
24123890Sjaap 
ptout0(pi)24223890Sjaap ptout0(pi)
24323890Sjaap tchar	*pi;
24423890Sjaap {
24523890Sjaap 	register short j, k, w;
24623890Sjaap 	short	z, dx, dy, dx2, dy2, n;
24723911Sjaap 	register tchar	i;
24823890Sjaap 	int outsize;	/* size of object being printed */
24923890Sjaap 
25023890Sjaap 	outsize = 1;	/* default */
25123890Sjaap 	i = *pi;
25223890Sjaap 	k = cbits(i);
25323890Sjaap 	if (ismot(i)) {
25423890Sjaap 		j = absmot(i);
25523890Sjaap 		if (isnmot(i))
25623890Sjaap 			j = -j;
25723890Sjaap 		if (isvmot(i))
25823890Sjaap 			lead += j;
25923890Sjaap 		else
26023890Sjaap 			esc += j;
26123890Sjaap 		return(outsize);
26223890Sjaap 	}
26323911Sjaap 	if (k == XON) {
26423911Sjaap 		int c;
26523911Sjaap 		if (xfont != mfont)
26623911Sjaap 			ptfont();
26723911Sjaap 		if (xpts != mpts)
26823911Sjaap 			ptps();
26923911Sjaap 		if (lead)
27023911Sjaap 			ptlead();
27133696Sjaap 		if (esc)	/* for psfig ???*/
27233696Sjaap 			ptesc();
27323911Sjaap 		fdprintf(ptid, "x X ");
27423911Sjaap 		for (j = 1; (c=cbits(pi[j])) != XOFF; j++)
27523911Sjaap 			outascii(pi[j]);
27623911Sjaap 		oput('\n');
27723911Sjaap 		return j+1;
27823911Sjaap 	}
27923911Sjaap 			;
28023890Sjaap 	if (k == CHARHT) {
28123890Sjaap 		if (xpts != mpts)
28223890Sjaap 			ptps();
28323911Sjaap 		fdprintf(ptid, "x H %d\n", sbits(i));
28423890Sjaap 		return(outsize);
28523890Sjaap 	}
28623890Sjaap 	if (k == SLANT) {
28723911Sjaap 		fdprintf(ptid, "x S %d\n", sfbits(i)-180);
28823890Sjaap 		return(outsize);
28923890Sjaap 	}
29023890Sjaap 	if (k == WORDSP) {
29123890Sjaap 		oput('w');
29223890Sjaap 		return(outsize);
29323890Sjaap 	}
29423890Sjaap 	if (sfbits(i) == oldbits) {
29523890Sjaap 		xfont = pfont;
29623890Sjaap 		xpts = ppts;
29723890Sjaap 	} else
29823911Sjaap 		xbits(i, 2);
29923890Sjaap 	if (k < 040 && k != DRAWFCN)
30023890Sjaap 		return(outsize);
30133753Sjaap 	/*
30233753Sjaap 	 * Bug fix, if k == DRAWFCN, thewidcache gets a negative index.
30333753Sjaap 	 * This worked by magic on the vax and tahoe, but caused somtimes
30433753Sjaap 	 * a segment violaton on the suns.
30533753Sjaap 	 *
30633753Sjaap 	 * The code was plainly wrong (jna).
30733753Sjaap 	 */
30833753Sjaap 	if ( k != DRAWFCN) {
30933753Sjaap 		if (widcache[k-32].fontpts == (xfont<<8) + xpts  && !setwdf) {
31033753Sjaap 			w = widcache[k-32].width;
31133753Sjaap 			bd = 0;
31233753Sjaap 			cs = 0;
31333753Sjaap 		} else
31433753Sjaap 			w = getcw(k-32);
31533753Sjaap 	}
31623890Sjaap 	j = z = 0;
31723890Sjaap 	if (k != DRAWFCN) {
31823890Sjaap 		if (cs) {
31923890Sjaap 			if (bd)
32023890Sjaap 				w += (bd - 1) * HOR;
32123890Sjaap 			j = (cs - w) / 2;
32223890Sjaap 			w = cs - j;
32323890Sjaap 			if (bd)
32423890Sjaap 				w -= (bd - 1) * HOR;
32523890Sjaap 		}
32623890Sjaap 		if (iszbit(i)) {
32723890Sjaap 			if (cs)
32823890Sjaap 				w = -j;
32923890Sjaap 			else
33023890Sjaap 				w = 0;
33123890Sjaap 			z = 1;
33223890Sjaap 		}
33323890Sjaap 	}
33423890Sjaap 	esc += j;
33523890Sjaap 	if (xfont != mfont)
33623890Sjaap 		ptfont();
33723890Sjaap 	if (xpts != mpts)
33823890Sjaap 		ptps();
33923890Sjaap 	if (lead)
34023890Sjaap 		ptlead();
34123890Sjaap 	/* put out the real character here */
34223890Sjaap 	if (k == DRAWFCN) {
34323890Sjaap 		if (esc)
34423890Sjaap 			ptesc();
34523890Sjaap 		dx = absmot(pi[3]);
34623890Sjaap 		if (isnmot(pi[3]))
34723890Sjaap 			dx = -dx;
34823890Sjaap 		dy = absmot(pi[4]);
34923890Sjaap 		if (isnmot(pi[4]))
35023890Sjaap 			dy = -dy;
35123890Sjaap 		switch (cbits(pi[1])) {
35223890Sjaap 		case DRAWCIRCLE:	/* circle */
35323911Sjaap 			fdprintf(ptid, "D%c %d\n", DRAWCIRCLE, dx);	/* dx is diameter */
35423890Sjaap 			w = 0;
35523890Sjaap 			hpos += dx;
35623890Sjaap 			break;
35723890Sjaap 		case DRAWELLIPSE:
35823911Sjaap 			fdprintf(ptid, "D%c %d %d\n", DRAWELLIPSE, dx, dy);
35923890Sjaap 			w = 0;
36023890Sjaap 			hpos += dx;
36123890Sjaap 			break;
36223890Sjaap 		case DRAWLINE:	/* line */
36323890Sjaap 			k = cbits(pi[2]);
36423911Sjaap 			fdprintf(ptid, "D%c %d %d ", DRAWLINE, dx, dy);
36523890Sjaap 			if (k < 128)
36623911Sjaap 				fdprintf(ptid, "%c\n", k);
36723890Sjaap 			else
36823911Sjaap 				fdprintf(ptid, "%s\n", &chname[chtab[k - 128]]);
36923890Sjaap 			w = 0;
37023890Sjaap 			hpos += dx;
37123890Sjaap 			vpos += dy;
37223890Sjaap 			break;
37323890Sjaap 		case DRAWARC:	/* arc */
37423890Sjaap 			dx2 = absmot(pi[5]);
37523890Sjaap 			if (isnmot(pi[5]))
37623890Sjaap 				dx2 = -dx2;
37723890Sjaap 			dy2 = absmot(pi[6]);
37823890Sjaap 			if (isnmot(pi[6]))
37923890Sjaap 				dy2 = -dy2;
38023911Sjaap 			fdprintf(ptid, "D%c %d %d %d %d\n", DRAWARC,
38123890Sjaap 				dx, dy, dx2, dy2);
38223890Sjaap 			w = 0;
38323890Sjaap 			hpos += dx + dx2;
38423890Sjaap 			vpos += dy + dy2;
38523890Sjaap 			break;
38623911Sjaap 		case DRAWSPLINE:	/* spline */
38723911Sjaap 		default:	/* something else; copy it like spline */
38823911Sjaap 			fdprintf(ptid, "D%c %d %d", cbits(pi[1]), dx, dy);
38923890Sjaap 			w = 0;
39023890Sjaap 			hpos += dx;
39123890Sjaap 			vpos += dy;
39223911Sjaap 			if (cbits(pi[3]) == DRAWFCN || cbits(pi[4]) == DRAWFCN) {
39323911Sjaap 				/* it was somehow defective */
39423911Sjaap 				fdprintf(ptid, "\n");
39523911Sjaap 				break;
39623911Sjaap 			}
39723911Sjaap 			for (n = 5; cbits(pi[n]) != DRAWFCN; n += 2) {
39823890Sjaap 				dx = absmot(pi[n]);
39923890Sjaap 				if (isnmot(pi[n]))
40023890Sjaap 					dx = -dx;
40123890Sjaap 				dy = absmot(pi[n+1]);
40223890Sjaap 				if (isnmot(pi[n+1]))
40323890Sjaap 					dy = -dy;
40423911Sjaap 				fdprintf(ptid, " %d %d", dx, dy);
40523890Sjaap 				hpos += dx;
40623890Sjaap 				vpos += dy;
40723890Sjaap 			}
40823911Sjaap 			fdprintf(ptid, "\n");
40923890Sjaap 			break;
41023890Sjaap 		}
41123911Sjaap 		for (n = 3; cbits(pi[n]) != DRAWFCN; n++)
41223890Sjaap 			;
41323890Sjaap 		outsize = n + 1;
41423890Sjaap 	} else if (k < 128) {
41523890Sjaap 		/* try to go faster and compress output */
41623890Sjaap 		/* by printing nnc for small positive motion followed by c */
41723890Sjaap 		/* kludgery; have to make sure set all the vars too */
41823890Sjaap 		if (esc > 0 && esc < 100) {
41923890Sjaap 			oput(esc / 10 + '0');
42023890Sjaap 			oput(esc % 10 + '0');
42123890Sjaap 			oput(k);
42223890Sjaap 			hpos += esc;
42323890Sjaap 			esc = 0;
42423890Sjaap 		} else {
42523890Sjaap 			if (esc)
42623890Sjaap 				ptesc();
42723911Sjaap 			oput('c');
42823911Sjaap 			oput(k);
42923911Sjaap 			oput('\n');
43023890Sjaap 		}
43123890Sjaap 	} else {
43223890Sjaap 		if (esc)
43323890Sjaap 			ptesc();
43423911Sjaap 		if (k >= nchtab + 128)
43523911Sjaap 			fdprintf(ptid, "N%d\n", k - (nchtab+128));
43623911Sjaap 		else
43723911Sjaap 			fdprintf(ptid, "C%s\n", &chname[chtab[k - 128]]);
43823890Sjaap 	}
43923890Sjaap 	if (bd) {
44023890Sjaap 		bd -= HOR;
44123890Sjaap 		if (esc += bd)
44223890Sjaap 			ptesc();
44323890Sjaap 		if (k < 128) {
44423911Sjaap 			fdprintf(ptid, "c%c\n", k);
44523911Sjaap 		} else if (k >= nchtab + 128) {
44623911Sjaap 			fdprintf(ptid, "N%d\n", k - (nchtab+128));
44723890Sjaap 		} else
44823911Sjaap 			fdprintf(ptid, "C%s\n", &chname[chtab[k - 128]]);
44923890Sjaap 		if (z)
45023890Sjaap 			esc -= bd;
45123890Sjaap 	}
45223890Sjaap 	esc += w;
45323890Sjaap 	return(outsize);
45423890Sjaap }
45523890Sjaap 
ptps()45623890Sjaap ptps()
45723890Sjaap {
45823890Sjaap 	register i, j, k;
45923890Sjaap 
46023890Sjaap 	i = xpts;
46123890Sjaap 	for (j = 0; i > (k = pstab[j]); j++)
46223890Sjaap 		if (!k) {
46323890Sjaap 			k = pstab[--j];
46423890Sjaap 			break;
46523890Sjaap 		}
46623911Sjaap 	fdprintf(ptid, "s%d\n", k);	/* really should put out string rep of size */
46723890Sjaap 	mpts = i;
46823890Sjaap }
46923890Sjaap 
ptfont()47023890Sjaap ptfont()
47123890Sjaap {
47223911Sjaap 	extern char *unpair();
47323890Sjaap 	mfont = xfont;
47423890Sjaap 	if( xfont > nfonts) {
47523911Sjaap 		register char *temp = unpair(fontlab[xfont]);
47623890Sjaap 		ptfpcmd(0, temp);	/* Put the desired font in the
47723890Sjaap 					 * fontcache of the filter */
47823911Sjaap 		fdprintf(ptid, "f0\n");	/* make sure that it gets noticed */
47923890Sjaap 	} else
48023911Sjaap 		fdprintf(ptid, "f%d\n", xfont);
48123890Sjaap }
48223890Sjaap 
ptfpcmd(f,s)48323890Sjaap ptfpcmd(f, s)
48423890Sjaap int	f;
48523890Sjaap char	*s;
48623890Sjaap {
48723890Sjaap 	if (ascii)
48823890Sjaap 		return;
48923911Sjaap 	fdprintf(ptid, "x font %d %s\n", f, s);
49023890Sjaap }
49123890Sjaap 
ptlead()49223890Sjaap ptlead()
49323890Sjaap {
49423890Sjaap 	vpos += lead;
49523890Sjaap 	if (!ascii)
49623911Sjaap 		fdprintf(ptid, "V%d\n", vpos);
49723890Sjaap 	lead = 0;
49823890Sjaap }
49923890Sjaap 
ptesc()50023890Sjaap ptesc()
50123890Sjaap {
50223890Sjaap 	hpos += esc;
50323911Sjaap 	if (esc > 0) {
50423911Sjaap 		oput('h');
50523911Sjaap 		if (esc>=10 && esc<100) {
50623911Sjaap 			oput(esc/10 + '0');
50723911Sjaap 			oput(esc%10 + '0');
50823911Sjaap 		} else
50923911Sjaap 			fdprintf(ptid, "%d", esc);
51023911Sjaap 	} else
51123911Sjaap 		fdprintf(ptid, "H%d\n", hpos);
51223890Sjaap 	esc = 0;
51323890Sjaap }
51423890Sjaap 
newpage(n)51523890Sjaap newpage(n)	/* called at end of each output page (we hope) */
51623890Sjaap {
51723911Sjaap 	int i;
51823911Sjaap 
51923890Sjaap 	ptlead();
52023890Sjaap 	vpos = 0;
52123890Sjaap 	if (ascii)
52223890Sjaap 		return;
52323911Sjaap 	fdprintf(ptid, "p%d\n", n);	/* new page */
52423911Sjaap 	for (i = 0; i <= nfonts; i++)
52523911Sjaap 		if (fontbase[i]->namefont && fontbase[i]->namefont[0])
52623911Sjaap 			fdprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont);
52723890Sjaap 	ptps();
52823890Sjaap 	ptfont();
52923890Sjaap }
53023890Sjaap 
pttrailer()53123890Sjaap pttrailer()
53223890Sjaap {
53323911Sjaap 	fdprintf(ptid, "x trailer\n");
53423890Sjaap }
53523890Sjaap 
ptstop()53623890Sjaap ptstop()
53723890Sjaap {
53823911Sjaap 	fdprintf(ptid, "x stop\n");
53923890Sjaap }
54023890Sjaap 
dostop()54123890Sjaap dostop()
54223890Sjaap {
54323890Sjaap 	if (ascii)
54423890Sjaap 		return;
54523890Sjaap 	ptlead();
54623890Sjaap 	vpos = 0;
54723911Sjaap 	/* fdprintf(ptid, "x xxx end of page\n");*/
54823890Sjaap 	if (!nofeed)
54923890Sjaap 		pttrailer();
55023890Sjaap 	ptlead();
55123911Sjaap 	fdprintf(ptid, "x pause\n");
55223890Sjaap 	flusho();
55323890Sjaap 	mpts = mfont = 0;
55423890Sjaap 	ptesc();
55523890Sjaap 	esc = po;
55623890Sjaap 	hpos = vpos = 0;	/* probably in wrong place */
55723890Sjaap }
558