v14i072: cat2deskjet (Part 2 of 3)

vp at cui.unige.ch vp at cui.unige.ch
Fri Aug 31 10:20:03 AEST 1990


Posting-number: Volume 14, Issue 72
Submitted-by: vp at cui.unige.ch
Archive-name: cat2deskjet/part02

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 3)."
# Contents:  lcat.c makefile.msdos makefile.unix railmag.1 rf.c vcat.1
#   lcat.1
# Wrapped by vp at cuisun29 on Tue Aug 28 14:24:45 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'lcat.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lcat.c'\"
else
echo shar: Extracting \"'lcat.c'\" \(12744 characters\)
sed "s/^X//" >'lcat.c' <<'END_OF_FILE'
X/*****************************************************************
X *
X *   Copyright 1985. Chris Lewis
X *
X *   Module          : lcat.c 1.5
X *   Date submitted  : 86/01/21 13:23:21
X *   Author          : Chris Lewis
X *   Origin          : Permission to copy and further distribute is 
X * 		       freely given provided this copyright notice remains 
X *		       intact and that this software is not sold for profit.
X *   Description     : Driver for troff WANG/CAT to HP laserjet filter.
X *
X *   Modifications (by vp at cui.unige.ch):
X *
X *	- modications for compatibility with BSD vfonts
X *	- modifications for porting to MS-LOSS
X *	- converted to use soft fonts instead of graphics mode
X *	- removed multiple resolutions option since with soft fonts
X *	  you don't get to chose.
X *
X******************************************************************/
X
X#ifndef lint
Xstatic char SrcId[] = "@(#)lcat.c:1.5";
X#endif
X
X#include <stdio.h>
X#include <ctype.h>
X#include <string.h>
Xextern void terminate();
X
X#define	ESC	0x80
X#define	FLASH	0x00
X#define	CONTROL	0x40
X#define	LEAD	0x60
X#define	SIZE	0x50
X
X#define	DOWN	0
X#define	UP	1
X#define	LOWER	2
X#define	UPPER	3
X#define	FORWARD	4
X#define	BACKWARD 5
X
X#ifdef UNIX
XFILE	*inFile = stdin;
XFILE	*outFile = stdout;
X#else
XFILE	*inFile = (FILE *) NULL;
XFILE	*outFile = (FILE *) NULL;
X#endif
XFILE	*diagFile = (FILE *) NULL;
X#define	DEBUGPRINTF	if (diagFile) fprintf
X
X
X/*
X * note: the BSD4.3 vfonts are really too big at 75 dpi, so we have to
X * always print them at a higher resolution (in this case 300 dpi).
X *
X * Unfortunately at this resolution they are too small, so for a given
X * pointsize request we have to select a larger pointsize.
X *
X * We try to select the one closest to the requested size plus 4 points.
X */
X#ifdef ORIG
Xchar ptab[16] = { 7, 8, 10, 11, 12, 14, 18, 9, 6, 16, 20, 22, 24, 28, 36, 72};
Xchar ptab[16] = { 10, 12, 14, 14, 16, 22, 22, 12, 10, 22, 24, 24, 28, 28, 36, 72 };
X#else
Xchar ptab[16] = { 11, 12, 16, 16, 18, 22, 28, 14, 9, 24, 28, 36, 36, 36, 36, 36};
X#endif
Xint	points;
Xint	vertChanged = 0;
Xint	quality	= 1;
Xint lcat;
X
X
X/*	Scale factors:
X		(td/ld) * (lu / tu)
X		Where:
X			td: troff dimension in inches
X			ld: laserjet dimension in inches
X			lu: laserjet precision/inch
X			tu: troff precision/inch
X
X		td = 6.5 (width), 11 (length)
X		tu = 432
X		ld = 6.5 (width), 10 (length)
X		lu = 720
X*/
X
X#define	XSF	1.6666666	/* X Scale factor (troff to laserjet units) */
X#define	YSF	1.5151515	/* Y Scale factor (troff to laserjet units) */
X
Xlong	xpos, oldypos = -9999, ypos = -153;
X
Xchar *words[] = {
X	"down", "up", "lower", "upper", "forward", "backwards"
X	};
X
Xstatic char	fontFamily[BUFSIZ];
Xstatic char	djfontFamily[BUFSIZ];
Xchar	*fontName;
X#ifdef UNIX
Xchar	*fontLib = "/usr1/tmp/vfonts/";
X#else
Xchar	*fontLib = "/usr/vfonts/";
X#endif
X
X#define	CTOINT(val,sig)	((~c)&sig)
X
X#define	UNITS	432
X#define	FONT4		/* 4 Font device */
X
X/*
X * calcfont -- calculate new font depending on the rail, mag and tilt options
X */
X#ifdef	FONT4
X#define	calcfont	((mag == UPPER)<<1)|((rail == UPPER))
X#else
X#define	calcfont	((mag == UPPER)<<2)|((rail == UPPER)<<1)|(tilt==DOWN)
X#endif
X
Xmain(argc, argv)
Xint	argc;
Xchar	**argv; {
X	register int nc, c;
X	register char *rp;
X	register int i,j;
X	register int decipoints;
X	register int units;
X	register int font, rail, mag, tilt, half, escape, lead;
X	char* ofile;
X	char* infile;
X
X	lead=half=rail=mag=tilt=font=0;
X	
X#ifdef UNIX
X	/* under UNIX default input and output files are the
X	 * standard input and output respectively.
X	 * Under MS-LOSS we have to use explicit files because of I/O
X	 * redirection probs.
X	 */
X	infile = NULL;
X	ofile = NULL;
X	fontName = "times.";
X#else
X	infile = "/tmp/out";
X	ofile = "prn:";
X	/* under MSLOSS (the system that likes to say no)
X	   filenames can only have one dot, so we use a '-' instead */
X	fontName = "times-";
X#endif
X	quality = 1;
X	lcat = (argv[0][strlen(argv[0])-4] == 'l');
X	argv++;
X	argc--;
X	if (argc > 0)	/* process parameters */
X	{
X		while (argc > 0 && **argv == '-')
X		{
X			switch (*(*argv+1)) {
X			case 'D':	/* diagnostic output */
X				diagFile = fopen("diag.txt", "w");
X				if (!diagFile)
X				{
X					fprintf(stderr, "Could not open diagnostics file\n");
X					exit(1);
X				}
X				argv++;
X				argc--;
X				break;
X			case 'f':	/* select different font family */
X				fontName = *++argv;
X				argv++;
X				argc -= 2;
X				break;
X			case 'O':	/* specify output file */
X				ofile = *++argv;
X				argv++;
X				argc -= 2;
X				break;
X			case 'l':	/* select low (draft) quality */
X				/* this option is valid ONLY for the lcat version */
X				quality = 2;
X				argv++;
X				argc -= 1;
X				if (lcat)
X					break;
X				/* otherwise fall through to the error code */
X			default:
X				usage();
X				exit(1);
X			}
X		}
X		if (argc > 0)
X		{
X			infile = *argv;
X			argv++;
X			argc--;
X		}
X	}
X	
X
X	/* if not absolute path, prepend vfont directory path */
X#ifdef UNIX
X	if (fontName[0] == '/' || fontName[1] == ':')
X		sprintf(fontFamily, "%s", fontName);
X	else
X		sprintf(fontFamily, "%s%s", fontLib, fontName);
X#else
X	if (fontName[0] == '/' || fontName[1] == ':')
X	{
X		char *vp;
X		sprintf(fontFamily, "%s", fontName);
X		/* isolate path to font directory */
X		vp = strrchr(fontName, '/');
X		*vp = '\0';
X		sprintf(djfontFamily, "%s/djfonts", fontName);
X		ft_init(djfontFamily);
X		sprintf(djfontFamily, "%s/djfonts/%s", fontName, vp+1);
X	} else {
X		sprintf(fontFamily, "%s%s", fontLib, fontName);
X		sprintf(djfontFamily, "%sdjfonts", fontLib);
X		ft_init(djfontFamily);
X		sprintf(djfontFamily, "%sdjfonts/%s", fontLib, fontName);
X	}
X#endif
X
X	DEBUGPRINTF(diagFile, "font family: %s\n", fontFamily);
X	if (ofile != NULL)
X		if ((outFile = fopen(ofile, "wb")) == NULL)
X		{
X			fprintf(stderr, "Couldn't open output file %s\n", ofile);
X			exit(1);
X		}
X	if (infile != NULL)
X		if ((inFile = fopen(infile, "rb")) == NULL)
X		{
X			fprintf(stderr,
X				"Couldn't open input file %s\n", infile);
X			exit(1);
X		}
X	vf_init(quality, fontFamily, djfontFamily);
X	while (!feof(inFile)) {
X		c = getc(inFile);
X		switch(c) {
X		case 0x00:
X			DEBUGPRINTF(diagFile, "NOP\n");
X			break;
X		/* Flash (print character) codes */
X		case 0x01: case 0x02: case 0x03: case 0x04: 
X		case 0x05: case 0x06: case 0x07: case 0x08: 
X		case 0x09: case 0x0a: case 0x0b: case 0x0c: 
X		case 0x0d: case 0x0e: case 0x0f: case 0x10: 
X		case 0x11: case 0x12: case 0x13: case 0x14:
X		case 0x15: case 0x16: case 0x17: case 0x18: 
X		case 0x19: case 0x1a: case 0x1b: case 0x1c: 
X		case 0x1d: case 0x1e: case 0x1f: case 0x20: 
X		case 0x21: case 0x22: case 0x23: case 0x24: 
X		case 0x25: case 0x26: case 0x27: case 0x28:
X		case 0x29: case 0x2a: case 0x2b: case 0x2c: 
X		case 0x2d: case 0x2e: case 0x2f: case 0x30: 
X		case 0x31: case 0x32: case 0x33: case 0x34: 
X		case 0x35: case 0x36: case 0x37: case 0x38: 
X		case 0x39: case 0x3a: case 0x3b: case 0x3c:
X		case 0x3d: case 0x3e: case 0x3f:
X			/* This is terribly kludgey:
X				In 432 units per inch, 4752 is 11 inches.
X				When we go beyond this, we subtract 4752
X				and ignore anything printed on this line.
X			*/
X			while (ypos >= 4752) {
X				ypos -= 4752;
X				oldypos = -9999;
X				DEBUGPRINTF(diagFile, "Page break\n", 0, 0);
X				vf_newpage();
X			}
X			if (ypos <= 20) {
X				DEBUGPRINTF(diagFile, "Ignoring: %d, %d\n", xpos, ypos);
X				break; /* ignore anything less than this
X					from the beginning of a page */
X			}
X			c &= 0x3f;
X			DEBUGPRINTF(diagFile, "Flash %02d %s font %d\n", c&0x3f, 
X				words[half], font);
X/*
Xprintf("font(%d)=%s,rail(%d)=%s,mag(%d)=%s,tilt(%d)=%s,half(%d)=%s\n",
X	font, words[font], rail, words[rail], mag, words[mag],
X	tilt, words[tilt], half, words[half]);
X*/
X			DEBUGPRINTF(diagFile, "x,y=%ld,%ld; font=%d; rail=%s; mag=%s; tilt=%s; half=%s\n",
X				xpos,ypos,font+1,words[rail],words[mag],words[tilt],
X				words[half]);
X			/*	Find the C/A/T code */
X			if (half == UPPER) {
X				if (c > 46) {
X					fprintf(stderr, "Illegal upper flash: %d\n", c);
X					terminate(1);
X				}
X				nc = c + 62;
X			} else
X				nc = c - 1;
X
X			/*
X			 * the new version of flashrast needs to know
X			 * where the letter will be placed.  Thus we
X			 * call a routine in newfonts.c that can then save
X			 * these numbers.
X			 */
X			vf_move((long) (xpos*XSF), (long) (ypos*YSF));
X			oldypos = ypos;
X			vertChanged = 0;
X			flashrast(nc, points, font);
X			vertChanged = 1;
X			break;
X		/* Control codes */
X		case 0x40:
X			DEBUGPRINTF(diagFile, "Initialize\n");
X			xpos = 0;
X			ypos = -153;
X			escape = FORWARD;
X			lead = FORWARD;
X			half = LOWER;
X			rail = LOWER;
X			mag = LOWER;
X			tilt = DOWN;
X			font = calcfont;
X			break;
X		case 0x41:
X			DEBUGPRINTF(diagFile, "Rail lower\n");
X			rail = LOWER;
X			font = calcfont;
X			break;
X		case 0x42:
X			DEBUGPRINTF(diagFile, "Rail upper\n");
X			rail = UPPER;
X			font = calcfont;
X			break;
X		case 0x43:
X			DEBUGPRINTF(diagFile, "Mag upper\n");
X			mag = UPPER;
X			font = calcfont;
X			break;
X		case 0x44:
X			DEBUGPRINTF(diagFile, "Mag lower\n");
X			mag = LOWER;
X			font = calcfont;
X			break;
X		case 0x45:
X			DEBUGPRINTF(diagFile, "half lower\n");
X			half = LOWER;
X			break;
X		case 0x46:
X			DEBUGPRINTF(diagFile, "half upper\n");
X			half = UPPER;
X			break;
X		case 0x47:
X			DEBUGPRINTF(diagFile, "Escape forward\n");
X			escape = FORWARD;
X			break;
X		case 0x48:
X			DEBUGPRINTF(diagFile, "Escape backward\n");
X			escape = BACKWARD;
X			break;
X		case 0x49:
X			DEBUGPRINTF(diagFile, "STOP\n");
X			break;
X		case 0x4a:
X			DEBUGPRINTF(diagFile, "Lead forward\n");
X			lead = FORWARD;
X			break;
X		case 0x4b:
X			DEBUGPRINTF(diagFile, "Software cut!\n");
X			break;
X		case 0x4c:
X			DEBUGPRINTF(diagFile, "Lead backward\n");
X			lead = BACKWARD;
X			break;
X		case 0x4d:
X			DEBUGPRINTF(diagFile, "UNKNOWN CONTROL CODE!\n");
X			terminate(0);
X		case 0x4e:
X			DEBUGPRINTF(diagFile, "Tilt up\n");
X			tilt = UP;
X			font = calcfont;
X			break;
X		case 0x4f:
X			DEBUGPRINTF(diagFile, "Tilt down\n");
X			tilt = DOWN;
X			font = calcfont;
X			break;
X
X		/* Size changes */
X		case 0x50: case 0x51: case 0x52: case 0x53:
X		case 0x54: case 0x55: case 0x56: case 0x57:
X		case 0x58: case 0x59: case 0x5a: case 0x5b:
X		case 0x5c: case 0x5d: case 0x5e: case 0x5f:
X			DEBUGPRINTF(diagFile, "Size change %02x\n", c&0xf);
X			points = ptab[c&0xf];
X			break;
X		/* Lead (vertical motion) codes */
X		case 0x60: case 0x61: case 0x62: case 0x63:
X		case 0x64: case 0x65: case 0x66: case 0x67:
X		case 0x68: case 0x69: case 0x6a: case 0x6b:
X		case 0x6c: case 0x6d: case 0x6e: case 0x6f:
X		case 0x70: case 0x71: case 0x72: case 0x73:
X		case 0x74: case 0x75: case 0x76: case 0x77:
X		case 0x78: case 0x79: case 0x7a: case 0x7b:
X		case 0x7c: case 0x7d: case 0x7e: case 0x7f:
X
X			DEBUGPRINTF(diagFile, "Lead(vertical) %02x\n", c&0x1f);
X			units = CTOINT(c,0x1f);
X			if (lead == FORWARD) {
X				ypos += 3*units;
X			} else {
X				ypos -= 3*units;
X			}
X			break;
X		/* Escape (horizontal motion) codes */
X		case 0x80: case 0x81: case 0x82: case 0x83:
X		case 0x84: case 0x85: case 0x86: case 0x87:
X		case 0x88: case 0x89: case 0x8a: case 0x8b:
X		case 0x8c: case 0x8d: case 0x8e: case 0x8f:
X		case 0x90: case 0x91: case 0x92: case 0x93:
X		case 0x94: case 0x95: case 0x96: case 0x97:
X		case 0x98: case 0x99: case 0x9a: case 0x9b:
X		case 0x9c: case 0x9d: case 0x9e: case 0x9f:
X		case 0xa0: case 0xa1: case 0xa2: case 0xa3:
X		case 0xa4: case 0xa5: case 0xa6: case 0xa7:
X		case 0xa8: case 0xa9: case 0xaa: case 0xab:
X		case 0xac: case 0xad: case 0xae: case 0xaf:
X		case 0xb0: case 0xb1: case 0xb2: case 0xb3:
X		case 0xb4: case 0xb5: case 0xb6: case 0xb7:
X		case 0xb8: case 0xb9: case 0xba: case 0xbb:
X		case 0xbc: case 0xbd: case 0xbe: case 0xbf:
X		case 0xc0: case 0xc1: case 0xc2: case 0xc3:
X		case 0xc4: case 0xc5: case 0xc6: case 0xc7:
X		case 0xc8: case 0xc9: case 0xca: case 0xcb:
X		case 0xcc: case 0xcd: case 0xce: case 0xcf:
X		case 0xd0: case 0xd1: case 0xd2: case 0xd3:
X		case 0xd4: case 0xd5: case 0xd6: case 0xd7:
X		case 0xd8: case 0xd9: case 0xda: case 0xdb:
X		case 0xdc: case 0xdd: case 0xde: case 0xdf:
X		case 0xe0: case 0xe1: case 0xe2: case 0xe3:
X		case 0xe4: case 0xe5: case 0xe6: case 0xe7:
X		case 0xe8: case 0xe9: case 0xea: case 0xeb:
X		case 0xec: case 0xed: case 0xee: case 0xef:
X		case 0xf0: case 0xf1: case 0xf2: case 0xf3:
X		case 0xf4: case 0xf5: case 0xf6: case 0xf7:
X		case 0xf8: case 0xf9: case 0xfa: case 0xfb:
X		case 0xfc: case 0xfd: case 0xfe:
X
X			units = CTOINT(c,0x7f);
X			if (escape == FORWARD) {
X				xpos += units;
X			} else {
X				xpos -= units;
X			}
X			DEBUGPRINTF(diagFile, "ESC (hor): %02x\n", c&0x7f);
X			break;
X
X		case 0xff:
X			DEBUGPRINTF(diagFile, "Illegal: %02x\n", c);
X			break;
X		}
X	}
X	vf_newpage();
X	terminate(0);
X}
X
Xvoid terminate(xx)
Xint xx;
X{
X#ifndef UNIX
X	ft_close();
X#endif
X	exit(xx);
X}
X
X
Xusage()
X{
X	if (lcat)
X		fprintf(stderr, "usage: lcat [-f fontname] [-l] [-O file] [file]\n");
X	else
X		fprintf(stderr, "usage: vcat [-f fontname] [-O file] [file]\n");
X}
X
END_OF_FILE
if test 12744 -ne `wc -c <'lcat.c'`; then
    echo shar: \"'lcat.c'\" unpacked with wrong size!
fi
# end of 'lcat.c'
fi
if test -f 'makefile.msdos' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.msdos'\"
else
echo shar: Extracting \"'makefile.msdos'\" \(616 characters\)
sed "s/^X//" >'makefile.msdos' <<'END_OF_FILE'
X#
X# MSDOS/TURBOC makefile
X#
X#			Vassilis Prevelakis (1990)
X#
X
XLD	= tlink
XLIB	= /usr/tc/lib
XLIBS	= $(LIB)/EMU $(LIB)/MATHh $(LIB)/Ch
XCC	= tcc
X
XCFLAGS = -mh -DMSDOS
XOBJ	= lcat.obj vf.obj bm.obj ftbl.obj
X
Xall:	railmag.exe djinfo.exe lcat.exe vcat.exe
X
Xvf.obj:	lcat.h
X
X.c.obj:
X	$(CC) $(CFLAGS) -c $<
X
Xbm.obj:	bm.c lcat.h
X	$(CC) $(CFLAGS) -DUSE_C -c bm.c
X
Xvcat.exe:	lcat.obj rf.obj ftbl.obj
X	$(CC) $(CFLAGS) -evcat.exe lcat.obj rf.obj ftbl.obj
X
Xdjinfo.exe: djinfo.c
X	$(CC) $(CFLAGS) -edjinfo djinfo.c
X
Xrailmag.exe: railmag.c
X	$(CC) $(CFLAGS) -erailmag.exe railmag.c
X
Xlcat.exe:	$(OBJ)
X	$(CC) $(CFLAGS) -elcat.exe $(OBJ)
X
X
END_OF_FILE
if test 616 -ne `wc -c <'makefile.msdos'`; then
    echo shar: \"'makefile.msdos'\" unpacked with wrong size!
fi
# end of 'makefile.msdos'
fi
if test -f 'makefile.unix' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.unix'\"
else
echo shar: Extracting \"'makefile.unix'\" \(471 characters\)
sed "s/^X//" >'makefile.unix' <<'END_OF_FILE'
X#
X# BSD Unix makefile
X#
X#				Vassilis Prevelakis (1990)
X#
X
X
XCC	= cc
XCFLAGS = -DUNIX 
XOBJ	= lcat.o vf.o bm.o ftbl.o
X
Xall:	railmag djinfo lcat vcat
X
Xvf.o:	lcat.h
X
X.c.o:
X	$(CC) $(CFLAGS) -c $<
X
Xbm.o:	bm.c lcat.h
X	$(CC) $(CFLAGS) -DUSE_C -c bm.c
X
Xvcat:	lcat.o rf.o ftbl.o
X	$(CC) $(CFLAGS) -o vcat lcat.o rf.o ftbl.o
X
Xdjinfo: djinfo.c
X	$(CC) $(CFLAGS) -o djinfo djinfo.c
X
Xrailmag: railmag.c
X	$(CC) $(CFLAGS) -o railmag railmag.c
X
Xlcat:	$(OBJ)
X	$(CC) $(CFLAGS) -o lcat $(OBJ)
X
END_OF_FILE
if test 471 -ne `wc -c <'makefile.unix'`; then
    echo shar: \"'makefile.unix'\" unpacked with wrong size!
fi
# end of 'makefile.unix'
fi
if test -f 'railmag.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'railmag.1'\"
else
echo shar: Extracting \"'railmag.1'\" \(1911 characters\)
sed "s/^X//" >'railmag.1' <<'END_OF_FILE'
X.TH RAILMAG L "28 August 1990"
X.SH NAME
Xrailmag \- download vfont file to HP DeskJet printer
X.SH SYNOPSIS
X.B railmag
X.BI [ " options " ]
X.BI filename
X
X.SH DESCRIPTION
X.B Railmag
Xconverts a vfont file to a format acceptable by the DeskJet
Xprinter and downloads it.  Since the vfont format is much simpler than
Xthe DeskJet format, many options are provided so that the user can overide
Xthe defaults.
X.LP
XThe DeskJet family has two printers, the older (DeskJet) can print fonts
Xthat have cells up to 100 dots high.  The newer DeskJet \s-2PLUS\s0, can
Xhave fonts up to 200 dots high.  If railmag is given a small font
Xit will automatically use the older format so that it can be used by both
Xprinters, while for lrger fonts it will use the DeskJet \s-2PLUS\s0 format.
X
X.SS Format Arguments
X.LP
XThe meanings of the format argument characters are:
X.TP 9
X.BI \-n " name"
Xis the name of the font as it will appear on the DeskJet font table.
X.TP 9
X.BI \-s " sname"
Xis the font selection name.  E.g. if you specify -s 12U 
Xyou'll be able to select the font by sending ESC(12U to the DeskJet.
X.TP 9
X.B "\-f"
Xspecify fixed width font (by default its assumed to be proportional).
X.TP 9
X.BI \-p " nn"
XOverride calculated pitch of file.  Forces fixed width font.
X.TP 9
X.BI \-o " nn"
Xwhere nn is the offset (i.e. the ASCII number of the
Xfirst character of the font.
X.TP 9
X.BI \-i " fid"
Xspecifies the fontid of the downloaded font.
X.TP 9
X.BI \-t " nn"
Xtypeface number.
X.B "\-T"
Xtemporary fonts (i.e. dissappear after reset)
X.TP 9
X.BI \-F " name"
X(\s-2MSDOS\s0 only) specify name of output file
X.TP 9
X.B "\-D"
X(\s-2MSDOS\s0 only) generate soft font file (i.e. no fontid)
X
X.SH "SEE ALSO"
X.BR vwidth (1),
X.BR vfontinfo (1)
X.SH BUGS
XMany parameters are arbitrarily set.  Could do with more `intelligent'
Xassumptions.
X.LP
XAssumes 127 character fonts \- avoid 256 character fonts, they ages to
Xdownload and take up a lot of space.
X 
END_OF_FILE
if test 1911 -ne `wc -c <'railmag.1'`; then
    echo shar: \"'railmag.1'\" unpacked with wrong size!
fi
# end of 'railmag.1'
fi
if test -f 'rf.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rf.c'\"
else
echo shar: Extracting \"'rf.c'\" \(11410 characters\)
sed "s/^X//" >'rf.c' <<'END_OF_FILE'
X#ifndef lint
Xstatic char ScrId[] = "@(#) rf.c:1.3";
X#endif
X
X/*****************************************************************
X
X    Copyright 1985. All Rights Reserved Chris Lewis
X
X    Module          : rf.c 1.3
X    Date submitted  : 86/01/30 09:19:57
X    Author          : Chris Lewis
X    Origin          : Permission to copy and further distribute is 
X		      freely given provided this copyright notice remains 
X		      intact and that this software is not sold for profit.
X    Description     : Description of the file
X    Modifications:
X
Xvp at cui.unige.ch 19.2.90:
X	modified to work with downloadble (soft) fonts.  The program
X	keeps a record of which fonts have been dent down so that only
X	new fonts are downloaded.
X
X	the size of the cache shoud be adjusted according to the
X	memory available on the printer and the size of the fonts
X	used.
X
X	BUGS:
X	      - may work with MSDOS/TURBOC but then again it may not
X	      - the names of the downloaded fonts should be kept in
X		a file so that subsequent programs know about them.
X	
X
X******************************************************************/
X
X#include <assert.h>
X#include <stdio.h>
X#include <fcntl.h>
X#ifdef UNIX
X#include <ctype.h>
X#include <vfont.h>
X#include <sys/file.h>
X#else
X#include <alloc.h>
X#include <mem.h>
X#include <vp/vfont.h>
X#endif
X#include "lcat.h"
X
Xextern FILE	*diagFile;
Xextern FILE	*outFile;
X#define	DEBUGPRINTF	if (diagFile) fprintf
X#define REGISTER	/**/
Xstatic char	*fontFamily;
Xstatic char	*djfontFamily;
X#define FONTS	"RIBS"
Xchar	fpos[] = FONTS;
X
Xextern char* ft_getname();
X
X#define STD_DPI 300
Xstatic int	dpi = STD_DPI;
Xstatic int	gl_dpi = STD_DPI;
X
X#define MAX_FONT	16
X#define SPEC_FONT	3
X#define IMG_SIZE	(unsigned int)(50000)
X
X/*
X * Construction of font identifier (fid):
X *	Since the fid is 15 bits wide, we can use it to encode information
X *	about the font that will be loaded in that position.
X *		+-+--------+------+-----------+
X *		|X| Family | type | pointsize |
X *		+-+--------+------+-----------+
X *	bits	|1|   6    |   3  |     6     |
X *		+-+--------+------+-----------+
X *	X:	is the sign bit and cannot be used.
X *	Family: is the font family and we use the same numbers as HP
X *		uses for the typeface field in the font control block
X *		(see page 5-10 of developers guide).
X *	Type:	0=normal, 1=italic, 2=bold, 3=special
X *	Pointsize:
X */
X#define FID_TIMES	5
X#define FID_HELVETICA	4
X#define FID_PRESTIGE	8
X#define FID_FAMO	9
X#define FID_FAMM	0x3f
X#define FID_TYPO	6
X#define FID_TYPM	0x7
X#define FID_PNTO	0
X#define FID_PNTM	0x3f
X
Xstatic long xpos = -1;
Xstatic long ypos = -1;
X
Xstruct ftbl {
X	int fnum;	/* number of downloaded font (R=0, I=1, B=2, S=3) */
X	int psize;	/* pointsize of font */
X	int count;	/* usage counter for LRU caching */
X	int used;	/* true if font appears on current page */
X	int fid;	/* only used by the MSDOS font cache */
X	int lpad_tbl_valid;		/* is left pad table valid? */
X	int lpad_tbl[NUM_DISPATCH];	/* left pad table */
X} fonttbl[MAX_FONT];
X
X/*
X * following vars hold data for selected font
X */
Xint cfnum, cpsize;
Xint *clpad_tbl;
Xstruct dispatch *cdsp;
Xu_char huge* imageTable;
Xint use_count=1;
X
X
X#define TRUE 1
X#define FALSE 0
Xstatic int new_page = TRUE;
Xstatic long y_base;	/* vertical position of baseline for current line */
Xstatic long max_up;	/* max height above baseline of glyphs on current line */
Xstatic long max_down;	/* max depth below baseline of glyphs on cur line */
Xstatic long min_x;	/* left horizontal offset of cur. line */
Xstatic long max_x;	/* rightmost position on current line */
X
Xvf_init(quality, ff, dj)
Xint quality;
Xchar* ff;
Xchar* dj;
X{
X	int i, j;
X	u_char *vp;
X
X	fontFamily = ff;
X#ifndef UNIX
X	djfontFamily = dj;
X#endif
X	new_page = TRUE;
X/* don't need that any more ...
X	if (quality == 2)
X		fprintf(outFile, "\033*r1Q");
X	else
X		fprintf(outFile, "\033*r0Q");
X*/
X	cfnum = -1;
X	for (i=0; i < MAX_FONT; i++)
X	{
X		int fid;
X
X		fonttbl[i].fnum = -1;
X		fonttbl[i].count = -1;
X		fonttbl[i].used = 0;
X		fonttbl[i].fid = -1;
X		fonttbl[i].lpad_tbl_valid = 0;
X
X		if ((fid = ft_getnextent()) > 0)
X			if (((fid >> FID_FAMO) & FID_FAMM) == FID_TIMES)
X			{
X				fonttbl[i].fnum = ((fid >> FID_TYPO) & FID_TYPM);
X				fonttbl[i].psize = ((fid >> FID_PNTO) & FID_PNTM);
X				fonttbl[i].fid = fid;
X				fonttbl[i].count = 0;
X				fonttbl[i].used = 0;
X			}
X	}
X}
X
X/*
X *	loadfont -- load vfont
X *
X */
Xloadfont(fnum, psize)
Xint fnum, psize;
X{
X	int i, c, sel;
X
X	if (cfnum == fnum && cpsize == psize)
X		return;
X	for (i=0; i < MAX_FONT; i++)
X	{
X		if (fonttbl[i].fnum == fnum && fonttbl[i].psize == psize)
X		{
X			cfnum = fnum;
X			cpsize = psize;
X			clpad_tbl = fonttbl[i].lpad_tbl;
X			if (!fonttbl[i].lpad_tbl_valid)
X			if (!fonttbl[i].lpad_tbl_valid)
X			{
X				get_lpad_tbl(fnum, psize, clpad_tbl);
X				fonttbl[i].lpad_tbl_valid = 1;
X			}
X			fonttbl[i].used = 1;
X			fonttbl[i].count = use_count++;
X			/* select it */
X#ifdef VERBOSE
X			printf("Using font %s (%d)\n",
X				ft_getname(fonttbl[i].fid), fonttbl[i].fid);
X#endif
X			fprintf(outFile, "\033(%dX", fonttbl[i].fid);
X			return;
X		}
X	}
X	/* not in downloaded set => load in place of LRU font */
X	c = use_count;
X	sel = -1;
X	for (i=0; i < MAX_FONT; i++)
X	{
X		if (fonttbl[i].used)
X			continue;
X		if (fonttbl[i].count < c)
X		{
X			c = fonttbl[i].count;
X			sel = i;
X		}
X	}
X	assert(sel != -1);
X
X	/* delete font from printer */
X	if (fonttbl[sel].fid != -1)
X	{
X		fprintf(outFile, "\033*c%D\033*c2D", fonttbl[sel].fid);
X		/* delete font from cache table, doesn't matter if its not there */
X		printf("deleting font %d\n", fonttbl[sel].fid);
X		ft_delent(fonttbl[sel].fid);
X	}
X	getfont(fnum, psize, sel);
X	/* recursively call loadfont to properly select the
X	 * font we've just loaded.  i.e. retry loadfont operation
X	 */
X	loadfont(fnum, psize);
X}
X
X/*
X * getfont -- 
X */
Xgetfont(fnum, psize, position)
Xint fnum, psize, position;
X{
X	static char fontBuf[BUFSIZ];
X#ifdef UNIX
X	static char sbuf[BUFSIZ];
X#endif
X	int fd;		/* file handle for vfont file */
X	int i;
X	int xx, c;
X	FILE* font_fd;
X	int fid;
X
X	assert(fnum <= (strlen(FONTS)-1));
X	fid = (FID_TIMES & FID_FAMM) << FID_FAMO;
X	fid |= ((fnum & FID_TYPM) << FID_TYPO);
X	fid |= ((psize & FID_PNTM) << FID_PNTO);
X#ifdef UNIX
X	sprintf(fontBuf, "%s%c.%d", fontFamily, tolower(fpos[fnum]), psize);
X	if (access(fontBuf, R_OK) < 0)
X	{
X		sprintf(fontBuf, "%s%c.%d", fontFamily, fpos[fnum], psize);
X		if (access(fontBuf, R_OK) < 0)
X		{
X			fprintf(stderr,
X				"lcat: Could not load font %s\n", fontBuf);
X			exit(1);
X		}
X	}
X	sprintf(sbuf, "./railmag -s %d0%c -i %d %s",
X		psize, fpos[fnum], fid, fontBuf);
X	/* fprintf(stderr, "calling %s\n", sbuf); */
X	if ((xx = system(sbuf)) != 0)
X	{
X		fprintf(stderr, "lcat: railmag reported an error (%x)\n", xx);
X		exit(1);
X	}
X#else
X	/* Unfortunately MSDOS systems cannot accomodate both
X	 * programs; instead we have to prepare the DeskJet files in
X	 * advance, so that here we only need to copy the data
X	 * to the printer.
X	 */
X	sprintf(fontBuf, "%s%c.%d", djfontFamily, fpos[fnum], psize);
X	if ((font_fd = fopen(fontBuf, "rb")) == NULL)
X	{
X		fprintf(stderr, "lcat: Could not load font %s\n", fontBuf);
X		exit(1);
X	}
X	/* specify font number */
X	fprintf(stderr, "Downloading font %s, fid %d\n", fontBuf, fid);
X	fprintf(outFile,"\033*c%dD", fid);
X	while ((c = getc(font_fd)) != EOF)
X		putc(c, outFile);
X	fclose(font_fd);
X	/* select font and make it permanent */
X	fprintf(outFile,"\033*c5F\033(%dX", fid);
X#endif
X
X	fonttbl[position].fnum = fnum;
X	fonttbl[position].psize = psize;
X	/* update font table */
X	fonttbl[position].fid = fid;
X	ft_addent(fid, fontBuf);
X	return;
X}
X
X/*
X *	 get_lpad_tbl -- get the left pad bytes for given font
X */
X
Xget_lpad_tbl(fnum, psize, tbl)
Xint fnum, psize;
Xint *tbl;
X{
X	static char fontBuf[BUFSIZ];
X	static struct dispatch dsptbl[NUM_DISPATCH];
X	static struct header vf_header;
X	int fd;		/* file handle for vfont file */
X	int i;
X	unsigned int len;
X
X#ifdef UNIX
X	sprintf(fontBuf, "%s%c.%d", fontFamily, tolower(fpos[fnum]), psize);
X	if ((fd = open(fontBuf, O_BINARY|O_RDONLY)) < 0)
X	{
X		sprintf(fontBuf, "%s%c.%d", fontFamily, fpos[fnum], psize);
X		if ((fd = open(fontBuf, O_BINARY|O_RDONLY)) < 0)
X		{
X			fprintf(stderr,
X				"lcat: Could not load font %s\n", fontBuf);
X			exit(1);
X		}
X	}
X#else
X	sprintf(fontBuf, "%s%c.%d", fontFamily, fpos[fnum], psize);
X
X	if ((fd = open(fontBuf, O_BINARY|O_RDONLY)) < 0)
X	{
X		fprintf(stderr, "lcat: Could not load font %s\n", fontBuf);
X		exit(1);
X	}
X#endif
X	fprintf(stderr, "\tLoaded description for %s\n", fontBuf);
X	len = sizeof(struct header);
X	if (read(fd, &vf_header, len) != len)
X	{
X		fprintf(stderr, "lcat: Bad font file header\n");
X		exit(1);
X	}
X	if (vf_header.magic != VFONT_MAGIC)
X	{
X		fprintf(stderr, "lcat: Bad font magic number\n");
X		exit(1);
X	}
X	len = NUM_DISPATCH*sizeof(struct dispatch);
X	if (read(fd, dsptbl, len) != len)
X	{
X		fprintf(stderr, "lcat: Could not load font dispatch table\n");
X		exit(1);
X	}
X	close(fd);
X
X	/* tranfer left pads to left pad table */
X	for (i=0; i < NUM_DISPATCH; i++)
X		tbl[i] = dsptbl[i].left;
X	return;
X}
X
X#define VF_FI	'\01'
X#define VF_FL	'\02'
X#define VF_FF	'\03'
X#define VF_FFL	'\012'
X#define VF_FFI	'\011'
X
Xflashrast(ch, ps, ftype)
Xint	ch, ps, ftype;
X{
X	int up, down, left, right;
X	char idx;
X	register int i,j,H,V;
X	u_char huge *bp;
X	u_char huge *vp;
X	int points;
X	long axpos;	/* adjusted xpos (by lpad) */
X	long x;
X
X	points = (gl_dpi == 150) ? ps>>1: ps;
X	if (ftype != cfnum || points != cpsize)
X		loadfont(ftype, points);
X	idx = (char)((ftype==SPEC_FONT) ? spectab[ch] : asctab[ch]);
X	if (clpad_tbl[idx] > 0)
X		axpos = xpos - (clpad_tbl[idx] * 2);
X	else
X		axpos = xpos;
X#ifdef USELIGATURES
X	/* Unfortunately the code for ligatures doesn't work!
X	 * Since we have to adjust the spacing of the characters
X	 * we cannot just send a string (e.g. ffi) to the printer,
X	 * the spacing will be all wrong.  Also if a font doesn't have
X	 * ligatures, then the clpad[idx] will be zero, we would have
X	 * to use the lpad of 'f'.  What I am trying to say that its too
X	 * much of a bother to implement when you can just ask troff
X	 * not to generate ligatures (.lg 0).
X	 */
X	/*
X	 * composite glyphs ff, fi, fl, ffi, ffl get special treatment
X	 * since they are not available on all fonts.
X	 */
X/*
Xfprintf(stderr, "ftype %d, ch %o\n", ftype, idx);
X*/
X	if (ftype != SPEC_FONT)
X		switch (idx) {
X		case VF_FFI:
X			fprintf(outFile, "\033&a%ldh%ldVffi", axpos, ypos);
X			return;
X		case VF_FI:
X			fprintf(outFile, "\033&a%ldh%ldVfi", axpos, ypos);
X			return;
X		case VF_FFL:
X			fprintf(outFile, "\033&a%ldh%ldVffl", axpos, ypos);
X			return;
X		case VF_FL:
X			fprintf(outFile, "\033&a%ldh%ldVfl", axpos, ypos);
X			return;
X		case VF_FF:
X			fprintf(outFile, "\033&a%ldh%ldVff", axpos, ypos);
X			return;
X		}
X#endif
X	/* if the character is in the unprintable region, escape it */
X	if (((idx & 0x7f) < 32) || ((idx & 0x7f) == 0x7f))
X		fprintf(outFile, "\033&a%ldh%ldV\033&p1X%c", axpos, ypos, idx);
X	else
X		fprintf(outFile, "\033&a%ldh%ldV%c", axpos, ypos, idx);
X}
X
Xvf_move(x, y)
Xlong x, y;
X{
X	xpos = x;
X	ypos = y;
X	if (new_page)
X		new_page = FALSE;
X}
X
Xvf_newpage()
X{
X	int i;
X
X	new_page = TRUE;
X	/* mark all fonts as unused */
X	for (i=0; i < MAX_FONT; i++)
X	{
X		fonttbl[i].used = 0;
X	}
X	/* eject page */
X	putc('\f', outFile);
X}
X
Xprt(s, vp, nb, nl)
Xchar *s;
Xu_char huge* vp;
Xint nb, nl;
X{
X	int i;
X
X	DEBUGPRINTF(diagFile, "%s= ", s);
X	for(i=0; i< nb; i++)
X		DEBUGPRINTF(diagFile, "%2x, ", *vp++);
X	if (nl)
X		DEBUGPRINTF(diagFile, "%2x\n", *vp);
X	else
X		DEBUGPRINTF(diagFile, "%2x\t", *vp);
X}
X
END_OF_FILE
if test 11410 -ne `wc -c <'rf.c'`; then
    echo shar: \"'rf.c'\" unpacked with wrong size!
fi
# end of 'rf.c'
fi
if test -f 'vcat.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'vcat.1'\"
else
echo shar: Extracting \"'vcat.1'\" \(3696 characters\)
sed "s/^X//" >'vcat.1' <<'END_OF_FILE'
X.TH VCAT L "28 August 1990"
X.SH NAME
Xvcat \- Cat Simulator for Hewlett-Packard DeskJet Printer
X.SH SYNOPSIS
X.B vcat
X.BI [ " \-f fontname " ]
X.BI [ " \-l " ]
X.BI [ " \-O output " ]
X.BI [ " file " ]
X
X.SH DESCRIPTION
X.B vcat
Xconverts
X.IR file ,
Xor its standard input, to a format suitable for downloading to
Xa Hewlett-Packard DeskJet.
XThis program supports downloadable fonts (soft fonts).  If the printer doesn't
Xhave the required font, the program calls railmag(1) which downloads the
Xfont to the printer.
X.LP
XNote that to use this program you
X.I must
Xhave at least one of the (optional) \s-2RAM\s0 cartridges for the DeskJet
Xor DeskJet \s-2PLUS\s0 printer.  Without this option the DeskJet printer
Xcannot accept soft fonts and you have to use the lcat (1) program (supplied
Xin this distribution) that is slower but works with the base configuration
Xof the DeskJet family.
X.LP
XThe program is designed to be used as a filter, but under \s-2MSDOS\s0
Xthis cannot be done (pipes are considered text streams and there is no way to
Xsuppress output processing; so tabs are converted to spaces etc.).
XFor this reason the
X.B \-O
Xflag is provided to specify an output file.
X.LP
XIf you use the default fonts (times) be sure to supply troff with
Xthe correct font width tables (see
X.BR vwidth (1)).
X.LP
XThe \s-2MSDOS\s0 version of
XVcat keeps (in a primitive sort of way) information about the fonts
Xthat have been sent to the printer in a file (font.tbl) in the font
Xdirectory.  Thus if you call vcat twice with the same input the second
Xfile will be printed much faster as it will not have to download any
Xfonts to the printer.
X.LP
XIf you switch the printer off you'll have to remove that file, a
Xutility (fcache.bat) may be used to flush the cache.  If the cache file
Xis missing vcat will complain but will work anyway assuming that the
Xcache is clear (at the end of the run vcat will recreate the cache
Xfile, so its ok to remove the cache file if you are not sure about its
Xcontents).
X.LP
XThe \s-2UNIX\s0 version keeps only a per job record.
X.LP
XUnder \s-2UNIX\s0 vcat creates the soft fonts from the vfonts on the fly so
Xyou don't need to keep two versions of the same files (no, you can't
Xerase the vfonts once you've created the DeskJet soft fonts, vcat needs
Xboth!).  The \s-2UNIX\s0 version keeps the font file in the vfont directory.
XUnder \s-2MSDOS\s0 (due to memory and processor speed limitations) its not
Xfeasable to perform the conversion on the fly, we thus have to generate
Xthe DeskJet soft fonts in advance and store them in a directory (called
Xdjfonts) under the vfont directory.  In this case the font.tbl is kept
Xin the djfonts directory.
X
X.SH EXAMPLES
X.LP
Xtroff -t -man /usr/man/man1/ls.1v | vcat > /dev/lp
X.SH "SEE ALSO"
X.BR lcat (l),
X.BR railmag (l),
X.BR djinfo (l)
X.SH BUGS
XThe cache management is rather primitive and this is the reason
Xwhy its only available under \s-2MSDOS\s0.
X.LP
XThe program assumes that the printer can hold up to 16 fonts.  This is
Xarbitrary (but experience with a DeskJet \s-2PLUS\s0 with one 256K byte
Xcartridge, shows that this is a good guess).  If you have a different
Xconfiguration you will have to use a different number and recompile.
XIdeally vcat should use the font size information in the header and
Xdetermine how much memory is available on the printer.
X.LP
XUnfortunately vcat does not support ligature expansion (ligatures are single
Xletters that represent letter combination like fi, ffi fl etc.).
XIf your font doesn't have ligatures and you want to use vcat, then be sure to
Xtell troff not to use ligatures (specify the command .lg 0 in the beginning
Xof your troff file).  Note that by default troff assumes that you do want
Xligatures generated.
X
END_OF_FILE
if test 3696 -ne `wc -c <'vcat.1'`; then
    echo shar: \"'vcat.1'\" unpacked with wrong size!
fi
# end of 'vcat.1'
fi
if test -f 'lcat.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lcat.1'\"
else
echo shar: Extracting \"'lcat.1'\" \(1596 characters\)
sed "s/^X//" >'lcat.1' <<'END_OF_FILE'
X.TH LCAT L "28 August 1990"
X.SH NAME
Xlcat \- Cat Simulator for Hewlett-Packard DeskJet Printer
X.SH SYNOPSIS
X.B lcat
X.BI [ " \-f fontname " ]
X.BI [ " \-l " ]
X.BI [ " \-O output " ]
X.BI [ " file " ]
X
X.SH DESCRIPTION
X.B lcat
Xconverts
X.IR file ,
Xor its standard input, to a format suitable for downloading to
Xa Hewlett-Packard DeskJet.
XThe program offers two output qualities: normal and draft.
XBy default the program selects the normal quality (300 dpi),
Xwhile the 
X.B \-l
Xflag selects the low quality mode (150 dpi).
X.LP
XThe program is designed to be used as a filter, but under \s-2MSDOS\s0
Xthis cannot be done (pipes are considered text streams and there is no way to
Xsuppress output processing; so tabs are converted to spaces etc.).
XFor this reason the
X.B \-O
Xflag is provided to specify an output file.
X.LP
XThe program uses a graphics compression algorithm unique to the DeskJet
Xfamily, so it cannot be used with the LaserJet series (but by specifying
Xthe -\s-2DLASERJET\s0 compile-time option it can be made to produce uncompressed
Xoutput that can be used on both printers).
X.LP
XIf you use the default fonts (times) be sure to supply troff with
Xthe correct font width tables (see
X.BR vwidth (1)).
X.SH EXAMPLES
X.LP
Xtroff -t -man /usr/man/man1/ls.1v | lcat -l > /dev/lp
X.SH "SEE ALSO"
X.BR vcat (l)
X.SH BUGS
X.LP
XVery slow in the normal mode, while the draft mode 
Xhas very poor quality.
X.LP
XDue to differences between the DeskJet resolution and the vfont resolution
X(DeskJet is 150 and 300 dpi, while the vfonts are 200 dpi), the program
Xconverts the requested pointsize to a more suitable one.
END_OF_FILE
if test 1596 -ne `wc -c <'lcat.1'`; then
    echo shar: \"'lcat.1'\" unpacked with wrong size!
fi
chmod +x 'lcat.1'
# end of 'lcat.1'
fi
echo shar: End of archive 2 \(of 3\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0



More information about the Comp.sources.misc mailing list