summaryrefslogtreecommitdiff
path: root/dviware/dvi2pcl/makepkdir.c
blob: fd0eec0214f14d6abb5d8302cac83cee64a1c217 (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
110
111
112
113
114
115
116
117
118
119
120
/* $Log:	makepkdir.c,v $
 * Revision 0.8  92/11/23  19:46:50  19:46:50  bt (Bo Thide')
 * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support
 * 
 * Revision 0.7  92/11/13  02:41:34  02:41:34  bt (Bo Thide')
 * More bug fixes and improvements. Support for PaintJet XL
 * 
 * Revision 0.6  92/11/10  21:47:50  21:47:50  bt (Bo Thide')
 * Bug fixes. Added -R option. Better font handling.
 * 
 * Revision 0.5  92/11/09  16:25:38  16:25:38  bt (Bo Thide')
 * Rewrite of dospecial.c. Extended \special support
 * 
 * Revision 0.4  92/11/08  02:45:54  02:45:54  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:20  12:43:20  bt (Bo Thide')
 * Fixed 8 bit (dc font) support.
 * 
 * Revision 0.2  92/08/23  17:28:58  17:28:58  bt (Bo Thide')
 * Source cleaned up.  Changed certain function calls.  Removed globals.
 * 
 * Revision 0.1  92/08/22  23:58:48  23:58:48  bt (Bo Thide')
 * First Release.
 *  */

/*
 * The coding scheme for the different characters in .pk files in general are
 * not stored in ascending order of the ascii value of the character. Access
 * to an individual character would need a lot of searching within the
 * pk buffer. So it is wise, to make a directory for all of the characters
 * in the .pk font which holds a pointer to the flag byte for each of the
 * characters when the pkfont is loaded the first time. These pointers are
 * relative to 'pkbase' and stored into '(cbase + c)->pk_char' of the
 * corresponding 'font'.
 */

#include <stdio.h>
#include "globals.h"
#include "macros.h"
#include "pk.h"
 
static char rcsid[] = "$Header: makepkdir.c,v 0.8 92/11/23 19:46:50 bt Exp $";

makepkdir()
{
	int		flag, i;
	byte		*p, *pc;
	int		format;
	long		ds, hppp, vppp, pkchksum;
	unsigned	cc, pl;

	for(i=0 ; i<256 ; i++)
		(cbase + i)->pk_char = 0;
	p = pkbase + *(pkbase + 2) + 3;
	ds = getpuquad(p);
	pkchksum = getpuquad(p);
#ifdef DEBUG2
	fprintf(stderr,"makepkdir: p-pkbase=%d, ds=%d, pkchksum=%d\n", p-pkbase, ds, pkchksum);
#endif /* DEBUG2 */
	if(font->checksum != pkchksum)
		fprintf(stderr,"makepkdir: Checksum mismatch between\n%s and the .dvi file\n", pkname);
	hppp = getpuquad(p);
	vppp = getpuquad(p);		/* points now to first pk charcter */

	font->height = (double)ds/(double)vppp;
#ifdef DEBUG2
	fprintf(stderr,"makepkdir: ds = %d, hppp = %d, vppp = %d, font->height = %g\n", ds, hppp, vppp, font->height);
#endif /* DEBUG2 */

	while((flag = getpubyte(p)) != PK_POST) { 
		if(flag < PK_CMD) { 
			pc = p - 1;
			format = flag & FMASK;
			if(format < 4) { 
				pl = getpubyte(p);
				cc = getpubyte(p);
				p += (format*256 + pl);
			}
			else if(format < 7) { 
				pl = getpupair(p);
				cc = getpubyte(p);
				p += ((format-4)*65536L + pl);
			}
			else { 
				pl = getpuquad(p);
				cc = getpuquad(p);
				p += pl;
			}
			if(cc < 256) (cbase + cc)->pk_char =  pc - pkbase;
		}
		else { 
			switch(flag) { 
			case PK_XXX1:
				pl = getpubyte(p);
				break;
			case PK_XXX2:
				pl = getpupair(p);
				break;
			case PK_XXX3:
				pl = getputrio(p);
				break;
			case PK_XXX4:
				pl = getpuquad(p);
				break;
			case PK_YYY:
				pl = 4;
				break;
			case PK_PRE:
				fprintf(stderr,"PK_PRE command in the .pk font file %s\n", pkname);
				exit(-1);
				break;
			default:
				pl = 0;
				break;
			}
			p += pl;
		}
	}
}