File: vflfont.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 (256 lines) | stat: -rw-r--r-- 5,558 bytes parent folder | download | duplicates (7)
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
 * VFlib font (family of vector fonts)
 */
#include	"defs.h"
#include	"global.h"
#include	"bifont.h"

/* ratio of depth of char (1 = 1<<20) */
#define	DEPTHRATIO	165565

char *vfontcap = NULL;
BOOLEAN vfl_init = FALSE;

void getvfcap();
struct confop vfccop = {
    "vfontcap",
    getvfcap
};

void
getvfcap()
{
    char field_file[PATHLEN];
    char vfcap[PATHLEN];

    getfield(field_file);
    skipline();
    defexpand(vfcap, field_file);
    vfontcap = strsave(vfcap);
}

int depthratio = DEPTHRATIO;

void getvflbase();
struct confop vfbcop = {
    "vflbaseline",
    getvflbase
};

void
getvflbase()
{
    char field_number[PATHLEN];
    char ratio[PATHLEN];

    getfield(field_number);
    skipline();
    defexpand(ratio, field_number);
    depthratio = atoi(ratio);
}

#ifdef VFLIB

void
init_vfl_fontinfo(fe)
struct font_entry *fe;
{
    int	jmm_markchar();
    void read_vfl_fontinfo();

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

vfl_initialize()
{
    if (!vfl_init) {
#ifdef DEBUG
	if (Debuguser)
	    (void)fprintf(stderr, "VFlib initializing with %s\n", vfontcap);
#endif
	if (VF_Init(vfontcap) < 0)
	    Fatal("VFlib cannot be initialized");
	vfl_init = TRUE;
    }
}

struct vflfntinfo *
read_vfl_finfo(fe, bii, tfmw, settfmw)
struct font_entry *fe;
struct biinitfontinfo *bii;
int tfmw;
BOOLEAN settfmw;
{
    struct vflfntinfo *vflfi;
    char *vfln;
    BOOLEAN raster;
    int fid;
    int width, depth, height, bwid, size;
    int xoff, nwidth, ndepth, nheight;
    char *pixel, *npixel;
    long *outline;
    int i, c;
    extern int hconv, vconv;
    long *VF_GetOutline();

    vflfi = (struct vflfntinfo *)
	alloc_check(malloc((unsigned)sizeof(struct vflfntinfo)+
			   bii->maxc*sizeof(struct vflchar_entry)),
		    "vflfont info");
    vflfi->vfl_bf = bii->bf;

    for (i = 0; i <= bii->maxc; i++)
	vflfi->ch[i].dev_font = DEV_NULLFONT;
    vfln = dev_fontpath(vflfi->vfl_bf);
    raster = dev_mf_kind(vflfi->vfl_bf) == MF_KIND_VFLIB;
#ifdef DEBUG
    if (Debuguser)
	(void)fprintf(stderr, "VFlib openfont %s (for %s, %s)\n", vfln, fe->n,
		      raster ? "raster" : "outline");
#endif
    if ((fid = VF_OpenFont1(vfln)) < 0) {
	Warning("VFlib font %s cannot be opened", vfln);
	return vflfi;
    }

    width = pixround(tfmw, hconv);
    depth = pixround(scale(tfmw,depthratio), vconv);
    height = pixround(tfmw, vconv);
    bwid = (width+7)>>3;
    size = height*bwid;
    if (raster) {
	if ((pixel = malloc(size)) == NULL)
	    Fatal("Unable to allocate memory for VFlib char\n");
	for (i = 0; i <= bii->maxc; i++) {
	    if (!(bii->mark[i]))
		continue;
	    if (settfmw)
		(vflfi->ch+i)->tfmw = tfmw;
	    memset(pixel, 0, size);
	    c = idx94_to_std(i);
	    VF_GetBitmap1(c, fid, width, height, bwid, 0, pixel);
	    trim_bitmap(width, bwid, height, 0, depth, pixel,
			&nwidth, &nheight, &xoff, &ndepth, &npixel);
	    dev_jft_initfontdict(fe, vflfi, i, c, tfmw, 
				 nwidth, nheight, xoff, ndepth, npixel);
	}
	free(pixel);
    } else {
	dev_vflo_begfontdict();
	for (i = 0; i <= bii->maxc; i++) {
	    if (!(bii->mark[i]))
		continue;
	    if (settfmw)
		(vflfi->ch+i)->tfmw = tfmw;
	    c = idx94_to_std(i);
	    outline = VF_GetOutline(c, fid);
	    dev_vflo_initfontdict(fe, vflfi, i, c, tfmw,
				  width, height, depth, outline);
	    VF_FreeOutline(outline, fid);
	}
    }

    VF_CloseFont(fid);
    return vflfi;
}

void
read_vfl_fontinfo(fe)
struct font_entry *fe;
{
    struct biinitfontinfo *bii;
    struct jfmfntinfo *jfmfi;
    void read_jfm_finfo();
    int tfmw;

    vfl_initialize();

    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_jft_initfe(fe);
    tfmw = dev_jft_begfontdict(fe);
    vflfinfo(fe) = read_vfl_finfo(fe, bii, tfmw, TRUE);

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


/* jstfm
 */
void
init_jsvfl_fontinfo(fe)
struct font_entry *fe;
{
    struct jsubshare *jss;
    int	jsmm_markchar();
    void read_jsvfl_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_jsvfl_fontinfo;
}

void
read_jsvfl_fontinfo(fe)
struct font_entry *fe;
{
    struct biinitfontinfo *bii;
    struct jsubshare *jss;
    struct jstfmfntinfo *jstfmfi;
    void read_jstfm_finfo();
    int tfmw;

    vfl_initialize();

    read_jstfm_finfo(fe);

    dev_jsft_initfe(fe);
    jss = jstfmfinfo(fe)->js_share;
    if (jss->jss_stat < JSS_READ) {
	bii = (struct biinitfontinfo *)jss->jss_info;
	jstfmfi = jstfmfinfo(fe);
	tfmw = dev_jsft_begfontdict(fe);
	jss->jss_info = (struct jssinfo *)
	    read_vfl_finfo(fe, bii, tfmw, FALSE);
	jss->jss_stat = JSS_READ;
	free((char *)bii);
    }
    jstfmfinfo(fe)->js_info = jss->jss_info;
}

#else

void
init_vfl_fontinfo(fe)
struct font_entry *fe;
{
    int null_markchar();
    void read_null_fontinfo();

    Warning("This %s is not compiled with VFlib option.\nFont %s is ignored",
	    G_progname, fe->n);
    fe->fnt_markchar = null_markchar;
    fe->fnt_readfontinfo = read_null_fontinfo;
}

void
init_jsvfl_fontinfo(fe)
struct font_entry *fe;
{
    init_vfl_fontinfo(fe);
}
#endif