summaryrefslogtreecommitdiff
path: root/dviware/dvi2pcl/cachefonts.c
blob: 930f3e73bc433285723bef62865dd84c7d1e7a9e (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
/* $Log:	cachefonts.c,v $
 * Revision 0.8  92/11/23  19:46:37  19:46:37  bt (Bo Thide')
 * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support
 * 
 * Revision 0.7  92/11/13  02:41:21  02:41:21  bt (Bo Thide')
 * More bug fixes and improvements. Support for PaintJet XL
 * 
 * Revision 0.6  92/11/10  21:47:37  21:47:37  bt (Bo Thide')
 * Bug fixes. Added -R option. Better font handling.
 * 
 * Revision 0.5  92/11/09  16:25:24  16:25:24  bt (Bo Thide')
 * Rewrite of dospecial.c. Extended \special support
 * 
 * Revision 0.4  92/11/08  02:45:39  02:45:39  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:45:32  12:45:32  bt (Bo Thide')
 * Fixed 8 bit (dc font) support.
 * 
 * Revision 0.2  92/08/23  17:28:54  17:28:54  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 is the procedure with caching font responsibility. On entrance to
 * this procedure, all the font usage information will have been loaded into
 * 'use_count' entries for each font. 'cachefonts' first checks which of the
 * fonts, used in the .dvi file, are permanently downloaded by calling
 * 'permfonts' which in turn returns the number of permanent downloaded fonts.
 * The remaining fonts are ordered in 'fontlist' in respect to their usage by
 * calling 'sortfonts' which in turn returns the number of remaining fonts
 * used in the document. These fonts will be downloaded in order of their
 * usage, those most heavily used comes first and with just the characters
 * used from these fonts. The downloading process continues so long the
 * printer's memory will allow more and the actual number of downloaded fonts
 * doesn't exceed MAXDOWN. If there are fonts which can't be download
 * anymore, their character's pixel patterns together with a small font and
 * character overhead are stored dynamically in memory. 
 */

#include <stdio.h>
#include "globals.h"
#include "pcl.h"

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

void cachefonts(bitfile, resfile, maxdown, device)
FILE	*bitfile;
FILE	*resfile;
short	maxdown;
short	device;
{
	int	f;
	int	n;
	int	actfontsdown;
	int	permfontsdown;
	int	fontnum;
	int	fontlist[MAXFONTS];

	/* Find all permanent downloaded fonts for dvifile in progress */
	actfontsdown = permfontsdown = permfonts(resfile);

	/* Sort additional fonts in respect to their usage */
	fontnum = sortfonts(fontlist);

	/* Decide for downloading or storage of fonts and chars and do it */
	for(n = 0 ; n < fontnum ; n++) {
		f = fontlist[n];
		font = fontptr[f];
		cbase = font->chr;
		loadpkfile();
		makepkdir();
		convtfm = (double)font->scaled_size/(double)FIX ;
		convpxl = (double)font->design_size/65536.0*
		  (double)font->dir_size/(double)SCALE;

#ifdef DEBUG
fprintf(stderr,"cachefonts: font->scaled_size = %d\n", font->scaled_size);
fprintf(stderr,"cachefonts: font->design_size = %d\n", font->design_size);
fprintf(stderr,"cachefonts: font->dir_size = %d\n", font->dir_size);
fprintf(stderr,"cachefonts: convtfm = %g, convpxl = %g\n", convtfm, convpxl);
#endif /* DEBUG */


		if(actfontsdown >= maxdown ||
		  (printer.mem-printermem_used) < MINPRINTERMEM)
			storefont(bitfile, f);
		else {
			printermem_used += downloadfont(bitfile,
			  permfontsdown, device);
			actfontsdown++;
		}

	}

	if(landscape)
		(void)fputs(PCL4_LANDSCAPE,bitfile);
	if(manualfeed)
		(void)fputs(PCL4_MANUAL_FEED,bitfile);
}