summaryrefslogtreecommitdiff
path: root/dviware/dvi2pcl/definefont.c
blob: b06d4a4239ccf7413416d26fa27b619e6d44fc79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* $Log:	definefont.c,v $
 * Revision 0.8  92/11/23  19:46:38  19:46:38  bt (Bo Thide')
 * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support
 * 
 * Revision 0.7  92/11/13  02:41:22  02:41:22  bt (Bo Thide')
 * More bug fixes and improvements. Support for PaintJet XL
 * 
 * Revision 0.6  92/11/10  21:47:38  21:47:38  bt (Bo Thide')
 * Bug fixes. Added -R option. Better font handling.
 * 
 * Revision 0.5  92/11/09  16:25:25  16:25:25  bt (Bo Thide')
 * Rewrite of dospecial.c. Extended \special support
 * 
 * Revision 0.4  92/11/08  02:45:40  02:45:40  bt (Bo Thide')
 * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's.
 * 
 * Revision 0.3  92/08/24  12:43:18  12:43:18  bt (Bo Thide')
 * Fixed 8 bit (dc font) support.
 * 
 * Revision 0.2  92/08/23  17:28:55  17:28:55  bt (Bo Thide')
 * Source cleaned up.  Changed certain function calls.  Removed globals.
 * 
 * Revision 0.1  92/08/22  23:58:47  23:58:47  bt (Bo Thide')
 * First Release.
 *  */

/*
 * This subroutine does the necessary things when a 'FNT_DEF' command is
 * being processed.
 */

#include <stdio.h>
#include <stdlib.h>
#include "globals.h"
#include "macros.h"

static char rcsid[] = "$Header: definefont.c,v 0.8 92/11/23 19:46:38 bt Exp $";

void definefont(dvifile, f)
FILE	*dvifile;
int	f;
{
	static  int knownsize[] = {1,90,130,150,180,210,240,270,300,329,360,
				   394,432,473,518,568,622,681,746,818,896,981,
				   1075,1178,1290,1413,1548,1858,2035,2229,2442,
				   2675,10000};
	int	k;
	int	a,l;		/* Font definition parameters */
	fontfmt	*safefont;
	charfmt	*u;
	int	*known;
	int	idealmag;
	double	s;

	if(!inpostamble)
	{ 
		if(f >= MAXFONTS)
			valerror("Max number of allowed fonts is %3d\n",
			  MAXFONTS);
		if(fontptr[f] != 0)
			valerror("Font number %d already defined\n", f);
		safefont = font;
		font = (fontfmt *)malloc(sizeof(*font));
		fontptr[f] = font;
		font->checksum = getsquad(dvifile);
		font->scaled_size = getsquad(dvifile);
		font->design_size = getsquad(dvifile);
		a = (int)getubyte(dvifile);
		l = (int)getubyte(dvifile);
		if((nextnamesfree-names+a+l+2) > NAMESIZE)
			valerror("Capacity exceeded (name size=%d)\n",NAMESIZE);
		font->name = nextnamesfree - names;
		if(verbose)
			fprintf(stderr,"Font %d: ", f);

		for(k=0; k<a; k++)
			*nextnamesfree++ = getubyte(dvifile);
		*nextnamesfree++ = '\0';

		for(k=0; k<l; k++)
			*nextnamesfree++ = getubyte(dvifile);
		*nextnamesfree++ = '\0';

		u = font->chr;
		for(k=0; k<=255; k++) { 
			u->use_count = 0;
			u++;
		}

		font->space = font->design_size / 6;
		font->down  = -3;
		if(verbose)
			printfont();
		idealmag = round((double)font->scaled_size/(double)font->design_size*magnification*RESOLUTION*0.001);
		if((idealmag < 10) || (idealmag > 9999))
			valerror("Font dpi size %d unrealistic\n", idealmag);
		known = knownsize;
		while(*known < idealmag) known++;
		if(((double) *known/idealmag) > ((double)idealmag/(*(known-1))))
			known--;
		s = (double) *known/idealmag;
		if((s > 1.02) || (s < 0.98))
			fprintf(stderr,"Warning: Size %d does not exist; substituting %d.\n",
			    idealmag, *known);
		font->dir_size = *known;
		font = safefont;

	}
}