Troff->HP Laserjet filter - newfonts.c

sources-request at panda.UUCP sources-request at panda.UUCP
Sat Feb 1 08:34:14 AEST 1986


Mod.sources:  Volume 3, Issue 100
Submitted by: linus!mnetor!clewis (Chris Lewis)


OOPS!  I somehow forgot to ship one of the source files for my
Troff->HP Laserjet filter.  Here it is:
[sorry about that]

#!/bin/sh
echo 'Start of pack.out, part 01 of 01:'
echo 'x - newfonts.c'
sed 's/^X//' > newfonts.c << '/'
X/*****************************************************************
X
X    Copyright 1985. All Rights Reserved Chris Lewis
X
X    Module          : newfonts.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
X******************************************************************/
X
X#ifndef lint
Xstatic char SrcId[] = "@(#) newfonts.c:1.3";
X#endif
X#include <stdio.h>
X#include "../fonts/mkfonts/vfont.h"
X
Xextern FILE	*diagFile;
X#define	DEBUGPRINTF	if (diagFile) debugprintf
Xextern	char	*fontLib;
X
Xstatic int	dpi = 75;
X
Xstatic struct header header;
Xstatic struct dispatch D[256];
Xstatic unsigned char imageTable[BUFSIZ*10];
X
X/*	"s" is font name, point is desired point size, if (flag), use
X	bigger fonts if possible	*/
Xloadfont(s, point, quality)
Xchar	*s;
Xint	point; 
Xint	quality; {
X	static char oldfont[BUFSIZ], buf[BUFSIZ], fontBuf[BUFSIZ];
X	FILE   *f;
X	register int i;
X	sprintf(buf, "%s.%d", s, point);
X	if (strcmp(oldfont, buf) == 0)
X		return(dpi);
X	strcpy(oldfont, buf);
X	if (s[0] != '/') {
X		strcpy(buf, fontLib);
X		strcat(buf, s);
X	}
X	if (quality > 1) {
X		i = point * 4;
X		dpi = 300;
X		do {
X			sprintf(fontBuf, "%s.%d", buf, i);
X			DEBUGPRINTF("Trying for font %s\n", fontBuf);
X			if (access(fontBuf, 04) == 0)
X				goto useit;
X			i >>= 1;
X			dpi /= 2;
X		} while (dpi >= 75);
X		dpi = 0;
X		return(0);
X	} else {
X		sprintf(fontBuf, "%s.%d", buf, point);
X		dpi = 75;
X	}
X
Xuseit:
X
X	if (!(f = fopen(fontBuf, "r"))) {
X		fprintf(stderr, "lcat: Could not load font %s, using native\n",
X			fontBuf);
X		dpi = 0;
X		return(0);
X	}
X	DEBUGPRINTF("Loaded font %s (dpi: %d)\n", fontBuf, dpi);
X	if (fread(&header, sizeof(header), 1, f) != 1) {
X		fprintf(stderr, "lcat: Bad font file header\n");
X		exit(1);
X	}
X	if (header.magic != 0436) {
X		fprintf(stderr, "lcat: Bad font magic number\n");
X		exit(1);
X	}
X	if (fread(D, sizeof(struct dispatch), 256, f) != 256) {
X		fprintf(stderr, "lcat: Could not load font dispatch table\n");
X		exit(1);
X	}
X	if (fread(imageTable, 1, header.size, f) != header.size) {
X		fprintf(stderr, "lcat: Error reading image table\n");
X		exit(1);
X	}
X	return(dpi);
X}
X
X#define	UNASS	0
X
Xstatic unsigned char flashtovfnt[108] = {
X	/*   1  */	'h',	/*h*/
X	/*   2  */	't',	/*t*/
X	/*   3  */	'n',	/*n*/
X	/*   4  */	'm',	/*m*/
X	/*   5  */	'l',	/*l*/
X	/*   6  */	'i',	/*i*/
X	/*   7  */	'z',	/*z*/
X	/*   8  */	's',	/*s*/
X	/*   9  */	'd',	/*d*/
X	/*  10  */	'b',	/*b*/
X	/*  11  */	'x',	/*x*/
X	/*  12  */	'f',	/*f*/
X	/*  13  */	'j',	/*j*/
X	/*  14  */	'u',	/*u*/
X	/*  15  */	'k',	/*k*/
X	/*  16  */	UNASS,	/*unassigned*/
X	/*  17  */	'p',	/*p*/
X	/*  18  */	UNASS,	/*3/4 em*/
X	/*  19  */	';',	/*;*/
X	/*  20  */	UNASS,	/*unassigned*/
X	/*  21  */	'a',	/*a*/
X	/*  22  */	'_',	/*horizontal rule*/
X	/*  23  */	'c',	/*c*/
X	/*  24  */	'`',	/*` open*/
X	/*  25  */	'e',	/*e*/
X	/*  26  */	'\'',	/*' close*/
X	/*  27  */	'o',	/*o*/
X	/*  28  */	UNASS,	/*1/4*/
X	/*  29  */	'r',	/*r*/
X	/*  30  */	UNASS,	/*1/2*/
X	/*  31  */	'v',	/*v*/
X	/*  32  */	'-',	/*- hyphen*/
X	/*  33  */	'w',	/*w*/
X	/*  34  */	'q',	/*q*/
X	/*  35  */	'/',	/*/*/
X	/*  36  */	'.',	/*.*/
X	/*  37  */	'g',	/*g*/
X	/*  38  */	UNASS,	/*3/4*/
X	/*  39  */	',',	/*,*/
X	/*  40  */	'&',	/*&*/
X	/*  41  */	'y',	/*y*/
X	/*  42  */	UNASS,	/*unassigned*/
X	/*  43  */	'%',	/*%*/
X	/*  44  */	UNASS,	/*unassigned*/
X	/*  45  */	'Q',	/*Q*/
X	/*  46  */	'T',	/*T*/
X	/*  47  */	'O',	/*O*/
X	/*  48  */	'H',	/*H*/
X	/*  49  */	'N',	/*N*/
X	/*  50  */	'M',	/*M*/
X	/*  51  */	'L',	/*L*/
X	/*  52  */	'R',	/*R*/
X	/*  53  */	'G',	/*G*/
X	/*  54  */	'I',	/*I*/
X	/*  55  */	'P',	/*P*/
X	/*  56  */	'C',	/*C*/
X	/*  57  */	'V',	/*V*/
X	/*  58  */	'E',	/*E*/
X	/*  59  */	'Z',	/*Z*/
X	/*  60  */	'D',	/*D*/
X	/*  61  */	'B',	/*B*/
X	/*  62  */	'S',	/*S*/
X	/*  63  */	'Y',	/*Y*/
X	/* from here on are actually code 1-45, upper half of font */
X	/*  64  */	'F',	/*F*/
X	/*  65  */	'X',	/*X*/
X	/*  66  */	'A',	/*A*/
X	/*  67  */	'W',	/*W*/
X	/*  68  */	'J',	/*J*/
X	/*  69  */	'U',	/*U*/
X	/*  70  */	'K',	/*K*/
X	/*  71  */	'0',	/*0*/
X	/*  72  */	'1',	/*1*/
X	/*  73  */	'2',	/*2*/
X	/*  74  */	'3',	/*3*/
X	/*  75  */	'4',	/*4*/
X	/*  76  */	'5',	/*5*/
X	/*  77  */	'6',	/*6*/
X	/*  78  */	'7',	/*7*/
X	/*  79  */	'8',	/*8*/
X	/*  80  */	'9',	/*9*/
X	/*  81  */	'*',	/***/
X	/*  82  */	'-',	/*minus*/
X	/*  83  */	UNASS,	/*fi*/
X	/*  84  */	UNASS,	/*fl*/
X	/*  85  */	UNASS,	/*ff*/
X	/*  86  */	0xa2,	/*cent sign*/
X	/*  87  */	UNASS,	/*ffl*/
X	/*  88  */	UNASS,	/*ffi*/
X	/*  89  */	'(',	/*(*/
X	/*  90  */	')',	/*)*/
X	/*  91  */	'[',	/*[*/
X	/*  92  */	']',	/*]*/
X	/*  93  */	UNASS,	/*degree*/
X	/*  94  */	UNASS,	/*dagger*/
X	/*  95  */	'=',	/*=*/
X	/*  96  */	0xa8,	/*registered*/
X	/*  97  */	':',	/*:*/
X	/*  98  */	'+',	/*+*/
X	/*  99  */	UNASS,	/*unassigned*/
X	/* 100  */	'!',	/*!*/
X	/* 101  */	0xd7,	/*bullet*/
X	/* 102  */	'?',	/*?*/
X	/* 103  */	UNASS,	/*foot mark*/
X	/* 104  */	'|',	/*|*/
X	/* 105  */	UNASS,	/*unassigned*/
X	/* 106  */	0xa9,	/*copyright*/
X	/* 107  */	UNASS,	/*square*/
X	/* 108  */	'$'	/*$*/
X};
X
Xflashrast(ch, points, ftype)
Xint	ch, points, ftype; {
X	register int idx = flashtovfnt[ch];
X	register int i,j,H,V;
X	register unsigned char *bp;
X	V = D[idx].up + D[idx].down;
X	H = (D[idx].left + D[idx].right + 7) / 8;
X	bp = &imageTable[D[idx].addr];
X	DEBUGPRINTF("ch=%d,idx=%d,V=%d,H=%d\n", ch, idx, V, H);
X	printf("\033&a-%dV", (D[idx].up * 720) / dpi);
X	printf("\033*t%dR", dpi);
X	for (i = 0; i < V; i++) {
X		printf("\033*r1A");
X		printf("\033*b%dW", H);
X		for (j = 0; j < H; j++)
X			putchar(*bp++);
X	}
X	printf("\033*rB");
X}
/
echo 'Part 01 of pack.out complete.'
exit



More information about the Mod.sources mailing list