File: rastfont.c

package info (click to toggle)
dvi2ps 3.0a1-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,392 kB
  • ctags: 1,750
  • sloc: ansic: 11,699; sh: 277; makefile: 235
file content (137 lines) | stat: -rw-r--r-- 3,142 bytes parent folder | download | duplicates (2)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include	"defs.h"
#include	"global.h"
#include	"rastfont.h"

struct rastaccessinfo raccinfo;

rast_mag(fe, acca, t)
struct font_entry *fe;
struct accarg *acca;
int t;
{
    fe->finfo = (struct finfo *)&raccinfo;
    switch (acca->acc_mode) {
    case ACC_EXACT:
    case ACC_GEN:
	acca->pv_mag = ROUND(acca->actmagfact*resolution*t);
	raccinfo.corrfact = 1;
	break;
    case ACC_SUBST:
	if (ROUND(acca->actmagfact*resolution*t) != acca->reqmag)
	    return FALSE;
	acca->pv_mag = acca->submag;
	raccinfo.corrfact = (float)acca->reqmag/(float)acca->submag;
	break;
    case ACC_MAGSTEP:
	acca->pv_mag = ROUND(acca->stepmagfact*resolution*t);
	raccinfo.corrfact = acca->rawmagfact/acca->stepmagfact;
	break;
    }
}

#ifdef DEBUG
rast_debug_report(fe, acca, ok)
struct font_entry *fe;
struct accarg *acca;
BOOLEAN ok;
{
    if (Debuguser) {
	if (acca->acc_mode == ACC_EXACT || acca->acc_mode == ACC_GEN)
	    (void)fprintf(stderr, "trying to access %s\n", fe->name);
	else if (ok)
	    (void)fprintf(stderr, "trying to access(%d) %s\n",
			  acca->acc_mode, fe->name);
    }
}
#endif

check_id(name, id)
char	*name;
int	id;
{
    FILE *tfp;

    if ((tfp = BINARYOPEN(name)) == NULL)
	Fatal("FNT file %s could not be opened", name);
    if (getuint(tfp, 4) != id) {
	(void)fclose(tfp);
	return (FALSE);
    }
    (void)fseek(tfp, -4L, 2);
    if (getuint(tfp, 4) != id) {
	(void)fclose(tfp);
	return (FALSE);
    }
    (void)fclose(tfp);
    return (TRUE);
}

init_rast_fontinfo(fe)
register struct font_entry *fe;
{
    register int i;
    struct rastinitfontinfo *k;
    int	rast_markchar();

    fe->fnt_markchar = rast_markchar;
    k = (struct rastinitfontinfo *)
	alloc_check(malloc((unsigned)sizeof(struct rastinitfontinfo)+
			   MAXMARKCHAR*sizeof(Boolean)),
		    "rastinitfontinfo");
    for (i = 0; i <= MAXMARKCHAR; i++)
	k->mark[i] = FALSE;
    k->maxc = 0;
    k->corrfact = rastaccinfo(fe)->corrfact;
    rastinifinfo(fe) = k;
}

rast_markchar(c)
int c;
{
    if (c > MAXMARKCHAR) {
	Warning("char %d in %s ignored", c, curfontent->name);
	return;
    }
    rastinifinfo(curfontent)->mark[c] = TRUE;
    if (c > rastinifinfo(curfontent)->maxc)
	rastinifinfo(curfontent)->maxc = c;
}

struct rastfntinfo *
alloc_rastfinfo(nchars, init, rii)
int nchars, init;
struct rastinitfontinfo *rii;
{
    register struct rastfntinfo *rfi;
    register struct rastchar_entry *ce;	/* temporary char_entry pointer  */
    register int i;

    rfi = (struct rastfntinfo *)
	  alloc_check(malloc((unsigned)sizeof(struct rastfntinfo)+
			     (nchars-1)*sizeof(struct rastchar_entry)),
		      "rastfont info");
    if (init)
	for (i = 0; i < nchars; i++) {
	    ce = &(rfi->ch[i]);
	    ce->width = 0;
	    ce->height = 0;
	    ce->xoffset= 0;
	    ce->yoffset = 0;
	    ce->dev_font = DEV_NULLFONT;
	    /*ce->dev_char = NONCHAR;*/
	    ce->where.fileoffset = NONEXISTANT;
	    ce->tfmw = 0;
	}
    rfi->corrfact = rii->corrfact;
    return (rfi);
}

/* returs the current fontdict of raster font */
DEV_FONT
rast_fontdict(fe, c)
struct font_entry *fe;
int c;
{
    /* char range check omitted */
    return (rastfinfo(fe)->ch[c].dev_font);
}