File: wlfont.c

package info (click to toggle)
dvi2ps 5.1j-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,428 kB
  • sloc: ansic: 15,077; sh: 10,353; makefile: 158
file content (210 lines) | stat: -rw-r--r-- 4,602 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * wadalab font (downlodable PostScript font)
 */
#include	"defs.h"
#include	"global.h"
#include	"bifont.h"
#ifdef KPATHSEA
#undef STREQ
#include	<kpathsea/config.h>
#include	<kpathsea/tex-file.h>
#endif

void
init_wl_fontinfo(fe)
struct font_entry *fe;
{
    int	jmm_markchar();
    void read_wl_fontinfo();

    biinifinfo(fe) = alloc_jbiinif(biaccinfo(fe)->bf);
    fe->fnt_markchar = jmm_markchar;
    fe->fnt_readfontinfo = read_wl_fontinfo;
}

static void
wlpave(path, proto, k)
char *path, *proto;
int k;
{
    char *p, *s, *t;
    char *pend;
    int len;
    char buf[32];

    for (p = path, s = proto, pend = path+PATHLEN-1; *s != '\0'; s++)
	if (*s == '%') {
	    switch (*++s) {
	    case 'K':
		(void)sprintf(t = buf, "%2x", k);
		break;
	    default:
		*(t = buf) = *s;  *(t+1) = '\0';
		break;
	    }
	    if (p + (len = strlen(t)) <= pend) {
		(void)strncpy(p, t, len);
		p += len;
	    } else
		Fatal("font path too long %s", proto);
	} else if (p < pend) {
	    *p++ = *s;
	} else
	    Fatal("font path too long %s", proto);
    *p = '\0';
}

struct wlfntinfo *
read_wl_finfo(fe, bii, jfmfi, settfmw)
struct font_entry *fe;
struct biinitfontinfo *bii;
struct jfmfntinfo *jfmfi;
BOOLEAN settfmw;
{
    struct wlfntinfo *wlfi;
    int nchars, i, k1, kk, c, k1end;
    BOOLEAN k1init;
    char k1wlfn[PATHLEN], *filename;
    FILE *k1fp;

    wlfi = (struct wlfntinfo *)
	alloc_check(malloc((unsigned)sizeof(struct wlfntinfo)+
			   bii->maxc*sizeof(struct wlchar_entry)),
		    "wlfont info");
    wlfi->wl_bf = bii->bf;
    for (nchars = 0, i = 0; i <= bii->maxc; i++) {
	wlfi->ch[i].dev_font = DEV_NULLFONT;
	if (bii->mark[i])
	    nchars++;
    }

    for (k1 = 0, kk = 0, k1end = 0; k1 < bii->maxc/94+1; k1++) {
	k1init = FALSE;
	k1end += 94;
	if (k1end > bii->maxc+1)
	    k1end = bii->maxc+1;
	for (kk = k1*94; kk < k1end; kk++) {
	    if (!(bii->mark[kk]))
		continue;
	    if (!k1init) {
		wlpave(k1wlfn, dev_fontpath(bii->bf), k1+0x21);
#ifdef KPATHSEA
		if ((filename = kpsearch_file(k1wlfn, fe->n,
					      kpse_type1_format)) == NULL) {
		    Warning("FreeType font file %s not found", k1wlfn);
		    read_null_fontinfo(fe);
		    return NULL;
		}
#else
		filename = k1wlfn;
#endif
#ifdef DEBUG
		if (Debuguser)
		    (void)fprintf(stderr, "wadalabfont open %s (for %s)\n",
				  filename, fe->n);
#endif
		if ((k1fp = BINARYOPEN(filename)) == NULL) {
		    Warning("chars 0x%2xXX in %s not found (open failed)",
			    k1+0x21, fe->n);
		    break;
		}
		k1init = TRUE;
	    }
	    c = idx94_to_std(kk);
	    if (settfmw)
		(wlfi->ch+kk)->tfmw = jfmfi->ch[getctype(c,jfmfi)].tfmw;
	    dev_wl_initfontdict(fe, wlfi, kk, c, nchars--, k1fp);
	}
	if (k1init)
	    (void)fclose(k1fp);
    }
    dev_wl_endfontdict();

    return wlfi;
}

void
read_wl_fontinfo(fe)
struct font_entry *fe;
{
    struct biinitfontinfo *bii;
    struct jfmfntinfo *jfmfi;
    void read_jfm_finfo();

    bii = biinifinfo(fe);
    jfmfi = NEW(struct jfmfntinfo, "jfmfont info");
    jfmfi->jfm_bf = bii->bf;
    jfmfinfo(fe) = jfmfi;	/* set only to use in read_jfm_finfo */
    read_jfm_finfo(fe);

    dev_wl_initfe(fe);
    dev_wl_begfontdict(fe);
    wlfinfo(fe) = read_wl_finfo(fe, bii, jfmfi, TRUE);

    free((char *)bii);
    free((char *)jfmfi->ctype);
    free((char *)jfmfi->ch);
    free((char *)jfmfi);
}

DEV_FONT
wl_fontdict(fe, c)
struct font_entry *fe;
int c;
{
    return wlfinfo(fe)->ch[jis_to_idx94(c)].dev_font;
}


/* jstfm
 */
void
init_jswl_fontinfo(fe)
struct font_entry *fe;
{
    struct jsubshare *jss;
    int	jsmm_markchar();
    void read_jswl_fontinfo();

    jss = jstfmfinfo(fe)->js_share;
    if (jss->jss_stat < JSS_INIT) {
	jss->jss_info = (struct jssinfo *)alloc_jbiinif(jss->jss_bf);
	jss->jss_stat = JSS_INIT;
    }
    jstfmfinfo(fe)->js_info = jss->jss_info;
    fe->fnt_markchar = jsmm_markchar;
    fe->fnt_readfontinfo = read_jswl_fontinfo;
}

void
read_jswl_fontinfo(fe)
struct font_entry *fe;
{
    struct biinitfontinfo *bii;
    struct jsubshare *jss;
    void read_jstfm_finfo();

    read_jstfm_finfo(fe);

    dev_jswl_initfe(fe);
    jss = jstfmfinfo(fe)->js_share;
    if (jss->jss_stat < JSS_READ) {
	bii = (struct biinitfontinfo *)jss->jss_info;
	dev_jswl_begfontdict(fe);
	jss->jss_info = (struct jssinfo *)
	    read_wl_finfo(fe, bii, NULL, FALSE);
	jss->jss_stat = JSS_READ;
	free((char *)bii);
    }
    jstfmfinfo(fe)->js_info = jss->jss_info;
}

DEV_FONT
jswl_fontdict(fe, c)
struct font_entry *fe;
int c;
{
    struct jstfmfntinfo *jsfi = jstfmfinfo(fe);

    return jswlfinfo(jsfi)->ch[jsub_to_idx94(jsfi->jsubfont,c)].dev_font;
}