7 * Default version: treat as file name
11 static int defaultpipe(void);
13 static void scalesubfont(Subfont*, int);
16 _getsubfont(Display *d, char *name)
23 scale = parsefontscale(name, &fname);
24 if(strcmp(fname, "*default*") == 0)
27 fd = open(fname, OREAD);
28 if(fd < 0 && strncmp(fname, "/mnt/font/", 10) == 0)
29 fd = _fontpipe(fname+10);
31 fprint(2, "getsubfont: can't open %s: %r\n", fname);
35 * unlock display so i/o happens with display released, unless
36 * user is doing his own locking, in which case this could break things.
37 * _getsubfont is called only from string.c and stringwidth.c,
38 * which are known to be safe to have this done.
40 if(d && d->locking == 0)
42 f = readsubfont(d, name, fd, d && d->locking==0);
43 if(d && d->locking == 0)
46 fprint(2, "getsubfont: can't read %s: %r\n", name);
49 scalesubfont(f, scale);
58 // Used to assume that defontdata (<5k) fit in the
59 // pipe buffer, especially since p9pipe is actually
60 // a socket pair. But OpenBSD in particular saw hangs,
61 // so feed the pipe it the "right" way with a subprocess.
64 if((pid = fork()) < 0) {
71 write(p[1], defontdata, sizeof defontdata);
79 scalesubfont(Subfont *f, int scale)
85 int srcn, dstn, n, mask, v, pack;
94 srcn = bytesperline(r, f->bits->depth);
96 dstn = bytesperline(r2, f->bits->depth);
98 i = allocimage(f->bits->display, r2, f->bits->chan, 0, DBlack);
99 for(y=r.min.y; y < r.max.y; y++) {
100 n = unloadimage(f->bits, Rect(r.min.x, y, r.max.x, y+1), src, srcn);
103 sysfatal("scalesubfont: bad unload %R %R: %d < %d: %r", f->bits->r, Rect(r.min.x, y, r.max.x, y+1), n, srcn);
105 memset(dst, 0, dstn+1);
106 pack = 8 / f->bits->depth;
107 mask = (1<<f->bits->depth) - 1;
108 for(x=0; x<Dx(r); x++) {
109 v = ((src[x/pack] << ((x%pack)*f->bits->depth)) >> (8 - f->bits->depth)) & mask;
110 for(j=0; j<scale; j++) {
112 dst[x2/pack] |= v << (8 - f->bits->depth) >> ((x2%pack)*f->bits->depth);
116 sysfatal("overflow dst");
117 for(j=0; j<scale; j++)
118 loadimage(i, Rect(r2.min.x, y*scale+j, r2.max.x, y*scale+j+1), dst, dstn);
125 for(j=0; j<f->n; j++) {
126 f->info[j].x *= scale;
127 f->info[j].top *= scale;
128 f->info[j].bottom *= scale;
129 f->info[j].left *= scale;
130 f->info[j].width *= scale;